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

📄 dojadescriptorcreator.java

📁 doja中文简体中文与繁体中文转换例子(doja2.5开发环境)
💻 JAVA
字号:
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

//import org.apache.tools.ant.BuildException;

import de.enough.polish.Attribute;
import de.enough.polish.Device;
import de.enough.polish.Environment;
import de.enough.polish.descriptor.DescriptorCreator;
import de.enough.polish.util.FileUtil;

/**
 * <p>Creates the descriptor JAM file for DoJa devices.</p>
 *
 * <p>Copyright Enough Software 2005</p>
 * <pre>
 * history
 *        25-Oct-2005 - rob creation
 * </pre>
 * @author Robert Virkus, j2mepolish@enough.de
 */
public class DoJaDescriptorCreator extends DescriptorCreator  {

	/**
	 * Creates a new instance
	 */
	public DoJaDescriptorCreator() {
		super();
	}

	/**
	 * Creates a new descriptor file.
	 * 
	 * @param descriptorFile the file that should be created
	 * @param descriptorAttributes the attributes
	 * @param encoding the encoding, usually UTF-8
	 * @param device the target device
	 * @param locale the target locale
	 * @param env the evironment
	 * @throws IOException when the descriptor could not be saved
	 */
	public void createDescriptor(File descriptorFile, Attribute[] descriptorAttributes, String encoding, Device device, Locale locale, Environment env)
	throws IOException
	{
//		for (int i = 0; i < descriptorAttributes.length; i++) {
//			Attribute attribute = descriptorAttributes[i];
//			env.addVariable( attribute.getName(), attribute.getValue() );
//		}
		String jamName = descriptorFile.getName();
		jamName = jamName.substring( 0, jamName.length() - 1 ) + "m";
		File jamFile = new File( descriptorFile.getParent(), jamName );
		
		env.setVariable( "polish.jamPath", jamFile.getAbsolutePath() );
		
		ArrayList jamEntries = new ArrayList();
		String value = env.resolveVariable("MIDlet-Name");
		jamEntries.add( "AppName = " + value );
		value = env.resolveVariable("MIDlet-Version");
		jamEntries.add( "AppVer = " + value );
		value = env.resolveVariable("MIDlet-Jar-URL");
		jamEntries.add( "PackageURL = " + value );
		value = env.resolveVariable("MIDlet-Jar-Size");
		jamEntries.add( "AppSize = " + value );
		value = env.resolveVariable("polish.classes.iapplication");
		jamEntries.add( "AppClass = " + value );
		jamEntries.add( "LastModified = " + getCurrentDate() );
		addOptionalAttribute("ConfigurationVer", jamEntries, env );
		addOptionalAttribute("ProfileVer", jamEntries, env );
		addOptionalAttribute("SPsize", jamEntries, env );
		addOptionalAttribute("UseNetwork", jamEntries, env );
		addOptionalAttribute("TargetDevice", jamEntries, env );
		addOptionalAttribute("LaunchAt", jamEntries, env );
		addOptionalAttribute("AppTrace", jamEntries, env );
		addOptionalAttribute("GetUtn", jamEntries, env );
		
		try {
			System.out.println("creating JAM file [" + jamFile.getAbsolutePath() + "].");
			String[] lines = (String[]) jamEntries.toArray(  new String[ jamEntries.size() ] );
			FileUtil.writeTextFile(jamFile, lines, encoding );
		} catch (IOException e) {
			//throw new BuildException("Unable to create JAM file [" + jamFile.getAbsolutePath() +"] for device [" + device.getIdentifier() + "]: " + e.getMessage() );
		}
		
	}

	private void addOptionalAttribute(String name, ArrayList jamEntries, Environment env ) {
		String value = env.resolveVariable("doja." + name);
		if (value != null) {
			jamEntries.add( name + " = " + value );
		}		
	}

	private String getCurrentDate() {
		SimpleDateFormat format = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss",Locale.ENGLISH);
		return format.format( new Date() );
	}

}

⌨️ 快捷键说明

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