Exemple #1
0
 @Override
 public void startElement(String uri, String localName, String qName, Attributes atts)
     throws SAXException {
   if ("".equals(uri)) {
     super.startElement(namespace, localName, qName, atts);
   } else {
     super.startElement(uri, localName, qName, atts);
   }
 }
  /** {@inheritDoc} */
  @Override
  public void characters(char[] ch, int start, int length) throws SAXException {
    if (!skipProperty) {
      super.characters(ch, start, length);
    } else {
      if (invalue) {
        invalue = false;
        // Arrays.copyOfRange(ch, start, start + length)
        char[] range = new char[length];
        System.arraycopy(ch, start, range, 0, length);
        String textContent = new String(range);

        // skip only if filter() say so
        boolean skip = filter(textContent, lastNodeName);

        if (!skip) {
          while (!elementBuffer.isEmpty()) {
            BufferedElement be = elementBuffer.remove(0);
            super.startElement(be.getUri(), be.getLocalName(), be.getQName(), be.getAtts());
          }
          super.characters(ch, start, length);
          skipProperty = false;
        }
      }
    }
  }
Exemple #3
0
 public void startElement(
     java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes atts)
     throws SAXException {
   // emit namespace declarations as attributes
   setNSDeclAsAttr(atts);
   super.startElement(uri, localName, qName, atts);
 }
Exemple #4
0
  public void startElement(String namespaceUri, String localName, String qname, Attributes atts)
      throws SAXException {
    // System.out.println(getClass().getName()+".startElement ns=" + namespaceUri + ", name=" +
    // localName + ", qname=" + qname);

    StackContext stackEntry = stack.peek();
    SaxPath saxPathParent = stackEntry.saxPath;

    SaxPath saxPath;
    if (saxPathParent == null) {
      saxPath = new SaxPath(context.getNameTable(), namespaceUri, localName, qname, atts);
    } else {
      saxPath = new SaxPath(namespaceUri, localName, qname, atts, saxPathParent);
    }
    SaxEventBufferBuilder bufferBuilder = stackEntry.bufferBuilder;
    // System.out.println(getClass().getName()+".startElement matched");
    // if (saxPathParent == null) {
    if (level == 0) {
      bufferBuilder = new SaxEventBufferBuilder();
      bufferBuilder.startDocument();
      Iterator<Map.Entry<String, String>> iter = prefixMap.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String, String> entry = iter.next();
        bufferBuilder.startPrefixMapping(entry.getValue(), entry.getKey());
      }
    }
    if (bufferBuilder != null) {
      bufferBuilder.startElement(namespaceUri, localName, qname, atts);
    }
    stack.push(new StackContext(saxPath, bufferBuilder));

    super.startElement(namespaceUri, localName, qname, atts);
    ++level;
    // System.out.println(getClass().getName()+".startElement " + qname + " leave");
  }
 /**
  * Checks if element is {@code isbn} element.
  *
  * <p>
  *
  * @see org.xml.sax.helpers.XMLFilterImpl#startElement(java.lang.String, java.lang.String,
  *     java.lang.String, org.xml.sax.Attributes)
  */
 @Override
 public void startElement(String uri, String localName, String qName, Attributes atts)
     throws SAXException {
   if (ISBN_TAG.equalsIgnoreCase(localName)) {
     workingOnIsbnElement = true;
   }
   super.startElement(uri, localName, qName, atts);
 }
  private void createStyleElement(String namespaceURI, String styleSheet) throws SAXException {
    AttributesImpl newAttrs = new AttributesImpl();
    newAttrs.addAttribute(
        ATTRIBUTE_URI, ATTRIBUTE_TYPE, ATTRIBUTE_TYPE, ATTRIBUTE_CDATA, ATTRIBUTE_VALUE_TEXT_CSS);

    super.startElement(namespaceURI, STYLE_ELEMENT_NAME, STYLE_ELEMENT_NAME, newAttrs);

    // now write the style sheet
    char[] text = styleSheet.toCharArray();
    super.characters(text, 0, text.length);
  }
 /**
  * Write a start tag.
  *
  * <p>Each tag will begin on a new line, and will be indented by the current indent step times the
  * number of ancestors that the element has.
  *
  * <p>The newline and indentation will be passed on down the filter chain through regular
  * characters events.
  *
  * @param uri The element's Namespace URI.
  * @param localName The element's local name.
  * @param qName The element's qualified (prefixed) name.
  * @param atts The element's attribute list.
  * @exception org.xml.sax.SAXException If there is an error writing the start tag, or if a filter
  *     further down the chain raises an exception.
  * @see XMLWriter#startElement(String, String, String,Attributes)
  */
 public void startElement(String uri, String localName, String qName, Attributes atts)
     throws SAXException {
   stateStack.push(SEEN_ELEMENT);
   state = SEEN_NOTHING;
   if (depth > 0) {
     writeNewLine();
   }
   doIndent();
   super.startElement(uri, localName, qName, atts);
   depth++;
 }
