Search in sources :

Example 41 with XMLElement

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

the class AttributeRegistry method write.

/**
 * @throws IOException
 */
public void write(final ITreeWriter writer) throws IOException {
    final XMLElement attributeRegistry = new XMLElement();
    boolean toBeSaved = false;
    if (isRestricted()) {
        attributeRegistry.setAttribute("RESTRICTED", "true");
        toBeSaved = true;
    }
    if (!attributeViewType.equals(AttributeTableLayoutModel.SHOW_ALL)) {
        attributeRegistry.setAttribute("SHOW_ATTRIBUTES", attributeViewType);
        toBeSaved = true;
    }
    for (int i = 0; i < size(); i++) {
        final AttributeRegistryElement element = getElement(i);
        if (element.isRestricted() || element.isVisible() || element.isManual()) {
            final XMLElement attributeData = element.save();
            attributeRegistry.addChild(attributeData);
            toBeSaved = true;
        }
    }
    if (toBeSaved) {
        attributeRegistry.setName(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY);
        writer.addElement(this, attributeRegistry);
    }
}
Also used : XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 42 with XMLElement

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

the class AttributeBuilder method registerAttributeHandlers.

private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "NAME", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
            rap.attributeName = value;
            AttributeRegistry.getRegistry(getMap()).registry(value);
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "VISIBLE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
            rap.visible = true;
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "RESTRICTED", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
            rap.restricted = true;
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, "MANUAL", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final RegisteredAttributeProperties rap = (RegisteredAttributeProperties) userObject;
            rap.manual = true;
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_VALUE, "VALUE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final AttributeProperties ap = (AttributeProperties) userObject;
            ap.attributeValue = value;
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_VALUE, "OBJECT", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final AttributeProperties ap = (AttributeProperties) userObject;
            ap.attributeObject = value;
        }
    });
    reader.addElementHandler(XML_NODE_ATTRIBUTE_LAYOUT, new IElementHandler() {

        public Object createElement(final Object parent, final String tag, final XMLElement attributes) {
            return parent;
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_LAYOUT, "NAME_WIDTH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            attributeController.createAttributeTableModel(node);
            final AttributeTableLayoutModel layout = NodeAttributeTableModel.getModel(node).getLayout();
            layout.setColumnWidth(0, LengthUnits.fromStringInPt(value));
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_LAYOUT, "VALUE_WIDTH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            attributeController.createAttributeTableModel(node);
            final AttributeTableLayoutModel layout = NodeAttributeTableModel.getModel(node).getLayout();
            layout.setColumnWidth(1, LengthUnits.fromStringInPt(value));
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "NAME", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final AttributeProperties ap = (AttributeProperties) userObject;
            ap.attributeName = value;
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "VALUE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final AttributeProperties ap = (AttributeProperties) userObject;
            ap.attributeValue = value;
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, "OBJECT", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final AttributeProperties ap = (AttributeProperties) userObject;
            ap.attributeObject = value;
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "RESTRICTED", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            AttributeRegistry.getRegistry(getMap()).setRestricted(true);
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "SHOW_ATTRIBUTES", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final AttributeRegistry attributes = AttributeRegistry.getRegistry(getMap());
            if (attributes != null)
                attributes.setAttributeViewType(value);
        }
    });
    reader.addAttributeHandler(AttributeBuilder.XML_NODE_ATTRIBUTE_REGISTRY, "FONT_SIZE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final int size = Integer.parseInt(value.toString());
            getMap().addExtension(new FontSizeExtension(size));
        }
    });
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IAttributeHandler(org.freeplane.core.io.IAttributeHandler) IElementHandler(org.freeplane.core.io.IElementHandler) XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 43 with XMLElement

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

the class NodeTextBuilder method writeContent.

/*
	 * (non-Javadoc)
	 * @see freeplane.io.INodeWriter#saveContent(freeplane.io.ITreeWriter,
	 * java.lang.Object, java.lang.String)
	 */
public void writeContent(final ITreeWriter writer, final Object element, final IExtension note) throws IOException {
    DetailTextModel model = (DetailTextModel) note;
    if (model.getXml() != null) {
        final XMLElement htmlElement = new XMLElement();
        htmlElement.setName(NodeTextBuilder.XML_NODE_XHTML_CONTENT_TAG);
        htmlElement.setAttribute(NodeTextBuilder.XML_NODE_XHTML_TYPE_TAG, NodeTextBuilder.XML_NODE_XHTML_TYPE_DETAILS);
        if (model.isHidden()) {
            htmlElement.setAttribute("HIDDEN", "true");
        }
        if (model.getLocalizedHtmlPropertyName() != null) {
            htmlElement.setAttribute("LOCALIZED_HTML", model.getLocalizedHtmlPropertyName());
            writer.addElement(null, htmlElement);
        } else {
            final String content = model.getXml().replace('\0', ' ');
            writer.addElement('\n' + content + '\n', htmlElement);
        }
    }
    return;
}
Also used : StyleString(org.freeplane.features.styles.StyleString) XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 44 with XMLElement

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

