示例#1
0
 /**
  * Puts a new element into the DOM Document. The new element is added as a child to the current
  * element in the DOM document. Then it becomes the current element. The element must be closed
  * using closeElement.
  */
 public void openElement(String tagName) {
   XMLElement newElement = new XMLElement(); // new HashMap(), false, false);
   newElement.setName(tagName);
   current.addChild(newElement);
   stack.push(current);
   current = newElement;
 }
示例#2
0
 /**
  * Adds a text to current element of the DOM Document. Note: Multiple consecutives texts will be
  * merged.
  */
 public void addText(String text) {
   String old = current.getContent();
   if (old == null) {
     current.setContent(text);
   } else {
     current.setContent(old + text);
   }
 }
 /**
  * Returns the attribute for the given attribute name. If no attribute exist, an
  * InstallerException with a detail message is thrown.
  *
  * @param element XML element which should contain the attribute
  * @param attrName key of the attribute
  * @return the attribute as string
  * @throws Exception
  */
 public String getRequiredAttribute(XMLElement element, String attrName)
     throws InstallerException {
   String attr = element.getAttribute(attrName);
   if (attr == null) {
     parseError(element, "<" + element.getName() + "> requires attribute '" + attrName + "'.");
   }
   return (attr);
 }
示例#4
0
 public Object getPrototype() {
   if (prototypes == null) {
     prototypes = new HashMap<String, Object>();
   }
   if (!prototypes.containsKey(current.getName())) {
     prototypes.put(current.getName(), factory.create(current.getName()));
   }
   return prototypes.get(current.getName());
 }
 private XMLElement getXmlElement(Object value, String name) {
   XMLElement xmlElement = new XMLElement(name);
   if (value != null) {
     String string = value.toString();
     if (value instanceof FinanceDate) {
       string = ((FinanceDate) value).toString("-");
     }
     xmlElement.setContent(string);
   }
   return xmlElement;
 }
  /**
   * Returns a XML element which represents the pack for the given name.
   *
   * @param packDestName name of the pack which should be returned
   * @return a XML element which represents the pack for the given name
   */
  public XMLElement getPackForName(String packDestName) {
    Vector packs = getSpec().getChildrenNamed(PACK_KEY);
    Iterator iter = null;
    if (packs == null) return (null);
    iter = packs.iterator();
    while (iter.hasNext()) {

      XMLElement pack = (XMLElement) iter.next();
      String packName = pack.getAttribute(PACK_NAME);
      if (packName.equals(packDestName)) return (pack);
    }
    return (null);
  }
  public static void main(String args[]) throws Exception {
    if (args.length == 0) {
      System.err.println("Usage: java DumpXML file.xml");
      Runtime.getRuntime().exit(1);
    }

    IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
    IXMLReader reader = StdXMLReader.fileReader(args[0]);
    parser.setReader(reader);
    XMLElement xml = (XMLElement) parser.parse();

    xml.addChild(null);
    (new XMLWriter(System.out)).write(xml);
  }
  public static void main(String args[]) throws Exception {
    if (args.length == 0) {
      System.err.println("Usage: java DumpXML file.xml");
      Runtime.getRuntime().exit(1);
    }

    IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
    IXMLReader reader = StdXMLReader.fileReader(args[0]);
    parser.setReader(reader);
    XMLElement xml = (XMLElement) parser.parse();

    Properties prop = xml.getAttributes();
    prop.list(System.out);
  }
  /**
   * Adds the contents of the given stream to the data base. The stream have to contain key value
   * pairs as declared by the DTD langpack.dtd.
   *
   * @param in an InputStream to read the translation from.
   * @throws Exception
   */
  public void add(InputStream in) throws Exception {
    // Initialises the parser
    StdXMLParser parser = new StdXMLParser();
    parser.setBuilder(XMLBuilderFactory.createXMLBuilder());
    parser.setReader(new StdXMLReader(in));
    parser.setValidator(new NonValidator());

    // We get the data
    XMLElement data = (XMLElement) parser.parse();

    // We check the data
    if (!"langpack".equalsIgnoreCase(data.getName()))
      throw new Exception("this is not an IzPack XML langpack file");

    // We fill the Hashtable
    Vector children = data.getChildren();
    int size = children.size();
    for (int i = 0; i < size; i++) {
      XMLElement e = (XMLElement) children.get(i);
      String text = e.getContent();
      if (text != null && !"".equals(text)) {
        put(e.getAttribute("id"), text.trim());
      } else {
        put(e.getAttribute("id"), e.getAttribute("txt"));
      }
    }
  }
  /**
   * Returns whether the value to the given attribute is "yes" or not. If the attribute does not
   * exist, or the value is not "yes" and not "no", the default value is returned.
   *
   * @param element the XML element which contains the attribute
   * @param attribute the name of the attribute
   * @param defaultValue the default value
   * @return whether the value to the given attribute is "yes" or not
   */
  public boolean isAttributeYes(XMLElement element, String attribute, boolean defaultValue) {
    String value = element.getAttribute(attribute, (defaultValue ? YES : NO));
    if (value.equalsIgnoreCase(YES)) return true;
    if (value.equalsIgnoreCase(NO)) return false;

    return defaultValue;
  }
