< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java

Print this page




  43 import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
  44 import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
  45 import java.io.File;
  46 import java.io.FileOutputStream;
  47 import java.io.IOException;
  48 import java.io.InputStream;
  49 import java.io.OutputStream;
  50 import java.io.Reader;
  51 import java.io.Writer;
  52 import java.net.URI;
  53 import java.net.URL;
  54 import java.net.URLConnection;
  55 import java.net.UnknownServiceException;
  56 import java.util.ArrayList;
  57 import java.util.Enumeration;
  58 import java.util.HashMap;
  59 import java.util.Map;
  60 import java.util.Properties;
  61 import java.util.StringTokenizer;
  62 import javax.xml.XMLConstants;

  63 import javax.xml.catalog.CatalogFeatures;
  64 import javax.xml.catalog.CatalogManager;
  65 import javax.xml.catalog.CatalogUriResolver;
  66 import javax.xml.parsers.DocumentBuilder;
  67 import javax.xml.parsers.DocumentBuilderFactory;
  68 import javax.xml.parsers.ParserConfigurationException;
  69 import javax.xml.stream.XMLEventReader;
  70 import javax.xml.stream.XMLStreamReader;
  71 import javax.xml.transform.ErrorListener;
  72 import javax.xml.transform.OutputKeys;
  73 import javax.xml.transform.Result;
  74 import javax.xml.transform.Source;
  75 import javax.xml.transform.Transformer;
  76 import javax.xml.transform.TransformerException;
  77 import javax.xml.transform.URIResolver;
  78 import javax.xml.transform.dom.DOMResult;
  79 import javax.xml.transform.dom.DOMSource;
  80 import javax.xml.transform.sax.SAXResult;
  81 import javax.xml.transform.sax.SAXSource;
  82 import javax.xml.transform.stax.StAXResult;
  83 import javax.xml.transform.stax.StAXSource;
  84 import javax.xml.transform.stream.StreamResult;
  85 import javax.xml.transform.stream.StreamSource;


 207     private boolean _useServicesMechanism;
 208     /**
 209      * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
 210      */
 211     private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 212      /**
 213      * protocols allowed for external DTD references in source file and/or stylesheet.
 214      */
 215     private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 216 
 217     private XMLSecurityManager _securityManager;
 218     /**
 219      * A map to store parameters for the identity transform. These
 220      * are not needed during the transformation, but we must keep track of
 221      * them to be fully complaint with the JAXP API.
 222      */
 223     private Map<String, Object> _parameters = null;
 224 
 225     // Catalog features
 226     CatalogFeatures _catalogFeatures;
 227     CatalogUriResolver _catalogUriResolver;
 228 
 229     // Catalog is enabled by default
 230     boolean _useCatalog = true;
 231 
 232 
 233     /**
 234      * This class wraps an ErrorListener into a MessageHandler in order to
 235      * capture messages reported via xsl:message.
 236      */
 237     static class MessageHandler
 238            extends com.sun.org.apache.xalan.internal.xsltc.runtime.MessageHandler
 239     {
 240         private ErrorListener _errorListener;
 241 
 242         public MessageHandler(ErrorListener errorListener) {
 243             _errorListener = errorListener;
 244         }
 245 
 246         @Override
 247         public void displayMessage(String msg) {


1320             if (href.length() == 0) {
1321                 href = baseURI;
1322             }
1323 
1324             /*
1325              *  Fix for bug 24188
1326              *  Incase the _uriResolver.resolve(href,base) is null
1327              *  try to still  retrieve the document before returning null
1328              *  and throwing the FileNotFoundException in
1329              *  com.sun.org.apache.xalan.internal.xsltc.dom.LoadDocument
1330              *
1331              */
1332             Source resolvedSource = null;
1333             if (_uriResolver != null) {
1334                 resolvedSource = _uriResolver.resolve(href, baseURI);
1335             }
1336 
1337             if (resolvedSource == null && _useCatalog &&
1338                     _catalogFeatures.get(CatalogFeatures.Feature.FILES) != null)  {
1339                 if (_catalogUriResolver == null) {
1340                     _catalogUriResolver = CatalogManager.catalogUriResolver(_catalogFeatures);
1341                 }
1342                 resolvedSource = _catalogUriResolver.resolve(href, baseURI);
1343             }
1344 
1345             if (resolvedSource == null)  {
1346                 StreamSource streamSource = new StreamSource(
1347                      SystemIDResolver.getAbsoluteURI(href, baseURI));
1348                 return getDOM(streamSource) ;
1349             }
1350 
1351             return getDOM(resolvedSource);
1352         }
1353         catch (TransformerException e) {
1354             if (_errorListener != null)
1355                 postErrorToListener("File not found: " + e.getMessage());
1356             return(null);
1357         }
1358     }
1359 
1360     /**
1361      * Receive notification of a recoverable error.
1362      * The transformer must continue to provide normal parsing events after
1363      * invoking this method. It should still be possible for the application
1364      * to process the document through to the end.
1365      *
1366      * @param e The warning information encapsulated in a transformer
1367      * exception.
1368      * @throws TransformerException if the application chooses to discontinue
1369      * the transformation (always does in our case).
1370      */
1371     @Override
1372     public void error(TransformerException e)
1373         throws TransformerException




  43 import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
  44 import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
  45 import java.io.File;
  46 import java.io.FileOutputStream;
  47 import java.io.IOException;
  48 import java.io.InputStream;
  49 import java.io.OutputStream;
  50 import java.io.Reader;
  51 import java.io.Writer;
  52 import java.net.URI;
  53 import java.net.URL;
  54 import java.net.URLConnection;
  55 import java.net.UnknownServiceException;
  56 import java.util.ArrayList;
  57 import java.util.Enumeration;
  58 import java.util.HashMap;
  59 import java.util.Map;
  60 import java.util.Properties;
  61 import java.util.StringTokenizer;
  62 import javax.xml.XMLConstants;
  63 import javax.xml.catalog.CatalogException;
  64 import javax.xml.catalog.CatalogFeatures;
  65 import javax.xml.catalog.CatalogManager;
  66 import javax.xml.catalog.CatalogResolver;
  67 import javax.xml.parsers.DocumentBuilder;
  68 import javax.xml.parsers.DocumentBuilderFactory;
  69 import javax.xml.parsers.ParserConfigurationException;
  70 import javax.xml.stream.XMLEventReader;
  71 import javax.xml.stream.XMLStreamReader;
  72 import javax.xml.transform.ErrorListener;
  73 import javax.xml.transform.OutputKeys;
  74 import javax.xml.transform.Result;
  75 import javax.xml.transform.Source;
  76 import javax.xml.transform.Transformer;
  77 import javax.xml.transform.TransformerException;
  78 import javax.xml.transform.URIResolver;
  79 import javax.xml.transform.dom.DOMResult;
  80 import javax.xml.transform.dom.DOMSource;
  81 import javax.xml.transform.sax.SAXResult;
  82 import javax.xml.transform.sax.SAXSource;
  83 import javax.xml.transform.stax.StAXResult;
  84 import javax.xml.transform.stax.StAXSource;
  85 import javax.xml.transform.stream.StreamResult;
  86 import javax.xml.transform.stream.StreamSource;


 208     private boolean _useServicesMechanism;
 209     /**
 210      * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
 211      */
 212     private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 213      /**
 214      * protocols allowed for external DTD references in source file and/or stylesheet.
 215      */
 216     private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 217 
 218     private XMLSecurityManager _securityManager;
 219     /**
 220      * A map to store parameters for the identity transform. These
 221      * are not needed during the transformation, but we must keep track of
 222      * them to be fully complaint with the JAXP API.
 223      */
 224     private Map<String, Object> _parameters = null;
 225 
 226     // Catalog features
 227     CatalogFeatures _catalogFeatures;
 228     CatalogResolver _catalogUriResolver;
 229 
 230     // Catalog is enabled by default
 231     boolean _useCatalog = true;
 232 
 233 
 234     /**
 235      * This class wraps an ErrorListener into a MessageHandler in order to
 236      * capture messages reported via xsl:message.
 237      */
 238     static class MessageHandler
 239            extends com.sun.org.apache.xalan.internal.xsltc.runtime.MessageHandler
 240     {
 241         private ErrorListener _errorListener;
 242 
 243         public MessageHandler(ErrorListener errorListener) {
 244             _errorListener = errorListener;
 245         }
 246 
 247         @Override
 248         public void displayMessage(String msg) {


1321             if (href.length() == 0) {
1322                 href = baseURI;
1323             }
1324 
1325             /*
1326              *  Fix for bug 24188
1327              *  Incase the _uriResolver.resolve(href,base) is null
1328              *  try to still  retrieve the document before returning null
1329              *  and throwing the FileNotFoundException in
1330              *  com.sun.org.apache.xalan.internal.xsltc.dom.LoadDocument
1331              *
1332              */
1333             Source resolvedSource = null;
1334             if (_uriResolver != null) {
1335                 resolvedSource = _uriResolver.resolve(href, baseURI);
1336             }
1337 
1338             if (resolvedSource == null && _useCatalog &&
1339                     _catalogFeatures.get(CatalogFeatures.Feature.FILES) != null)  {
1340                 if (_catalogUriResolver == null) {
1341                     _catalogUriResolver = CatalogManager.catalogResolver(_catalogFeatures);
1342                 }
1343                 resolvedSource = _catalogUriResolver.resolve(href, baseURI);
1344             }
1345 
1346             if (resolvedSource == null)  {
1347                 StreamSource streamSource = new StreamSource(
1348                      SystemIDResolver.getAbsoluteURI(href, baseURI));
1349                 return getDOM(streamSource) ;
1350             }
1351 
1352             return getDOM(resolvedSource);
1353         }
1354         catch (TransformerException | CatalogException e) {
1355             if (_errorListener != null)
1356                 postErrorToListener("File not found: " + e.getMessage());
1357             return(null);
1358         }
1359     }
1360 
1361     /**
1362      * Receive notification of a recoverable error.
1363      * The transformer must continue to provide normal parsing events after
1364      * invoking this method. It should still be possible for the application
1365      * to process the document through to the end.
1366      *
1367      * @param e The warning information encapsulated in a transformer
1368      * exception.
1369      * @throws TransformerException if the application chooses to discontinue
1370      * the transformation (always does in our case).
1371      */
1372     @Override
1373     public void error(TransformerException e)
1374         throws TransformerException


< prev index next >