Package org.codehaus.staxmate.out

Examples of org.codehaus.staxmate.out.SMOutputElement


              && (programVersion.length() > 0) ? programVersion
              : "?", date, JSBML.getJSBMLDottedVersion()));
      outputDocument.addCharacters("\n");
    }

    SMOutputElement smOutputElement = outputDocument.addElement(namespace,
        sbmlDocument.getElementName());

    SBMLObjectForXML xmlObject = new SBMLObjectForXML();
    xmlObject.setName(sbmlDocument.getElementName());
    xmlObject.setNamespace(SBMLNamespace);
    xmlObject.addAttributes(sbmlDocument.writeXMLAttributes());

    // register all the name spaces of the SBMLDocument to the writer
    Iterator<Map.Entry<String, String>> it = sbmlDocument
        .getSBMLDocumentNamespaces().entrySet().iterator();

    logger.debug(" SBML name spaces size = "
        + sbmlDocument.getSBMLDocumentNamespaces().size());

    while (it.hasNext()) {
      Map.Entry<String, String> entry = it.next();
      if (!entry.getKey().equals("xmlns")) {

        logger.debug(" SBML name spaces: " + entry.getKey() + " = "
            + entry.getValue());

        String namespacePrefix = entry.getKey().substring(
            entry.getKey().indexOf(":") + 1);
        streamWriter.setPrefix(namespacePrefix, entry.getValue());

        logger.debug(" SBML namespaces: " + namespacePrefix + " = "
            + entry.getValue());

      }
    }

    if (sbmlDocument.getDeclaredNamespaces().size() > 0) {
         
      logger.debug(" SBML declared namespaces size = "
          + sbmlDocument.getDeclaredNamespaces().size());

      xmlObject.addAttributes(sbmlDocument.getDeclaredNamespaces());
     
      for (String prefix : sbmlDocument.getDeclaredNamespaces().keySet()) {

        if (!prefix.equals("xmlns")) {

          String namespaceURI = sbmlDocument.getDeclaredNamespaces().get(prefix);

          logger.debug(" SBML name spaces: " + prefix + " = " + namespaceURI);

          String namespacePrefix = prefix.substring(prefix.indexOf(":") + 1);

          streamWriter.setPrefix(namespacePrefix, namespaceURI);

          logger.debug(" SBML namespaces: " + namespacePrefix + " = " + namespaceURI);
        }
      }
    }

    it = xmlObject.getAttributes().entrySet().iterator();
    while (it.hasNext()) {
      Entry<String, String> entry = it.next();
      smOutputElement.addAttribute(entry.getKey(), entry.getValue());
    }

    int indent = indentCount;
    if (sbmlDocument.isSetNotes()) {
      writeNotes(sbmlDocument, smOutputElement, streamWriter,
          SBMLNamespace, indent);
    }
    if (sbmlDocument.isSetAnnotation()) {
      writeAnnotation(sbmlDocument, smOutputElement, streamWriter,
          indent, false);
    }
    smOutputElement.addCharacters("\n");

    writeSBMLElements(xmlObject, smOutputElement, streamWriter,
        sbmlDocument, indent);

    outputDocument.closeRoot();
