示例#1
0
 public int writePretty(boolean eoln) throws IOException {
   if (isPretty()) {
     if (eoln) write(lineType == LINE_UNIX ? "\n" : "\r\n");
     for (int i = 0; i < levels.size() - 1; i++) write("  ");
     return (levels.size() - 1) * 2;
   } else return 0;
 }
示例#2
0
 protected XMLNamespace findDefaultNamespace() {
   for (int i = levels.size() - 1; i >= 0; i--) {
     XMLNamespace ns = levels.item(i).getDefaultNamespace();
     if (ns != null) return ns;
   }
   return null;
 }
示例#3
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#findByAbbreviation(java.lang.String)
  */
 public XMLNamespace findByAbbreviation(String abbreviation) {
   for (int i = levels.size() - 1; i >= 0; i--) {
     XMLNamespace ns = levels.item(i).getDefnByAbbreviation(abbreviation);
     if (ns != null) return ns;
   }
   return null;
 }
示例#4
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#findByNamespace(java.lang.String)
  */
 public XMLNamespace findByNamespace(String namespace) {
   for (int i = levels.size() - 1; i >= 0; i--) {
     XMLNamespace ns = levels.item(i).getDefnByNamespace(namespace);
     if (ns != null) return ns;
   }
   return null;
 }
示例#5
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();
 }
示例#6
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;
   }
 }
示例#7
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);
 }
示例#8
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();
 }
示例#9
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;
  }
示例#10
0
 private void writePendingComment() throws IOException {
   if (pendingComment != null) {
     if (isPretty()) write("   ");
     if (levels.inComment()) write("<!-- " + pendingComment + " -- >");
     else write("<!-- " + pendingComment + " -->");
   }
 }
示例#11
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#comment(java.lang.String, boolean)
  */
 @Override
 public void comment(String comment, boolean doPretty) throws IOException {
   checkStarted();
   if (pendingClose) {
     write('>');
     writePendingComment();
     pendingClose = false;
   }
   if (doPretty) {
     writePretty();
     if (isPretty()) {
       for (int i = 0; i < levels.size(); i++) write("  ");
     }
   }
   if (levels.inComment()) write("<!-- " + comment + " -- >");
   else write("<!-- " + comment + " -->");
   if (doPretty && !isPretty()) writePretty();
 }
示例#12
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);
    }
  }
示例#13
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();
   }
 }
示例#14
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);
 }
示例#15
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();
 }
示例#16
0
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#closeToLevel(int)
  */
 @Override
 public void closeToLevel(int count) throws IOException {
   while (levels.size() > count) close();
 }