示例#1
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#endCommentBlock()
  */
 @Override
 public void endCommentBlock() throws IOException {
   if (!levels.inComment()) throw new IOException("cannot close a comment block when it is open");
   if (!levels.current().isInComment())
     throw new IOException("cannot close a comment block when it is open");
   if (isPretty()) writePretty();
   write("-->");
   if (isPretty()) writePretty();
   levels.current().setInComment(false);
 }
示例#2
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#close(java.lang.String)
  */
 @Override
 public void close(String name) throws IOException {
   checkStarted();
   if (levels.empty())
     throw new IOException("Unable to close null|" + name + ", nothing to close");
   if (levels.current().getNamespace() != null || !levels.current().getName().equals(name))
     throw new IOException(
         "Unable to close null|"
             + name
             + ", found "
             + levels.current().getNamespace()
             + "|"
             + levels.current().getName());
   close();
 }
示例#3
0
  /* (non-Javadoc)
   * @see org.eclipse.ohf.utilities.xml.IXMLWriter#open(java.lang.String, java.lang.String, java.lang.String)
   */
  @Override
  public void open(String namespace, String name, String comment) throws IOException {
    if (!XMLUtil.isNMToken(name)) throw new IOException("XML name " + name + " is not valid");
    checkStarted();
    if (pendingClose) {
      write('>');
      writePendingComment();
      pendingClose = false;
    }

    if (name == null) {
      throw new IOException("name is null");
    }
    newLevelIfRequired();
    levels.current().setName(name);
    levels.current().setNamespace(namespace);
    int col = writePretty();
    write('<');
    if (namespace == null) {
      write(name);
      col = col + name.length() + 1;
    } else {
      String n = getNSAbbreviation(namespace) + name;
      write(n);
      col = col + n.length() + 1;
    }
    writeAttributes(col);
    pendingOpen = false;
    pendingClose = true;
    pendingComment = comment;
  }
示例#4
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#startCommentBlock()
  */
 @Override
 public void startCommentBlock() throws IOException {
   if (levels.inComment()) throw new IOException("cannot nest comments");
   levels.current().setInComment(true);
   if (isPretty()) writePretty();
   write("<!--");
   if (isPretty()) writePretty();
 }
示例#5
0
 private void newLevelIfRequired() throws IOException {
   if (!pendingOpen) {
     if (!levels.empty()) levels.current().seeChild();
     XMLWriterState level = new XMLWriterState();
     level.setPretty(isPretty());
     levels.push(level);
     pendingOpen = true;
   }
 }
示例#6
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#close()
  */
 @Override
 public void close() throws IOException {
   checkStarted();
   if (levels.empty()) {
     super.close();
   } else {
     if (pendingClose) {
       write("/>");
       writePendingComment();
       pendingClose = false;
     } else {
       if (levels.current().hasChildren()) writePretty();
       write("</");
       if (levels.current().getNamespace() == null) write(levels.current().getName());
       else write(getNSAbbreviation(levels.current().getNamespace()) + levels.current().getName());
       write('>');
     }
     levels.pop();
   }
 }
示例#7
0
  private void defineNamespace(String namespace, String abbrev) throws IOException {
    checkStarted();
    if (namespace != null && !namespace.equals("")) {
      if ("".equals(abbrev)) abbrev = null;

      newLevelIfRequired();

      levels.current().addNamespaceDefn(namespace, abbrev);
      if (abbrev == null) addAttribute("xmlns", namespace);
      else addAttribute("xmlns:" + abbrev, namespace);
    }
  }
示例#8
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#setPretty(boolean)
  */
 @Override
 public void setPretty(boolean pretty) throws IOException {
   if (levels == null || levels.empty()) this.prettyBase = pretty;
   else levels.current().setPretty(pretty);
 }
示例#9
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#isPretty()
  */
 @Override
 public boolean isPretty() throws IOException {
   return (levels == null || levels.empty()) ? prettyBase : levels.current().isPretty();
 }