Esempio n. 1
0
  /**
   * This method is called when a new attribute of an XML element is encountered.
   *
   * @param key the key (name) of the attribute
   * @param nsPrefix the prefix used to identify the namespace
   * @param nsSystemID the system ID associated with the namespace
   * @param value the value of the attribute
   * @param type the type of the attribute ("CDATA" if unknown)
   * @throws java.lang.Exception If an exception occurred while processing the event.
   */
  public void addAttribute(
      String key, String nsPrefix, String nsSystemID, String value, String type) throws Exception {
    XMLElement top = (XMLElement) this.stack.peek();

    if (top.hasAttribute(key)) {
      throw new XMLParseException(
          top.getSystemID(), top.getLineNr(), "Duplicate attribute: " + key);
    }

    top.setAttribute(key, value);
  }
Esempio n. 2
0
 /**
  * Writes the figures to the specified output stream.
  * This method applies the specified drawingTransform to the drawing, and draws
  * it on an image of the specified getChildCount.
  * 
  * All other write methods delegate their work to here.
  */
 public void write(OutputStream out, java.util.List<Figure> figures,
         AffineTransform drawingTransform, Dimension imageSize) throws IOException {
     
     this.drawingTransform = (drawingTransform == null) ? new AffineTransform() : drawingTransform;
     this.bounds = (imageSize == null) ? 
         new Rectangle(0,0,Integer.MAX_VALUE,Integer.MAX_VALUE) :
         new Rectangle(0, 0, imageSize.width, imageSize.height);
     
     XMLElement document = new XMLElement("map");
     
     // Note: Image map elements need to be written from front to back
     for (Figure f: new ReversedList<Figure>(figures)) {
         writeElement(document, f);
     }
     
     // Strip AREA elements with "nohref" attributes from the end of the
     // map
     if (! isIncludeNohref) {
         for (int i=document.getChildrenCount() - 1; i >= 0; i--) {
             XMLElement child = (XMLElement) document.getChildAtIndex(i);
             if (child.hasAttribute("nohref")) {
                 document.removeChildAtIndex(i);
             }
         }
     }
     
     
     // Write XML content
     PrintWriter writer = new PrintWriter(
             new OutputStreamWriter(out, "UTF-8")
             );
     //new XMLWriter(writer).write(document);
     for (Object o : document.getChildren()) {
         XMLElement child = (XMLElement) o;
         new XMLWriter(writer).write(child);
     }
     
     // Flush writer
     writer.flush();
 }