Exemple #8
0
 public void startElement(String uri, String localName, String qName, Attributes atts)
     throws SAXException {
   if (!isPruning() && localName.equals(this.tagName)) {
     this.depth = 1;
     return;
   }
   if (isPruning()) {
     this.depth++;
     return;
   }
   super.startElement(uri, localName, qName, atts);
 }
  /**
   * {@inheritDoc}
   *
   * @see org.xml.sax.helpers.XMLFilterImpl#startElement(java.lang.String, java.lang.String,
   *     java.lang.String, org.xml.sax.Attributes)
   */
  @Override
  public void startElement(String uri, String localName, String qName, Attributes attrs)
      throws SAXException {
    AttributesImpl attributes =
        (attrs instanceof AttributesImpl) ? (AttributesImpl) attrs : new AttributesImpl(attrs);

    int length = attributes.getLength();
    for (int i = 0; i < length; ++i) {
      attributes.setValue(i, this.replace(attributes.getValue(i)));
    }

    super.startElement(uri, localName, qName, attributes);
  }
 @Override
 public void startElement(
     String namespaceURI, String localName, String qualifiedName, Attributes attrs)
     throws SAXException {
   if (!localName.equals(LINK_ELEMENT_NAME)) {
     super.startElement(namespaceURI, localName, qualifiedName, attrs);
   } else if (isStyleSheet(attrs)) {
     String href = XmlUtil.getAttributesValue(attrs, ATTRIBUTE_HREF);
     String styleSheet = fetchStyleSheet(href);
     if (!styleSheet.isEmpty()) {
       mReplacingElement = true;
       createStyleElement(namespaceURI, styleSheet);
     }
   }
 }
Exemple #11
0
    @Override
    public void startElement(String uri, String localName, String name, Attributes atts)
        throws SAXException {
      // Always lower-case element names, for easier XPath matching
      String lower = localName.toLowerCase();

      if (_removeNamespaces) {
        AttributesImpl attributes = new AttributesImpl();
        for (int i = 0; i < atts.getLength(); i++) {
          String local = atts.getLocalName(i);
          String qname = atts.getQName(i);
          if (!XMLConstants.NULL_NS_URI.equals(atts.getURI(i).length())
              && !local.equals(XMLConstants.XMLNS_ATTRIBUTE)
              && !qname.startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) {
            attributes.addAttribute(
                atts.getURI(i), local, qname, atts.getType(i), atts.getValue(i));
          }
        }

        super.startElement(XMLConstants.NULL_NS_URI, lower, lower, attributes);
      } else {
        super.startElement(uri, lower, lower, atts);
      }
    }
