org.tizen.web.common_2.0.0.201311011708

16:50:35.239 INFO  jd.cli.Main - Decompiling org.tizen.web.common_2.0.0.201311011708.jar
package org.tizen.web.common;

import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;

class ChromeLauncher$ProfileUtil$1
  implements IWorkbenchListener
{
  public boolean preShutdown(IWorkbench workbench, boolean forced)
  {
    ChromeLauncher.ProfileUtil.createBackupLastProfile();
    ChromeLauncher.ProfileUtil.removeProfileListAll();
    return true;
  }
  
  public void postShutdown(IWorkbench workbench) {}
}

/* Location:
 * Qualified Name:     org.tizen.web.common.ChromeLauncher.ProfileUtil.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;
import org.eclipse.ui.PlatformUI;
import org.tizen.common.AppIdGenerator;
import org.tizen.common.util.CollectionUtil;
import org.tizen.common.util.FileUtil;
import org.tizen.common.util.FilenameUtil;
import org.tizen.common.util.OSChecker;
import org.tizen.common.util.log.Logger;

public class ChromeLauncher$ProfileUtil
{
  public static ArrayList<String> profileList = new ArrayList();
  public static final String PROFILE_BASE_NAME = ".CustomProfile";
  public static final String PROFILE_BACKUP_NAME = "Default";
  
  public static boolean isEnableProfile(String profile)
  {
    boolean bEnable = false;
    if (!FilenameUtil.isVaildName(profile)) {
      return false;
    }
    if (!FileUtil.isExist(profile)) {
      return true;
    }
    return bEnable;
  }
  
  public static boolean isFirstRun()
  {
    if (profileList.size() < 1) {
      return true;
    }
    return false;
  }
  
  public static void removeProfile(String profile)
  {
    File file = new File(profile);
    if (file.isDirectory())
    {
      File[] arrayOfFile;
      int j = (arrayOfFile = file.listFiles()).length;
      for (int i = 0; i < j; i++)
      {
        File f = arrayOfFile[i];
        removeProfile(f.getAbsolutePath());
      }
    }
    file.delete();
  }
  
  public static void removeProfileAll()
  {
    Iterator<String> iter = profileList.iterator();
    while (iter.hasNext()) {
      removeProfile((String)iter.next());
    }
  }
  
  public static void addProfileList(String profile)
  {
    if (profileList.contains(profile)) {
      return;
    }
    profileList.add(profile);
  }
  
  public static void removeProfileList(String profile)
  {
    if (!profileList.contains(profile)) {
      return;
    }
    removeProfile(profile);
    profileList.remove(profile);
  }
  
  public static void removeProfileListAll()
  {
    removeProfileAll();
    profileList.removeAll(profileList);
  }
  
  public static String getBaseProfileDirectory()
  {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    
    File workspaceDir = workspace.getRoot().getLocation().toFile();
    File profileDir = new File(workspaceDir, ".CustomProfile");
    if (!FileUtil.isExist(profileDir.getAbsolutePath())) {
      FileUtil.createDirectory(profileDir);
    }
    return profileDir.getAbsolutePath();
  }
  
  public static void copyBackupProfile(String dest)
  {
    File destfile = new File(dest);
    if (!destfile.isDirectory()) {
      dest = destfile.getParent();
    }
    if (!"Default".equals(FilenameUtil.getFilename(dest))) {
      dest = FilenameUtil.addTailingPath(dest, "Default");
    }
    String backupProfileDir = FilenameUtil.addTailingPath(getBaseProfileDirectory(), "Default");
    try
    {
      FileUtil.copyRecursively(backupProfileDir, dest, true);
    }
    catch (IOException e)
    {
      Logger.log(e);
    }
  }
  
  public static void crearteBackupProfile(String ori)
  {
    File orifile = new File(ori);
    if (!orifile.isDirectory()) {
      ori = orifile.getParent();
    }
    if (!"Default".equals(FilenameUtil.getFilename(ori))) {
      ori = FilenameUtil.addTailingPath(ori, "Default");
    }
    String backupProfileDir = FilenameUtil.addTailingPath(getBaseProfileDirectory(), "Default");
    try
    {
      FileUtil.copyRecursively(ori, backupProfileDir, true);
    }
    catch (IOException e)
    {
      Logger.log(e);
    }
  }
  
  public static void createBackupLastProfile()
  {
    if (OSChecker.isMAC())
    {
      String profile = (String)CollectionUtil.pickupLast(profileList);
      crearteBackupProfile(profile);
    }
  }
  
  public static String createProfile()
  {
    File profileDir = new File(getBaseProfileDirectory());
    if (isFirstRun())
    {
      File[] arrayOfFile;
      int j = (arrayOfFile = profileDir.listFiles()).length;
      for (int i = 0; i < j; i++)
      {
        File file = arrayOfFile[i];
        if (!"Default".equals(file.getName())) {
          removeProfile(file.getAbsolutePath());
        }
      }
      PlatformUI.getWorkbench().addWorkbenchListener(new IWorkbenchListener()
      {
        public boolean preShutdown(IWorkbench workbench, boolean forced)
        {
          ChromeLauncher.ProfileUtil.createBackupLastProfile();
          ChromeLauncher.ProfileUtil.removeProfileListAll();
          return true;
        }
        
        public void postShutdown(IWorkbench workbench) {}
      });
    }
    String randomValue = AppIdGenerator.getInstance().create();
    String profile = FilenameUtil.addTailingPath(profileDir.getAbsolutePath(), randomValue);
    FileUtil.createDirectory(profile);
    
    copyBackupProfile(profile);
    addProfileList(profile);
    
    return profile;
  }
  
  public static void backupLastProfile() {}
}

/* Location:
 * Qualified Name:     org.tizen.web.common.ChromeLauncher.ProfileUtil
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

public enum ChromeLauncher$TYPE
{
  APP,  URL;
}

/* Location:
 * Qualified Name:     org.tizen.web.common.ChromeLauncher.TYPE
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.tizen.common.AppIdGenerator;
import org.tizen.common.util.CollectionUtil;
import org.tizen.common.util.FileUtil;
import org.tizen.common.util.FilenameUtil;
import org.tizen.common.util.OSChecker;
import org.tizen.common.util.StringUtil;
import org.tizen.common.util.log.Logger;

public class ChromeLauncher
{
  public static final String CHROME_PARAM_APP = "--app=";
  public static final String CHROME_PARAM_USERDATADIR = "--user-data-dir=";
  public static ArrayList<Process> procList = new ArrayList();
  
  public static class ProfileUtil
  {
    public static ArrayList<String> profileList = new ArrayList();
    public static final String PROFILE_BASE_NAME = ".CustomProfile";
    public static final String PROFILE_BACKUP_NAME = "Default";
    
    public static boolean isEnableProfile(String profile)
    {
      boolean bEnable = false;
      if (!FilenameUtil.isVaildName(profile)) {
        return false;
      }
      if (!FileUtil.isExist(profile)) {
        return true;
      }
      return bEnable;
    }
    
    public static boolean isFirstRun()
    {
      if (profileList.size() < 1) {
        return true;
      }
      return false;
    }
    
    public static void removeProfile(String profile)
    {
      File file = new File(profile);
      if (file.isDirectory())
      {
        File[] arrayOfFile;
        int j = (arrayOfFile = file.listFiles()).length;
        for (int i = 0; i < j; i++)
        {
          File f = arrayOfFile[i];
          removeProfile(f.getAbsolutePath());
        }
      }
      file.delete();
    }
    
    public static void removeProfileAll()
    {
      Iterator<String> iter = profileList.iterator();
      while (iter.hasNext()) {
        removeProfile((String)iter.next());
      }
    }
    
    public static void addProfileList(String profile)
    {
      if (profileList.contains(profile)) {
        return;
      }
      profileList.add(profile);
    }
    
    public static void removeProfileList(String profile)
    {
      if (!profileList.contains(profile)) {
        return;
      }
      removeProfile(profile);
      profileList.remove(profile);
    }
    
    public static void removeProfileListAll()
    {
      removeProfileAll();
      profileList.removeAll(profileList);
    }
    
    public static String getBaseProfileDirectory()
    {
      IWorkspace workspace = ResourcesPlugin.getWorkspace();
      
      File workspaceDir = workspace.getRoot().getLocation().toFile();
      File profileDir = new File(workspaceDir, ".CustomProfile");
      if (!FileUtil.isExist(profileDir.getAbsolutePath())) {
        FileUtil.createDirectory(profileDir);
      }
      return profileDir.getAbsolutePath();
    }
    
    public static void copyBackupProfile(String dest)
    {
      File destfile = new File(dest);
      if (!destfile.isDirectory()) {
        dest = destfile.getParent();
      }
      if (!"Default".equals(FilenameUtil.getFilename(dest))) {
        dest = FilenameUtil.addTailingPath(dest, "Default");
      }
      String backupProfileDir = FilenameUtil.addTailingPath(getBaseProfileDirectory(), "Default");
      try
      {
        FileUtil.copyRecursively(backupProfileDir, dest, true);
      }
      catch (IOException e)
      {
        Logger.log(e);
      }
    }
    
    public static void crearteBackupProfile(String ori)
    {
      File orifile = new File(ori);
      if (!orifile.isDirectory()) {
        ori = orifile.getParent();
      }
      if (!"Default".equals(FilenameUtil.getFilename(ori))) {
        ori = FilenameUtil.addTailingPath(ori, "Default");
      }
      String backupProfileDir = FilenameUtil.addTailingPath(getBaseProfileDirectory(), "Default");
      try
      {
        FileUtil.copyRecursively(ori, backupProfileDir, true);
      }
      catch (IOException e)
      {
        Logger.log(e);
      }
    }
    
    public static void createBackupLastProfile()
    {
      if (OSChecker.isMAC())
      {
        String profile = (String)CollectionUtil.pickupLast(profileList);
        crearteBackupProfile(profile);
      }
    }
    
    public static String createProfile()
    {
      File profileDir = new File(getBaseProfileDirectory());
      if (isFirstRun())
      {
        File[] arrayOfFile;
        int j = (arrayOfFile = profileDir.listFiles()).length;
        for (int i = 0; i < j; i++)
        {
          File file = arrayOfFile[i];
          if (!"Default".equals(file.getName())) {
            removeProfile(file.getAbsolutePath());
          }
        }
        PlatformUI.getWorkbench().addWorkbenchListener(new IWorkbenchListener()
        {
          public boolean preShutdown(IWorkbench workbench, boolean forced)
          {
            ChromeLauncher.ProfileUtil.createBackupLastProfile();
            ChromeLauncher.ProfileUtil.removeProfileListAll();
            return true;
          }
          
          public void postShutdown(IWorkbench workbench) {}
        });
      }
      String randomValue = AppIdGenerator.getInstance().create();
      String profile = FilenameUtil.addTailingPath(profileDir.getAbsolutePath(), randomValue);
      FileUtil.createDirectory(profile);
      
      copyBackupProfile(profile);
      addProfileList(profile);
      
      return profile;
    }
    
    public static void backupLastProfile() {}
  }
  
  private List<String> options = new ArrayList();
  
  public static enum TYPE
  {
    APP,  URL;
  }
  
  protected String[] createCommandArgs(String url, TYPE type)
    throws FileNotFoundException
  {
    String chrome = WebCommonActivator.getChromeExceutePath();
    if (StringUtil.isEmpty(chrome)) {
      throw new FileNotFoundException(CommonMessages.CANNOT_FIND_CHROME);
    }
    List<String> commandArgs = new ArrayList();
    commandArgs.add(chrome);
    commandArgs.addAll(Arrays.asList(getOptions()));
    if (TYPE.APP.equals(type)) {
      commandArgs.add("--app=" + url);
    } else if (TYPE.URL.equals(type)) {
      commandArgs.add(url);
    }
    if (OSChecker.isMAC()) {
      commandArgs.add("--user-data-dir=" + ProfileUtil.createProfile());
    }
    return (String[])commandArgs.toArray(new String[commandArgs.size()]);
  }
  
  public IWorkbench getWorkbench()
  {
    return PlatformUI.getWorkbench();
  }
  
  public Shell getShell()
  {
    IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
    if (window == null)
    {
      IWorkbenchWindow[] windows = getWorkbench().getWorkbenchWindows();
      if (windows.length > 0) {
        return windows[0].getShell();
      }
    }
    else
    {
      return window.getShell();
    }
    return null;
  }
  
  public Process launch(String url, TYPE type)
    throws IOException
  {
    String[] cmd = createCommandArgs(url, type);
    Process proc = Runtime.getRuntime().exec(cmd);
    ProfileUtil.createBackupLastProfile();
    procList.add(proc);
    
    return proc;
  }
  
  public void setOptions(String... options)
  {
    this.options.clear();
    this.options.addAll(Arrays.asList(options));
  }
  
  public void addOption(String option)
  {
    if (!options.contains(option)) {
      options.add(option);
    }
  }
  
  public String[] getOptions()
  {
    return (String[])options.toArray(new String[options.size()]);
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.common.ChromeLauncher
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

import org.eclipse.osgi.util.NLS;

public class CommonMessages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.tizen.web.common.messages";
  public static String Dialog_browse;
  public static String Project_does_not_exist;
  public static String Part_creation_error;
  public static String IDEPathUtil_template_error;
  public static String TizenWebSettingPropertyPage_Description;
  public static String CANNOT_FIND_CHROME;
  public static String CANNOT_FIND_TARGET;
  
  static
  {
    NLS.initializeMessages("org.tizen.web.common.messages", CommonMessages.class);
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.common.CommonMessages
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.URIUtil;
import org.osgi.framework.Bundle;
import org.tizen.common.core.application.InstallPathConfig;
import org.tizen.common.util.log.Logger;

public class IDEPathUtil
{
  private static final String PROJECT_WIZARD_SYMBOLIC_NAME = "org.tizen.web.project.wizard";
  
  public static String getTemplateConfigPath()
    throws Exception
  {
    return 
    
      getUserTemplatePathByString().concat(File.separator).concat("tizen-template-config.xml");
  }
  
  public static IPath getUserTemplatePath()
  {
    String sdkPath = InstallPathConfig.getUserDataPath();
    IPath templatePath = new Path(sdkPath).append("ide")
      .append("user-templates").append("web");
    return templatePath;
  }
  
  public static String getUserTemplatePathByString()
  {
    return getUserTemplatePath().toOSString();
  }
  
  public static String getBuiltInTemplatePath()
  {
    return getBuiltInPath("org.tizen.web.project.wizard", 
      "templates");
  }
  
  public static String getBuiltInTemplateLibrariesPath()
  {
    return getBuiltInPath("org.tizen.web.project.wizard", 
      "templateLibraries");
  }
  
  public static String getBuiltInPath(String symbolicName, String entryPath)
  {
    URI sourceURI = null;
    try
    {
      URL sourceURL = FileLocator.toFileURL(
        Platform.getBundle(symbolicName).getEntry(entryPath));
      sourceURI = URIUtil.toURI(sourceURL);
    }
    catch (IOException e)
    {
      Logger.error(CommonMessages.IDEPathUtil_template_error, e);
    }
    catch (URISyntaxException e)
    {
      Logger.error(CommonMessages.IDEPathUtil_template_error, e);
    }
    return sourceURI == null ? null : sourceURI.getPath();
  }
  
  public static String getWebUIFWTemplateLibrariesPath()
  {
    String platformPath = InstallPathConfig.getPlatformVersionPath();
    IPath uiFWPath = new Path(platformPath).append("web-ui-fw");
    return uiFWPath.toOSString();
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.common.IDEPathUtil
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

public class JSONArray
{
  private ArrayList myArrayList;
  
  public JSONArray()
  {
    myArrayList = new ArrayList();
  }
  
  public JSONArray(JSONTokener x)
    throws JSONException
  {
    this();
    if (x.nextClean() != '[') {
      throw x.syntaxError("A JSONArray text must start with '['");
    }
    if (x.nextClean() != ']')
    {
      x.back();
      for (;;)
      {
        if (x.nextClean() == ',')
        {
          x.back();
          myArrayList.add(JSONObject.NULL);
        }
        else
        {
          x.back();
          myArrayList.add(x.nextValue());
        }
        switch (x.nextClean())
        {
        case ',': 
        case ';': 
          if (x.nextClean() == ']') {
            return;
          }
          x.back();
        }
      }
      return;
      
      throw x.syntaxError("Expected a ',' or ']'");
    }
  }
  
  public JSONArray(String source)
    throws JSONException
  {
    this(new JSONTokener(source));
  }
  
  public JSONArray(Collection collection)
  {
    myArrayList = new ArrayList();
    if (collection != null)
    {
      Iterator iter = collection.iterator();
      while (iter.hasNext()) {
        myArrayList.add(JSONObject.wrap(iter.next()));
      }
    }
  }
  
  public JSONArray(Object array)
    throws JSONException
  {
    this();
    if (array.getClass().isArray())
    {
      int length = Array.getLength(array);
      for (int i = 0; i < length; i++) {
        put(JSONObject.wrap(Array.get(array, i)));
      }
    }
    else
    {
      throw new JSONException(
        "JSONArray initial value should be a string or collection or array.");
    }
  }
  
  public Object get(int index)
    throws JSONException
  {
    Object object = opt(index);
    if (object == null) {
      throw new JSONException("JSONArray[" + index + "] not found.");
    }
    return object;
  }
  
  public boolean getBoolean(int index)
    throws JSONException
  {
    Object object = get(index);
    if ((object.equals(Boolean.FALSE)) || (
      ((object instanceof String)) && 
      (((String)object).equalsIgnoreCase("false")))) {
      return false;
    }
    if ((object.equals(Boolean.TRUE)) || (
      ((object instanceof String)) && 
      (((String)object).equalsIgnoreCase("true")))) {
      return true;
    }
    throw new JSONException("JSONArray[" + index + "] is not a boolean.");
  }
  
  public double getDouble(int index)
    throws JSONException
  {
    Object object = get(index);
    try
    {
      return (object instanceof Number) ? 
        ((Number)object).doubleValue() : 
        Double.parseDouble((String)object);
    }
    catch (Exception localException)
    {
      throw new JSONException("JSONArray[" + index + 
        "] is not a number.");
    }
  }
  
  public int getInt(int index)
    throws JSONException
  {
    Object object = get(index);
    try
    {
      return (object instanceof Number) ? 
        ((Number)object).intValue() : 
        Integer.parseInt((String)object);
    }
    catch (Exception localException)
    {
      throw new JSONException("JSONArray[" + index + 
        "] is not a number.");
    }
  }
  
  public JSONArray getJSONArray(int index)
    throws JSONException
  {
    Object object = get(index);
    if ((object instanceof JSONArray)) {
      return (JSONArray)object;
    }
    throw new JSONException("JSONArray[" + index + 
      "] is not a JSONArray.");
  }
  
  public JSONObject getJSONObject(int index)
    throws JSONException
  {
    Object object = get(index);
    if ((object instanceof JSONObject)) {
      return (JSONObject)object;
    }
    throw new JSONException("JSONArray[" + index + 
      "] is not a JSONObject.");
  }
  
  public long getLong(int index)
    throws JSONException
  {
    Object object = get(index);
    try
    {
      return (object instanceof Number) ? 
        ((Number)object).longValue() : 
        Long.parseLong((String)object);
    }
    catch (Exception localException)
    {
      throw new JSONException("JSONArray[" + index + 
        "] is not a number.");
    }
  }
  
  public String getString(int index)
    throws JSONException
  {
    Object object = get(index);
    if ((object instanceof String)) {
      return (String)object;
    }
    throw new JSONException("JSONArray[" + index + "] not a string.");
  }
  
  public boolean isNull(int index)
  {
    return JSONObject.NULL.equals(opt(index));
  }
  
  public String join(String separator)
    throws JSONException
  {
    int len = length();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < len; i++)
    {
      if (i > 0) {
        sb.append(separator);
      }
      sb.append(JSONObject.valueToString(myArrayList.get(i)));
    }
    return sb.toString();
  }
  
  public int length()
  {
    return myArrayList.size();
  }
  
  public Object opt(int index)
  {
    return (index < 0) || (index >= length()) ? 
      null : myArrayList.get(index);
  }
  
  public boolean optBoolean(int index)
  {
    return optBoolean(index, false);
  }
  
  public boolean optBoolean(int index, boolean defaultValue)
  {
    try
    {
      return getBoolean(index);
    }
    catch (Exception localException) {}
    return defaultValue;
  }
  
  public double optDouble(int index)
  {
    return optDouble(index, NaN.0D);
  }
  
  public double optDouble(int index, double defaultValue)
  {
    try
    {
      return getDouble(index);
    }
    catch (Exception localException) {}
    return defaultValue;
  }
  
  public int optInt(int index)
  {
    return optInt(index, 0);
  }
  
  public int optInt(int index, int defaultValue)
  {
    try
    {
      return getInt(index);
    }
    catch (Exception localException) {}
    return defaultValue;
  }
  
  public JSONArray optJSONArray(int index)
  {
    Object o = opt(index);
    return (o instanceof JSONArray) ? (JSONArray)o : null;
  }
  
  public JSONObject optJSONObject(int index)
  {
    Object o = opt(index);
    return (o instanceof JSONObject) ? (JSONObject)o : null;
  }
  
  public long optLong(int index)
  {
    return optLong(index, 0L);
  }
  
  public long optLong(int index, long defaultValue)
  {
    try
    {
      return getLong(index);
    }
    catch (Exception localException) {}
    return defaultValue;
  }
  
  public String optString(int index)
  {
    return optString(index, "");
  }
  
  public String optString(int index, String defaultValue)
  {
    Object object = opt(index);
    return JSONObject.NULL.equals(object) ? object.toString() : defaultValue;
  }
  
  public JSONArray put(boolean value)
  {
    put(value ? Boolean.TRUE : Boolean.FALSE);
    return this;
  }
  
  public JSONArray put(Collection value)
  {
    put(new JSONArray(value));
    return this;
  }
  
  public JSONArray put(double value)
    throws JSONException
  {
    Double d = new Double(value);
    JSONObject.testValidity(d);
    put(d);
    return this;
  }
  
  public JSONArray put(int value)
  {
    put(new Integer(value));
    return this;
  }
  
  public JSONArray put(long value)
  {
    put(new Long(value));
    return this;
  }
  
  public JSONArray put(Map value)
  {
    put(new JSONObject(value));
    return this;
  }
  
  public JSONArray put(Object value)
  {
    myArrayList.add(value);
    return this;
  }
  
  public JSONArray put(int index, boolean value)
    throws JSONException
  {
    put(index, value ? Boolean.TRUE : Boolean.FALSE);
    return this;
  }
  
  public JSONArray put(int index, Collection value)
    throws JSONException
  {
    put(index, new JSONArray(value));
    return this;
  }
  
  public JSONArray put(int index, double value)
    throws JSONException
  {
    put(index, new Double(value));
    return this;
  }
  
  public JSONArray put(int index, int value)
    throws JSONException
  {
    put(index, new Integer(value));
    return this;
  }
  
  public JSONArray put(int index, long value)
    throws JSONException
  {
    put(index, new Long(value));
    return this;
  }
  
  public JSONArray put(int index, Map value)
    throws JSONException
  {
    put(index, new JSONObject(value));
    return this;
  }
  
  public JSONArray put(int index, Object value)
    throws JSONException
  {
    JSONObject.testValidity(value);
    if (index < 0) {
      throw new JSONException("JSONArray[" + index + "] not found.");
    }
    if (index < length())
    {
      myArrayList.set(index, value);
    }
    else
    {
      while (index != length()) {
        put(JSONObject.NULL);
      }
      put(value);
    }
    return this;
  }
  
  public Object remove(int index)
  {
    Object o = opt(index);
    myArrayList.remove(index);
    return o;
  }
  
  public JSONObject toJSONObject(JSONArray names)
    throws JSONException
  {
    if ((names == null) || (names.length() == 0) || (length() == 0)) {
      return null;
    }
    JSONObject jo = new JSONObject();
    for (int i = 0; i < names.length(); i++) {
      jo.put(names.getString(i), opt(i));
    }
    return jo;
  }
  
  public String toString()
  {
    try
    {
      return '[' + join(",") + ']';
    }
    catch (Exception localException) {}
    return null;
  }
  
  public String toString(int indentFactor)
    throws JSONException
  {
    return toString(indentFactor, 0);
  }
  
  String toString(int indentFactor, int indent)
    throws JSONException
  {
    int len = length();
    if (len == 0) {
      return "[]";
    }
    StringBuffer sb = new StringBuffer("[");
    if (len == 1)
    {
      sb.append(JSONObject.valueToString(myArrayList.get(0), 
        indentFactor, indent));
    }
    else
    {
      int newindent = indent + indentFactor;
      sb.append('\n');
      for (int i = 0; i < len; i++)
      {
        if (i > 0) {
          sb.append(",\n");
        }
        for (int j = 0; j < newindent; j++) {
          sb.append(' ');
        }
        sb.append(JSONObject.valueToString(myArrayList.get(i), 
          indentFactor, newindent));
      }
      sb.append('\n');
      for (i = 0; i < indent; i++) {
        sb.append(' ');
      }
    }
    sb.append(']');
    return sb.toString();
  }
  
  public Writer write(Writer writer)
    throws JSONException
  {
    try
    {
      boolean b = false;
      int len = length();
      
      writer.write(91);
      for (int i = 0; i < len; i++)
      {
        if (b) {
          writer.write(44);
        }
        Object v = myArrayList.get(i);
        if ((v instanceof JSONObject)) {
          ((JSONObject)v).write(writer);
        } else if ((v instanceof JSONArray)) {
          ((JSONArray)v).write(writer);
        } else {
          writer.write(JSONObject.valueToString(v));
        }
        b = true;
      }
      writer.write(93);
      return writer;
    }
    catch (IOException e)
    {
      throw new JSONException(e);
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.common.JSONArray
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

public class JSONException
  extends Exception
{
  private static final long serialVersionUID = 0L;
  private Throwable cause;
  
  public JSONException(String message)
  {
    super(message);
  }
  
  public JSONException(Throwable cause)
  {
    super(cause.getMessage());
    this.cause = cause;
  }
  
  public Throwable getCause()
  {
    return cause;
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.common.JSONException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

final class JSONObject$Null
{
  protected final Object clone()
  {
    return this;
  }
  
  public boolean equals(Object object)
  {
    return (object == null) || (object == this);
  }
  
  public String toString()
  {
    return "null";
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.common.JSONObject.Null
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.common;

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ResourceBundle;
import java.util.Set;

public class JSONObject
{
  private Map map;
  
  private static final class Null
  {
    protected final Object clone()
    {
      return this;
    }
    
    public boolean equals(Object object)
    {
      return (object == null) || (object == this);
    }
    
    public String toString()
    {
      return "null";
    }
  }
  
  public static final Object NULL = new Null(null);
  
  public JSONObject()
  {
    map = new HashMap();
  }
  
  public JSONObject(JSONObject jo, String[] names)
  {
    this();
    for (int i = 0; i < names.length; i++) {
      try
      {
        putOnce(names[i], jo.opt(names[i]));
      }
      catch (Exception localException) {}
    }
  }
  
  public JSONObject(JSONTokener x)
    throws JSONException
  {
    this();
    if (x.nextClean() != '{') {
      throw x.syntaxError("A JSONObject text must begin with '{'");
    }
    for (;;)
    {
      char c = x.nextClean();
      switch (c)
      {
      case '\000': 
        throw x.syntaxError("A JSONObject text must end with '}'");
      case '}': 
        return;
      }
      x.back();
      String key = x.nextValue().toString();
      
      c = x.nextClean();
      if (c == '=')
      {
        if (x.next() != '>') {
          x.back();
        }
      }
      else if (c != ':') {
        throw x.syntaxError("Expected a ':' after a key");
      }
      putOnce(key, x.nextValue());
      switch (x.nextClean())
      {
      case ',': 
      case ';': 
        if (x.nextClean() == '}') {
          return;
        }
        x.back();
      }
    }
    return;
    
    throw x.syntaxError("Expected a ',' or '}'");
  }
  
  public JSONObject(Map map)
  {
    this.map = new HashMap();
    if (map != null)
    {
      Iterator i = map.entrySet().iterator();
      while (i.hasNext())
      {
        Map.Entry e = (Map.Entry)i.next();
        Object value = e.getValue();
        if (value != null) {
          this.map.put(e.getKey(), wrap(value));
        }
      }
    }
  }
  
  public JSONObject(Object bean)
  {
    this();
    populateMap(bean);
  }
  
  public JSONObject(Object object, String[] names)
  {
    this();
    Class c = object.getClass();
    for (int i = 0; i < names.length; i++)
    {
      String name = names[i];
      try
      {
        putOpt(name, c.getField(name).get(object));
      }
      catch (Exception localException) {}
    }
  }
  
  public JSONObject(String source)
    throws JSONException
  {
    this(new JSONTokener(source));
  }
  
  public JSONObject(String baseName, Locale locale)
    throws JSONException
  {
    this();
    ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, 
      Thread.currentThread().getContextClassLoader());
    
    Enumeration keys = bundle.getKeys();
    while (keys.hasMoreElements())
    {
      Object key = keys.nextElement();
      if ((key instanceof String))
      {
        String[] path = ((String)key).split("\\.");
        int last = path.length - 1;
        JSONObject target = this;
        for (int i = 0; i < last; i++)
        {
          String segment = path[i];
          JSONObject nextTarget = target.optJSONObject(segment);
          if (nextTarget == null)
          {
            nextTarget = new JSONObject();
            target.put(segment, nextTarget);
          }
          target = nextTarget;
        }
        target.put(path[last], bundle.getString((String)key));
      }
    }
  }
  
  public JSONObject accumulate(String key, Object value)
    throws JSONException
  {
    testValidity(value);
    Object object = opt(key);
    if (object == null) {
      put(key, (value instanceof JSONArray) ? 
        new JSONArray().put(value) : value);
    } else if ((object instanceof JSONArray)) {
      ((JSONArray)object).put(value);
    } else {
      put(key, new JSONArray().put(object).put(value));
    }
    return this;
  }
  
  public JSONObject append(String key, Object value)
    throws JSONException
  {
    testValidity(value);
    Object object = opt(key);
    if (object == null) {
      put(key, new JSONArray().put(value));
    } else if ((object instanceof JSONArray)) {
      put(key, ((JSONArray)object).put(value));
    } else {
      throw new JSONException("JSONObject[" + key + 
        "] is not a JSONArray.");
    }
    return this;
  }
  
  public static String doubleToString(double d)
  {
    if ((Double.isInfinite(d)) || (Double.isNaN(d))) {
      return "null";
    }
    String string = Double.toString(d);
    if ((string.indexOf('.') > 0) && (string.indexOf('e') < 0) && 
      (string.indexOf('E') < 0))
    {
      while (string.endsWith("0")) {
        string = string.substring(0, string.length() - 1);
      }
      if (string.endsWith(".")) {
        string = string.substring(0, string.length() - 1);
      }
    }
    return string;
  }
  
  public Object get(String key)
    throws JSONException
  {
    if (key == null) {
      throw new JSONException("Null key.");
    }
    Object object = opt(key);
    if (object == null) {
      throw new JSONException("JSONObject[" + quote(key) + 
        "] not found.");
    }
    return object;
  }
  
  public boolean getBoolean(String key)
    throws JSONException
  {
    Object object = get(key);
    if ((object.equals(Boolean.FALSE)) || (
      ((object instanceof String)) && 
      (((String)object).equalsIgnoreCase("false")))) {
      return false;
    }
    if ((object.equals(Boolean.TRUE)) || (
      ((object instanceof String)) && 
      (((String)object).equalsIgnoreCase("true")))) {
      return true;
    }
    throw new JSONException("JSONObject[" + quote(key) + 
      "] is not a Boolean.");
  }
  
  public double getDouble(String key)
    throws JSONException
  {
    Object object = get(key);
    try
    {
      return (object instanceof Number) ? 
        ((Number)object).doubleValue() : 
        Double.parseDouble((String)object);
    }
    catch (Exception localException)
    {
      throw new JSONException("JSONObject[" + quote(key) + 
        "] is not a number.");
    }
  }
  
  public int getInt(String key)
    throws JSONException
  {
    Object object = get(key);
    try
    {
      return (object instanceof Number) ? 
        ((Number)object).intValue() : 
        Integer.parseInt((String)object);
    }
    catch (Exception localException)
    {
      throw new JSONException("JSONObject[" + quote(key) + 
        "] is not an int.");
    }
  }
  
  public JSONArray getJSONArray(String key)
    throws JSONException
  {
    Object object = get(key);
    if ((object instanceof JSONArray)) {
      return (JSONArray)object;
    }
    throw new JSONException("JSONObject[" + quote(key) + 
      "] is not a JSONArray.");
  }
  
  public JSONObject getJSONObject(String key)
    throws JSONException
  {
    Object object = get(key);
    if ((object instanceof JSONObject)) {
      return (JSONObject)object;
    }
    throw new JSONException("JSONObject[" + quote(key) + 
      "] is not a JSONObject.");
  }
  
  public long getLong(String key)
    throws JSONException
  {
    Object object = get(key);
    try
    {
      return (object instanceof Number) ? 
        ((Number)object).longValue() : 
        Long.parseLong((String)object);
    }
    catch (Exception localException)
    {
      throw new JSONException("JSONObject[" + quote(key) + 
        "] is not a long.");
    }
  }
  
  public static String[] getNames(JSONObject jo)
  {
    int length = jo.length();
    if (length == 0) {
      return null;
    }
    Iterator iterator = jo.keys();
    String[] names = new String[length];
    int i = 0;
    while (iterator.hasNext())
    {
      names[i] = ((String)iterator.next());
      i++;
    }
    return names;
  }
  
  public static String[] getNames(Object object)
  {
    if (object == null) {
      return null;
    }
    Class klass = object.getClass();
    Field[] fields = klass.getFields();
    int length = fields.length;
    if (length == 0) {
      return null;
    }
    String[] names = new String[length];
    for (int i = 0; i < length; i++) {
      names[i] = fields[i].getName();
    }
    return names;
  }
  
  public String getString(String key)
    throws JSONException
  {
    Object object = get(key);
    if ((object instanceof String)) {
      return (String)object;
    }
    throw new JSONException("JSONObject[" + quote(key) + 
      "] not a string.");
  }
  
  public boolean has(String key)
  {
    return map.containsKey(key);
  }
  
  public JSONObject increment(String key)
    throws JSONException
  {
    Object value = opt(key);
    if (value == null) {
      put(key, 1);
    } else if ((value instanceof Integer)) {
      put(key, ((Integer)value).intValue() + 1);
    } else if ((value instanceof Long)) {
      put(key, ((Long)value).longValue() + 1L);
    } else if ((value instanceof Double)) {
      put(key, ((Double)value).doubleValue() + 1.0D);
    } else if ((value instanceof Float)) {
      put(key, ((Float)value).floatValue() + 1.0F);
    } else {
      throw new JSONException("Unable to increment [" + quote(key) + "].");
    }
    return this;
  }
  
  public boolean isNull(String key)
  {
    return NULL.equals(opt(key));
  }
  
  public Iterator keys()
  {
    return map.keySet().iterator();
  }
  
  public int length()
  {
    return map.size();
  }
  
  public JSONArray names()
  {
    JSONArray ja = new JSONArray();
    Iterator keys = keys();
    while (keys.hasNext()) {
      ja.put(keys.next());
    }
    return ja.length() == 0 ? null : ja;
  }
  
  public static String numberToString(Number number)
    throws JSONException
  {
    if (number == null) {
      throw new JSONException("Null pointer");
    }
    testValidity(number);
    
    String string = number.toString();
    if ((string.indexOf('.') > 0) && (string.indexOf('e') < 0) && 
      (string.indexOf('E') < 0))
    {
      while (string.endsWith("0")) {
        string = string.substring(0, string.length() - 1);
      }
      if (string.endsWith(".")) {
        string = string.substring(0, string.length() - 1);
      }
    }
    return string;
  }
  
  public Object opt(String key)
  {
    return key == null ? null 
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd