📄 metadata.java
字号:
}
signatureProps = sp;
}
private String encodePassword(String password)
{
if (password == null)
{
return("");
}
try
{
byte[] passwordBytes = password.getBytes("UTF8");
byte[] cryptBytes = new byte[passwordBytes.length];
RC4Engine crypter = new RC4Engine();
crypter.setKey(cryptoPass.getBytes("UTF8"));
crypter.processBytes(passwordBytes, 0, passwordBytes.length, cryptBytes, 0);
return(Base64EncDec.encode(cryptBytes));
}
catch(UnsupportedEncodingException e)
{
}
return("");
}
private String decodePassword(Element base, String subElementName)
{
Element subElement = XMLUtils.getFirstElementWithTagName(base, subElementName);
if (subElement == null)
{
return(null);
}
String encoded = XMLUtils.getElementText(subElement);
byte[] cryptBytes = Base64EncDec.decode(encoded);
if (cryptBytes == null)
{
return(null);
}
try
{
byte[] passwordBytes = new byte[cryptBytes.length];
RC4Engine crypter = new RC4Engine();
crypter.setKey(cryptoPass.getBytes("UTF8"));
crypter.processBytes(cryptBytes, 0, cryptBytes.length, passwordBytes, 0);
return(new String(passwordBytes, "UTF8"));
}
catch(UnsupportedEncodingException e)
{
}
return(null);
}
/**
* Attempt to save the metadata. This has the potential to fail.
* @throws CoreException
*/
public void saveMetaData()
throws CoreException
{
IFile storeFile = getStoreFile();
if (storeFile == null) {
EclipseMECorePlugin.log(IStatus.WARNING, "saveMetaData failed due to null store file");
} else {
if (storeFile.exists() && storeFile.isReadOnly()) {
// Attempt to clear the read-only flag via the IResource
// interface. This should invoke the team provider and
// do necessary checkouts.
ResourceAttributes attributes = storeFile.getResourceAttributes();
attributes.setReadOnly(false);
storeFile.setResourceAttributes(attributes);
}
saveMetaDataToFile(storeFile);
}
}
/**
* Save the metadata to the storage file. This file is expected to
* be non-null.
*
* @param storeFile
* @throws CoreException
*/
public void saveMetaDataToFile(IFile storeFile)
throws CoreException
{
try {
String pluginVersion = EclipseMECorePlugin.getPluginVersion();
Version newVersion = new Version(pluginVersion);
Element rootElement = XMLUtils.createRootElement(ELEM_ROOT_NAME, newVersion);
if (jadFile != null) {
rootElement.setAttribute(ATTR_JAD_FILE, jadFile);
}
if (device != null) {
Element deviceElement = XMLUtils.createChild(rootElement, ELEM_DEVICE);
deviceElement.setAttribute(ATTR_DEVICEGROUP, device.getGroupName());
deviceElement.setAttribute(ATTR_DEVICENAME, device.getName());
}
Element signRoot = XMLUtils.createChild(rootElement, ELEM_SIGNING);
boolean bSign = signatureProps.getSignProject();
signRoot.setAttribute(ATTR_SIGN_PROJECT, Boolean.toString(bSign));
if (bSign)
{
XMLUtils.createTextElement(signRoot, ELEM_KEYSTORE, signatureProps.getKeyStoreDisplayPath());
XMLUtils.createTextElement(signRoot, ELEM_ALIAS, signatureProps.getKeyAlias());
XMLUtils.createTextElement(signRoot, ELEM_PROVIDER, signatureProps.getKeyStoreProvider());
XMLUtils.createTextElement(signRoot, ELEM_KEYSTORETYPE, signatureProps.getKeyStoreType());
Element passRoot = XMLUtils.createChild(signRoot, ELEM_PASSWORDS);
passRoot.setAttribute(ATTR_STOREPASSWORDS, Integer.toString(signatureProps.getPasswordStorageMethod()));
Map keyMap;
Platform.flushAuthorizationInfo(getKeyringURL(), KEYRING_REALM, KEYRING_SCHEME);
switch(signatureProps.getPasswordStorageMethod())
{
case ISignatureProperties.PASSMETHOD_IN_PROJECT:
XMLUtils.createTextElement(passRoot, ELEM_PWD_KEYSTORE, encodePassword(signatureProps.getKeyStorePassword()));
XMLUtils.createTextElement(passRoot, ELEM_PWD_KEY, encodePassword(signatureProps.getKeyPassword()));
break;
case ISignatureProperties.PASSMETHOD_IN_KEYRING:
keyMap = new HashMap();
keyMap.put(KEYRING_KEYSTOREPASS_KEY, signatureProps.getKeyStorePassword());
keyMap.put(KEYRING_KEYPASS_KEY, signatureProps.getKeyPassword());
Platform.addAuthorizationInfo(getKeyringURL(), KEYRING_REALM, KEYRING_SCHEME, keyMap);
break;
case ISignatureProperties.PASSMETHOD_PROMPT:
default:
break;
}
}
File localFile = storeFile.getLocation().toFile();
XMLUtils.writeDocument(localFile, rootElement.getOwnerDocument());
version = newVersion;
getStoreIFile().refreshLocal(1, new NullProgressMonitor());
}
catch(ParserConfigurationException pce)
{
EclipseMECorePlugin.throwCoreException(
IStatus.WARNING,
99999,
pce);
}
catch(TransformerException te)
{
EclipseMECorePlugin.throwCoreException(
IStatus.WARNING,
99999,
te);
}
catch(IOException ioe)
{
EclipseMECorePlugin.throwCoreException(
IStatus.WARNING,
99999,
ioe);
}
}
/**
* Return the device stored in the project metadata.
* @return
*/
public IDevice getDevice() {
return device;
}
/**
* Return the project-relative path to the project's jad file as
* specified in the project's metadata file. If the attributes
* has not been set, this method will return an empty string.
*
* @return
*/
public String getJadFile()
{
return jadFile;
}
/**
* Set the device stored in the project metadata.
*
* @param device
*/
public void setDevice(IDevice device) {
this.device = device;
}
/**
* Set the project-relative path to the project's jad file.
*
* @param jadFile
*/
public void setJadFile(String jadFile)
{
this.jadFile = jadFile;
}
public ISignatureProperties getSignatureProperties() throws CoreException
{
return signatureProps;
}
/**
* @return Returns the version.
*/
public Version getVersion() {
return version;
}
public void setSignatureProperties(ISignatureProperties p)
{
if (signatureProps == null)
{
signatureProps = new SignatureProperties();
}
signatureProps.copy(p);
}
/**
* Get the IFile instance in which the metadata is to be stored.
*
* @return
*/
private IFile getStoreIFile() {
return project.getFile(METADATA_FILE);
}
private URL getKeyringURL() throws CoreException
{
StringBuffer buf = new StringBuffer();
buf.append(KEYRING_URL_BASE);
String projectName = project.getName();
int nLength = projectName.length();
for (int i = 0; i < nLength; i++)
{
char c = projectName.charAt(i);
if (Character.isLetterOrDigit(c) || c == '.')
{
buf.append(c);
}
else
{
buf.append('%');
String hexString = Integer.toHexString((int)c);
if ((hexString.length() & 0x01) != 0)
{
buf.append('0');
}
buf.append(hexString);
}
}
URL retval = null;
try
{
retval = new URL(buf.toString());
}
catch(Exception ex)
{
EclipseMECoreErrors.throwCoreExceptionError(EclipseMECoreErrors.SIGNING_INTERNAL_UNABLE_TO_BUILD_KEYRING_URL, ex);
}
return(retval);
}
}
/*
********************************************************************
* CVS History:
* $$Log: MetaData.java,v $
* $Revision 1.15 2006/11/12 01:11:03 setera
* $Merging the preprocessor functionality back to the mainline
* $
* $Revision 1.14.4.2 2006/10/09 13:48:24 setera
* $Transitioning to secondary project for preprocessed output
* $
* $Revision 1.14.4.1 2006/09/14 00:49:10 setera
* $More preprocessing work via file system
* $
* $Revision 1.14 2006/05/29 00:43:02 setera
* $Use the resource API to set files read/write before saving (Bugs 1454656 & 1471342)
* $
* $Revision 1.13 2006/02/11 21:26:56 setera
* $Massive rework of emulator/device handling
* $
* $Revision 1.12 2005/12/18 19:36:57 setera
* $- Improve midlet refactoring support for JAD files including midlet moves and deletes
* $- Improve JAD file refactoring, allowing the JAD file to be moved and renamed
* $- Allow JAD file location during midlet suite creation (RFE 1044272)
* $
* $Revision 1.11 2005/10/29 15:39:29 setera
* $Refactor packaging and signing functionality into their own packages
* $Warn user while trying to package a project with an invalid platform definition (Bug 1304273)
* $
* $Revision 1.10 2005/07/07 02:37:17 setera
* $Final updates for 1.0.0 release
* $
* $Revision 1.9 2005/02/19 23:39:44 setera
* $Migration support for new identifier requirement
* $
* $Revision 1.8 2005/02/12 23:56:06 setera
* $First pass at platform component identifier support
* $
* $Revision 1.7 2004/12/17 01:33:29 setera
* $Documentation updates for the 0.7.0
* $
* $Revision 1.6 2004/12/16 00:56:57 setera
* $Fix some midlet suite metadata regression problems
* $
* $Revision 1.5 2004/12/15 01:24:28 setera
* $Fix some potential concurrency issues
* $
* $Revision 1.4 2004/12/12 20:21:10 kdhunter
* $Support for storing passwords in keyring
* $
* $Revision 1.3 2004/12/09 01:21:00 kdhunter
* $Mods to support two different buttons for "external"
* $or "internal" keystore files
* $
* $Revision 1.2 2004/12/07 01:10:19 kdhunter
* $Changes to allow project-relative or absolute
* $keystore paths
* $
* $Revision 1.1 2004/11/27 04:31:46 kdhunter
* $Refactored MetaData out of MidletSuiteProject
* $Additions for signing support
* $$
*
********************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -