use of com.mucommander.commons.util.xml.XmlAttributes in project mucommander by mucommander.
the class AssociationWriter method setIsSymlink.
public void setIsSymlink(boolean isSymlink) throws CommandException {
XmlAttributes attr;
attr = new XmlAttributes();
attr.add(ATTRIBUTE_VALUE, isSymlink ? VALUE_TRUE : VALUE_FALSE);
try {
out.writeStandAloneElement(ELEMENT_IS_SYMLINK, attr);
} catch (IOException e) {
throw new CommandException(e);
}
}
use of com.mucommander.commons.util.xml.XmlAttributes in project mucommander by mucommander.
the class AssociationWriter method setIsWritable.
public void setIsWritable(boolean isWritable) throws CommandException {
XmlAttributes attr;
attr = new XmlAttributes();
attr.add(ATTRIBUTE_VALUE, isWritable ? VALUE_TRUE : VALUE_FALSE);
try {
out.writeStandAloneElement(ELEMENT_IS_WRITABLE, attr);
} catch (IOException e) {
throw new CommandException(e);
}
}
use of com.mucommander.commons.util.xml.XmlAttributes in project mucommander by mucommander.
the class ThemeWriter method getFontAttributes.
// - Helper methods ------------------------------------------------------------------
// -----------------------------------------------------------------------------------
/**
* Returns the XML attributes describing the specified font.
* @param font font to described as XML attributes.
* @return the XML attributes describing the specified font.
*/
private static XmlAttributes getFontAttributes(Font font) {
// Stores the font's description.
XmlAttributes attributes;
attributes = new XmlAttributes();
// Font family and size.
attributes.add(ATTRIBUTE_FAMILY, font.getFamily());
attributes.add(ATTRIBUTE_SIZE, Integer.toString(font.getSize()));
// Font style.
if (font.isBold())
attributes.add(ATTRIBUTE_BOLD, VALUE_TRUE);
if (font.isItalic())
attributes.add(ATTRIBUTE_ITALIC, VALUE_TRUE);
return attributes;
}
use of com.mucommander.commons.util.xml.XmlAttributes in project mucommander by mucommander.
the class ShellHistoryWriter method write.
/**
* Writes the content of the {@link com.mucommander.shell.ShellHistoryManager} to the specified output stream.
* @param stream where to save the shell history.
*/
public static void write(OutputStream stream) {
// Iterator on the shell history.
Iterator<String> history;
// Where to write the shell history to.
XmlWriter out;
// Initialises writing.
history = ShellHistoryManager.getHistoryIterator();
try {
// Opens the file for writing.
out = new XmlWriter(stream);
// Version the file
XmlAttributes attributes = new XmlAttributes();
attributes.add(ATTRIBUTE_VERSION, RuntimeConstants.VERSION);
out.startElement(ROOT_ELEMENT, attributes);
out.println();
// Writes the content of the shell history.
while (history.hasNext()) {
out.startElement(COMMAND_ELEMENT);
out.writeCData(history.next());
out.endElement(COMMAND_ELEMENT);
}
out.endElement(ROOT_ELEMENT);
} catch (Exception e) {
LOGGER.debug("Failed to write shell history", e);
}
}
use of com.mucommander.commons.util.xml.XmlAttributes in project mucommander by mucommander.
the class CredentialsWriter method write.
/**
* Writes the credentials XML file in the user's preferences folder.
* This method should only be called by {@link CredentialsManager}.
*/
static void write(OutputStream stream) throws IOException {
XmlWriter out = new XmlWriter(stream);
// Root element, add the encryption method used
XmlAttributes attributes = new XmlAttributes();
attributes.add(ATTRIBUTE_ENCRYPTION, WEAK_ENCRYPTION_METHOD);
// Version the file
attributes.add(ATTRIBUTE_VERSION, RuntimeConstants.VERSION);
out.startElement(ELEMENT_ROOT, attributes);
out.println();
Iterator<CredentialsMapping> iterator = CredentialsManager.getPersistentCredentialMappings().iterator();
CredentialsMapping credentialsMapping;
FileURL realm;
Enumeration<String> propertyKeys;
String name;
while (iterator.hasNext()) {
credentialsMapping = iterator.next();
realm = credentialsMapping.getRealm();
// Start credentials element
out.startElement(ELEMENT_CREDENTIALS);
out.println();
// Write URL
out.startElement(ELEMENT_URL);
out.writeCData(realm.toString(false));
out.endElement(ELEMENT_URL);
Credentials credentials = credentialsMapping.getCredentials();
// Write login
out.startElement(ELEMENT_LOGIN);
out.writeCData(credentials.getLogin());
out.endElement(ELEMENT_LOGIN);
// Write password (XOR encrypted)
out.startElement(ELEMENT_PASSWORD);
out.writeCData(XORCipher.encryptXORBase64(credentials.getPassword()));
out.endElement(ELEMENT_PASSWORD);
// Write properties, each property is stored in a separate 'property' element
propertyKeys = realm.getPropertyNames();
while (propertyKeys.hasMoreElements()) {
name = propertyKeys.nextElement();
attributes = new XmlAttributes();
attributes.add(ATTRIBUTE_NAME, name);
attributes.add(ATTRIBUTE_VALUE, realm.getProperty(name));
out.startElement(ELEMENT_PROPERTY, attributes);
out.endElement(ELEMENT_PROPERTY);
}
// End credentials element
out.endElement(ELEMENT_CREDENTIALS);
}
// End root element
out.endElement(ELEMENT_ROOT);
}
Aggregations