⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jad.java

📁 MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自JUnit框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.momeunit.ant.jad;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.Reader;import java.io.Writer;import java.util.Collection;import java.util.Enumeration;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Properties;import java.util.jar.Attributes;import java.util.jar.JarFile;import java.util.jar.Manifest;import java.util.regex.Matcher;import java.util.regex.Pattern;/** * Class that represents JAD descriptor of J2ME application. Contains methods * for accessing and modifying predefined and application attributes. *  * @author Sergio Morozov * @version 1.1.2 */public class JAD{  /**   * Name of <code>MIDlet-Name</code> attribute.   *    * @since 1.1   */  public static final String NAME = "MIDlet-Name";  /**   * Name of <code>MIDlet-Version</code> attribute.   *    * @since 1.1   */  public static final String VERSION = "MIDlet-Version";  /**   * Name of <code>MIDlet-Vendor</code> attribute.   *    * @since 1.1   */  public static final String VENDOR = "MIDlet-Vendor";  /**   * Name of <code>MIDlet-Icon</code> attribute.   *    * @since 1.1   */  public static final String ICON = "MIDlet-Icon";  /**   * Name of <code>MIDlet-Description</code> attribute.   *    * @since 1.1   */  public static final String DESCRIPTION = "MIDlet-Description";  /**   * Name of <code>MIDlet-Info-URL</code> attribute.   *    * @since 1.1   */  public static final String INFO_URL = "MIDlet-Info-URL";  /**   * Prefix of <code>MIDlet-&lt;n&gt;</code> attribute.   *    * @since 1.1   */  public static final String MIDLET_PREFIX = "MIDlet-";  /**   * Name of <code>MIDlet-Jar-URL</code> attribute.   *    * @since 1.1   */  public static final String JAR = "MIDlet-Jar-URL";  /**   * Name of <code>MIDlet-Jar-Size</code> attribute.   *    * @since 1.1   */  public static final String JAR_SIZE = "MIDlet-Jar-Size";  /**   * Name of <code>MIDlet-Data-Size</code> attribute.   *    * @since 1.1   */  public static final String DATA_SIZE = "MIDlet-Data-Size";  /**   * Name of <code>MicroEdition-Profile</code> attribute.   *    * @since 1.1   */  public static final String PROFILE = "MicroEdition-Profile";  /**   * Name of <code>MicroEdition-Configuration</code> attribute.   *    * @since 1.1   */  public static final String CONFIGURATION = "MicroEdition-Configuration";  /**   * Name of <code>MIDlet-Permissions</code> attribute.   *    * @since 1.1   */  public static final String PERMISSIONS = "MIDlet-Permissions";  /**   * Name of <code>MIDlet-Permissions-Opt</code> attribute.   *    * @since 1.1   */  public static final String PERMISSIONS_OPT = "MIDlet-Permissions-Opt";  /**   * Prefix of <code>MIDlet-Push-&lt;n&gt;</code> attribute.   *    * @since 1.1   */  public static final String PUSH_PREFIX = "MIDlet-Push-";  /**   * Name of <code>MIDlet-Install-Notify</code> attribute.   *    * @since 1.1   */  public static final String INSTALL_NOTIFY = "MIDlet-Install-Notify";  /**   * Name of <code>MIDlet-Delete-Notify</code> attribute.   *    * @since 1.1   */  public static final String DELETE_NOTIFY = "MIDlet-Delete-Notify";  /**   * Name of <code>MIDlet-Delete-Confirm</code> attribute.   *    * @since 1.1   */  public static final String DELETE_CONFIRM = "MIDlet-Delete-Confirm";  private Properties props = null;  private Map midlets = null;  private int maxMIDletNumber = 0;  private Map pushs = null;  private int maxPushNumber = 0;  /**   * Checks given name to be complied with attribute name requirements.   *    * @param name   *          string to check.   * @return the checked and trimmed string.   * @throws IllegalArgumentException   *           if specified name does not satisfy attribute name requirements.   * @since 1.1   */  public static String checkName(String name)  {    if (name == null || name.length() == 0) throw new IllegalArgumentException(        "Attribute name is empty.");    if (name != null) for (int i = name.length() - 1; i >= 0; i--)    {      char c = name.charAt(i);      if (c <= 0x1F || c == 0x7F) throw new IllegalArgumentException(          "control char (" + (short) c + " is not valid for attribute name");      char[] seps = "()<>@,;:'\"/[]?={} \t".toCharArray();      for (int j = seps.length - 1; j >= 0; j--)      {        if (seps[j] == c) throw new IllegalArgumentException(            "invalid character \"" + c + "\" in attribyte name: " + name);      }    }    return name.trim();  }  /**   * Checks given value to be complied with attribute value requirements.   *    * @param value   *          string to check.   * @return the checked and trimmed string.   * @throws IllegalArgumentException   *           if specified value does not satisfy attribute value requirements.   * @since 1.1   */  public static String checkValue(String value)  {    if (value == null) throw new NullPointerException("Attribute value.");    if (value != null) for (int i = value.length() - 1; i >= 0; i--)    {      char c = value.charAt(i);      if (c <= 0x1F || c == 0x7F) throw new IllegalArgumentException(          "control char is not valid for attribute value");    }    return value.trim();  }  /**   * Instantiates an empty JAD.   *    * @since 1.1   */  public JAD()  {    super();    this.props = new Properties();    this.midlets = new HashMap();    this.pushs = new HashMap();  }  /**   * Adds attributes from given JAD.   *    * @param jad   *          JAD attributes from which to add.   * @since 1.1   */  public void add(JAD jad)  {    this.props.putAll(jad.props);    for (int i = 1; i <= jad.maxMIDletNumber; i++)    {      MIDletInfo mi = (MIDletInfo) jad.getMIDlet(i);      if (mi != null) setMIDlet(i, mi);    }    for (int i = 1; i <= jad.maxPushNumber; i++)    {      PushInfo mi = (PushInfo) jad.getPush(i);      if (mi != null) setPush(i, mi);    }  }  /**   * Returns <code>MIDlet-Name</code> attribute.   *    * @return the value of <code>MIDlet-Name</code> attribute.   * @since 1.1   */  public String getName()  {    return this.props.getProperty(NAME);  }  /**   * Sets <code>MIDlet-Name</code> attribute value.   *    * @param suiteName   *          <code>MIDlet-Name</code> attribute value to set.   * @since 1.1   */  public void setName(String suiteName)  {    this.props.setProperty(NAME, checkValue(suiteName));  }  /**   * Returns <code>MIDlet-Vendor</code> attribute value.   *    * @return the <code>MIDlet-Vendor</code> attribute value.   * @since 1.1   */  public String getVendor()  {    return this.props.getProperty(VENDOR);  }  /**   * Sets <code>MIDlet-Vendor</code> attribute value.   *    * @param suiteVendor   *          <code>MIDlet-Vendor</code> attribute value to set.   * @since 1.1   */  public void setVendor(String suiteVendor)  {    this.props.setProperty(VENDOR, checkValue(suiteVendor));  }  /**   * Returns <code>MIDlet-Version</code> attribute value.   *    * @return the <code>MIDlet-Version</code> attribute value.   * @since 1.1   */  public String getVersion()  {    return this.props.getProperty(VERSION);  }  /**   * Sets <code>MIDlet-Version</code> attribute value.   *    * @param suiteVersion   *          <code>MIDlet-Version</code> attribute value to set.   * @since 1.1   */  public void setVersion(String suiteVersion)  {    this.props.setProperty(VERSION, checkValue(suiteVersion));  }  /**   * Returns <code>MIDlet-Info-URL</code> attribute value.   *    * @return the <code>MIDlet-Info-URL</code> attribute value.   * @since 1.1   */  public String getInfoUrl()  {    return this.props.getProperty(INFO_URL);  }  /**   * Sets <code>MIDlet-Info-URL</code> attribute value.   *    * @param url   *          <code>MIDlet-Info-URL</code> attribute value to set.   * @since 1.1   */  public void setInfoUrl(String url)  {    this.props.setProperty(INFO_URL, checkValue(url));  }  /**   * Returns <code>MIDlet-Icon</code> attribute value.   *    * @return the <code>MIDlet-Icon</code> attribute value.   * @since 1.1   */  public String getIcon()  {    return this.props.getProperty(ICON);  }  /**   * Sets <code>MIDlet-Icon</code> attribute value.   *    * @param icon   *          <code>MIDlet-Icon</code> attribute value to set.   * @since 1.1   */  public void setIcon(String icon)  {    this.props.setProperty(ICON, checkValue(icon));  }  /**   * Returns <code>MIDlet-Description</code> attribute value.   *    * @return the <code>MIDlet-Description</code> attribute value.   * @since 1.1   */  public String getDescription()  {    return this.props.getProperty(DESCRIPTION);  }  /**   * Sets <code>MIDlet-Description</code> attribute value.   *    * @param descrition   *          <code>MIDlet-Description</code> attribute value to set.   * @since 1.1   */  public void setDescription(String descrition)  {    this.props.setProperty(DESCRIPTION, checkValue(descrition));  }  /**   * Returns <code>MIDlet-Jar-URL</code> attribute value.   *    * @return the <code>MIDlet-Jar-URL</code> attribute value.   * @since 1.1   */  public String getJar()  {    return this.props.getProperty(JAR);  }  /**   * Sets <code>MIDlet-Jar-URL</code> attribute value.   *    * @param url   *          <code>MIDlet-Jar-URL</code> attribute value to set.   * @since 1.1   */  public void setJar(String url)  {    this.props.setProperty(JAR, checkValue(url));  }  /**   * Returns <code>MIDlet-Jar-Size</code> attribute value.   *    * @return the <code>MIDlet-Jar-Size</code> attribute value.   * @since 1.1   */  public String getJarSize()  {    return this.props.getProperty(JAR_SIZE);  }  /**   * Sets <code>MIDlet-Jar-Size</code> attribute value.   *    * @param size   *          <code>MIDlet-Jar-Size</code> attribute value to set.   * @since 1.1   */  public void setJarSize(String size)  {    this.props.setProperty(JAR_SIZE, checkValue(size));  }  /**   * Returns <code>MIDlet-Data-Size</code> attribute value.   *    * @return the <code>MIDlet-Data-Size</code> attribute value.   * @since 1.1   */  public String getDataSize()  {    return this.props.getProperty(DATA_SIZE);  }  /**   * Sets <code>MIDlet-Data-Size</code> attribute value.   *    * @param size   *          <code>MIDlet-Data-Size</code> attribute value to set.   * @since 1.1   */  public void setDataSize(String size)  {    this.props.setProperty(DATA_SIZE, checkValue(size));  }  /**   * Returns <code>MicroEdition-Profile</code> attribute value.   *    * @return the <code>MicroEdition-Profile</code> attribute value.   * @since 1.1   */  public String getProfile()  {    return this.props.getProperty(PROFILE);  }  /**   * Sets <code>MicroEdition-Profile</code> attribute value.   *    * @param version   *          <code>MicroEdition-Profile</code> attribute value to set.   * @since 1.1   */  public void setProfile(String version)  {    this.props.setProperty(PROFILE, checkValue(version));  }  /**   * Returns <code>MicroEdition-Configuration</code> attribute value.   *    * @return the <code>MicroEdition-Configuration</code> attribute value.   * @since 1.1   */  public String getConfiguration()  {    return this.props.getProperty(CONFIGURATION);  }  /**   * Sets <code>MicroEdition-Configuration</code> attribute value.   *    * @param version   *          <code>MicroEdition-Configuration</code> attribute value to set.   * @since 1.1   */  public void setConfiguration(String version)  {    this.props.setProperty(CONFIGURATION, checkValue(version));  }  /**   * Returns <code>MIDlet-Permissions</code> attribute value.   *    * @return the <code>MIDlet-Permissions</code> attribute value.   * @since 1.1   */  public String getPermissions()  {    return this.props.getProperty(PERMISSIONS);  }  /**   * Sets <code>MIDlet-Permissions</code> attribute value.   *    * @param permissions   *          <code>MIDlet-Permissions</code> attribute value to set.   * @since 1.1   */  public void setPermissions(String permissions)  {    this.props.setProperty(PERMISSIONS, checkValue(permissions));  }  /**   * Returns <code>MIDlet-Permissions-Opt</code> attribute value.   *    * @return the <code>MIDlet-Permissions-Opt</code> attribute value.   * @since 1.1   */  public String getOptionalPermissions()  {    return this.props.getProperty(PERMISSIONS_OPT);  }  /**   * Sets <code>MIDlet-Permissions-Opt</code> attribute value.   *    * @param permissions   *          <code>MIDlet-Permissions-Opt</code> attribute value to set.   * @since 1.1   */  public void setOptionalPermissions(String permissions)  {    this.props.setProperty(PERMISSIONS_OPT, checkValue(permissions));  }  /**   * Returns <code>MIDlet-Install-Notify</code> attribute value.   *    * @return the <code>MIDlet-Install-Notify</code> attribute value.   * @since 1.1   */  public String getInstallNotify()  {    return this.props.getProperty(INSTALL_NOTIFY);  }  /**   * Sets <code>MIDlet-Install-Notify</code> attribute value.   *    * @param prop   *          <code>MIDlet-Install-Notify</code> attribute value to set.   * @since 1.1   */  public void setInstallNotify(String prop)  {    this.props.setProperty(INSTALL_NOTIFY, checkValue(prop));  }  /**   * Returns <code>MIDlet-Delete-Notify</code> attribute value.   *    * @return the <code>MIDlet-Delete-Notify</code> attribute value.   * @since 1.1   */  public String getDeleteNotify()  {    return this.props.getProperty(DELETE_NOTIFY);  }  /**   * Sets <code>MIDlet-Delete-Notify</code> attribute value.   *    * @param prop   *          <code>MIDlet-Delete-Notify</code> attribute value to set.   * @since 1.1   */  public void setDeleteNotify(String prop)  {    this.props.setProperty(DELETE_NOTIFY, checkValue(prop));  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -