Beispiel #1
0
  /**
   * Creates a new {@link WSEndpointReference} by replacing the address of this EPR to the new one.
   *
   * <p>The following example shows how you can use this to force an HTTPS EPR, when the endpoint
   * can serve both HTTP and HTTPS requests.
   *
   * <pre>
   * if(epr.getAddress().startsWith("http:"))
   *   epr = epr.createWithAddress("https:"+epr.getAddress().substring(5));
   * </pre>
   *
   * @param newAddress This is a complete URL to be written inside &lt;Adress> element of the EPR,
   *     such as "http://foo.bar/abc/def"
   */
  public @NotNull WSEndpointReference createWithAddress(@NotNull final String newAddress) {
    MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
    XMLFilterImpl filter =
        new XMLFilterImpl() {
          private boolean inAddress = false;

          public void startElement(String uri, String localName, String qName, Attributes atts)
              throws SAXException {
            if (localName.equals("Address") && uri.equals(version.nsUri)) inAddress = true;
            super.startElement(uri, localName, qName, atts);
          }

          public void characters(char ch[], int start, int length) throws SAXException {
            if (!inAddress) super.characters(ch, start, length);
          }

          public void endElement(String uri, String localName, String qName) throws SAXException {
            if (inAddress) super.characters(newAddress.toCharArray(), 0, newAddress.length());
            inAddress = false;
            super.endElement(uri, localName, qName);
          }
        };
    filter.setContentHandler(xsb.createFromSAXBufferCreator());
    try {
      infoset.writeTo(filter, false);
    } catch (SAXException e) {
      throw new AssertionError(e); // impossible since we are writing from XSB to XSB.
    }

    return new WSEndpointReference(xsb, version);
  }
  /** {@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;
        }
      }
    }
  }
Beispiel #3
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);
   }
 }
 @Override
 public void endElement(String namespaceURI, String localName, String qualifiedName)
     throws SAXException {
   if (!localName.equals(LINK_ELEMENT_NAME)) {
     super.endElement(namespaceURI, localName, qualifiedName);
   } else if (mReplacingElement) {
     super.endElement(namespaceURI, STYLE_ELEMENT_NAME, STYLE_ELEMENT_NAME);
     mReplacingElement = false;
   }
 }
  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);
  }
 /**
  * If character sequence belongs to {@code isbn} element, isbn is validated against regular
  * expression.
  *
  * <p>If pattern does not match, isbn is filtered out.
  *
  * @see org.xml.sax.helpers.XMLFilterImpl#characters(char[], int, int)
  */
 @Override
 public void characters(char[] ch, int start, int length) throws SAXException {
   if (workingOnIsbnElement) {
     String isbn = String.valueOf(ch, start, length);
     Matcher matcher = ISBNPATTERN.matcher(isbn);
     if (matcher.matches()) {
       super.characters(ch, start, length);
     }
   } else {
     super.characters(ch, start, length);
   }
 }
Beispiel #7
0
  public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    try {
      charsAdded = false;
      --indentLevel;

      if (lastElementClosed) {
        writePrintln();
        indent();
      }

      // XXXX: need to determine this using a stack and checking for
      // content / children
      boolean hadContent = true;

      if (hadContent) {
        writeClose(qName);
      } else {
        writeEmptyElementClose(qName);
      }

      lastOutputNodeType = Node.ELEMENT_NODE;
      lastElementClosed = true;

      super.endElement(namespaceURI, localName, qName);
    } catch (IOException e) {
      handleException(e);
    }
  }
Beispiel #8
0
 public void endDocument() throws SAXException {
   // System.out.println(getClass().getName()+".endDocument enter" );
   if (stack != null && !stack.empty()) {
     stack.pop();
   }
   super.endDocument();
 }
 /**
  * Checks if ending element is {@code isbn}.
  *
  * <p>
  *
  * @see org.xml.sax.helpers.XMLFilterImpl#endElement(java.lang.String, java.lang.String,
  *     java.lang.String)
  */
 @Override
 public void endElement(String uri, String localName, String qName) throws SAXException {
   if (ISBN_TAG.equalsIgnoreCase(localName)) {
     workingOnIsbnElement = false;
   }
   super.endElement(uri, localName, qName);
 }
Beispiel #10
0
  public void endElement(String namespaceUri, String localName, String qname) throws SAXException {
    --level;
    // System.out.println(getClass().getName()+".endElement enter " + qname);
    try {
      StackContext stackEntry = stack.peek();
      SaxEventBufferBuilder bufferBuilder = stackEntry.bufferBuilder;
      if (bufferBuilder != null) {
        bufferBuilder.endElement(namespaceUri, localName, qname);
        if (level == 0) {
          bufferBuilder.endDocument();
          SaxEventBuffer buffer = bufferBuilder.getBuffer();
          SaxSource saxSource =
              new SaxEventBufferSource(buffer, "", context.getTransformerFactory());

          DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
          builderFactory.setValidating(false);
          builderFactory.setNamespaceAware(true);
          DocumentBuilder builder = builderFactory.newDocumentBuilder();

          XMLReader reader = saxSource.createXmlReader();
          // InputSource inputSource = new InputSource(reader);
          // Document doc = builder.parse(inputSource);

        }
      }
      stack.pop();
    } catch (ServingXmlException e) {
      throw new SAXException(e.getMessage(), e);
    } catch (Exception e) {
      throw new SAXException(e.getMessage(), e);
    }

    super.endElement(namespaceUri, localName, qname);
    // System.out.println(getClass().getName()+".endElement " + qname + " leave");
  }
Beispiel #11
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);
 }
Beispiel #12
0
 public void endElement(String uri, String localName, String qName) throws SAXException {
   if (isPruning()) {
     this.depth--;
   } else {
     super.endElement(uri, localName, qName);
   }
 }
Beispiel #13
0
    /**
     * <i>[SAX ContentHandler interface support]</i> Processes a start of document event.
     *
     * <p>This implementation creates a new JDOM document builder and marks the current result as
     * "under construction".
     *
     * @throws SAXException if any error occurred while creating the document builder.
     */
    public void startDocument() throws SAXException {
      this.startDocumentReceived = true;

      // Reset any previously set result.
      setResult(null);

      // Create the actual JDOM document builder and register it as
      // ContentHandler on the superclass (XMLFilterImpl): this
      // implementation will take care of propagating the LexicalHandler
      // events.
      this.saxHandler = new FragmentHandler(getFactory());
      super.setContentHandler(this.saxHandler);

      // And propagate event.
      super.startDocument();
    }
Beispiel #14
0
 public void setContentHandler(ContentHandler handler) {
   // System.out.println(getClass().getName()+".setContentHandler " +
   // handler.getClass().getName());
   SaxSink saxSink = new SimpleSaxSink(handler);
   flow = flow.replaceDefaultSaxSink(context, saxSink);
   super.setContentHandler(handler);
 }
Beispiel #15
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");
  }
  /**
   * SAX ContentHandler API.
   *
   * <p>Detect and use the oasis-xml-catalog PI if it occurs.
   */
  public void processingInstruction(String target, String pidata) throws SAXException {
    if (target.equals("oasis-xml-catalog")) {
      URL catalog = null;
      String data = pidata;

      int pos = data.indexOf("catalog=");
      if (pos >= 0) {
        data = data.substring(pos + 8);
        if (data.length() > 1) {
          String quote = data.substring(0, 1);
          data = data.substring(1);
          pos = data.indexOf(quote);
          if (pos >= 0) {
            data = data.substring(0, pos);
            try {
              if (baseURL != null) {
                catalog = new URL(baseURL, data);
              } else {
                catalog = new URL(data);
              }
            } catch (MalformedURLException mue) {
              // nevermind
            }
          }
        }
      }

      if (allowXMLCatalogPI) {
        if (catalogManager.getAllowOasisXMLCatalogPI()) {
          catalogManager.debug.message(4, "oasis-xml-catalog PI", pidata);

          if (catalog != null) {
            try {
              catalogManager.debug.message(4, "oasis-xml-catalog", catalog.toString());
              oasisXMLCatalogPI = true;

              if (piCatalogResolver == null) {
                piCatalogResolver = new CatalogResolver(true);
              }

              piCatalogResolver.getCatalog().parseCatalog(catalog.toString());
            } catch (Exception e) {
              catalogManager.debug.message(
                  3, "Exception parsing oasis-xml-catalog: " + catalog.toString());
            }
          } else {
            catalogManager.debug.message(3, "PI oasis-xml-catalog unparseable: " + pidata);
          }
        } else {
          catalogManager.debug.message(4, "PI oasis-xml-catalog ignored: " + pidata);
        }
      } else {
        catalogManager.debug.message(
            3, "PI oasis-xml-catalog occurred in an invalid place: " + pidata);
      }
    } else {
      super.processingInstruction(target, pidata);
    }
  }
Beispiel #17
0
 public void characters(char[] ch, int start, int length) throws SAXException {
   StackContext stackEntry = stack.peek();
   SaxEventBufferBuilder bufferBuilder = stackEntry.bufferBuilder;
   if (bufferBuilder != null) {
     bufferBuilder.characters(ch, start, length);
   }
   super.characters(ch, start, length);
 }
Beispiel #18
0
 public void setParent(XMLReader parent) {
   super.setParent(parent);
   // if (parent != null) {
   // System.out.println(getClass().getName()+".setParent " + parent.getClass().getName());
   // } else {
   // System.out.println(getClass().getName()+".setParent to null");
   // }
 }
Beispiel #19
0
 public void processingInstruction(String target, String data) throws SAXException {
   StackContext stackEntry = stack.peek();
   SaxEventBufferBuilder bufferBuilder = stackEntry.bufferBuilder;
   if (bufferBuilder != null) {
     bufferBuilder.processingInstruction(target, data);
   }
   super.processingInstruction(target, data);
 }
Beispiel #20
0
 public void skippedEntity(String name) throws SAXException {
   StackContext stackEntry = stack.peek();
   SaxEventBufferBuilder bufferBuilder = stackEntry.bufferBuilder;
   if (bufferBuilder != null) {
     bufferBuilder.skippedEntity(name);
   }
   super.skippedEntity(name);
 }
Beispiel #21
0
 public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
   StackContext stackEntry = stack.peek();
   SaxEventBufferBuilder bufferBuilder = stackEntry.bufferBuilder;
   if (bufferBuilder != null) {
     bufferBuilder.ignorableWhitespace(ch, start, length);
   }
   super.ignorableWhitespace(ch, start, length);
 }
Beispiel #22
0
 /**
  * Write a newline at the end of the document.
  *
  * <p>Pass the event on down the filter chain for further processing.
  *
  * @exception org.xml.sax.SAXException If there is an error writing the newline, or if a handler
  *     further down the filter chain raises an exception.
  * @see org.xml.sax.ContentHandler#endDocument()
  */
 public void endDocument() throws SAXException {
   try {
     super.endDocument();
     flush();
   } catch (IOException e) {
     throw new SAXException(e);
   }
 }
Beispiel #23
0
 /**
  * Write ignorable whitespace.
  *
  * <p>Pass the event on down the filter chain for further processing.
  *
  * @param ch The array of characters to write.
  * @param start The starting position in the array.
  * @param length The number of characters to write.
  * @exception org.xml.sax.SAXException If there is an error writing the whitespace, or if a
  *     handler further down the filter chain raises an exception.
  * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
  */
 public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
   try {
     writeEsc(ch, start, length, false);
     super.ignorableWhitespace(ch, start, length);
   } catch (IOException e) {
     throw new SAXException(e);
   }
 }
Beispiel #24
0
  public void startDocument() throws SAXException {
    // System.out.println(getClass().getName()+".startDocument enter" );
    stack = new Stack<StackContext>();
    stack.push(new StackContext(null, null));
    level = 0;

    super.startDocument();
  }
Beispiel #25
0
  public void startPrefixMapping(String prefix, String uri) throws SAXException {
    if (namespacesMap == null) {
      namespacesMap = new HashMap<String, String>();
    }

    namespacesMap.put(prefix, uri);
    super.startPrefixMapping(prefix, uri);
  }
Beispiel #26
0
 public void startDocument() throws SAXException {
   try {
     writeDeclaration();
     super.startDocument();
   } catch (IOException e) {
     handleException(e);
   }
 }
 /**
  * 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);
 }
 /**
  * Write an end tag.
  *
  * <p>If the element has contained other elements, the tag will appear indented on a new line;
  * otherwise, it will appear immediately following whatever came before.
  *
  * <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.
  * @exception org.xml.sax.SAXException If there is an error writing the end tag, or if a filter
  *     further down the chain raises an exception.
  * @see XMLWriter#endElement(String, String, String)
  */
 public void endElement(String uri, String localName, String qName) throws SAXException {
   depth--;
   if (state == SEEN_ELEMENT) {
     writeNewLine();
     doIndent();
   }
   super.endElement(uri, localName, qName);
   state = stateStack.pop();
 }
Beispiel #29
0
  public void endPrefixMapping(String prefix) throws SAXException {

    StackContext stackEntry = stack.peek();
    SaxEventBufferBuilder bufferBuilder = stackEntry.bufferBuilder;
    if (bufferBuilder != null) {
      bufferBuilder.endPrefixMapping(prefix);
    }

    super.endPrefixMapping(prefix);
  }
Beispiel #30
0
 public void setDocumentLocator(Locator locator) {
   if (stack != null && !stack.empty()) {
     StackContext stackEntry = stack.peek();
     SaxEventBufferBuilder bufferBuilder = stackEntry.bufferBuilder;
     if (bufferBuilder != null) {
       bufferBuilder.setDocumentLocator(locator);
     }
   }
   super.setDocumentLocator(locator);
 }