Exemple #12
0
  /**
   * Write a start tag.
   *
   * <p>Pass the event on down the filter chain for further processing.
   *
   * @param uri The Namespace URI, or the empty string if none is available.
   * @param localName The element's local (unprefixed) name (required).
   * @param qName The element's qualified (prefixed) name, or the empty string is none is available.
   *     This method will use the qName as a template for generating a prefix if necessary, but it
   *     is not guaranteed to use the same qName.
   * @param atts The element's attribute list (must not be null).
   * @exception org.xml.sax.SAXException If there is an error writing the start tag, or if a handler
   *     further down the filter chain raises an exception.
   * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String,
   *     java.lang.String, org.xml.sax.Attributes)
   */
  public void startElement(String uri, String localName, String qName, Attributes atts)
      throws SAXException {
    try {
      if (!startTagIsClosed) {
        write(">");
      }
      elementLevel++;
      //            nsSupport.pushContext();

      write('<');
      write(qName);
      writeAttributes(atts);

      // declare namespaces specified by the startPrefixMapping methods
      if (!locallyDeclaredPrefix.isEmpty()) {
        for (Map.Entry<String, String> e : locallyDeclaredPrefix.entrySet()) {
          String p = e.getKey();
          String u = e.getValue();
          if (u == null) {
            u = "";
          }
          write(' ');
          if ("".equals(p)) {
            write("xmlns=\"");
          } else {
            write("xmlns:");
            write(p);
            write("=\"");
          }
          char ch[] = u.toCharArray();
          writeEsc(ch, 0, ch.length, true);
          write('\"');
        }
        locallyDeclaredPrefix.clear(); // clear the contents
      }

      //            if (elementLevel == 1) {
      //                forceNSDecls();
      //            }
      //            writeNSDecls();
      super.startElement(uri, localName, qName, atts);
      startTagIsClosed = false;
    } catch (IOException e) {
      throw new SAXException(e);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void startElement(String uri, String localName, String qName, Attributes atts)
      throws SAXException {

    String svname = atts.getValue("sv:name");
    if ("sv:node".equals(qName)) {
      lastNodeName = svname;
    } else if ("sv:property".equals(qName) && (getFilteredPropertyName().equals(svname))) {
      elementBuffer.add(new BufferedElement(uri, localName, qName, new AttributesImpl(atts)));

      skipProperty = true;
      invalue = false;
    } else if (skipProperty && "sv:value".equals(qName)) {
      elementBuffer.add(new BufferedElement(uri, localName, qName, new AttributesImpl(atts)));
      invalue = true;
    }

    if (skipProperty) {
      return;
    }
    super.startElement(uri, localName, qName, atts);
  }
Exemple #14
0
  public void startElement(
      String namespaceURI, String localName, String qName, Attributes attributes)
      throws SAXException {
    try {
      charsAdded = false;

      writePrintln();
      indent();
      writer.write("<");
      writer.write(qName);
      writeNamespaces();
      writeAttributes(attributes);
      writer.write(">");
      ++indentLevel;
      lastOutputNodeType = Node.ELEMENT_NODE;
      lastElementClosed = false;

      super.startElement(namespaceURI, localName, qName, attributes);
    } catch (IOException e) {
      handleException(e);
    }
  }
  @Override
  public void startElement(String uri, String localName, String qName, Attributes atts)
      throws SAXException {
    super.startElement(uri, localName, qName, atts);

    if (uri != null && uri.equals(XSPEC_NS) && localName.equals("pendingTests")) {
      pendingWrapper++;
    }

    if (uri != null
        && uri.equals(XSPEC_NS)
        && localName.equals("scenario")
        && atts.getValue("pendingTests") != null) {
      pendingWrapper++;
      pendingScenario = true;
    }

    if (uri != null && uri.equals(XSPEC_NS) && localName.equals("expect")) {
      if (pendingWrapper > 0) {
        pendingTests++;
      }
      tests++;
    }
  }
Exemple #16
0
 /**
  * <i>[SAX ContentHandler interface support]</i> Receives notification of the beginning of an
  * element.
  *
  * <p>This implementation ensures that startDocument() has been called prior processing an
  * element.
  *
  * @param nsURI the Namespace URI, or the empty string if the element has no Namespace URI or if
  *     Namespace processing is not being performed.
  * @param localName the local name (without prefix), or the empty string if Namespace processing
  *     is not being performed.
  * @param qName the qualified name (with prefix), or the empty string if qualified names are not
  *     available.
  * @param atts The attributes attached to the element. If there are no attributes, it shall be
  *     an empty Attributes object.
  * @throws SAXException if any error occurred while creating the document builder.
  */
 public void startElement(String nsURI, String localName, String qName, Attributes atts)
     throws SAXException {
   this.ensureInitialization();
   super.startElement(nsURI, localName, qName, atts);
 }
 /**
  * SAX ContentHandler API.
  *
  * <p>Captured here only to detect the end of the prolog so that we can ignore subsequent
  * oasis-xml-catalog PIs. Otherwise the events are just passed through.
  */
 public void startElement(String uri, String localName, String qName, Attributes atts)
     throws SAXException {
   allowXMLCatalogPI = false;
   super.startElement(uri, localName, qName, atts);
 }