| Method from com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl Detail: |
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 Source getAssociatedStylesheet(Source source,
String media,
String title,
String charset) throws TransformerConfigurationException {
String baseId;
XMLReader reader = null;
InputSource isource = null;
/**
* Fix for bugzilla bug 24187
*/
StylesheetPIHandler _stylesheetPIHandler = new StylesheetPIHandler(null,media,title,charset);
try {
if (source instanceof DOMSource ) {
final DOMSource domsrc = (DOMSource) source;
baseId = domsrc.getSystemId();
final org.w3c.dom.Node node = domsrc.getNode();
final DOM2SAX dom2sax = new DOM2SAX(node);
_stylesheetPIHandler.setBaseId(baseId);
dom2sax.setContentHandler( _stylesheetPIHandler);
dom2sax.parse();
} else {
isource = SAXSource.sourceToInputSource(source);
baseId = isource.getSystemId();
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
if (_isSecureProcessing) {
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
}
catch (org.xml.sax.SAXException e) {}
}
SAXParser jaxpParser = factory.newSAXParser();
reader = jaxpParser.getXMLReader();
if (reader == null) {
reader = XMLReaderFactory.createXMLReader();
}
_stylesheetPIHandler.setBaseId(baseId);
reader.setContentHandler(_stylesheetPIHandler);
reader.parse(isource);
}
if (_uriResolver != null ) {
_stylesheetPIHandler.setURIResolver(_uriResolver);
}
} catch (StopParseException e ) {
// startElement encountered so do not parse further
} catch (javax.xml.parsers.ParserConfigurationException e) {
throw new TransformerConfigurationException(
"getAssociatedStylesheets failed", e);
} catch (org.xml.sax.SAXException se) {
throw new TransformerConfigurationException(
"getAssociatedStylesheets failed", se);
} catch (IOException ioe ) {
throw new TransformerConfigurationException(
"getAssociatedStylesheets failed", ioe);
}
return _stylesheetPIHandler.getAssociatedStylesheet();
}
javax.xml.transform.sax.TransformerFactory implementation.
Get the stylesheet specification(s) associated via the xml-stylesheet
processing instruction (see http://www.w3.org/TR/xml-stylesheet/) with
the document document specified in the source parameter, and that match
the given criteria. |
public Object getAttribute(String name) throws IllegalArgumentException {
// Return value for attribute 'translet-name'
if (name.equals(TRANSLET_NAME)) {
return _transletName;
}
else if (name.equals(GENERATE_TRANSLET)) {
return new Boolean(_generateTranslet);
}
else if (name.equals(AUTO_TRANSLET)) {
return new Boolean(_autoTranslet);
}
// Throw an exception for all other attributes
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
throw new IllegalArgumentException(err.toString());
}
javax.xml.transform.sax.TransformerFactory implementation.
Returns the value set for a TransformerFactory attribute |
protected Class getDTMManagerClass() {
return m_DTMManagerClass;
}
Returns the Class object the provides the XSLTC DTM Manager service. |
public ErrorListener getErrorListener() {
return _errorListener;
}
javax.xml.transform.sax.TransformerFactory implementation.
Get the error event handler for the TransformerFactory. |
public boolean getFeature(String name) {
// All supported features should be listed here
String[] features = {
DOMSource.FEATURE,
DOMResult.FEATURE,
SAXSource.FEATURE,
SAXResult.FEATURE,
StreamSource.FEATURE,
StreamResult.FEATURE,
SAXTransformerFactory.FEATURE,
SAXTransformerFactory.FEATURE_XMLFILTER
};
// feature name cannot be null
if (name == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME);
throw new NullPointerException(err.toString());
}
// Inefficient, but array is small
for (int i =0; i < features.length; i++) {
if (name.equals(features[i])) {
return true;
}
}
// secure processing?
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
return _isSecureProcessing;
}
// Feature not supported
return false;
}
javax.xml.transform.sax.TransformerFactory implementation.
Look up the value of a feature (to see if it is supported).
This method must be updated as the various methods and features of this
class are implemented. |
public URIResolver getURIResolver() {
return _uriResolver;
}
javax.xml.transform.sax.TransformerFactory implementation.
Get the object that is used by default during the transformation to
resolve URIs used in document(), xsl:import, or xsl:include. |
public InputSource loadSource(String href,
String context,
XSLTC xsltc) {
try {
if (_uriResolver != null) {
final Source source = _uriResolver.resolve(href, context);
if (source != null) {
return Util.getInputSource(xsltc, source);
}
}
}
catch (TransformerException e) {
// should catch it when the resolver explicitly throws the exception
final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this);
xsltc.getParser().reportError(Constants.FATAL, msg);
}
return null;
}
This method implements XSLTC's SourceLoader interface. It is used to
glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes. |
public Templates newTemplates(Source source) throws TransformerConfigurationException {
// If the _useClasspath attribute is true, try to load the translet from
// the CLASSPATH and create a template object using the loaded
// translet.
if (_useClasspath) {
String transletName = getTransletBaseName(source);
if (_packageName != null)
transletName = _packageName + "." + transletName;
try {
final Class clazz = ObjectFactory.findProviderClass(
transletName, ObjectFactory.findClassLoader(), true);
resetTransientAttributes();
return new TemplatesImpl(new Class[]{clazz}, transletName, null, _indentNumber, this);
}
catch (ClassNotFoundException cnfe) {
ErrorMsg err = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, transletName);
throw new TransformerConfigurationException(err.toString());
}
catch (Exception e) {
ErrorMsg err = new ErrorMsg(
new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY)
+ e.getMessage());
throw new TransformerConfigurationException(err.toString());
}
}
// If _autoTranslet is true, we will try to load the bytecodes
// from the translet classes without compiling the stylesheet.
if (_autoTranslet) {
byte[][] bytecodes = null;
String transletClassName = getTransletBaseName(source);
if (_packageName != null)
transletClassName = _packageName + "." + transletClassName;
if (_jarFileName != null)
bytecodes = getBytecodesFromJar(source, transletClassName);
else
bytecodes = getBytecodesFromClasses(source, transletClassName);
if (bytecodes != null) {
if (_debug) {
if (_jarFileName != null)
System.err.println(new ErrorMsg(
ErrorMsg.TRANSFORM_WITH_JAR_STR, transletClassName, _jarFileName));
else
System.err.println(new ErrorMsg(
ErrorMsg.TRANSFORM_WITH_TRANSLET_STR, transletClassName));
}
// Reset the per-session attributes to their default values
// after each newTemplates() call.
resetTransientAttributes();
return new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this);
}
}
// Create and initialize a stylesheet compiler
final XSLTC xsltc = new XSLTC();
if (_debug) xsltc.setDebug(true);
if (_enableInlining) xsltc.setTemplateInlining(true);
if (_isSecureProcessing) xsltc.setSecureProcessing(true);
xsltc.init();
// Set a document loader (for xsl:include/import) if defined
if (_uriResolver != null) {
xsltc.setSourceLoader(this);
}
// Pass parameters to the Parser to make sure it locates the correct
// < ?xml-stylesheet ...? > PI in an XML input document
if ((_piParams != null) && (_piParams.get(source) != null)) {
// Get the parameters for this Source object
PIParamWrapper p = (PIParamWrapper)_piParams.get(source);
// Pass them on to the compiler (which will pass then to the parser)
if (p != null) {
xsltc.setPIParameters(p._media, p._title, p._charset);
}
}
// Set the attributes for translet generation
int outputType = XSLTC.BYTEARRAY_OUTPUT;
if (_generateTranslet || _autoTranslet) {
// Set the translet name
xsltc.setClassName(getTransletBaseName(source));
if (_destinationDirectory != null)
xsltc.setDestDirectory(_destinationDirectory);
else {
String xslName = getStylesheetFileName(source);
if (xslName != null) {
File xslFile = new File(xslName);
String xslDir = xslFile.getParent();
if (xslDir != null)
xsltc.setDestDirectory(xslDir);
}
}
if (_packageName != null)
xsltc.setPackageName(_packageName);
if (_jarFileName != null) {
xsltc.setJarFileName(_jarFileName);
outputType = XSLTC.BYTEARRAY_AND_JAR_OUTPUT;
}
else
outputType = XSLTC.BYTEARRAY_AND_FILE_OUTPUT;
}
// Compile the stylesheet
final InputSource input = Util.getInputSource(xsltc, source);
byte[][] bytecodes = xsltc.compile(null, input, outputType);
final String transletName = xsltc.getClassName();
// Output to the jar file if the jar file name is set.
if ((_generateTranslet || _autoTranslet)
&& bytecodes != null && _jarFileName != null) {
try {
xsltc.outputToJar();
}
catch (java.io.IOException e) { }
}
// Reset the per-session attributes to their default values
// after each newTemplates() call.
resetTransientAttributes();
// Pass compiler warnings to the error listener
if (_errorListener != this) {
try {
passWarningsToListener(xsltc.getWarnings());
}
catch (TransformerException e) {
throw new TransformerConfigurationException(e);
}
}
else {
xsltc.printWarnings();
}
// Check that the transformation went well before returning
if (bytecodes == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
TransformerConfigurationException exc = new TransformerConfigurationException(err.toString());
// Pass compiler errors to the error listener
if (_errorListener != null) {
passErrorsToListener(xsltc.getErrors());
// As required by TCK 1.2, send a fatalError to the
// error listener because compilation of the stylesheet
// failed and no further processing will be possible.
try {
_errorListener.fatalError(exc);
} catch (TransformerException te) {
// well, we tried.
}
}
else {
xsltc.printErrors();
}
throw exc;
}
return new TemplatesImpl(bytecodes, transletName,
xsltc.getOutputProperties(), _indentNumber, this);
}
javax.xml.transform.sax.TransformerFactory implementation.
Process the Source into a Templates object, which is a a compiled
representation of the source. |
public TemplatesHandler newTemplatesHandler() throws TransformerConfigurationException {
final TemplatesHandlerImpl handler =
new TemplatesHandlerImpl(_indentNumber, this);
if (_uriResolver != null) {
handler.setURIResolver(_uriResolver);
}
return handler;
}
javax.xml.transform.sax.SAXTransformerFactory implementation.
Get a TemplatesHandler object that can process SAX ContentHandler
events into a Templates object. |
public Transformer newTransformer() throws TransformerConfigurationException {
TransformerImpl result = new TransformerImpl(new Properties(),
_indentNumber, this);
if (_uriResolver != null) {
result.setURIResolver(_uriResolver);
}
if (_isSecureProcessing) {
result.setSecureProcessing(true);
}
return result;
}
javax.xml.transform.sax.TransformerFactory implementation.
Create a Transformer object that copies the input document to the result. |
public Transformer newTransformer(Source source) throws TransformerConfigurationException {
final Templates templates = newTemplates(source);
final Transformer transformer = templates.newTransformer();
if (_uriResolver != null) {
transformer.setURIResolver(_uriResolver);
}
return(transformer);
}
javax.xml.transform.sax.TransformerFactory implementation.
Process the Source into a Templates object, which is a a compiled
representation of the source. Note that this method should not be
used with XSLTC, as the time-consuming compilation is done for each
and every transformation. |
public TransformerHandler newTransformerHandler() throws TransformerConfigurationException {
final Transformer transformer = newTransformer();
if (_uriResolver != null) {
transformer.setURIResolver(_uriResolver);
}
return new TransformerHandlerImpl((TransformerImpl) transformer);
}
javax.xml.transform.sax.SAXTransformerFactory implementation.
Get a TransformerHandler object that can process SAX ContentHandler
events into a Result. This method will return a pure copy transformer. |
public TransformerHandler newTransformerHandler(Source src) throws TransformerConfigurationException {
final Transformer transformer = newTransformer(src);
if (_uriResolver != null) {
transformer.setURIResolver(_uriResolver);
}
return new TransformerHandlerImpl((TransformerImpl) transformer);
}
javax.xml.transform.sax.SAXTransformerFactory implementation.
Get a TransformerHandler object that can process SAX ContentHandler
events into a Result, based on the transformation instructions
specified by the argument. |
public TransformerHandler newTransformerHandler(Templates templates) throws TransformerConfigurationException {
final Transformer transformer = templates.newTransformer();
final TransformerImpl internal = (TransformerImpl)transformer;
return new TransformerHandlerImpl(internal);
}
javax.xml.transform.sax.SAXTransformerFactory implementation.
Get a TransformerHandler object that can process SAX ContentHandler
events into a Result, based on the transformation instructions
specified by the argument. |
public XMLFilter newXMLFilter(Source src) throws TransformerConfigurationException {
Templates templates = newTemplates(src);
if (templates == null) return null;
return newXMLFilter(templates);
}
javax.xml.transform.sax.SAXTransformerFactory implementation.
Create an XMLFilter that uses the given source as the
transformation instructions. |
public XMLFilter newXMLFilter(Templates templates) throws TransformerConfigurationException {
try {
return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
}
catch (TransformerConfigurationException e1) {
if (_errorListener != null) {
try {
_errorListener.fatalError(e1);
return null;
}
catch (TransformerException e2) {
new TransformerConfigurationException(e2);
}
}
throw e1;
}
}
javax.xml.transform.sax.SAXTransformerFactory implementation.
Create an XMLFilter that uses the given source as the
transformation instructions. |
public void setAttribute(String name,
Object value) throws IllegalArgumentException {
// Set the default translet name (ie. class name), which will be used
// for translets that cannot be given a name from their system-id.
if (name.equals(TRANSLET_NAME) && value instanceof String) {
_transletName = (String) value;
return;
}
else if (name.equals(DESTINATION_DIRECTORY) && value instanceof String) {
_destinationDirectory = (String) value;
return;
}
else if (name.equals(PACKAGE_NAME) && value instanceof String) {
_packageName = (String) value;
return;
}
else if (name.equals(JAR_NAME) && value instanceof String) {
_jarFileName = (String) value;
return;
}
else if (name.equals(GENERATE_TRANSLET)) {
if (value instanceof Boolean) {
_generateTranslet = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_generateTranslet = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(AUTO_TRANSLET)) {
if (value instanceof Boolean) {
_autoTranslet = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_autoTranslet = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(USE_CLASSPATH)) {
if (value instanceof Boolean) {
_useClasspath = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_useClasspath = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(DEBUG)) {
if (value instanceof Boolean) {
_debug = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_debug = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(ENABLE_INLINING)) {
if (value instanceof Boolean) {
_enableInlining = ((Boolean) value).booleanValue();
return;
}
else if (value instanceof String) {
_enableInlining = ((String) value).equalsIgnoreCase("true");
return;
}
}
else if (name.equals(INDENT_NUMBER)) {
if (value instanceof String) {
try {
_indentNumber = Integer.parseInt((String) value);
return;
}
catch (NumberFormatException e) {
// Falls through
}
}
else if (value instanceof Integer) {
_indentNumber = ((Integer) value).intValue();
return;
}
}
// Throw an exception for all other attributes
final ErrorMsg err
= new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
throw new IllegalArgumentException(err.toString());
}
javax.xml.transform.sax.TransformerFactory implementation.
Sets the value for a TransformerFactory attribute. |
public void setErrorListener(ErrorListener listener) throws IllegalArgumentException {
if (listener == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
"TransformerFactory");
throw new IllegalArgumentException(err.toString());
}
_errorListener = listener;
}
javax.xml.transform.sax.TransformerFactory implementation.
Set the error event listener for the TransformerFactory, which is used
for the processing of transformation instructions, and not for the
transformation itself. |
public void setFeature(String name,
boolean value) throws TransformerConfigurationException {
// feature name cannot be null
if (name == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SET_FEATURE_NULL_NAME);
throw new NullPointerException(err.toString());
}
// secure processing?
else if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
_isSecureProcessing = value;
// all done processing feature
return;
}
else {
// unknown feature
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name);
throw new TransformerConfigurationException(err.toString());
}
}
Set a feature for this TransformerFactory and Transformers
or Templates created by this factory.
Feature names are fully qualified java.net.URI s.
Implementations may define their own features.
An TransformerConfigurationException is thrown if this TransformerFactory or the
Transformers or Templates it creates cannot support the feature.
It is possible for an TransformerFactory to expose a feature value but be unable to change its state.
See javax.xml.transform.TransformerFactory for full documentation of specific features.
|
public void setURIResolver(URIResolver resolver) {
_uriResolver = resolver;
}
javax.xml.transform.sax.TransformerFactory implementation.
Set the object that is used by default during the transformation to
resolve URIs used in document(), xsl:import, or xsl:include. Note that
this does not affect Templates and Transformers that are already
created with this factory. |
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. |