FileDocCategorySizeDatePackage
TransformerHandlerImpl.javaAPI DocJava SE 6 API14570Tue Jun 10 00:22:34 BST 2008com.sun.org.apache.xalan.internal.xsltc.trax

TransformerHandlerImpl

public class TransformerHandlerImpl extends Object implements TransformerHandler, DeclHandler
Implementation of a JAXP1.1 TransformerHandler
author
Morten Jorgensen

Fields Summary
private TransformerImpl
_transformer
private AbstractTranslet
_translet
private String
_systemId
private SAXImpl
_dom
private ContentHandler
_handler
private LexicalHandler
_lexHandler
private DTDHandler
_dtdHandler
private DeclHandler
_declHandler
private Result
_result
private Locator
_locator
private boolean
_done
private boolean
_isIdentity
A flag indicating whether this transformer handler implements the identity transform.
Constructors Summary
public TransformerHandlerImpl(TransformerImpl transformer)
Cosntructor - pass in reference to a TransformerImpl object


                  
       
	// Save the reference to the transformer
	_transformer = transformer;

	if (transformer.isIdentity()) {
	    // Set initial handler to the empty handler
	    _handler = new DefaultHandler();
	    _isIdentity = true;
	}
	else {
	    // Get a reference to the translet wrapped inside the transformer
	    _translet = _transformer.getTranslet();
	}
    
Methods Summary
public voidattributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)
Implements org.xml.sax.ext.DeclHandler.attributeDecl()

        if (_declHandler != null) {
	    _declHandler.attributeDecl(eName, aName, type, valueDefault, value);
        }
    
public voidcharacters(char[] ch, int start, int length)
Implements org.xml.sax.ContentHandler.characters() Receive notification of character data.

	_handler.characters(ch, start, length);
    
public voidcomment(char[] ch, int start, int length)
Implements org.xml.sax.ext.LexicalHandler.comment() Receieve notification of a comment

 
	if (_lexHandler != null) {
	    _lexHandler.comment(ch, start, length);
	}
    
public voidelementDecl(java.lang.String name, java.lang.String model)
Implements org.xml.sax.ext.DeclHandler.elementDecl()

        if (_declHandler != null) {
	    _declHandler.elementDecl(name, model);
        }
    
public voidendCDATA()
Implements org.xml.sax.ext.LexicalHandler.endCDATA()

 
	if (_lexHandler != null) {
	    _lexHandler.endCDATA();
	}
    
public voidendDTD()
Implements org.xml.sax.ext.LexicalHandler.endDTD()

	if (_lexHandler != null) {
	    _lexHandler.endDTD();
	}
    
public voidendDocument()
Implements org.xml.sax.ContentHandler.endDocument() Receive notification of the end of a document.

	// Signal to the DOMBuilder that the document is complete
	_handler.endDocument();

	if (!_isIdentity) {
	    // Run the transformation now if we have a reference to a Result object
	    if (_result != null) {
		try {
		    _transformer.setDOM(_dom);
		    _transformer.transform(null, _result);
		}
		catch (TransformerException e) {
		    throw new SAXException(e);
		}
	    }
	    // Signal that the internal DOM is built (see 'setResult()').
	    _done = true;

	    // Set this DOM as the transformer's DOM
	    _transformer.setDOM(_dom);
	}
	if (_isIdentity && _result instanceof DOMResult) {
	    ((DOMResult)_result).setNode(_transformer.getTransletOutputHandlerFactory().getNode());
        }
    
public voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qname)
Implements org.xml.sax.ContentHandler.endElement() Receive notification of the end of an element.

	_handler.endElement(namespaceURI, localName, qname);
    
public voidendEntity(java.lang.String name)
Implements org.xml.sax.ext.LexicalHandler.endEntity()

 
	if (_lexHandler != null) {
	    _lexHandler.endEntity(name);
	}
    
public voidendPrefixMapping(java.lang.String prefix)
Implements org.xml.sax.ContentHandler.endPrefixMapping() End the scope of a prefix-URI Namespace mapping.

	_handler.endPrefixMapping(prefix);
    
public voidexternalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
Implements org.xml.sax.ext.DeclHandler.externalEntityDecl()

        if (_declHandler != null) {
	    _declHandler.externalEntityDecl(name, publicId, systemId);
        }
    
public java.lang.StringgetSystemId()
Implements javax.xml.transform.sax.TransformerHandler.getSystemId() Get the base ID (URI or system ID) from where relative URLs will be resolved.

return
The systemID that was set with setSystemId(String id)

	return _systemId;
    
public javax.xml.transform.TransformergetTransformer()
Implements javax.xml.transform.sax.TransformerHandler.getTransformer() Get the Transformer associated with this handler, which is needed in order to set parameters and output properties.

return
The Transformer object

	return _transformer;
    
public voidignorableWhitespace(char[] ch, int start, int length)
Implements org.xml.sax.ContentHandler.ignorableWhitespace() Receive notification of ignorable whitespace in element content. Similar to characters(char[], int, int).

	_handler.ignorableWhitespace(ch, start, length);
    
public voidinternalEntityDecl(java.lang.String name, java.lang.String value)
Implements org.xml.sax.ext.DeclHandler.externalEntityDecl()

        if (_declHandler != null) {
	    _declHandler.internalEntityDecl(name, value);
        }
    
public voidnotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
Implements org.xml.sax.DTDHandler.notationDecl()

        if (_dtdHandler != null) {
	    _dtdHandler.notationDecl(name, publicId, systemId);
        }
    
public voidprocessingInstruction(java.lang.String target, java.lang.String data)
Implements org.xml.sax.ContentHandler.processingInstruction() Receive notification of a processing instruction.

	_handler.processingInstruction(target, data);
    
public voidreset()
Implementation of the reset() method

       _systemId = null;
       _dom = null;
       _handler = null;
       _lexHandler = null;
       _dtdHandler = null;
       _declHandler = null;
       _result = null;
       _locator = null;
   
public voidsetDocumentLocator(org.xml.sax.Locator locator)
Implements org.xml.sax.ContentHandler.setDocumentLocator() Receive an object for locating the origin of SAX document events.

        _locator = locator;

        if (_handler != null) {
            _handler.setDocumentLocator(locator);
        }
    
public voidsetResult(javax.xml.transform.Result result)
Implements javax.xml.transform.sax.TransformerHandler.setResult() Enables the user of the TransformerHandler to set the to set the Result for the transformation.

param
result A Result instance, should not be null
throws
IllegalArgumentException if result is invalid for some reason

	_result = result;

    if (null == result) {
       ErrorMsg err = new ErrorMsg(ErrorMsg.ER_RESULT_NULL);
       throw new IllegalArgumentException(err.toString()); //"result should not be null");
    }    
       
	if (_isIdentity) {
	    try {
		// Connect this object with output system directly
		SerializationHandler outputHandler =
		    _transformer.getOutputHandler(result);
		_transformer.transferOutputProperties(outputHandler);

		_handler = outputHandler;
		_lexHandler = outputHandler;
	    }
	    catch (TransformerException e) {
		_result = null;
	    }
	}
	else if (_done) {
	    // Run the transformation now, if not already done
	    try {
		_transformer.setDOM(_dom);
		_transformer.transform(null, _result);
	    }
	    catch (TransformerException e) {
		// What the hell are we supposed to do with this???
		throw new IllegalArgumentException(e.getMessage());
	    }
	}
    
public voidsetSystemId(java.lang.String id)
Implements javax.xml.transform.sax.TransformerHandler.setSystemId() Get the base ID (URI or system ID) from where relative URLs will be resolved.

param
id Base URI for this stylesheet

	_systemId = id;
    
public voidskippedEntity(java.lang.String name)
Implements org.xml.sax.ContentHandler.skippedEntity() Receive notification of a skipped entity.

	_handler.skippedEntity(name);
    
public voidstartCDATA()
Implements org.xml.sax.ext.LexicalHandler.startCDATA()

 
	if (_lexHandler != null) {
	    _lexHandler.startCDATA();
	}
    
public voidstartDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
Implements org.xml.sax.ext.LexicalHandler.startDTD()

 
	if (_lexHandler != null) {
	    _lexHandler.startDTD(name, publicId, systemId);
	}
    
public voidstartDocument()
Implements org.xml.sax.ContentHandler.startDocument() Receive notification of the beginning of a document.

	// Make sure setResult() was called before the first SAX event
	if (_result == null) {
	    ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SET_RESULT_ERR);
	    throw new SAXException(err.toString());
	}

        if (!_isIdentity) {
            boolean hasIdCall = (_translet != null) ? _translet.hasIdCall() : false;
            XSLTCDTMManager dtmManager = null;
            
            // Create an internal DOM (not W3C) and get SAX2 input handler
            try {
                dtmManager = 
                    (XSLTCDTMManager)_transformer.getTransformerFactory()
                                                 .getDTMManagerClass()
                                                 .newInstance();
            } catch (Exception e) {
                throw new SAXException(e);
            }

            DTMWSFilter wsFilter;
            if (_translet != null && _translet instanceof StripFilter) {
                wsFilter = new DOMWSFilter(_translet);
            } else {
                wsFilter = null;
            }            
          
            // Construct the DTM using the SAX events that come through
            _dom = (SAXImpl)dtmManager.getDTM(null, false, wsFilter, true,
                                              false, hasIdCall);         

            _handler = _dom.getBuilder();
            _lexHandler = (LexicalHandler) _handler;
            _dtdHandler = (DTDHandler) _handler;
            _declHandler = (DeclHandler) _handler;  
            
            
            // Set document URI
            _dom.setDocumentURI(_systemId);
            
            if (_locator != null) {
                _handler.setDocumentLocator(_locator);
            }            
        }

	// Proxy call
	_handler.startDocument();
    
public voidstartElement(java.lang.String uri, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes attributes)
Implements org.xml.sax.ContentHandler.startElement() Receive notification of the beginning of an element.

	_handler.startElement(uri, localName, qname, attributes);
    
public voidstartEntity(java.lang.String name)
Implements org.xml.sax.ext.LexicalHandler.startEntity()

 
	if (_lexHandler != null) {
	    _lexHandler.startEntity(name);
	}
    
public voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)
Implements org.xml.sax.ContentHandler.startPrefixMapping() Begin the scope of a prefix-URI Namespace mapping.

	_handler.startPrefixMapping(prefix, uri);
    
public voidunparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
Implements org.xml.sax.DTDHandler.unparsedEntityDecl()

        if (_dtdHandler != null) {
	    _dtdHandler.unparsedEntityDecl(name, publicId, systemId,
                                           notationName);
        }