Package nanoxml

Examples of nanoxml.XMLElement


    }
    try {
      final IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
      final IXMLReader reader = new StdXMLReader(new BufferedInputStream(new FileInputStream(configXml)));
      parser.setReader(reader);
      final XMLElement loader = (XMLElement) parser.parse();
      final Vector<XMLElement> scannerElements = loader.getChildren();
      for (XMLElement elem : scannerElements) {
        scanners.add(parseScanner(elem));
      }
      boolean haveDefault = false;
      for (Scanner scanner : scanners) {
View Full Code Here


            LogUtils.warn("cannot save create " + pathToFile, e);
        }
  }

  private void saveScanners(final List<Scanner> scanners) throws IOException {
    final XMLElement saver = new XMLElement();
    saver.setName(ROOT_ELEMENT);
    final String sep = System.getProperty("line.separator");
    final String description = commentLines("Description:" //
        , "" //
        , "<scanner> Scanners are locale dependent. If there is no scanner for" //
        , "the selected locale the scanner marked with default=\"true\" is choosen." //
        , " 'locales': A comma-separated list of locale names." //
        , "   The locale is selected via Preferences -> Environment -> Language" //
        , "   It's a pattern like 'en' (generic English) or 'en_US'" //
        , "   (English/USA). Use the more general two-letter form if appropriate." //
        , " 'default': Set to \"true\" for only one locale. The standard is 'en'." //
        , "" //
        , "<checkfirstchar> allows to enable a fast check for the first input" //
        , "character. If the first input character is not contained in the string" //
        , "given in attribute 'chars' no further attempts are made to parse the" //
        , "input as a number or date." //
        , "Do not use this option if you have have scanner formats that can" //
        , "recognize arbitrary text at the beginning of the pattern. To disable" //
        , "this check omit <checkfirstchar> or add the attribute disabled=\"true\"." //
        , " 'chars': A string of characters that may start data." //
        , "" //
        , "<type> selects the kind of data the scanner should recognize." //
        , " 'style' selects the formatter implementation:" //
        , "  - \"isodate\": flexible ISO date reader for strings like 2011-04-29 22:31:21" //
        , "    Only creates datetimes if time part is given, so no differentiation" //
        , "    between date and date/time is necessary." //
        , "  - \"date\": a special format for dates; needs attribute 'format'. See" //
        , "    http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html" //
        , "  - \"numberliteral\": parses Java float or integral number literals only, with" //
        , "    a dot as decimal separator and no thousands separator. See" //
        , "    http://en.wikibooks.org/wiki/Java_Programming/Literals/Numeric_Literals/Floating_Point_Literals" //
        , "  - \"decimal\": a special format for numbers; needs attribute 'format'. See" //
        , "    http://download.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html" //
        , " 'format': The format code of a \"date\" or \"decimal\" scanner." //
        , " 'comment': Inline comment, not used by the application.");
    final String header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + sep + description;
    for (Scanner scanner : scanners) {
      saver.addChild(scanner.toXml());
    }
    final Writer writer = new FileWriter(pathToFile);
    final XMLWriter xmlWriter = new XMLWriter(writer);
    xmlWriter.addRawContent(header);
    xmlWriter.write(saver, true);
View Full Code Here

  /**
   * @throws IOException
   */
  public void write(final ITreeWriter writer) throws IOException {
    final XMLElement attributeRegistry = new XMLElement();
    boolean toBeSaved = false;
    if (isRestricted()) {
      attributeRegistry.setAttribute("RESTRICTED", "true");
      toBeSaved = true;
    }
    if (!attributeViewType.equals(AttributeTableLayoutModel.SHOW_ALL)) {
      attributeRegistry.setAttribute("SHOW_ATTRIBUTES", attributeViewType);
      toBeSaved = true;
    }
    if (getFontSize() != AttributeRegistry.TABLE_FONT_SIZE) {
      attributeRegistry.setAttribute("FONT_SIZE", Integer.toString(getFontSize()));
      toBeSaved = true;
    }
    for (int i = 0; i < size(); i++) {
      final AttributeRegistryElement element = getElement(i);
      if (element.isRestricted() || element.isVisible() || element.isManual()) {
        final XMLElement attributeData = element.save();
        attributeRegistry.addChild(attributeData);
        toBeSaved = true;
      }
    }
    if (toBeSaved) {
View Full Code Here

  /**
   * Creates the builder.
   */
  public StdXMLBuilder() {
    this(new XMLElement());
  }
View Full Code Here

                           final String type) throws Exception {
    String fullName = key;
    if (nsPrefix != null) {
      fullName = nsPrefix + ':' + key;
    }
    final XMLElement top = stack.peek();
    if (top.hasAttribute(fullName)) {
      throw new XMLParseException(top.getSystemID(), top.getLineNr(), "Duplicate attribute: " + key);
    }
    if (nsPrefix != null) {
      top.setAttribute(fullName, nsURI, value);
    }
    else {
      top.setAttribute(fullName, value);
    }
  }
View Full Code Here

        break;
      }
      str.append(buf, 0, size);
      sizeRead += size;
    }
    final XMLElement elt = prototype.createElement(null, systemID, lineNr);
    elt.setContent(str.toString());
    if (!stack.empty()) {
      final XMLElement top = (XMLElement) stack.peek();
      top.addChild(elt);
    }
  }
View Full Code Here

   *            the URI associated with the namespace. If no namespace has
   *            been specified, or no URI is associated with nsPrefix, this
   *            parameter is null.
   */
  public void endElement(final String name, final String nsPrefix, final String nsURI) {
    final XMLElement elt = (XMLElement) stack.pop();
    if (elt.getChildrenCount() == 1) {
      final XMLElement child = elt.getChildAtIndex(0);
      if (child.getName() == null) {
        elt.setContent(child.getContent());
        elt.removeChildAtIndex(0);
      }
    }
  }
View Full Code Here

                           final int lineNr) {
    String fullName = name;
    if (nsPrefix != null) {
      fullName = nsPrefix + ':' + name;
    }
    final XMLElement elt = new XMLElement(fullName, nsURI, systemID, lineNr);
    last = elt;
    if (stack.empty()) {
      root = elt;
    }
    else {
      final XMLElement top = (XMLElement) stack.peek();
      top.addChild(elt);
    }
    stack.push(elt);
  }
View Full Code Here

* 17.01.2009
*/
public class UnknownElementWriter implements IExtensionAttributeWriter, IExtensionElementWriter {
  public void writeAttributes(final ITreeWriter writer, final Object userObject, final IExtension extension) {
    final UnknownElements elements = (UnknownElements) extension;
    final XMLElement unknownElements = elements.getUnknownElements();
    if (unknownElements != null) {
      final Enumeration<String> unknownAttributes = unknownElements.enumerateAttributeNames();
      while (unknownAttributes.hasMoreElements()) {
        final String name = unknownAttributes.nextElement();
        final String value = unknownElements.getAttribute(name, null);
        writer.addAttribute(name, value);
      }
    }
  }
View Full Code Here

  }

  public void writeContent(final ITreeWriter writer, final Object element, final IExtension extension)
          throws IOException {
    final UnknownElements elements = (UnknownElements) extension;
    final XMLElement unknownElements = elements.getUnknownElements();
    if (unknownElements != null) {
      final Enumeration<XMLElement> unknownChildren = unknownElements.enumerateChildren();
      while (unknownChildren.hasMoreElements()) {
        writer.addElement(null, unknownChildren.nextElement());
      }
    }
  }
View Full Code Here

TOP

Related Classes of nanoxml.XMLElement

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.