示例#11
0
 /** Writes the contents of the DOMOutput into the specified writer. */
 public void save(Writer out) throws IOException {
   if (doctype != null) {
     out.write("<!DOCTYPE ");
     out.write(doctype);
     out.write(">\n");
   }
   XMLWriter writer = new XMLWriter(out);
   writer.write((XMLElement) document.getChildren().get(0));
 }
示例#12
0
  /** Prints the contents of the DOMOutput into the specified print writer. */
  public void print(PrintWriter out) {
    XMLWriter writer = new XMLWriter(out);

    try {
      // writer.write(document);
      writer.write((XMLElement) document.getChildren().get(0), true);
    } catch (IOException e) {
      InternalError error = new InternalError();
      error.initCause(e);
      throw error;
    }
    // ((XMLElement) document.getChildren().get(0)).print(out);
  }
  // helper function
  private void readChoices(XMLElement element, ArrayList result) {
    Vector choices = element.getChildrenNamed("choice");

    if (choices == null) return;

    result.clear();

    Iterator choice_it = choices.iterator();

    while (choice_it.hasNext()) {
      XMLElement choice = (XMLElement) choice_it.next();

      String value = choice.getAttribute("value");

      if (value != null) {
        List osconstraints = OsConstraint.getOsList(choice);

        if (OsConstraint.oneMatchesCurrentSystem(osconstraints)) {
          result.add(this.vs.substitute(value, "plain"));
        }
      }
    }
  }
  /** helper: process a <code>&lt;classpath&gt;</code> tag. */
  private void changeClassPath(ArrayList classpath, XMLElement child) throws Exception {
    String add = child.getAttribute("add");
    if (add != null) {
      add = this.vs.substitute(add, "plain");
      if (!new File(add).exists()) {
        if (!this.handler.emitWarning(
            "Invalid classpath", "The path " + add + " could not be found.\nCompilation may fail."))
          throw new Exception("Classpath " + add + " does not exist.");
      } else {
        classpath.add(this.vs.substitute(add, "plain"));
      }
    }

    String sub = child.getAttribute("sub");
    if (sub != null) {
      int cpidx = -1;
      sub = this.vs.substitute(sub, "plain");

      do {
        cpidx = classpath.indexOf(sub);
        classpath.remove(cpidx);
      } while (cpidx >= 0);
    }
  }
 /**
  * Returns a Vector with all leafs of the tree which is described with childdef beginning at the
  * given depth.
  *
  * @param root the XMLElement which is the current root for the search
  * @param childdef a String array which describes the tree; the last element contains the leaf
  *     name
  * @param depth depth to start in childdef
  * @return a Vector of XMLElements of all leafs founded under root
  */
 private Vector getSubChildren(XMLElement root, String[] childdef, int depth) {
   Vector retval = null;
   Vector retval2 = null;
   Vector children = root != null ? root.getChildrenNamed(childdef[depth]) : null;
   if (children == null) return (null);
   if (depth < childdef.length - 1) {
     Iterator iter = children.iterator();
     while (iter.hasNext()) {
       retval2 = getSubChildren((XMLElement) iter.next(), childdef, depth + 1);
       if (retval2 != null) {
         if (retval == null) retval = new Vector();
         retval.addAll(retval2);
       }
     }
   } else return (children);
   return (retval);
 }
示例#16
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();
 }
