Search in sources :

Example 11 with XMLElement

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);
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 12 with XMLElement

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;
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 13 with XMLElement

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;
}
Also used : Locale(java.util.Locale) XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 14 with XMLElement

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"));
        }
    }
}
Also used : IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) FileNotFoundException(java.io.FileNotFoundException) AccessControlException(java.security.AccessControlException) XMLElement(org.freeplane.n3.nanoxml.XMLElement) FileInputStream(java.io.FileInputStream) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition) FileNotFoundException(java.io.FileNotFoundException) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) BufferedInputStream(java.io.BufferedInputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) File(java.io.File)

Example 15 with XMLElement

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);
    }
}
Also used : IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) InputStream(java.io.InputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) XMLElement(org.freeplane.n3.nanoxml.XMLElement) Properties(java.util.Properties) URL(java.net.URL)

Aggregations

XMLElement (org.freeplane.n3.nanoxml.XMLElement)65 IOException (java.io.IOException)8 IXMLParser (org.freeplane.n3.nanoxml.IXMLParser)6 IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)6 StdXMLReader (org.freeplane.n3.nanoxml.StdXMLReader)6 ASelectableCondition (org.freeplane.features.filter.condition.ASelectableCondition)5 NodeModel (org.freeplane.features.map.NodeModel)5 BufferedInputStream (java.io.BufferedInputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 XMLWriter (org.freeplane.n3.nanoxml.XMLWriter)4 Color (java.awt.Color)3 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 IXMLElement (net.n3.nanoxml.IXMLElement)3 XMLElement (net.n3.nanoxml.XMLElement)3 Point (java.awt.Point)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Locale (java.util.Locale)2