use of net.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class AttributeBuilder method saveAttribute.
private void saveAttribute(NodeModel node, final ITreeWriter writer, final Attribute attr) throws IOException {
final XMLElement attributeElement = new XMLElement();
attributeElement.setName(AttributeBuilder.XML_NODE_ATTRIBUTE);
attributeElement.setAttribute("NAME", attr.getName());
final Object value = attr.getValue();
final boolean forceFormatting = Boolean.TRUE.equals(writer.getHint(MapWriter.WriterHint.FORCE_FORMATTING));
if (forceFormatting) {
attributeElement.setAttribute("VALUE", TextController.getController().getTransformedTextNoThrow(value, node, null));
} else {
attributeElement.setAttribute("VALUE", value.toString());
if (!(value instanceof String))
attributeElement.setAttribute("OBJECT", TypeReference.toSpec(value));
}
writer.addElement(attr, attributeElement);
}
use of net.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class AttributeRegistryElement method save.
/**
*/
public XMLElement save() {
final XMLElement element = new XMLElement();
if (isVisible()) {
element.setAttribute("VISIBLE", "true");
}
if (isManual()) {
element.setAttribute("MANUAL", "true");
}
if (isRestricted()) {
element.setAttribute("RESTRICTED", "true");
}
if (isManual() || isRestricted()) {
for (int i = 0; i < values.getSize(); i++) {
final XMLElement xmlValue = new XMLElement();
xmlValue.setName(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_VALUE);
final Object value = values.getElementAt(i);
final String string = value.toString();
xmlValue.setAttribute("VALUE", string);
if (!(value instanceof String)) {
final String spec = TypeReference.toSpec(value);
xmlValue.setAttribute("OBJECT", spec);
}
element.addChild(xmlValue);
}
}
element.setName(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME);
element.setAttribute("NAME", key.toString());
return element;
}
use of net.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class ScannerController method parseScanner.
private Scanner parseScanner(XMLElement elem) {
final String locales = elem.getAttribute("locale", "");
final String isDefault = elem.getAttribute("default", "false");
if (StringUtils.isEmpty(locales)) {
throw new RuntimeException("wrong scanner in " + pathToFile + ": none of the following must be empty: locales=" + locales + ".");
}
final Scanner scanner = new Scanner(locales.trim().split(","), Boolean.parseBoolean(isDefault));
final Locale locale = new Locale(scanner.getLocales().get(0));
for (XMLElement child : elem.getChildren()) {
if (child.getName().equals("checkfirstchar")) {
final String chars = elem.getAttribute("chars", "");
final boolean disabled = Boolean.parseBoolean(elem.getAttribute("disabled", "false"));
if (!disabled)
scanner.setFirstChars(chars);
} else if (child.getName().equals("parser")) {
scanner.addParser(parseParser(child, locale));
}
}
return scanner;
}
use of net.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class FilterController method loadConditions.
void loadConditions(final DefaultComboBoxModel filterConditionModel, final String pathToFilterFile, final boolean showPopupOnError) throws IOException {
try {
final IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
File filterFile = new File(pathToFilterFile);
final IXMLReader reader = new StdXMLReader(new BufferedInputStream(new FileInputStream(filterFile)));
parser.setReader(reader);
reader.setSystemID(filterFile.toURL().toString());
final XMLElement loader = (XMLElement) parser.parse();
final Vector<XMLElement> conditions = loader.getChildren();
for (int i = 0; i < conditions.size(); i++) {
final ASelectableCondition condition = getConditionFactory().loadCondition(conditions.get(i));
if (condition != null) {
filterConditionModel.addElement(condition);
}
}
} catch (final FileNotFoundException e) {
} catch (final AccessControlException e) {
} catch (final Exception e) {
LogUtils.warn(e);
if (showPopupOnError) {
UITools.errorMessage(TextUtils.getText("filters_not_loaded"));
}
}
}
use of net.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class ExportController method createXSLTExportActions.
private void createXSLTExportActions(final String xmlDescriptorFile) {
InputStream xmlDescriptorStream = null;
try {
final IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
final URL resource = ResourceController.getResourceController().getResource(xmlDescriptorFile);
xmlDescriptorStream = resource.openStream();
final IXMLReader reader = new StdXMLReader(xmlDescriptorStream);
parser.setReader(reader);
final XMLElement xml = (XMLElement) parser.parse();
final Enumeration<XMLElement> actionDescriptors = xml.enumerateChildren();
while (actionDescriptors.hasMoreElements()) {
final XMLElement descriptor = actionDescriptors.nextElement();
final String name = descriptor.getAttribute("name", null);
final XMLElement xmlProperties = descriptor.getFirstChildNamed("properties");
final Properties properties = xmlProperties.getAttributes();
final ExportWithXSLT action = new ExportWithXSLT(name, properties);
addExportEngine(action.getFileFilter(), action);
}
} catch (final Exception e) {
LogUtils.severe(e);
} finally {
FileUtils.silentlyClose(xmlDescriptorStream);
}
}
Aggregations