< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java

Print this page


   1 /*
   2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  * @modifiedBy: Oracle Inc.
   5  * @modifiedOn: Nov 2015, Sept 2017
   6  */
   7 /*
   8  * Licensed to the Apache Software Foundation (ASF) under one or more
   9  * contributor license agreements.  See the NOTICE file distributed with
  10  * this work for additional information regarding copyright ownership.
  11  * The ASF licenses this file to You under the Apache License, Version 2.0
  12  * (the "License"); you may not use this file except in compliance with
  13  * the License.  You may obtain a copy of the License at
  14  *
  15  *      http://www.apache.org/licenses/LICENSE-2.0
  16  *
  17  * Unless required by applicable law or agreed to in writing, software
  18  * distributed under the License is distributed on an "AS IS" BASIS,
  19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20  * See the License for the specific language governing permissions and
  21  * limitations under the License.
  22  */
  23 
  24 package com.sun.org.apache.xerces.internal.xinclude;
  25 


 604             if (componentManager.getFeature(SCHEMA_VALIDATION)) {
 605                 fSettings.setFeature(SCHEMA_VALIDATION, false);
 606                 if (componentManager.getFeature(VALIDATION)) {
 607                     fSettings.setFeature(DYNAMIC_VALIDATION, true);
 608                 }
 609             }
 610         }
 611         catch (XMLConfigurationException e) {}
 612 
 613         // Don't reset fChildConfig -- we don't want it to share the same components.
 614         // It will be reset when it is actually used to parse something.
 615     } // reset(XMLComponentManager)
 616 
 617     /**
 618      * Returns a list of feature identifiers that are recognized by
 619      * this component. This method may return null if no features
 620      * are recognized by this component.
 621      */
 622     @Override
 623     public String[] getRecognizedFeatures() {
 624         return (String[])(RECOGNIZED_FEATURES.clone());
 625     } // getRecognizedFeatures():String[]
 626 
 627     /**
 628      * Sets the state of a feature. This method is called by the component
 629      * manager any time after reset when a feature changes state.
 630      * <p>
 631      * <strong>Note:</strong> Components should silently ignore features
 632      * that do not affect the operation of the component.
 633      *
 634      * @param featureId The feature identifier.
 635      * @param state     The state of the feature.
 636      *
 637      * @throws SAXNotRecognizedException The component should not throw
 638      *                                   this exception.
 639      * @throws SAXNotSupportedException The component should not throw
 640      *                                  this exception.
 641      */
 642     @Override
 643     public void setFeature(String featureId, boolean state)
 644         throws XMLConfigurationException {
 645         if (featureId.equals(ALLOW_UE_AND_NOTATION_EVENTS)) {
 646             fSendUEAndNotationEvents = state;
 647         }
 648         if (fSettings != null) {
 649             fNeedCopyFeatures = true;
 650             fSettings.setFeature(featureId, state);
 651         }
 652     } // setFeature(String,boolean)
 653 
 654     /**
 655      * Returns a list of property identifiers that are recognized by
 656      * this component. This method may return null if no properties
 657      * are recognized by this component.
 658      */
 659     @Override
 660     public String[] getRecognizedProperties() {
 661         return (String[])(RECOGNIZED_PROPERTIES.clone());
 662     } // getRecognizedProperties():String[]
 663 
 664     /**
 665      * Sets the value of a property. This method is called by the component
 666      * manager any time after reset when a property changes value.
 667      * <p>
 668      * <strong>Note:</strong> Components should silently ignore properties
 669      * that do not affect the operation of the component.
 670      *
 671      * @param propertyId The property identifier.
 672      * @param value      The value of the property.
 673      *
 674      * @throws SAXNotRecognizedException The component should not throw
 675      *                                   this exception.
 676      * @throws SAXNotSupportedException The component should not throw
 677      *                                  this exception.
 678      */
 679     @Override
 680     public void setProperty(String propertyId, Object value)
 681         throws XMLConfigurationException {


1755                     newHandler.setDocumentHandler(this.getDocumentHandler());
1756                     fXPointerChildConfig = fChildConfig;
1757                 } else {
1758                     XIncludeHandler newHandler =
1759                         (XIncludeHandler)fChildConfig.getProperty(
1760                             Constants.XERCES_PROPERTY_PREFIX
1761                                 + Constants.XINCLUDE_HANDLER_PROPERTY);
1762 
1763                         newHandler.setParent(this);
1764                     newHandler.setDocumentHandler(this.getDocumentHandler());
1765                     fXIncludeChildConfig = fChildConfig;
1766                 }
1767             }
1768 
1769             // If an xpointer attribute is present
1770             if (xpointer != null ) {
1771                 fChildConfig = fXPointerChildConfig ;
1772 
1773                 // Parse the XPointer expression
1774                 try {
1775                     ((XPointerProcessor)fXPtrProcessor).parseXPointer(xpointer);
1776 
1777                 } catch (XNIException ex) {
1778                     // report the XPointer error as a resource error
1779                     reportResourceError(
1780                             "XMLResourceError",
1781                             new Object[] { href, ex.getMessage()});
1782                         return false;
1783                 }
1784             } else {
1785                 fChildConfig = fXIncludeChildConfig;
1786             }
1787 
1788             // set all features on parserConfig to match this parser configuration
1789             if (fNeedCopyFeatures) {
1790                 copyFeatures(fSettings, fChildConfig);
1791             }
1792             fNeedCopyFeatures = false;
1793 
1794             try {
1795                 fNamespaceContext.pushScope();
1796 
1797                 fChildConfig.parse(includedSource);
1798                 // necessary to make sure proper location is reported in errors
1799                 if (fErrorReporter != null) {
1800                     fErrorReporter.setDocumentLocator(fDocLocation);
1801                 }
1802 
1803                 // If the xpointer attribute is present
1804                 if (xpointer != null ) {
1805                         // and it was not resolved
1806                         if (!((XPointerProcessor)fXPtrProcessor).isXPointerResolved()) {
1807                         Locale locale = (fErrorReporter != null) ? fErrorReporter.getLocale() : null;
1808                         String reason = fXIncludeMessageFormatter.formatMessage(locale, "XPointerResolutionUnsuccessful", null);
1809                         reportResourceError("XMLResourceError", new Object[] {href, reason});
1810                                 // use the fallback
1811                                 return false;
1812                         }
1813                 }
1814             }
1815             catch (XNIException e) {
1816                 // necessary to make sure proper location is reported in errors
1817                 if (fErrorReporter != null) {
1818                     fErrorReporter.setDocumentLocator(fDocLocation);
1819                 }
1820                 reportFatalError("XMLParseError", new Object[] { href, e.getMessage() });
1821             }
1822             catch (IOException e) {
1823                 // necessary to make sure proper location is reported in errors
1824                 if (fErrorReporter != null) {
1825                     fErrorReporter.setDocumentLocator(fDocLocation);
1826                 }


2824     // The following methods are used for XML Base processing
2825 
2826     /**
2827      * Saves the current base URI to the top of the stack.
2828      */
2829     protected void saveBaseURI() {
2830         fBaseURIScope.push(fDepth);
2831         fBaseURI.push(fCurrentBaseURI.getBaseSystemId());
2832         fLiteralSystemID.push(fCurrentBaseURI.getLiteralSystemId());
2833         fExpandedSystemID.push(fCurrentBaseURI.getExpandedSystemId());
2834     }
2835 
2836     /**
2837      * Discards the URIs at the top of the stack, and restores the ones beneath it.
2838      */
2839     protected void restoreBaseURI() {
2840         fBaseURI.pop();
2841         fLiteralSystemID.pop();
2842         fExpandedSystemID.pop();
2843         fBaseURIScope.pop();
2844         fCurrentBaseURI.setBaseSystemId((String)fBaseURI.peek());
2845         fCurrentBaseURI.setLiteralSystemId((String)fLiteralSystemID.peek());
2846         fCurrentBaseURI.setExpandedSystemId((String)fExpandedSystemID.peek());
2847     }
2848 
2849     // The following methods are used for language processing
2850 
2851     /**
2852      * Saves the given language on the top of the stack.
2853      *
2854      * @param lanaguage the language to push onto the stack.
2855      */
2856     protected void saveLanguage(String language) {
2857         fLanguageScope.push(fDepth);
2858         fLanguageStack.push(language);
2859     }
2860 
2861     /**
2862      * Discards the language at the top of the stack, and returns the one beneath it.
2863      */
2864     public String restoreLanguage() {
2865         fLanguageStack.pop();
2866         fLanguageScope.pop();
2867         return (String) fLanguageStack.peek();
2868     }
2869 
2870     /**
2871      * Gets the base URI that was in use at that depth
2872      * @param depth
2873      * @return the base URI
2874      */
2875     public String getBaseURI(int depth) {
2876         int scope = scopeOfBaseURI(depth);
2877         return fExpandedSystemID.get(scope);
2878     }
2879 
2880     /**
2881      * Gets the language that was in use at that depth.
2882      * @param depth
2883      * @return the language
2884      */
2885     public String getLanguage(int depth) {
2886         int scope = scopeOfLanguage(depth);
2887         return fLanguageStack.get(scope);


   1 /*
   2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017


   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.xinclude;
  23 


 602             if (componentManager.getFeature(SCHEMA_VALIDATION)) {
 603                 fSettings.setFeature(SCHEMA_VALIDATION, false);
 604                 if (componentManager.getFeature(VALIDATION)) {
 605                     fSettings.setFeature(DYNAMIC_VALIDATION, true);
 606                 }
 607             }
 608         }
 609         catch (XMLConfigurationException e) {}
 610 
 611         // Don't reset fChildConfig -- we don't want it to share the same components.
 612         // It will be reset when it is actually used to parse something.
 613     } // reset(XMLComponentManager)
 614 
 615     /**
 616      * Returns a list of feature identifiers that are recognized by
 617      * this component. This method may return null if no features
 618      * are recognized by this component.
 619      */
 620     @Override
 621     public String[] getRecognizedFeatures() {
 622         return RECOGNIZED_FEATURES.clone();
 623     } // getRecognizedFeatures():String[]
 624 
 625     /**
 626      * Sets the state of a feature. This method is called by the component
 627      * manager any time after reset when a feature changes state.
 628      * <p>
 629      * <strong>Note:</strong> Components should silently ignore features
 630      * that do not affect the operation of the component.
 631      *
 632      * @param featureId The feature identifier.
 633      * @param state     The state of the feature.
 634      *
 635      * @throws SAXNotRecognizedException The component should not throw
 636      *                                   this exception.
 637      * @throws SAXNotSupportedException The component should not throw
 638      *                                  this exception.
 639      */
 640     @Override
 641     public void setFeature(String featureId, boolean state)
 642         throws XMLConfigurationException {
 643         if (featureId.equals(ALLOW_UE_AND_NOTATION_EVENTS)) {
 644             fSendUEAndNotationEvents = state;
 645         }
 646         if (fSettings != null) {
 647             fNeedCopyFeatures = true;
 648             fSettings.setFeature(featureId, state);
 649         }
 650     } // setFeature(String,boolean)
 651 
 652     /**
 653      * Returns a list of property identifiers that are recognized by
 654      * this component. This method may return null if no properties
 655      * are recognized by this component.
 656      */
 657     @Override
 658     public String[] getRecognizedProperties() {
 659         return RECOGNIZED_PROPERTIES.clone();
 660     } // getRecognizedProperties():String[]
 661 
 662     /**
 663      * Sets the value of a property. This method is called by the component
 664      * manager any time after reset when a property changes value.
 665      * <p>
 666      * <strong>Note:</strong> Components should silently ignore properties
 667      * that do not affect the operation of the component.
 668      *
 669      * @param propertyId The property identifier.
 670      * @param value      The value of the property.
 671      *
 672      * @throws SAXNotRecognizedException The component should not throw
 673      *                                   this exception.
 674      * @throws SAXNotSupportedException The component should not throw
 675      *                                  this exception.
 676      */
 677     @Override
 678     public void setProperty(String propertyId, Object value)
 679         throws XMLConfigurationException {


1753                     newHandler.setDocumentHandler(this.getDocumentHandler());
1754                     fXPointerChildConfig = fChildConfig;
1755                 } else {
1756                     XIncludeHandler newHandler =
1757                         (XIncludeHandler)fChildConfig.getProperty(
1758                             Constants.XERCES_PROPERTY_PREFIX
1759                                 + Constants.XINCLUDE_HANDLER_PROPERTY);
1760 
1761                         newHandler.setParent(this);
1762                     newHandler.setDocumentHandler(this.getDocumentHandler());
1763                     fXIncludeChildConfig = fChildConfig;
1764                 }
1765             }
1766 
1767             // If an xpointer attribute is present
1768             if (xpointer != null ) {
1769                 fChildConfig = fXPointerChildConfig ;
1770 
1771                 // Parse the XPointer expression
1772                 try {
1773                     fXPtrProcessor.parseXPointer(xpointer);
1774 
1775                 } catch (XNIException ex) {
1776                     // report the XPointer error as a resource error
1777                     reportResourceError(
1778                             "XMLResourceError",
1779                             new Object[] { href, ex.getMessage()});
1780                         return false;
1781                 }
1782             } else {
1783                 fChildConfig = fXIncludeChildConfig;
1784             }
1785 
1786             // set all features on parserConfig to match this parser configuration
1787             if (fNeedCopyFeatures) {
1788                 copyFeatures(fSettings, fChildConfig);
1789             }
1790             fNeedCopyFeatures = false;
1791 
1792             try {
1793                 fNamespaceContext.pushScope();
1794 
1795                 fChildConfig.parse(includedSource);
1796                 // necessary to make sure proper location is reported in errors
1797                 if (fErrorReporter != null) {
1798                     fErrorReporter.setDocumentLocator(fDocLocation);
1799                 }
1800 
1801                 // If the xpointer attribute is present
1802                 if (xpointer != null ) {
1803                         // and it was not resolved
1804                         if (!fXPtrProcessor.isXPointerResolved()) {
1805                         Locale locale = (fErrorReporter != null) ? fErrorReporter.getLocale() : null;
1806                         String reason = fXIncludeMessageFormatter.formatMessage(locale, "XPointerResolutionUnsuccessful", null);
1807                         reportResourceError("XMLResourceError", new Object[] {href, reason});
1808                                 // use the fallback
1809                                 return false;
1810                         }
1811                 }
1812             }
1813             catch (XNIException e) {
1814                 // necessary to make sure proper location is reported in errors
1815                 if (fErrorReporter != null) {
1816                     fErrorReporter.setDocumentLocator(fDocLocation);
1817                 }
1818                 reportFatalError("XMLParseError", new Object[] { href, e.getMessage() });
1819             }
1820             catch (IOException e) {
1821                 // necessary to make sure proper location is reported in errors
1822                 if (fErrorReporter != null) {
1823                     fErrorReporter.setDocumentLocator(fDocLocation);
1824                 }


2822     // The following methods are used for XML Base processing
2823 
2824     /**
2825      * Saves the current base URI to the top of the stack.
2826      */
2827     protected void saveBaseURI() {
2828         fBaseURIScope.push(fDepth);
2829         fBaseURI.push(fCurrentBaseURI.getBaseSystemId());
2830         fLiteralSystemID.push(fCurrentBaseURI.getLiteralSystemId());
2831         fExpandedSystemID.push(fCurrentBaseURI.getExpandedSystemId());
2832     }
2833 
2834     /**
2835      * Discards the URIs at the top of the stack, and restores the ones beneath it.
2836      */
2837     protected void restoreBaseURI() {
2838         fBaseURI.pop();
2839         fLiteralSystemID.pop();
2840         fExpandedSystemID.pop();
2841         fBaseURIScope.pop();
2842         fCurrentBaseURI.setBaseSystemId(fBaseURI.peek());
2843         fCurrentBaseURI.setLiteralSystemId(fLiteralSystemID.peek());
2844         fCurrentBaseURI.setExpandedSystemId(fExpandedSystemID.peek());
2845     }
2846 
2847     // The following methods are used for language processing
2848 
2849     /**
2850      * Saves the given language on the top of the stack.
2851      *
2852      * @param lanaguage the language to push onto the stack.
2853      */
2854     protected void saveLanguage(String language) {
2855         fLanguageScope.push(fDepth);
2856         fLanguageStack.push(language);
2857     }
2858 
2859     /**
2860      * Discards the language at the top of the stack, and returns the one beneath it.
2861      */
2862     public String restoreLanguage() {
2863         fLanguageStack.pop();
2864         fLanguageScope.pop();
2865         return fLanguageStack.peek();
2866     }
2867 
2868     /**
2869      * Gets the base URI that was in use at that depth
2870      * @param depth
2871      * @return the base URI
2872      */
2873     public String getBaseURI(int depth) {
2874         int scope = scopeOfBaseURI(depth);
2875         return fExpandedSystemID.get(scope);
2876     }
2877 
2878     /**
2879      * Gets the language that was in use at that depth.
2880      * @param depth
2881      * @return the language
2882      */
2883     public String getLanguage(int depth) {
2884         int scope = scopeOfLanguage(depth);
2885         return fLanguageStack.get(scope);


< prev index next >