f.setContentHandler(validator); out = new ForkXmlOutput( new SAXOutput(f) { @Override
/** * <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".</p> * * @throws SAXException if any error occurred while creating * the document builder. */ @Override 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(); }
@Override public void setContentHandler(ContentHandler contentHandler) { if(contentHandler==null) contentHandler = DUMMY; super.setContentHandler(contentHandler); }
/** * Starts cutting a sub-tree. Should be called from within the * {@link #startElement(String, String, String, Attributes)} implementation * before the execution is passed to {@link SubtreeCutter#startElement(String, String, String, Attributes)} . * The current element will be cut. */ public void startCutting() { super.setContentHandler(stub); cutDepth=1; }
/** * Wraps the specified content handler by a filter. * It is little awkward to use a helper implementation class like XMLFilterImpl * as the method parameter, but this simplifies the code. */ private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) { filter.setContentHandler(handler); return filter; } }
@Override public void setContentHandler(ContentHandler contentHandler) { if(contentHandler==null) contentHandler = DUMMY; super.setContentHandler(contentHandler); }
/** * Wraps the specified content handler by a filter. * It is little awkward to use a helper implementation class like XMLFilterImpl * as the method parameter, but this simplifies the code. */ private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) { filter.setContentHandler(handler); return filter; } };
/** * Wraps the specified content handler by a filter. * It is little awkward to use a helper implementation class like XMLFilterImpl * as the method parameter, but this simplifies the code. */ private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) { filter.setContentHandler(handler); return filter; } };
/** * Wraps the specified content handler by a filter. * It is little awkward to use a helper implementation class like XMLFilterImpl * as the method parameter, but this simplifies the code. */ private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) { filter.setContentHandler(handler); return filter; } }
@Override public void setContentHandler(ContentHandler contentHandler) { if(contentHandler==null) contentHandler = DUMMY; super.setContentHandler(contentHandler); }
/** * Wraps the specified content handler by a filter. * It is little awkward to use a helper implementation class like XMLFilterImpl * as the method parameter, but this simplifies the code. */ private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) { filter.setContentHandler(handler); return filter; } };
/** pops the previous state from the stack */ public void popState() { State currentState = getCurrentState(); if( currentState.parentState!=null ) super.setContentHandler( currentState.parentState ); else // if the root state is poped, supply a dummy. super.setContentHandler( new org.xml.sax.helpers.DefaultHandler() ); }
f.setContentHandler(validator); out = new ForkXmlOutput( new SAXOutput(f) { @Override
public void setContentHandler(ContentHandler handler) { next = handler; // changes take effect immediately unless the sub-tree is being pruned if(getContentHandler()!=stub) super.setContentHandler(handler); }
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { super.endElement(namespaceURI, localName, qName); if( cutDepth!=0 ) { cutDepth--; if( cutDepth == 1 ) { // pruning completed. restore the user handler super.setContentHandler(next); cutDepth=0; } } } }
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { super.endElement(namespaceURI, localName, qName); if( cutDepth!=0 ) { cutDepth--; if( cutDepth == 1 ) { // pruning completed. restore the user handler super.setContentHandler(next); cutDepth=0; } } } }
/** pushs the current state into the stack and sets new one */ public void pushState( State newState, State parentState, StartTagInfo startTag ) { super.setContentHandler(newState); newState.init( this, parentState, startTag ); // this order of statements ensures that // getCurrentState can be implemented by using getContentHandler() }
SAXTransformerFactory factory = (SAXTransformerFactory)TransformerFactory.newInstance(); TransformerHandler serializer = factory.newTransformerHandler(); Result result = new StreamResult(...); serializer.setResult(result); XMLFilterImpl filter = new MyFilter(); filter.setContentHandler(serializer); XMLReader xmlreader = XMLReaderFactory.createXMLReader(); xmlreader.setFeature("http://xml.org/sax/features/namespaces", true); xmlreader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); xmlreader.setContentHandler(filter); xmlreader.parse(new InputSource(...));
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { super.endElement(namespaceURI, localName, qName); if( cutDepth!=0 ) { cutDepth--; if( cutDepth == 1 ) { // pruning completed. restore the user handler super.setContentHandler(next); cutDepth=0; } } } }
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { super.endElement(namespaceURI, localName, qName); if( cutDepth!=0 ) { cutDepth--; if( cutDepth == 1 ) { // pruning completed. restore the user handler super.setContentHandler(next); cutDepth=0; } } } }