Package org.sbml.jsbml.xml

Examples of org.sbml.jsbml.xml.XMLNode


            .newInstance();
       
        if (elementName.equals("notes")
            && contextObject instanceof SBase) {
          SBase sbase = (SBase) contextObject;
          sbase.setNotes(new XMLNode(new XMLTriple("notes", null, null), new XMLAttributes()));
        } else if (elementName.equals("annotation")
            && contextObject instanceof SBase) {
          SBase sbase = (SBase) contextObject;
          Annotation annotation = (Annotation) newContextObject;
          sbase.setAnnotation(annotation);
View Full Code Here


   * (non-Javadoc)
   *
   * @see org.sbml.jlibsbml.SBase#appendNotes(java.lang.String)
   */
  public void appendNotes(String notes) {
    XMLNode addedNotes = XMLNode.convertStringToXMLNode(StringTools
        .toXMLNotesString(notes));
    if (isSetNotes()) {
      XMLNode oldNotes = notesXMLNode.clone();
      appendNotes(addedNotes);
      firePropertyChange(TreeNodeChangeEvent.notes, oldNotes, notesXMLNode);
    } else {
      setNotes(addedNotes);
    }
View Full Code Here

    //     (notesType is NotesAny.)
    //


    NOTES_TYPE addedNotesType = NOTES_TYPE.NotesAny;
    XMLNode   addedNotes = new XMLNode();
   
    //------------------------------------------------------------
    //
    // STEP1 : identifies the type of the given notes
    //
    //------------------------------------------------------------

    if (name == "notes")
    {
      /* check for notes tags on the added notes and strip if present and
           the notes tag has "html" or "body" element */

        if (notes.getChildCount() > 0
        {
          // notes.getChildAt(0) must be "html", "body", or any XHTML
          // element that would be permitted within a "body" element
          // (e.g. <p>..</p>,  <br>..</br> and so forth).

          String cname = notes.getChildAt(0).getName();

          if (cname == "html")
          {
            addedNotes = notes.getChildAt(0);
            addedNotesType = NOTES_TYPE.NotesHTML;
          }
          else if (cname == "body")
          {
            addedNotes = notes.getChildAt(0);
            addedNotesType = NOTES_TYPE.NotesBody;
          }
          else
          {
            // the notes tag must NOT be stripped if notes.getChildAt(0) node
            // is neither "html" nor "body" element because the children of
            // the addedNotes will be added to the current notes later if the node
            // is neither "html" nor "body".
            addedNotes = notes;
            addedNotesType = NOTES_TYPE.NotesAny;
          }
        }
        else
        {
          // the given notes is empty
            // TODO : log an error
          return;
        }
      }
      else
      {
        // if the XMLNode argument notes has been created from a string and
        // it is a set of subelements there may be a single empty node
        // as parent - leaving this in doesn't affect the writing out of notes
        // but messes up the check for correct syntax
       
        // TODO : check that we are doing that when parsing a String into XMLNode
       
        if (!notes.isStart() && !notes.isEnd() && !notes.isText() )
        {
          if (notes.getChildCount() > 0)
          {
            addedNotes = notes;
            addedNotesType = NOTES_TYPE.NotesAny;
          }
          else
          {
            // the given notes is empty
            return;
          }
        }
        else
        {
          if (name == "html")
          {
            addedNotes = notes;
            addedNotesType = NOTES_TYPE.NotesHTML;
          }
          else if (name == "body")
          {
            addedNotes = notes;
            addedNotesType = NOTES_TYPE.NotesBody;
          }
          else
          {
            // The given notes node needs to be added to a parent node
            // if the node is neither "html" nor "body" element because the
            // children of addedNotes will be added to the current notes later if the
            // node is neither "html" nor "body" (i.e. any XHTML element that
            // would be permitted within a "body" element)
            addedNotes.addChild(notes);
            addedNotesType = NOTES_TYPE.NotesAny;
          }
        }
      }

      //
      // checks the addedNotes of "html" if the html tag contains "head" and
      // "body" tags which must be located in this order.
      //
      if (addedNotesType == NOTES_TYPE.NotesHTML)
      {
        if ((addedNotes.getChildCount() != 2) ||
            ( (addedNotes.getChildAt(0).getName() != "head") ||
              (addedNotes.getChildAt(1).getName() != "body")
            )
           )
        {
          // TODO : log an error to the user or throw an exception or both ?         
          return;
        }
      }

      // We do not have a Syntax checker working on XMLNode !!       
      // check whether notes is valid xhtml ?? (libsbml is doing that)

      if ( notesXMLNode != null )
      {
        //------------------------------------------------------------
        //
        //  STEP2: identifies the type of the existing notes
        //
        //------------------------------------------------------------

        NOTES_TYPE curNotesType   = NOTES_TYPE.NotesAny;
        XMLNode  curNotes = notesXMLNode;

        // curNotes.getChildAt(0) must be "html", "body", or any XHTML
        // element that would be permitted within a "body" element .

        String cname = curNotes.getChildAt(0).getName();
     
        if (cname == "html")
        {
          XMLNode curHTML = curNotes.getChildAt(0);
          //
          // checks the curHTML if the html tag contains "head" and "body" tags
          // which must be located in this order, otherwise nothing will be done.
          //
          if ((curHTML.getChildCount() != 2) ||
              ( (curHTML.getChildAt(0).getName() != "head") ||
                (curHTML.getChildAt(1).getName() != "body")
              )
             )
          {
            // TODO : log an error
            return;
          }
          curNotesType = NOTES_TYPE.NotesHTML;
        }
        else if (cname == "body")
        {
          curNotesType = NOTES_TYPE.NotesBody;
        }
        else
        {
          curNotesType = NOTES_TYPE.NotesAny;
        }
     
        /*
         * BUT we also have the issue of the rules relating to notes
         * contents and where to add them ie we cannot add a second body element
         * etc...
         */

        //------------------------------------------------------------
        //
        //  STEP3: appends the given notes to the current notes
        //
        //------------------------------------------------------------
     
        int i;
     
        if (curNotesType == NOTES_TYPE.NotesHTML)
        {
          XMLNode curHTML = curNotes.getChildAt(0);
          XMLNode curBody = curHTML.getChildAt(1);
         
          if (addedNotesType == NOTES_TYPE.NotesHTML)
          {
            // adds the given html tag to the current html tag
     
            XMLNode addedBody = addedNotes.getChildAt(1);  
     
            for (i=0; i < addedBody.getChildCount(); i++)
            {
              if (curBody.addChild(addedBody.getChildAt(i)) < 0 )
              // TODO : log an error
                return;         
            }
          }
          else if ((addedNotesType == NOTES_TYPE.NotesBody) || (addedNotesType == NOTES_TYPE.NotesAny))
          {
            // adds the given body or other tag (permitted in the body) to the current
            // html tag
     
            for (i=0; i < addedNotes.getChildCount(); i++)
            {
              if (curBody.addChild(addedNotes.getChildAt(i)) < 0 )
              // TODO : log an error
                return;
            }
          }
        }
        else if (curNotesType == NOTES_TYPE.NotesBody)
        {
          if (addedNotesType == NOTES_TYPE.NotesHTML)
          {
            // adds the given html tag to the current body tag
     
            XMLNode addedHTML = new XMLNode(addedNotes);
            XMLNode addedBody = addedHTML.getChildAt(1);
            XMLNode curBody   = curNotes.getChildAt(0);
     
            for (i=0; i < curBody.getChildCount(); i++)
            {
              addedBody.insertChild(i,curBody.getChildAt(i));
            }
           
            curNotes.removeChildren();
            if (curNotes.addChild(addedHTML) < 0)
              // TODO : log an error
              return;
          }
          else if ((addedNotesType == NOTES_TYPE.NotesBody) || (addedNotesType == NOTES_TYPE.NotesAny))
          {
            // adds the given body or other tag (permitted in the body) to the current
            // body tag
     
            XMLNode curBody = curNotes.getChildAt(0);
     
            for (i=0; i < addedNotes.getChildCount(); i++)
            {
              if (curBody.addChild(addedNotes.getChildAt(i)) < 0)
              // TODO : log an error
                return;
            }
          }
        }
        else if (curNotesType == NOTES_TYPE.NotesAny)
        {
          if (addedNotesType == NOTES_TYPE.NotesHTML)
          {
            // adds the given html tag to the current any tag permitted in the body.
     
            XMLNode addedHTML = new XMLNode(addedNotes);
            XMLNode addedBody = addedHTML.getChildAt(1);
     
            for (i=0; i < curNotes.getChildCount(); i++)
            {
              addedBody.insertChild(i,curNotes.getChildAt(i));
            }
     
            curNotes.removeChildren();
            if (curNotes.addChild(addedHTML) < 0)
              // TODO : log an error
              return;
          }
          else if (addedNotesType == NOTES_TYPE.NotesBody)
          {
            // adds the given body tag to the current any tag permitted in the body.
     
            XMLNode addedBody = new XMLNode(addedNotes);
     
            for (i=0; i < curNotes.getChildCount(); i++)
            {
              addedBody.insertChild(i,curNotes.getChildAt(i));
            }
     
            curNotes.removeChildren();
            if (curNotes.addChild(addedBody) < 0)
              // TODO : log an error
View Full Code Here

  /*
   * (non-Javadoc)
   * @see org.sbml.jsbml.SBase#setNotes(java.lang.String)
   */
  public void setNotes(XMLNode notes) {
    XMLNode oldNotes = this.notesXMLNode;
    this.notesXMLNode = notes;
    this.notesXMLNode.setParent(this);
    firePropertyChange(TreeNodeChangeEvent.notes, oldNotes, this.notesXMLNode);
  }
View Full Code Here

   *
   * @see org.sbml.jlibsbml.SBase#unsetNotes()
   */
  public void unsetNotes() {
    if (isSetNotes()) {
      XMLNode oldNotes = notesXMLNode;
      notesXMLNode = null;
      firePropertyChange(TreeNodeChangeEvent.notes, oldNotes, getNotes());
    }
  }
View Full Code Here

   
    logger.debug("processAttribute : attribute name = " + attributeName + ", value = " + value);
   
    if (contextObject instanceof XMLNode) {
     
      XMLNode xmlNode = (XMLNode) contextObject;
      xmlNode.addAttr(attributeName, value, null, prefix);
     
     
    } else {
      logger.debug("processAttribute : context Object is not an XMLNode !!! " + contextObject);
    }
View Full Code Here

   
    logger.debug("processCharactersOf called : characters = @" + characters + "@");
   
    // characters = StringTools.encodeForHTML(characters); // TODO : use an apache util for that.

    XMLNode textNode = new XMLNode(characters);

    if (contextObject instanceof XMLNode) {
     
      XMLNode xmlNode = (XMLNode) contextObject;

      xmlNode.addChild(textNode);
     
    } else if (contextObject instanceof SBase) {
      SBase parentSBMLElement = (SBase) contextObject;
     
      XMLNode xmlNode = null;

      if (parentSBMLElement.isSetNotes() && typeOfNotes.equals("notes"))
      {
        xmlNode = parentSBMLElement.getNotes();
      }
      else if (typeOfNotes.equals("message") && parentSBMLElement instanceof Constraint
          && ((Constraint) parentSBMLElement).isSetMessage())
      {
        xmlNode = ((Constraint) parentSBMLElement).getMessage();
      }
      else
      {
        logger.warn("The type of String " + typeOfNotes + " on the element " +
            parentSBMLElement.getElementName() + " is unknown !! Some data might be lost");
        return;
      }

      xmlNode.addChild(textNode);
     
    } else
      logger.debug("processCharactersOf : context Object is not an XMLNode or SBase !!! " + contextObject);
    }
View Full Code Here

   */
  public boolean processEndElement(String elementName, String prefix,
      boolean isNested, Object contextObject)
  {
    if (contextObject instanceof XMLNode) {
      XMLNode xmlNode = (XMLNode) contextObject;
     
      if (xmlNode.getChildCount() == 0) {
        xmlNode.setEnd();
      }
    }
   
    return true;
  }
View Full Code Here

      String localName, boolean hasAttributes, boolean isLastNamespace,
      Object contextObject)
  {
    if (contextObject instanceof XMLNode) {
     
      XMLNode xmlNode = (XMLNode) contextObject;
      if (!xmlNode.isStart()) {
        logger.debug("processNamespace : context Object is not a start node !!! " + contextObject);
      }
     
      xmlNode.addNamespace(URI, prefix);
     
    } else {
      logger.debug("processNamespace : context Object is not an XMLNode !!! " + contextObject);
      logger.debug("processNamespace : element name = " + elementName + ", namespace = " + prefix + ":" + URI);
    }
View Full Code Here

    logger.debug("processStartElement : element name = " + elementName);
   
    if (elementName.equals("notes")
        && (contextObject instanceof SBase)) {
      SBase sbase = (SBase) contextObject;
      sbase.setNotes(new XMLNode(new XMLTriple("notes", null, null), new XMLAttributes()));
      return contextObject;
    }
   
    // Creating a StartElement XMLNode !! 
    XMLNode xmlNode = new XMLNode(new XMLTriple(elementName, null, prefix), new XMLAttributes(), new XMLNamespaces());
   
    if (contextObject instanceof SBase) {
      SBase parentSBMLElement = (SBase) contextObject;
     
      if (typeOfNotes.equals("notes")) {
        parentSBMLElement.getNotes().addChild(xmlNode);
      } else if (typeOfNotes.equals("message") && parentSBMLElement instanceof Constraint) {
        ((Constraint) parentSBMLElement).getMessage().addChild(xmlNode);
      } else {
        logger.warn("The type of String " + typeOfNotes + " on the element " +
            parentSBMLElement.getElementName() + " is unknown !! Some data might be lost");
      }
     
    } else if (contextObject instanceof XMLNode) {
      XMLNode parentNode = (XMLNode) contextObject;
     
      parentNode.addChild(xmlNode);
    }
   
    return xmlNode;
  }
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.xml.XMLNode

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.