Search in sources :

Example 11 with Comment

use of org.jdom.Comment in project vcell by virtualcell.

the class XmlHelper method mathModelToXML.

static String mathModelToXML(MathModel mathModel, boolean printkeys) throws XmlParseException {
    String xmlString = null;
    if (mathModel == null) {
        throw new XmlParseException("Invalid input for BioModel: " + mathModel);
    }
    // NEW WAY, with XML declaration, vcml element, namespace, version #, etc.
    // create root vcml element
    Element vcmlElement = new Element(XMLTags.VcmlRootNodeTag);
    vcmlElement.setAttribute(XMLTags.VersionTag, getEscapedSoftwareVersion());
    // get mathmodel element from xmlProducer and add it to vcml root element
    Xmlproducer xmlProducer = new Xmlproducer(printkeys);
    Element mathElement = xmlProducer.getXML(mathModel);
    vcmlElement.addContent(mathElement);
    // set namespace for vcmlElement
    vcmlElement = XmlUtil.setDefaultNamespace(vcmlElement, Namespace.getNamespace(XMLTags.VCML_NS));
    // create xml doc with vcml root element and convert to string
    Document mathDoc = new Document();
    Comment docComment = new Comment("This mathmodel was generated in VCML Version " + getEscapedSoftwareVersion());
    mathDoc.addContent(docComment);
    mathDoc.setRootElement(vcmlElement);
    xmlString = XmlUtil.xmlToString(mathDoc, false);
    // xmlString = XmlUtil.xmlToString(element);
    if (lg.isTraceEnabled())
        lg.trace(xmlString);
    return xmlString;
}
Also used : Comment(org.jdom.Comment) Element(org.jdom.Element) Document(org.jdom.Document) VCDocument(org.vcell.util.document.VCDocument)

Example 12 with Comment

use of org.jdom.Comment in project cxf by apache.

the class StaxSerializer method writeElement.

public void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException {
    // need to check if the namespace is declared before we write the
    // start element because that will put the namespace in the context.
    String elPrefix = e.getNamespacePrefix();
    String elUri = e.getNamespaceURI();
    String boundPrefix = writer.getPrefix(elUri);
    boolean writeElementNS = false;
    if (boundPrefix == null || !elPrefix.equals(boundPrefix)) {
        writeElementNS = true;
    }
    writer.writeStartElement(elPrefix, e.getName(), elUri);
    List<?> namespaces = e.getAdditionalNamespaces();
    for (Iterator<?> itr = namespaces.iterator(); itr.hasNext(); ) {
        Namespace ns = (Namespace) itr.next();
        String prefix = ns.getPrefix();
        String uri = ns.getURI();
        writer.setPrefix(prefix, uri);
        writer.writeNamespace(prefix, uri);
        if (elUri.equals(uri) && elPrefix.equals(prefix)) {
            writeElementNS = false;
        }
    }
    for (Iterator<?> itr = e.getAttributes().iterator(); itr.hasNext(); ) {
        Attribute attr = (Attribute) itr.next();
        String attPrefix = attr.getNamespacePrefix();
        String attUri = attr.getNamespaceURI();
        if (attUri == null || attUri.isEmpty()) {
            writer.writeAttribute(attr.getName(), attr.getValue());
        } else {
            writer.writeAttribute(attPrefix, attUri, attr.getName(), attr.getValue());
            if (!isDeclared(writer, attPrefix, attUri)) {
                if (elUri.equals(attUri) && elPrefix.equals(attPrefix)) {
                    if (writeElementNS) {
                        writer.setPrefix(attPrefix, attUri);
                        writer.writeNamespace(attPrefix, attUri);
                        writeElementNS = false;
                    }
                } else {
                    writer.setPrefix(attPrefix, attUri);
                    writer.writeNamespace(attPrefix, attUri);
                }
            }
        }
    }
    if (writeElementNS) {
        if (elPrefix == null || elPrefix.length() == 0) {
            writer.writeDefaultNamespace(elUri);
        } else {
            writer.writeNamespace(elPrefix, elUri);
        }
    }
    for (Iterator<?> itr = e.getContent().iterator(); itr.hasNext(); ) {
        Content n = (Content) itr.next();
        if (n instanceof CDATA) {
            writer.writeCData(n.getValue());
        } else if (n instanceof Text) {
            writer.writeCharacters(((Text) n).getText());
        } else if (n instanceof Element) {
            writeElement((Element) n, writer);
        } else if (n instanceof Comment) {
            writer.writeComment(n.getValue());
        } else if (n instanceof EntityRef) {
        // EntityRef ref = (EntityRef) n;
        // writer.writeEntityRef(ref.)
        }
    }
    writer.writeEndElement();
}
Also used : Comment(org.jdom.Comment) Attribute(org.jdom.Attribute) Content(org.jdom.Content) Element(org.jdom.Element) Text(org.jdom.Text) CDATA(org.jdom.CDATA) EntityRef(org.jdom.EntityRef) Namespace(org.jdom.Namespace)

Example 13 with Comment

use of org.jdom.Comment in project openolat by klemens.

the class SequencerModel method init.

/**
 * Initilise this JDOM doc - adding comment and setting root node
 */
protected void init() {
    Document _model;
    Element root = new Element(ROOT_NODE_NAME);
    _model = new Document(root);
    for (int i = 0; i < scorm_comments.length; i++) {
        Comment comment = new Comment(scorm_comments[i]);
        _model.getContent().add(0, comment);
    }
    this.setDocument(_model);
}
Also used : Comment(org.jdom.Comment) Element(org.jdom.Element) XMLDocument(uk.ac.reload.jdom.XMLDocument) Document(org.jdom.Document)

Aggregations

Comment (org.jdom.Comment)13 Element (org.jdom.Element)13 Document (org.jdom.Document)10 XMLDocument (uk.ac.reload.jdom.XMLDocument)4 Attribute (org.jdom.Attribute)3 VCDocument (org.vcell.util.document.VCDocument)3 ExpressionException (cbit.vcell.parser.ExpressionException)2 IOException (java.io.IOException)2 EntityRef (org.jdom.EntityRef)2 Namespace (org.jdom.Namespace)2 Text (org.jdom.Text)2 Action (cbit.vcell.math.Action)1 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)1 JumpProcessRateDefinition (cbit.vcell.math.JumpProcessRateDefinition)1 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)1 MathDescription (cbit.vcell.math.MathDescription)1 MathException (cbit.vcell.math.MathException)1 MathRuleFactory (cbit.vcell.math.MathRuleFactory)1 MathRuleEntry (cbit.vcell.math.MathRuleFactory.MathRuleEntry)1 ParticleComponentStateDefinition (cbit.vcell.math.ParticleComponentStateDefinition)1