View Full Code Here


    String sbmlNamespace = JSBML.getNamespaceFrom(sbase.getLevel(), sbase.getVersion());
    SMNamespace namespace = element.getContext().getNamespace(sbmlNamespace);
    namespace.setPreferredPrefix("");

    Annotation annotation = sbase.getAnnotation();
    SMOutputElement annotationElement;
    String whiteSpaces = createIndentationString(indent);
   
    if (xmlFragment) {
      annotationElement = element.addElement("annotation");
    } else {
      element.addCharacters("\n");
      element.setIndentation(whiteSpaces, indent, indentCount);   
      annotationElement = element.addElement(namespace, "annotation");
    }
    annotationElement.setIndentation(whiteSpaces, indent, indentCount);

    if ((annotation.getNonRDFannotation() != null)
        && (annotation.getNonRDFannotation().length() > 0)) {
      StringBuffer annotationBeginning = StringTools.concat(whiteSpaces,
          "<annotation");

      // Adding the name spaces of the annotation element
      Map<String, String> otherNamespaces = annotation
          .getAnnotationNamespaces();

      for (String namespacePrefix : otherNamespaces.keySet()) {
        StringTools.append(annotationBeginning, " ", namespacePrefix,
            "=\"", otherNamespaces.get(namespacePrefix), "\"");
        annotationElement.addAttribute(namespacePrefix, otherNamespaces.get(namespacePrefix));
      }
           
      boolean allNamespacesDefined = true;
     
      // Adding the name spaces of the sbml element
View Full Code Here

      // set the indentation for the math opening tag     
      element.setIndentation(whitespaces, indent + indentCount, indentCount);

      // Creating an SMOutputElement to be sure that the previous nested element tag is closed properly.
      SMNamespace mathMLNamespace = element.getNamespace(ASTNode.URI_MATHML_DEFINITION, ASTNode.URI_MATHML_PREFIX);
      SMOutputElement mathElement = element.addElement(mathMLNamespace, "math");
      MathMLXMLStreamCompiler compiler = new MathMLXMLStreamCompiler(
          writer, createIndentationString(indent + indentCount));
      boolean isSBMLNamespaceNeeded = compiler.isSBMLNamespaceNeeded(m.getMath());

      // TODO: add all other namespaces !!

      if (isSBMLNamespaceNeeded) {
        // writing the SBML namespace
        SBMLDocument doc = null;
        SBase sbase = m.getMath().getParentSBMLObject();
        String sbmlNamespace = SBMLDocument.URI_NAMESPACE_L3V1Core;
       
        if (sbase != null) {
          doc = sbase.getSBMLDocument();
          sbmlNamespace = doc.getSBMLDocumentNamespaces().get("xmlns");
         
          if (sbmlNamespace == null) {
            logger.warn("writeMathML: the SBML namespace of this SBMLDocument" +
                " could not be found, using the default namespace (" +
                SBMLDocument.URI_NAMESPACE_L3V1Core + ") instead.");
            sbmlNamespace = SBMLDocument.URI_NAMESPACE_L3V1Core;
          }
        }
        writer.writeNamespace("sbml", sbmlNamespace);
      }
     
      mathElement.setIndentation(createIndentationString(indent + 2), indent + indentCount, indentCount);
     
      writer.writeCharacters(whitespaces);
      writer.writeCharacters("\n");

      compiler.compile(m.getMath());
View Full Code Here

    // set the indentation for the math opening tag     
    element.setIndentation(whitespaces, indent + indentCount, indentCount);

    // Creating an SMOutputElement to be sure that the previous nested element tag is closed properly.
    SMNamespace sbmlSMNamespace = element.getNamespace();
    SMOutputElement messageElement = element.addElement(sbmlSMNamespace, "message");
    messageElement.setIndentation(createIndentationString(indent + 2), indent + indentCount, indentCount);
   
    writer.writeCharacters(whitespaces);
    writer.writeCharacters("\n");
   
    XMLNodeWriter xmlNodeWriter = new XMLNodeWriter(writer, indent,
View Full Code Here

    String whiteSpace = createIndentationString(indent);
    SMNamespace namespace = annotationElement.getNamespace(
        Annotation.URI_RDF_SYNTAX_NS, "rdf");
    annotationElement.setIndentation(whiteSpace, indent, indentCount);
    SMOutputElement rdfElement = annotationElement.addElement(namespace,
        "RDF");

    /*
     * TODO: Check which name spaces are really required and add only those;
     * particularly, if name spaces are missing and it is known from the
     * kind of RDF annotation, which name spaces are needed, these should be
     * added automatically here.
     */
    Map<String, String> rdfNamespaces = annotation.getRDFAnnotationNamespaces();

    for (String namespaceURI : rdfNamespaces.keySet()) {
     
      if (!namespaceURI.equals(namespace.getURI())) {
        writer.writeNamespace(rdfNamespaces.get(namespaceURI), namespaceURI);
      }
    }

    // Checking if all the necessary namespaces are defined
    // TODO: In fact, we could remove the rdfNamespaces map ?

    if (rdfNamespaces.get(Annotation.URI_RDF_SYNTAX_NS) == null
        || rdfNamespaces.get(Annotation.URI_RDF_SYNTAX_NS).equals("xmlns"))
    {
      // writer.writeNamespace("rdf", Annotation.URI_RDF_SYNTAX_NS); // already registered previously
      rdfNamespaces.put(Annotation.URI_RDF_SYNTAX_NS, "rdf");
    }

    if (annotation.isSetHistory() && annotation.getHistory().getCreatorCount() > 0)
    {
      if (rdfNamespaces.get(JSBML.URI_PURL_ELEMENTS) == null) {
        writer.writeNamespace("dc", JSBML.URI_PURL_ELEMENTS);
        rdfNamespaces.put(JSBML.URI_PURL_ELEMENTS, "dc");
      }

      if (rdfNamespaces.get(Creator.URI_RDF_VCARD_NS) == null) {
        writer.writeNamespace("vCard", Creator.URI_RDF_VCARD_NS);
        rdfNamespaces.put(Creator.URI_RDF_VCARD_NS, "vCard");
      }
    }
   
    if (annotation.isSetHistory() && rdfNamespaces.get(JSBML.URI_PURL_TERMS) == null)
    {
      boolean isModelHistory = annotation.getParent() instanceof Model;
     
      if (isModelHistory || (annotation.getHistory().isSetCreatedDate() || annotation.getHistory().isSetModifiedDate())) {
        writer.writeNamespace("dcterms", JSBML.URI_PURL_TERMS);
        rdfNamespaces.put(JSBML.URI_PURL_TERMS, "dcterms");
      }     
    }
   
    if (annotation.getCVTermCount() > 0)
    {
      if (rdfNamespaces.get(CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS) == null) {
        writer.writeNamespace("bqbiol", CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS);
        rdfNamespaces.put(CVTerm.URI_BIOMODELS_NET_BIOLOGY_QUALIFIERS, "bqbiol");
      }

      if (rdfNamespaces.get(CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS) == null) {
        writer.writeNamespace("bqmodel", CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS);
        rdfNamespaces.put(CVTerm.URI_BIOMODELS_NET_MODEL_QUALIFIERS, "bqmodel");
      }
     
    }
   
   
    rdfElement.addCharacters("\n");
    rdfElement.setIndentation(whiteSpace + createIndentationString(indentCount), indent + indentCount, indentCount);
    SMOutputElement descriptionElement = rdfElement.addElement(namespace,
        "Description");
    descriptionElement.addAttribute(namespace, "about",
        annotation.getAbout());
    descriptionElement.addCharacters("\n");
    if (annotation.isSetHistory()) {
      writeHistory(annotation.getHistory(), rdfNamespaces, writer,
          indent + 4);
    }
    if (annotation.getListOfCVTerms().size() > 0) {
      writeCVTerms(annotation.getListOfCVTerms(), rdfNamespaces, writer,
          indent + indentCount);
    }
    descriptionElement.setIndentation(whiteSpace + createIndentationString(indentCount), indent + indentCount, indentCount);
    descriptionElement.addCharacters(whiteSpace + createIndentationString(indentCount));
    annotationElement.setIndentation(whiteSpace, indent, indentCount);
    rdfElement.addCharacters("\n");
    rdfElement.addCharacters(whiteSpace);
    annotationElement.addCharacters("\n");
  }
View Full Code Here

          // TODO: add a log message that this is ignored ??
          logger.debug("XML name not set, element ignored!");
          continue;
        }
       
        SMOutputElement newOutPutElement = null;
        boolean isClosedMathContainer = false, isClosedAnnotation = false;

        SMNamespace namespace = null;

        if (childXmlObject.isSetNamespace()) {
          namespace = smOutputParentElement.getNamespace(childXmlObject.getNamespace(), childXmlObject.getPrefix());
        } else {
          namespace = smOutputParentElement.getNamespace();
        }

        newOutPutElement = smOutputParentElement.addElement(namespace, childXmlObject.getName());

        // adding the attributes to the {@link SMOutputElement}
        for (String attributeName : childXmlObject.getAttributes().keySet())
        {
          newOutPutElement.addAttribute(attributeName, childXmlObject.getAttributes().get(attributeName));         
        }
       
        if (nextObjectToWrite instanceof SBase) {
          SBase s = (SBase) nextObjectToWrite;
          if (s.isSetNotes()) {
            writeNotes(s, newOutPutElement, streamWriter,
                newOutPutElement.getNamespace()
                .getURI(), indent + indentCount);
            elementIsNested = true;
          }
          if (s.isSetAnnotation()) {
            writeAnnotation(s, newOutPutElement,
                streamWriter,
                indent + indentCount, false);
            elementIsNested = isClosedAnnotation = true;
          }
          if (s.getChildCount() > 0) {
            // make sure that we'll have line breaks if an element has any sub elements.
            elementIsNested = true;
          }
        }
        if (nextObjectToWrite instanceof MathContainer) {
          MathContainer mathContainer = (MathContainer) nextObjectToWrite;
          if (mathContainer.getLevel() > 1) {
            writeMathML(mathContainer, newOutPutElement,
                streamWriter, indent + indentCount);
            elementIsNested = true;
          }
          isClosedMathContainer = true;
        }
        if (nextObjectToWrite instanceof Constraint) {
          Constraint constraint = (Constraint) nextObjectToWrite;
          if (constraint.isSetMessage()) {
            writeMessage(constraint, newOutPutElement,
                streamWriter, newOutPutElement
                .getNamespace().getURI(),
                indent + indentCount);
            elementIsNested = true;
          }
        }
        if (!elementIsNested
            && ((nextObjectToWrite instanceof Model) || (nextObjectToWrite instanceof UnitDefinition))) {
          elementIsNested = true;
        }

        // to allow the XML parser to prune empty element, this line should not be added in all the cases.
        if (elementIsNested) {
          newOutPutElement.addCharacters("\n");
          if (isClosedMathContainer || isClosedAnnotation) {
            newOutPutElement.addCharacters(whiteSpaces);
          }
        }

        writeSBMLElements(childXmlObject, newOutPutElement,
            streamWriter, nextObjectToWrite, indent + indentCount);
