| Method from com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl Detail: |
public void clearParameters() {
if (_isIdentity && _parameters != null) {
_parameters.clear();
}
else {
_translet.clearParameters();
}
}
Implements JAXP's Transformer.clearParameters()
Clear all parameters set with setParameter. Clears the translet's
parameter stack. |
public void error(TransformerException e) throws TransformerException {
Throwable wrapped = e.getException();
if (wrapped != null) {
System.err.println(new ErrorMsg(ErrorMsg.ERROR_PLUS_WRAPPED_MSG,
e.getMessageAndLocation(),
wrapped.getMessage()));
} else {
System.err.println(new ErrorMsg(ErrorMsg.ERROR_MSG,
e.getMessageAndLocation()));
}
throw e;
}
Receive notification of a recoverable error.
The transformer must continue to provide normal parsing events after
invoking this method. It should still be possible for the application
to process the document through to the end. |
public void fatalError(TransformerException e) throws TransformerException {
Throwable wrapped = e.getException();
if (wrapped != null) {
System.err.println(new ErrorMsg(ErrorMsg.FATAL_ERR_PLUS_WRAPPED_MSG,
e.getMessageAndLocation(),
wrapped.getMessage()));
} else {
System.err.println(new ErrorMsg(ErrorMsg.FATAL_ERR_MSG,
e.getMessageAndLocation()));
}
throw e;
}
Receive notification of a non-recoverable error.
The application must assume that the transformation cannot continue
after the Transformer has invoked this method, and should continue
(if at all) only to collect addition error messages. In fact,
Transformers are free to stop reporting events once this method has
been invoked. |
public ErrorListener getErrorListener() {
return _errorListener;
}
Implements JAXP's Transformer.getErrorListener()
Get the error event handler in effect for the transformation. |
public SerializationHandler getOutputHandler(Result result) throws TransformerException {
// Get output method using get() to ignore defaults
_method = (String) _properties.get(OutputKeys.METHOD);
// Get encoding using getProperty() to use defaults
_encoding = (String) _properties.getProperty(OutputKeys.ENCODING);
_tohFactory = TransletOutputHandlerFactory.newInstance();
_tohFactory.setEncoding(_encoding);
if (_method != null) {
_tohFactory.setOutputMethod(_method);
}
// Set indentation number in the factory
if (_indentNumber >= 0) {
_tohFactory.setIndentNumber(_indentNumber);
}
// Return the content handler for this Result object
try {
// Result object could be SAXResult, DOMResult, or StreamResult
if (result instanceof SAXResult) {
final SAXResult target = (SAXResult)result;
final ContentHandler handler = target.getHandler();
_tohFactory.setHandler(handler);
/**
* Fix for bug 24414
* If the lexicalHandler is set then we need to get that
* for obtaining the lexical information
*/
LexicalHandler lexicalHandler = target.getLexicalHandler();
if (lexicalHandler != null ) {
_tohFactory.setLexicalHandler(lexicalHandler);
}
_tohFactory.setOutputType(TransletOutputHandlerFactory.SAX);
return _tohFactory.getSerializationHandler();
}
else if (result instanceof StAXResult) {
if (((StAXResult) result).getXMLEventWriter() != null)
_tohFactory.setXMLEventWriter(((StAXResult) result).getXMLEventWriter());
else if (((StAXResult) result).getXMLStreamWriter() != null)
_tohFactory.setXMLStreamWriter(((StAXResult) result).getXMLStreamWriter());
_tohFactory.setOutputType(TransletOutputHandlerFactory.STAX);
return _tohFactory.getSerializationHandler();
}
else if (result instanceof DOMResult) {
_tohFactory.setNode(((DOMResult) result).getNode());
_tohFactory.setNextSibling(((DOMResult) result).getNextSibling());
_tohFactory.setOutputType(TransletOutputHandlerFactory.DOM);
return _tohFactory.getSerializationHandler();
}
else if (result instanceof StreamResult) {
// Get StreamResult
final StreamResult target = (StreamResult) result;
// StreamResult may have been created with a java.io.File,
// java.io.Writer, java.io.OutputStream or just a String
// systemId.
_tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM);
// try to get a Writer from Result object
final Writer writer = target.getWriter();
if (writer != null) {
_tohFactory.setWriter(writer);
return _tohFactory.getSerializationHandler();
}
// or try to get an OutputStream from Result object
final OutputStream ostream = target.getOutputStream();
if (ostream != null) {
_tohFactory.setOutputStream(ostream);
return _tohFactory.getSerializationHandler();
}
// or try to get just a systemId string from Result object
String systemId = result.getSystemId();
if (systemId == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_RESULT_ERR);
throw new TransformerException(err.toString());
}
// System Id may be in one of several forms, (1) a uri
// that starts with 'file:', (2) uri that starts with 'http:'
// or (3) just a filename on the local system.
URL url = null;
if (systemId.startsWith("file:")) {
// if StreamResult(File) or setSystemID(File) was used,
// the systemId will be URI encoded as a result of File.toURI(),
// it must be decoded for use by URL
try{
Class clazz = ObjectFactory.findProviderClass("java.net.URI", ObjectFactory.findClassLoader(), true);
Constructor construct = clazz.getConstructor(new Class[] {java.lang.String.class} );
URI uri = (URI) construct.newInstance(new Object[]{systemId}) ;
systemId = "file:";
String host = uri.getHost(); // decoded String
String path = uri.getPath(); //decoded String
if (path == null) {
path = "";
}
// if host (URI authority) then file:// + host + path
// else just path (may be absolute or relative)
if (host != null) {
systemId += "//" + host + path;
} else {
systemId += "//" + path;
}
}
catch(ClassNotFoundException e){
// running on J2SE 1.3 which doesn't have URI Class so OK to ignore
//ClassNotFoundException.
}
catch (Exception exception) {
// URI exception which means nothing can be done so OK to ignore
}
url = new URL(systemId);
_ostream = new FileOutputStream(url.getFile());
_tohFactory.setOutputStream(_ostream);
return _tohFactory.getSerializationHandler();
}
else if (systemId.startsWith("http:")) {
url = new URL(systemId);
final URLConnection connection = url.openConnection();
_tohFactory.setOutputStream(_ostream = connection.getOutputStream());
return _tohFactory.getSerializationHandler();
}
else {
// system id is just a filename
url = new File(systemId).toURL();
_tohFactory.setOutputStream(
_ostream = new FileOutputStream(url.getFile()));
return _tohFactory.getSerializationHandler();
}
}
}
// If we cannot write to the location specified by the SystemId
catch (UnknownServiceException e) {
throw new TransformerException(e);
}
catch (ParserConfigurationException e) {
throw new TransformerException(e);
}
// If we cannot create the file specified by the SystemId
catch (IOException e) {
throw new TransformerException(e);
}
return null;
}
Create an output handler for the transformation output based on
the type and contents of the TrAX Result object passed to the
transform() method. |
public Properties getOutputProperties() {
return (Properties) _properties.clone();
}
Implements JAXP's Transformer.getOutputProperties().
Returns a copy of the output properties for the transformation. This is
a set of layered properties. The first layer contains properties set by
calls to setOutputProperty() and setOutputProperties() on this class,
and the output settings defined in the stylesheet's
element makes up the second level, while the default XSLT output
settings are returned on the third level. |
public String getOutputProperty(String name) throws IllegalArgumentException {
if (!validOutputProperty(name)) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
throw new IllegalArgumentException(err.toString());
}
return _properties.getProperty(name);
}
Implements JAXP's Transformer.getOutputProperty().
Get an output property that is in effect for the transformation. The
property specified may be a property that was set with setOutputProperty,
or it may be a property specified in the stylesheet. |
public final Object getParameter(String name) {
if (_isIdentity) {
return (_parameters != null) ? _parameters.get(name) : null;
}
else {
return _translet.getParameter(name);
}
}
Implements JAXP's Transformer.getParameter()
Returns the value of a given parameter. Note that the translet will not
keep values for parameters that were not defined in the stylesheet. |
protected TransformerFactoryImpl getTransformerFactory() {
return _tfactory;
}
|
protected AbstractTranslet getTranslet() {
return _translet;
}
Returns the translet wrapped inside this Transformer or
null if this is the identity transform. |
protected TransletOutputHandlerFactory getTransletOutputHandlerFactory() {
return _tohFactory;
}
|
public URIResolver getURIResolver() {
return _uriResolver;
}
Implements JAXP's Transformer.getURIResolver()
Set the object currently used to resolve URIs used in document(). |
public boolean isIdentity() {
return _isIdentity;
}
|
public boolean isSecureProcessing() {
return _isSecureProcessing;
}
Return the state of the secure processing feature. |
public void reset() {
_method = null;
_encoding = null;
_sourceSystemId = null;
_errorListener = this;
_uriResolver = null;
_dom = null;
_parameters = null;
_indentNumber = 0;
setOutputProperties (null);
}
This method resets the Transformer to its original configuration
Transformer code is reset to the same state it was when it was
created |
public DOM retrieveDocument(String baseURI,
String href,
Translet translet) {
try {
// Argument to document function was: document('');
if (href.length() == 0) {
href = new String(baseURI);
}
/*
* Fix for bug 24188
* Incase the _uriResolver.resolve(href,base) is null
* try to still retrieve the document before returning null
* and throwing the FileNotFoundException in
* com.sun.org.apache.xalan.internal.xsltc.dom.LoadDocument
*
*/
Source resolvedSource = _uriResolver.resolve(href, baseURI);
if (resolvedSource == null) {
StreamSource streamSource = new StreamSource(
SystemIDResolver.getAbsoluteURI(href, baseURI));
return getDOM(streamSource) ;
}
return getDOM(resolvedSource);
}
catch (TransformerException e) {
if (_errorListener != null)
postErrorToListener("File not found: " + e.getMessage());
return(null);
}
}
This class should only be used as a DOMCache for the translet if the
URIResolver has been set.
The method implements XSLTC's DOMCache interface, which is used to
plug in an external document loader into a translet. This method acts
as an adapter between TrAX's URIResolver interface and XSLTC's
DOMCache interface. This approach is simple, but removes the
possibility of using external document caches with XSLTC. |
protected void setDOM(DOM dom) {
_dom = dom;
}
Set the internal DOM that will be used for the next transformation |
public void setErrorListener(ErrorListener listener) throws IllegalArgumentException {
if (listener == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
"Transformer");
throw new IllegalArgumentException(err.toString());
}
_errorListener = listener;
// Register a message handler to report xsl:messages
if (_translet != null)
_translet.setMessageHandler(new MessageHandler(_errorListener));
}
Implements JAXP's Transformer.setErrorListener()
Set the error event listener in effect for the transformation.
Register a message handler in the translet in order to forward
xsl:messages to error listener. |
public void setOutputProperties(Properties properties) throws IllegalArgumentException {
if (properties != null) {
final Enumeration names = properties.propertyNames();
while (names.hasMoreElements()) {
final String name = (String) names.nextElement();
// Ignore lower layer properties
if (isDefaultProperty(name, properties)) continue;
if (validOutputProperty(name)) {
_properties.setProperty(name, properties.getProperty(name));
}
else {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
throw new IllegalArgumentException(err.toString());
}
}
}
else {
_properties = _propertiesClone;
}
}
Implements JAXP's Transformer.setOutputProperties().
Set the output properties for the transformation. These properties
will override properties set in the Templates with xsl:output.
Unrecognised properties will be quitely ignored. |
public void setOutputProperty(String name,
String value) throws IllegalArgumentException {
if (!validOutputProperty(name)) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNKNOWN_PROP_ERR, name);
throw new IllegalArgumentException(err.toString());
}
_properties.setProperty(name, value);
}
Implements JAXP's Transformer.setOutputProperty().
Get an output property that is in effect for the transformation. The
property specified may be a property that was set with
setOutputProperty(), or it may be a property specified in the stylesheet. |
public void setParameter(String name,
Object value) {
if (value == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_SET_PARAM_VALUE, name);
throw new IllegalArgumentException(err.toString());
}
if (_isIdentity) {
if (_parameters == null) {
_parameters = new Hashtable();
}
_parameters.put(name, value);
}
else {
_translet.addParameter(name, value);
}
}
Implements JAXP's Transformer.setParameter()
Add a parameter for the transformation. The parameter is simply passed
on to the translet - no validation is performed - so any unused
parameters are quitely ignored by the translet. |
public void setSecureProcessing(boolean flag) {
_isSecureProcessing = flag;
}
Set the state of the secure processing feature. |
public void setURIResolver(URIResolver resolver) {
_uriResolver = resolver;
}
Implements JAXP's Transformer.setURIResolver()
Set an object that will be used to resolve URIs used in document(). |
public void transferOutputProperties(SerializationHandler handler) {
// Return right now if no properties are set
if (_properties == null) return;
String doctypePublic = null;
String doctypeSystem = null;
// Get a list of all the defined properties
Enumeration names = _properties.propertyNames();
while (names.hasMoreElements()) {
// Note the use of get() instead of getProperty()
String name = (String) names.nextElement();
String value = (String) _properties.get(name);
// Ignore default properties
if (value == null) continue;
// Pass property value to translet - override previous setting
if (name.equals(OutputKeys.DOCTYPE_PUBLIC)) {
doctypePublic = value;
}
else if (name.equals(OutputKeys.DOCTYPE_SYSTEM)) {
doctypeSystem = value;
}
else if (name.equals(OutputKeys.MEDIA_TYPE)) {
handler.setMediaType(value);
}
else if (name.equals(OutputKeys.STANDALONE)) {
handler.setStandalone(value);
}
else if (name.equals(OutputKeys.VERSION)) {
handler.setVersion(value);
}
else if (name.equals(OutputKeys.OMIT_XML_DECLARATION)) {
handler.setOmitXMLDeclaration(
value != null && value.toLowerCase().equals("yes"));
}
else if (name.equals(OutputKeys.INDENT)) {
handler.setIndent(
value != null && value.toLowerCase().equals("yes"));
}
else if (name.equals(OutputPropertiesFactory.S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL +"indent-amount")) {
if (value != null) {
handler.setIndentAmount(Integer.parseInt(value));
}
}
else if (name.equals(OutputPropertiesFactory.S_BUILTIN_EXTENSIONS_UNIVERSAL +"indent-amount")) {
if (value != null) {
handler.setIndentAmount(Integer.parseInt(value));
}
}
else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
if (value != null) {
StringTokenizer e = new StringTokenizer(value);
Vector uriAndLocalNames = null;
while (e.hasMoreTokens()) {
final String token = e.nextToken();
// look for the last colon, as the String may be
// something like "http://abc.com:local"
int lastcolon = token.lastIndexOf(':");
String uri;
String localName;
if (lastcolon > 0) {
uri = token.substring(0, lastcolon);
localName = token.substring(lastcolon+1);
} else {
// no colon at all, lets hope this is the
// local name itself then
uri = null;
localName = token;
}
if (uriAndLocalNames == null) {
uriAndLocalNames = new Vector();
}
// add the uri/localName as a pair, in that order
uriAndLocalNames.addElement(uri);
uriAndLocalNames.addElement(localName);
}
handler.setCdataSectionElements(uriAndLocalNames);
}
}
}
// Call setDoctype() if needed
if (doctypePublic != null || doctypeSystem != null) {
handler.setDoctype(doctypeSystem, doctypePublic);
}
}
This method is used to pass any properties to the output handler
when running the identity transform. |
public void transform(Source source,
Result result) throws TransformerException {
if (!_isIdentity) {
if (_translet == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_TRANSLET_ERR);
throw new TransformerException(err.toString());
}
// Pass output properties to the translet
transferOutputProperties(_translet);
}
final SerializationHandler toHandler = getOutputHandler(result);
if (toHandler == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_NO_HANDLER_ERR);
throw new TransformerException(err.toString());
}
if (_uriResolver != null && !_isIdentity) {
_translet.setDOMCache(this);
}
// Pass output properties to handler if identity
if (_isIdentity) {
transferOutputProperties(toHandler);
}
transform(source, toHandler, _encoding);
try{
if (result instanceof DOMResult) {
((DOMResult)result).setNode(_tohFactory.getNode());
} else if (result instanceof StAXResult) {
if (((StAXResult) result).getXMLEventWriter() != null)
{
(_tohFactory.getXMLEventWriter()).flush();
}
else if (((StAXResult) result).getXMLStreamWriter() != null) {
(_tohFactory.getXMLStreamWriter()).flush();
//result = new StAXResult(_tohFactory.getXMLStreamWriter());
}
}
} catch (Exception e) {
System.out.println("Result writing error");
}
}
Implements JAXP's Transformer.transform() |
public void warning(TransformerException e) throws TransformerException {
Throwable wrapped = e.getException();
if (wrapped != null) {
System.err.println(new ErrorMsg(ErrorMsg.WARNING_PLUS_WRAPPED_MSG,
e.getMessageAndLocation(),
wrapped.getMessage()));
} else {
System.err.println(new ErrorMsg(ErrorMsg.WARNING_MSG,
e.getMessageAndLocation()));
}
}
Receive notification of a warning.
Transformers can use this method to report conditions that are not
errors or fatal errors. The default behaviour is to take no action.
After invoking this method, the Transformer must continue with the
transformation. It should still be possible for the application to
process the document through to the end. |