Search in sources :

Example 46 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class ScannerController method loadScanners.

void loadScanners() throws Exception {
    final File configXml = new File(pathToFile);
    if (!configXml.exists()) {
        LogUtils.info(pathToFile + " does not exist yet");
        return;
    }
    try {
        final IXMLParser parser = XMLLocalParserFactory.createLocalXMLParser();
        final IXMLReader reader = new StdXMLReader(new BufferedInputStream(new FileInputStream(configXml)));
        parser.setReader(reader);
        final XMLElement loader = (XMLElement) parser.parse();
        final Vector<XMLElement> scannerElements = loader.getChildren();
        for (XMLElement elem : scannerElements) {
            scanners.add(parseScanner(elem));
        }
        boolean haveDefault = false;
        for (Scanner scanner : scanners) {
            if (scanner.isDefault()) {
                if (haveDefault)
                    LogUtils.warn(configXml + ": multiple scanners are marked as default - fix that!");
                else
                    haveDefault = true;
            }
        }
        if (!haveDefault)
            LogUtils.warn(configXml + ": no scanner is marked as default - fix that!");
    } catch (final IOException e) {
        LogUtils.warn("error parsing " + configXml, e);
    }
}
Also used : IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) BufferedInputStream(java.io.BufferedInputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) IOException(java.io.IOException) XMLElement(org.freeplane.n3.nanoxml.XMLElement) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 47 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class FilterController method saveConditions.

void saveConditions(final DefaultComboBoxModel filterConditionModel, final String pathToFilterFile) throws IOException {
    final XMLElement saver = new XMLElement();
    saver.setName("filter_conditions");
    final Writer writer = new FileWriter(pathToFilterFile);
    for (int i = 0; i < filterConditionModel.getSize(); i++) {
        final ASelectableCondition cond = (ASelectableCondition) filterConditionModel.getElementAt(i);
        if (cond != null && !(cond instanceof NoFilteringCondition)) {
            cond.toXml(saver);
        }
    }
    final XMLWriter xmlWriter = new XMLWriter(writer);
    xmlWriter.write(saver, true);
    writer.close();
}
Also used : FileWriter(java.io.FileWriter) NoFilteringCondition(org.freeplane.features.filter.condition.NoFilteringCondition) XMLElement(org.freeplane.n3.nanoxml.XMLElement) XMLWriter(org.freeplane.n3.nanoxml.XMLWriter) Writer(java.io.Writer) FileWriter(java.io.FileWriter) XMLWriter(org.freeplane.n3.nanoxml.XMLWriter) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition)

Example 48 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class IconBuilder method writeContent.

@Override
public void writeContent(final ITreeWriter writer, final Object element, final String tag) throws IOException {
    if (!NodeWriter.shouldWriteSharedContent(writer))
        return;
    final boolean forceFormatting = Boolean.TRUE.equals(writer.getHint(MapWriter.WriterHint.FORCE_FORMATTING));
    final NodeModel node = (NodeModel) element;
    final IconController iconController = IconController.getController();
    final Collection<MindIcon> icons = forceFormatting ? iconController.getIcons(node) : node.getIcons();
    for (MindIcon icon : icons) {
        final XMLElement iconElement = new XMLElement();
        iconElement.setName("icon");
        iconElement.setAttribute("BUILTIN", icon.getName());
        if (forceFormatting) {
            iconElement.setAttribute("src", icon.getSource());
            iconElement.setAttribute("height", Integer.toString(iconController.getIconSize(node).toBaseUnitsRounded()));
        }
        writer.addElement(node, iconElement);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 49 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class FormatController method loadFormats.

private void loadFormats() throws Exception {
    BufferedInputStream inputStream = null;
    final File configXml = new File(pathToFile);
    if (!configXml.exists()) {
        LogUtils.info(pathToFile + " does not exist yet");
        return;
    }
    try {
        final IXMLParser parser = XMLLocalParserFactory.createLocalXMLParser();
        inputStream = new BufferedInputStream(new FileInputStream(configXml));
        final IXMLReader reader = new StdXMLReader(inputStream);
        parser.setReader(reader);
        final XMLElement loader = (XMLElement) parser.parse();
        final Vector<XMLElement> formats = loader.getChildren();
        for (XMLElement elem : formats) {
            final String type = elem.getAttribute("type", null);
            final String style = elem.getAttribute("style", null);
            final String name = elem.getAttribute("name", null);
            final String locale = elem.getAttribute("locale", null);
            final String content = elem.getContent();
            if (StringUtils.isEmpty(type) || StringUtils.isEmpty(style) || StringUtils.isEmpty(content)) {
                throw new RuntimeException("wrong format in " + configXml + ": none of the following must be empty: type=" + type + ", style=" + style + ", element content=" + content);
            } else {
                final PatternFormat format = createFormat(content, style, type, name, (locale == null ? null : new Locale(locale)));
                if (type.equals(IFormattedObject.TYPE_DATE)) {
                    dateFormats.add(format);
                } else if (type.equals(IFormattedObject.TYPE_NUMBER)) {
                    numberFormats.add(format);
                } else if (type.equals(IFormattedObject.TYPE_STRING)) {
                    stringFormats.add(format);
                } else if (type.equals(PatternFormat.TYPE_STANDARD)) {
                // ignore this pattern that crept in in some 1.2 beta version
                } else {
                    throw new RuntimeException("unknown type in " + configXml + ": type=" + type + ", style=" + style + ", element content=" + content);
                }
            }
        }
    } catch (final IOException e) {
        LogUtils.warn("error parsing " + configXml, e);
    } finally {
        FileUtils.silentlyClose(inputStream);
    }
}
Also used : Locale(java.util.Locale) IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) IOException(java.io.IOException) XMLElement(org.freeplane.n3.nanoxml.XMLElement) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) File(java.io.File)

Example 50 with XMLElement

use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.

the class ASelectableCondition method toXml.

public void toXml(final XMLElement element) {
    final XMLElement child = new XMLElement();
    child.setName(getName());
    if (userName != null) {
        child.setAttribute("user_name", userName);
    }
    fillXML(child);
    element.addChild(child);
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Aggregations

XMLElement (org.freeplane.n3.nanoxml.XMLElement)63 IOException (java.io.IOException)8 IXMLParser (org.freeplane.n3.nanoxml.IXMLParser)7 IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)7 StdXMLReader (org.freeplane.n3.nanoxml.StdXMLReader)7 BufferedInputStream (java.io.BufferedInputStream)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 ASelectableCondition (org.freeplane.features.filter.condition.ASelectableCondition)5 NodeModel (org.freeplane.features.map.NodeModel)5 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 XMLException (org.freeplane.n3.nanoxml.XMLException)3 Point (java.awt.Point)2 FilenameFilter (java.io.FilenameFilter)2 HashMap (java.util.HashMap)2