the class NodeTextBuilder method writeContent.

public void writeContent(final ITreeWriter writer, final Object element, final String tag) throws IOException {
    if (!NodeWriter.shouldWriteSharedContent(writer))
        return;
    final NodeModel node = (NodeModel) element;
    final TransformedXMLExtension transformedXML = node.getExtension(TransformedXMLExtension.class);
    if (transformedXML != null || node.getXmlText() != null) {
        final XMLElement htmlElement = new XMLElement();
        htmlElement.setName(NodeTextBuilder.XML_NODE_XHTML_CONTENT_TAG);
        htmlElement.setAttribute(NodeTextBuilder.XML_NODE_XHTML_TYPE_TAG, NodeTextBuilder.XML_NODE_XHTML_TYPE_NODE);
        final String xmlText;
        if (transformedXML != null) {
            xmlText = transformedXML.xml;
            node.removeExtension(transformedXML);
        } else
            xmlText = node.getXmlText();
        final String content = xmlText.replace('\0', ' ');
        writer.addElement('\n' + content + '\n', htmlElement);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) StyleString(org.freeplane.features.styles.StyleString) XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 45 with XMLElement

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

the class ScannerController method saveScanners.

private void saveScanners(final List<Scanner> scanners) throws IOException {
    final XMLElement saver = new XMLElement();
    saver.setName(ROOT_ELEMENT);
    final String sep = System.getProperty("line.separator");
    final String description = commentLines(// 
    "Description:", // 
    "", // 
    "<scanner> Scanners are locale dependent. If there is no scanner for", // 
    "the selected locale the scanner marked with default=\"true\" is choosen.", // 
    " 'locales': A comma-separated list of locale names.", // 
    "   The locale is selected via Preferences -> Environment -> Language", // 
    "   It's a pattern like 'en' (generic English) or 'en_US'", // 
    "   (English/USA). Use the more general two-letter form if appropriate.", // 
    " 'default': Set to \"true\" for only one locale. The standard is 'en'.", // 
    "", // 
    "<checkfirstchar> allows to enable a fast check for the first input", // 
    "character. If the first input character is not contained in the string", // 
    "given in attribute 'chars' no further attempts are made to parse the", // 
    "input as a number or date.", // 
    "Do not use this option if you have have scanner formats that can", // 
    "recognize arbitrary text at the beginning of the pattern. To disable", // 
    "this check omit <checkfirstchar> or add the attribute disabled=\"true\".", // 
    " 'chars': A string of characters that may start data.", // 
    "", // 
    "<type> selects the kind of data the scanner should recognize.", // 
    " 'style' selects the formatter implementation:", // 
    "  - \"isodate\": flexible ISO date reader for strings like 2011-04-29 22:31:21", // 
    "    Only creates datetimes if time part is given, so no differentiation", // 
    "    between date and date/time is necessary.", // 
    "  - \"date\": a special format for dates; needs attribute 'format'. See", // 
    "    http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html", // 
    "  - \"numberliteral\": parses Java float or integral number literals only, with", // 
    "    a dot as decimal separator and no thousands separator. See", // 
    "    http://en.wikibooks.org/wiki/Java_Programming/Literals/Numeric_Literals/Floating_Point_Literals", // 
    "  - \"decimal\": a special format for numbers; needs attribute 'format'. See", // 
    "    http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html", // 
    " 'format': The format code of a \"date\" or \"decimal\" scanner.", " 'comment': Inline comment, not used by the application.");
    final String header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + sep + description;
    for (Scanner scanner : scanners) {
        saver.addChild(scanner.toXml());
    }
    final Writer writer = new FileWriter(pathToFile);
    final XMLWriter xmlWriter = new XMLWriter(writer);
    xmlWriter.addRawContent(header);
    xmlWriter.write(saver, true);
    writer.close();
}
Also used : FileWriter(java.io.FileWriter) XMLElement(org.freeplane.n3.nanoxml.XMLElement) XMLWriter(org.freeplane.n3.nanoxml.XMLWriter) FileWriter(java.io.FileWriter) XMLWriter(org.freeplane.n3.nanoxml.XMLWriter) Writer(java.io.Writer)

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