View Full Code Here

      SMOutputDocument doc = StaxMateSupport.getSmOutputFactory().createOutputDocument( out );

      String nameSpaceUri = getNameSpaceUri();
      SMNamespace nameSpace = doc.getNamespace( nameSpaceUri );

      SMOutputElement root = doc.addElement( nameSpace, getDefaultElementName() );
      serialize( root, object );
      doc.closeRoot();
    } catch ( XMLStreamException e ) {
      throw new IOException( e );
    }
View Full Code Here

   * @throws XMLStreamException
   * @throws IOException
   */
  protected <T> void serializeCollection( @NotNull Iterable<? extends T> objects, @NotNull Class<T> type, @NotNull @NonNls String elementName, @NotNull SMOutputElement serializeTo ) throws XMLStreamException, IOException {
    for ( T object : objects ) {
      SMOutputElement doorElement = serializeTo.addElement( serializeTo.getNamespace(), elementName );
      getSerializer( type ).serialize( doorElement, object );
    }
  }
View Full Code Here

   * @param serializeTo           the object the elements are serialized to
   * @throws XMLStreamException
   * @throws IOException
   */
  protected <T> void serializeCollectionToElement( @NotNull Iterable<? extends T> objects, @NotNull Class<T> type, @NotNull @NonNls String collectionElementName, @NotNull @NonNls String elementName, @NotNull SMOutputElement serializeTo ) throws XMLStreamException, IOException {
    SMOutputElement collectionElement = serializeTo.addElement( serializeTo.getNamespace(), collectionElementName );
    serializeCollection( objects, type, elementName, collectionElement );
  }
View Full Code Here

  @Override
  public void serialize( @NotNull SMOutputElement serializeTo, @NotNull Application object ) throws IOException, XMLStreamException {
    serializeTo.addElement( serializeTo.getNamespace(), ELEMENT_NAME ).addCharacters( object.getName() );

    SMOutputElement versionElement = serializeTo.addElement( serializeTo.getNamespace(), ELEMENT_VERSION );
    versionSerializer.serialize( versionElement, object.getVersion() );


  }
View Full Code Here

TOP

Related Classes of org.codehaus.staxmate.out.SMOutputElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.