示例#17
0
 /** Adds an attribute to current element of the DOM Document. */
 public void addAttribute(String name, String value) {
   if (value != null) {
     current.setAttribute(name, value);
   }
 }
 /**
  * Create parse error with consistent messages. Includes file name and line # of parent. It is an
  * error for 'parent' to be null.
  *
  * @param parent The element in which the error occured
  * @param message Brief message explaining error
  */
 public void parseError(XMLElement parent, String message) throws InstallerException {
   throw new InstallerException(specFilename + ":" + parent.getLineNr() + ": " + message);
 }
  private CompilationJob collectJobsRecursive(XMLElement node, ArrayList classpath)
      throws Exception {
    Enumeration toplevel_tags = node.enumerateChildren();
    ArrayList ourclasspath = (ArrayList) classpath.clone();
    ArrayList files = new ArrayList();

    while (toplevel_tags.hasMoreElements()) {
      XMLElement child = (XMLElement) toplevel_tags.nextElement();

      if (child.getName().equals("classpath")) {
        changeClassPath(ourclasspath, child);
      } else if (child.getName().equals("job")) {
        CompilationJob subjob = collectJobsRecursive(child, ourclasspath);
        if (subjob != null) this.jobs.add(subjob);
      } else if (child.getName().equals("directory")) {
        String name = child.getAttribute("name");

        if (name != null) {
          // substitute variables
          String finalname = this.vs.substitute(name, "plain");

          files.addAll(scanDirectory(new File(finalname)));
        }

      } else if (child.getName().equals("file")) {
        String name = child.getAttribute("name");

        if (name != null) {
          // substitute variables
          String finalname = this.vs.substitute(name, "plain");

          files.add(new File(finalname));
        }

      } else if (child.getName().equals("packdepency")) {
        String name = child.getAttribute("name");

        if (name == null) {
          System.out.println("invalid compilation spec: <packdepency> without name attribute");
          return null;
        }

        // check whether the wanted pack was selected for installation
        Iterator pack_it = this.idata.selectedPacks.iterator();
        boolean found = false;

        while (pack_it.hasNext()) {
          com.izforge.izpack.Pack pack = (com.izforge.izpack.Pack) pack_it.next();

          if (pack.name.equals(name)) {
            found = true;
            break;
          }
        }

        if (!found) {
          Debug.trace("skipping job because pack " + name + " was not selected.");
          return null;
        }
      }
    }

    if (files.size() > 0)
      return new CompilationJob(
          this.handler,
          this.idata.langpack,
          (String) node.getAttribute("name"),
          files,
          ourclasspath);

    return null;
  }
示例#20
0
 /** Adds an attribute to current element of the DOM Document. */
 public void addAttribute(String name, int value) {
   current.setAttribute(name, Integer.toString(value));
 }
示例#21
0
 /** Adds an attribute to current element of the DOM Document. */
 public void addAttribute(String name, boolean value) {
   current.setAttribute(name, new Boolean(value).toString());
 }
  private boolean readSpec() {
    InputStream input;
    try {
      input = ResourceManager.getInstance().getInputStream(SPEC_RESOURCE_NAME);
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }

    StdXMLParser parser = new StdXMLParser();
    parser.setBuilder(new StdXMLBuilder());
    parser.setValidator(new NonValidator());

    try {
      parser.setReader(new StdXMLReader(input));

      this.spec = (XMLElement) parser.parse();
    } catch (Exception e) {
      System.out.println("Error parsing XML specification for compilation.");
      e.printStackTrace();
      return false;
    }

    if (!this.spec.hasChildren()) return false;

    this.compilerArgumentsList = new ArrayList();
    this.compilerList = new ArrayList();

    // read <global> information
    XMLElement global = this.spec.getFirstChildNamed("global");

    // use some default values if no <global> section found
    if (global != null) {

      // get list of compilers
      this.compilerSpec = global.getFirstChildNamed("compiler");

      if (this.compilerSpec != null) {
        readChoices(this.compilerSpec, this.compilerList);
      }

      this.compilerArgumentsSpec = global.getFirstChildNamed("arguments");

      if (this.compilerArgumentsSpec != null) {
        // basicly perform sanity check
        readChoices(this.compilerArgumentsSpec, this.compilerArgumentsList);
      }
    }

    // supply default values if no useful ones where found
    if (this.compilerList.size() == 0) {
      this.compilerList.add("javac");
      this.compilerList.add("jikes");
    }

    if (this.compilerArgumentsList.size() == 0) {
      this.compilerArgumentsList.add("-O -g:none");
      this.compilerArgumentsList.add("-O");
      this.compilerArgumentsList.add("-g");
      this.compilerArgumentsList.add("");
    }

    return true;
  }
示例#23
0
 /** Adds an attribute to current element of the DOM Document. */
 public void addAttribute(String name, double value) {
   // Remove the awkard .0 at the end of each number
   String str = Double.toString(value);
   if (str.endsWith(".0")) str = str.substring(0, str.length() - 2);
   current.setAttribute(name, str);
 }
示例#24
0
 public static void main(String args[]) throws Exception {
   XMLElement elt = new XMLElement("FOO");
   elt.setAttribute(null, "good");
   XMLWriter writer = new XMLWriter(System.out);
   writer.write(elt);
 }
  public XMLElement toXML() {
    XMLElement glElement = new XMLElement("GLDataLines");

    glElement.addChild(getXmlElement(transactionDate, "TransactionDate"));
    glElement.addChild(getXmlElement(accountID, "AccountID"));
    glElement.addChild(getXmlElement(accountName, "AccountName"));
    glElement.addChild(getXmlElement(transactionDescription, "TransactionDescription"));
    glElement.addChild(getXmlElement(name, "Name"));
    glElement.addChild(getXmlElement(transactionID, "TransactionID"));
    glElement.addChild(getXmlElement(sourceDocumentID, "SourceDocumentID"));
    glElement.addChild(getXmlElement(sourceType, "SourceType"));
    glElement.addChild(getXmlElement(debit, "Debit"));
    glElement.addChild(getXmlElement(credit, "Credit"));
    glElement.addChild(getXmlElement(balance, "Balance"));

    return glElement;
  }