You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2003/01/17 00:03:09 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/xs/traversers XSDHandler.java

sandygao    2003/01/16 15:03:08

  Modified:    java/src/org/apache/xerces/impl Constants.java
                        XMLDTDScannerImpl.java XMLEntityManager.java
               java/src/org/apache/xerces/impl/dtd XMLDTDLoader.java
                        XMLDTDValidator.java
               java/src/org/apache/xerces/impl/xs XMLSchemaLoader.java
                        XMLSchemaValidator.java
               java/src/org/apache/xerces/impl/xs/traversers
                        XSDHandler.java
  Log:
  A new feature: http://apache.org/xml/features/standard-uri-conformant
  When it's turned on, it has to be a URI where a URI is expected, otherwise
  a URI.MalformedURI excpetion (a subclass of IOException) is thrown.
  
  Revision  Changes    Path
  1.28      +4 -1      xml-xerces/java/src/org/apache/xerces/impl/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Constants.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- Constants.java	8 Jan 2003 23:03:12 -0000	1.27
  +++ Constants.java	16 Jan 2003 23:03:07 -0000	1.28
  @@ -263,6 +263,9 @@
       /** Notify built-in (&, etc.) references feature (scanner/notify-builtin-refs"). */
       public static final String NOTIFY_BUILTIN_REFS_FEATURE = "scanner/notify-builtin-refs";
   
  +    /** Standard URI conformant feature ("standard-uri-conformant"). */
  +    public static final String STANDARD_URI_CONFORMANT_FEATURE = "standard-uri-conformant";
  +    
       // xerces properties
   
       /** Xerces properties prefix ("http://apache.org/xml/properties/"). */
  
  
  
  1.35      +3 -4      xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java
  
  Index: XMLDTDScannerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDTDScannerImpl.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- XMLDTDScannerImpl.java	7 Dec 2002 00:32:21 -0000	1.34
  +++ XMLDTDScannerImpl.java	16 Jan 2003 23:03:07 -0000	1.35
  @@ -1545,7 +1545,6 @@
           }
           if (systemId != null) {
               String baseSystemId = fEntityScanner.getBaseSystemId();
  -            String expandedSystemId = XMLEntityManager.expandSystemId(systemId, baseSystemId);
               if (notation != null) {
                   fEntityManager.addUnparsedEntity(name, publicId, systemId, baseSystemId, notation);
               }
  @@ -1554,7 +1553,7 @@
                                                    baseSystemId);
               }
               if (fDTDHandler != null) {
  -                fResourceIdentifier.setValues(publicId, systemId, baseSystemId, XMLEntityManager.expandSystemId(systemId, baseSystemId));
  +                fResourceIdentifier.setValues(publicId, systemId, baseSystemId, XMLEntityManager.expandSystemId(systemId, baseSystemId, false));
                   if (notation != null) {
                       fDTDHandler.unparsedEntityDecl(name, fResourceIdentifier, 
                                                      notation, null);
  @@ -1746,7 +1745,7 @@
   
           // call handler
           if (fDTDHandler != null) {
  -            fResourceIdentifier.setValues(publicId, systemId, baseSystemId, XMLEntityManager.expandSystemId(systemId, baseSystemId));
  +            fResourceIdentifier.setValues(publicId, systemId, baseSystemId, XMLEntityManager.expandSystemId(systemId, baseSystemId, false));
               fDTDHandler.notationDecl(name, fResourceIdentifier, null);
           }
           fReportEntity = true;
  
  
  
  1.59      +110 -33   xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java
  
  Index: XMLEntityManager.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- XMLEntityManager.java	16 Jan 2003 17:14:02 -0000	1.58
  +++ XMLEntityManager.java	16 Jan 2003 23:03:07 -0000	1.59
  @@ -159,6 +159,10 @@
       protected static final String WARN_ON_DUPLICATE_ENTITYDEF =
       Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
   
  +    /** Feature identifier: standard uri conformant */
  +    protected static final String STANDARD_URI_CONFORMANT =
  +    Constants.XERCES_FEATURE_PREFIX +Constants.STANDARD_URI_CONFORMANT_FEATURE;
  +
       // property identifiers
   
       /** Property identifier: symbol table. */
  @@ -193,7 +197,8 @@
           EXTERNAL_GENERAL_ENTITIES,
           EXTERNAL_PARAMETER_ENTITIES,
           ALLOW_JAVA_ENCODINGS,
  -        WARN_ON_DUPLICATE_ENTITYDEF
  +        WARN_ON_DUPLICATE_ENTITYDEF,
  +        STANDARD_URI_CONFORMANT
       };
   
       /** Feature defaults. */
  @@ -203,6 +208,7 @@
           Boolean.TRUE,
           Boolean.FALSE,
           Boolean.FALSE,
  +        Boolean.FALSE
       };
   
       /** Recognized properties. */
  @@ -281,6 +287,12 @@
        */
       protected boolean fWarnDuplicateEntityDef;
   
  +    /**
  +     * standard uri conformant (strict uri).
  +     * http://apache.org/xml/features/standard-uri-conformant
  +     */
  +    protected boolean fStrictURI;
  +
       // properties
   
       /**
  @@ -500,7 +512,7 @@
        */
       public void addExternalEntity(String name,
                                     String publicId, String literalSystemId,
  -                                  String baseSystemId) {
  +                                  String baseSystemId) throws IOException {
           if (!fEntities.containsKey(name)) {
               if (baseSystemId == null) {
                   // search for the first external entity on the stack
  @@ -518,7 +530,7 @@
                   }
               }
               Entity entity = new ExternalEntity(name,
  -                    new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandSystemId(literalSystemId, baseSystemId)), null, fInExternalSubset);
  +                    new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandSystemId(literalSystemId, baseSystemId, false)), null, fInExternalSubset);
               fEntities.put(name, entity);
           }
           else{
  @@ -671,7 +683,7 @@
                   needExpand = true;
            }
            if (needExpand)
  -            expandedSystemId = expandSystemId(literalSystemId, baseSystemId);
  +            expandedSystemId = expandSystemId(literalSystemId, baseSystemId, false);
   
          // give the entity resolver a chance
           XMLInputSource xmlInputSource = null;
  @@ -751,7 +763,7 @@
                       // expanded??? - neilg
                       String extLitSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getLiteralSystemId() : null);
                       String extBaseSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getBaseSystemId() : null);
  -                    String expandedSystemId = expandSystemId(extLitSysId, extBaseSysId);
  +                    String expandedSystemId = expandSystemId(extLitSysId, extBaseSysId, false);
                       fResourceIdentifier.setValues(
                               (externalEntity.entityLocation != null ? externalEntity.entityLocation.getPublicId() : null),
                               extLitSysId, extBaseSysId, expandedSystemId);
  @@ -788,7 +800,7 @@
                           // REVISIT:  for the same reason above...
                           String extLitSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getLiteralSystemId() : null);
                           String extBaseSysId = (externalEntity.entityLocation != null ? externalEntity.entityLocation.getBaseSystemId() : null);
  -                        String expandedSystemId = expandSystemId(extLitSysId, extBaseSysId);
  +                        String expandedSystemId = expandSystemId(extLitSysId, extBaseSysId, false);
                           fResourceIdentifier.setValues(
                                   (externalEntity.entityLocation != null ? externalEntity.entityLocation.getPublicId() : null),
                                   extLitSysId, extBaseSysId, expandedSystemId);
  @@ -929,7 +941,8 @@
           // create reader
           InputStream stream = null;
           Reader reader = xmlInputSource.getCharacterStream();
  -        String expandedSystemId = expandSystemId(literalSystemId, baseSystemId);
  +        // First chance checking strict URI
  +        String expandedSystemId = expandSystemId(literalSystemId, baseSystemId, fStrictURI);
           if (baseSystemId == null) {
               baseSystemId = expandedSystemId;
           }
  @@ -1182,6 +1195,13 @@
               fWarnDuplicateEntityDef = false;
           }
   
  +        try {
  +            fStrictURI = componentManager.getFeature(STANDARD_URI_CONFORMANT);
  +        }
  +        catch (XMLConfigurationException e) {
  +            fStrictURI = false;
  +        }
  +
           // xerces properties
           fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);
           fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
  @@ -1239,11 +1259,15 @@
               addInternalEntity("recursive-entity", "<foo>&recursive-entity2;</foo>");
               addInternalEntity("recursive-entity2", "<bar>&recursive-entity3;</bar>");
               addInternalEntity("recursive-entity3", "<baz>&recursive-entity;</baz>");
  -
  -            addExternalEntity("external-text", null, "external-text.ent", "test/external-text.xml");
  -            addExternalEntity("external-balanced-element", null, "external-balanced-element.ent", "test/external-balanced-element.xml");
  -            addExternalEntity("one", null, "ent/one.ent", "test/external-entity.xml");
  -            addExternalEntity("two", null, "ent/two.ent", "test/ent/one.xml");
  +            try {
  +                addExternalEntity("external-text", null, "external-text.ent", "test/external-text.xml");
  +                addExternalEntity("external-balanced-element", null, "external-balanced-element.ent", "test/external-balanced-element.xml");
  +                addExternalEntity("one", null, "ent/one.ent", "test/external-entity.xml");
  +                addExternalEntity("two", null, "ent/two.ent", "test/ent/one.xml");
  +            }
  +            catch (IOException ex) {
  +                // should never happen
  +            }
           }
   
           // copy declared entities
  @@ -1393,23 +1417,6 @@
       // Public static methods
       //
   
  -    /**
  -     * Expands a system id and returns the system id as a URI, if
  -     * it can be expanded. A return value of null means that the
  -     * identifier is already expanded. An exception thrown
  -     * indicates a failure to expand the id.
  -     *
  -     * @param systemId The systemId to be expanded.
  -     *
  -     * @return Returns the URI string representing the expanded system
  -     *         identifier. A null value indicates that the given
  -     *         system identifier is already expanded.
  -     *
  -     */
  -    public static String expandSystemId(String systemId) {
  -        return expandSystemId(systemId, null);
  -    } // expandSystemId(String):String
  -
       // current value of the "user.dir" property
       private static String gUserDir;
       // escaped value of the current "user.dir" property
  @@ -1562,7 +1569,43 @@
        *         system identifier is already expanded.
        *
        */
  -    public static String expandSystemId(String systemId, String baseSystemId) {
  +    public static String expandSystemId(String systemId, String baseSystemId,
  +                                        boolean strict)
  +            throws URI.MalformedURIException {
  +
  +        // system id has to be a valid URI
  +        if (strict) {
  +            try {
  +                // if it's already an absolute one, return it
  +                URI uri = new URI(systemId);
  +                return systemId;
  +            }
  +            catch (URI.MalformedURIException ex) {
  +            }
  +            URI base = null;
  +            // if there isn't a base uri, use the working directory
  +            if (baseSystemId == null || baseSystemId.length() == 0) {
  +                base = new URI("file", "", getUserDir(), null, null);
  +            }
  +            // otherwise, use the base uri
  +            else {
  +                try {
  +                    base = new URI(baseSystemId);
  +                }
  +                catch (URI.MalformedURIException e) {
  +                    // assume "base" is also a relative uri
  +                    String dir = getUserDir();
  +                    dir = dir + baseSystemId;
  +                    base = new URI("file", "", dir, null, null);
  +                }
  +            }
  +            // absolutize the system id using the base
  +            URI uri = new URI(base, systemId);
  +            // return the string rep of the new uri (an absolute one)
  +            return uri.toString();
  +            
  +            // if any exception is thrown, it'll get thrown to the caller.
  +        }
   
           // check for bad parameters id
           if (systemId == null || systemId.length() == 0) {
  @@ -1876,6 +1919,8 @@
           // handle platform dependent strings
           str = str.replace(java.io.File.separatorChar, '/');
   
  +        StringBuffer sb = null;
  +
           // Windows fix
           if (str.length() >= 2) {
               char ch1 = str.charAt(1);
  @@ -1883,13 +1928,45 @@
               if (ch1 == ':') {
                   char ch0 = Character.toUpperCase(str.charAt(0));
                   if (ch0 >= 'A' && ch0 <= 'Z') {
  -                    str = "/" + str;
  +                    sb = new StringBuffer(str.length());
  +                    sb.append('/');
                   }
               }
               // change "//blah" to "file://blah"
               else if (ch1 == '/' && str.charAt(0) == '/') {
  -                str = "file:" + str;
  +                sb = new StringBuffer(str.length());
  +                sb.append("file:");
  +            }
  +        }
  +
  +        int pos = str.indexOf(' ');
  +        // there is no space in the string
  +        // we just append "str" to the end of sb
  +        if (pos < 0) {
  +            if (sb != null) {
  +                sb.append(str);
  +                str = sb.toString();
  +            }
  +        }
  +        // otherwise, convert all ' ' to "%20".
  +        // Note: the following algorithm might not be very performant,
  +        // but people who want to use invalid URI's have to pay the price.
  +        else {
  +            if (sb == null)
  +                sb = new StringBuffer(str.length());
  +            // put characters before ' ' into the string buffer
  +            for (int i = 0; i < pos; i++)
  +                sb.append(str.charAt(i));
  +            // and %20 for the space
  +            sb.append("%20");
  +            // for the remamining part, also convert ' ' to "%20".
  +            for (int i = pos+1; i < str.length(); i++) {
  +                if (str.charAt(i) == ' ')
  +                    sb.append("%20");
  +                else
  +                    sb.append(str.charAt(i));
               }
  +            str = sb.toString();
           }
   
           // done
  
  
  
  1.7       +24 -2     xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDLoader.java
  
  Index: XMLDTDLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDLoader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XMLDTDLoader.java	16 Jan 2003 17:10:10 -0000	1.6
  +++ XMLDTDLoader.java	16 Jan 2003 23:03:08 -0000	1.7
  @@ -107,6 +107,20 @@
       // Constants
       //
   
  +    // feature identifiers
  +
  +    /** Feature identifier: standard uri conformant feature. */
  +    protected static final String STANDARD_URI_CONFORMANT_FEATURE =
  +        Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE;
  +
  +    // recognized features:
  +    private static final String[] RECOGNIZED_FEATURES = {
  +        VALIDATION,
  +        WARN_ON_DUPLICATE_ATTDEF,
  +        NOTIFY_CHAR_REFS,
  +        STANDARD_URI_CONFORMANT_FEATURE
  +    };
  +
       // property identifiers
   
       /** Property identifier: error handler. */
  @@ -127,6 +141,9 @@
           DTD_VALIDATOR,
       };
   
  +    // enforcing strict uri?
  +    private boolean fStrictURI = false;
  +
       /** Entity resolver . */
       protected XMLEntityResolver fEntityResolver;
   
  @@ -173,6 +190,7 @@
           } else {
               fEntityManager = new XMLEntityManager();
           }
  +        fEntityManager.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY, errorReporter);
           fDTDScanner = new XMLDTDScannerImpl(fSymbolTable, fErrorReporter, fEntityManager);
           fDTDScanner.setDTDHandler(this);
           fDTDScanner.setDTDContentModelHandler(this);
  @@ -204,6 +222,8 @@
               fWarnDuplicateAttdef = state;
           } else if(featureId.equals(NOTIFY_CHAR_REFS)) {
               fDTDScanner.setFeature(featureId, state);
  +        } else if(featureId.equals(STANDARD_URI_CONFORMANT_FEATURE)) {
  +            fStrictURI = state;
           }  else {
               throw new XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, featureId);
           }
  @@ -357,7 +377,9 @@
       public Grammar loadGrammar(XMLInputSource source)
               throws IOException, XNIException {
           reset();
  -        fDTDGrammar = new DTDGrammar(fSymbolTable, new XMLDTDDescription(source.getPublicId(), source.getSystemId(), source.getBaseSystemId(), fEntityManager.expandSystemId(source.getSystemId()), null));
  +        // First chance checking strict URI
  +        String eid = XMLEntityManager.expandSystemId(source.getSystemId(), source.getBaseSystemId(), fStrictURI);
  +        fDTDGrammar = new DTDGrammar(fSymbolTable, new XMLDTDDescription(source.getPublicId(), source.getSystemId(), source.getBaseSystemId(), eid, null));
           fGrammarBucket = new DTDGrammarBucket();
           fGrammarBucket.setStandalone(false);
           fGrammarBucket.setActiveGrammar(fDTDGrammar); 
  
  
  
  1.44      +7 -2      xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java
  
  Index: XMLDTDValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- XMLDTDValidator.java	16 Dec 2002 01:26:20 -0000	1.43
  +++ XMLDTDValidator.java	16 Jan 2003 23:03:08 -0000	1.44
  @@ -729,7 +729,12 @@
           fSeenDoctypeDecl = true;
           fRootElement.setValues(null, rootElement, rootElement, null);
           // find or create grammar:
  -        XMLDTDDescription grammarDesc = new XMLDTDDescription(publicId, systemId, fDocLocation.getExpandedSystemId(), XMLEntityManager.expandSystemId(systemId), rootElement);
  +        String eid = null;
  +        try {
  +            eid = XMLEntityManager.expandSystemId(systemId, fDocLocation.getExpandedSystemId(), false);
  +        } catch (java.io.IOException e) {
  +        }
  +        XMLDTDDescription grammarDesc = new XMLDTDDescription(publicId, systemId, fDocLocation.getExpandedSystemId(), eid, rootElement);
           fDTDGrammar = fGrammarBucket.getGrammar(grammarDesc);
           if(fDTDGrammar == null) {
               // give grammar pool a chance...
  
  
  
  1.14      +83 -14    xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java
  
  Index: XMLSchemaLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XMLSchemaLoader.java	16 Jan 2003 18:40:31 -0000	1.13
  +++ XMLSchemaLoader.java	16 Jan 2003 23:03:08 -0000	1.14
  @@ -69,6 +69,7 @@
   import org.xml.sax.InputSource;
   
   import org.apache.xerces.impl.XMLErrorReporter;
  +import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
   import org.apache.xerces.impl.xs.models.CMBuilder;
   import org.apache.xerces.impl.xs.traversers.XSDHandler;
   import org.apache.xerces.impl.Constants;
  @@ -120,11 +121,16 @@
       protected static final String ALLOW_JAVA_ENCODINGS =
           Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
   
  +    /** Feature identifier: standard uri conformant feature. */
  +    protected static final String STANDARD_URI_CONFORMANT_FEATURE =
  +        Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE;
  +
       // recognized features:
       private static final String[] RECOGNIZED_FEATURES = {
           SCHEMA_FULL_CHECKING,
           CONTINUE_AFTER_FATAL_ERROR,
           ALLOW_JAVA_ENCODINGS,
  +        STANDARD_URI_CONFORMANT_FEATURE
       };
   
       // property identifiers
  @@ -180,6 +186,9 @@
   
       // is allow-java-encodings enabled?
       private boolean fAllowJavaEncodings = false;
  +    
  +    // enforcing strict uri?
  +    private boolean fStrictURI = false;
   
       private SymbolTable fSymbolTable = null;
       private XMLErrorReporter fErrorReporter = new XMLErrorReporter ();
  @@ -295,6 +304,8 @@
               fErrorReporter.setFeature(CONTINUE_AFTER_FATAL_ERROR, state);
           } else if(featureId.equals(ALLOW_JAVA_ENCODINGS)) {
               fAllowJavaEncodings = state;
  +        } else if(featureId.equals(STANDARD_URI_CONFORMANT_FEATURE)) {
  +            fStrictURI = state;
           } else {
               throw new XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, featureId);
           }
  @@ -447,7 +458,7 @@
           }
   
           fSchemaHandler.reset(fErrorReporter, fEntityResolver,
  -                fSymbolTable, fGrammarPool, fAllowJavaEncodings);
  +                fSymbolTable, fGrammarPool, fAllowJavaEncodings, fStrictURI);
           if(fGrammarPool == null) {
               fDeclPool.reset();
               fSchemaHandler.setDeclPool(fDeclPool);
  @@ -477,17 +488,11 @@
           desc.setLiteralSystemId( source.getSystemId());
           // none of the other fields make sense for preparsing
           Hashtable locationPairs = new Hashtable();
  -        if(!tokenizeSchemaLocationStr(fExternalSchemas, locationPairs)) {
  -            fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  -                                          "SchemaLocation",
  -                                          new Object[]{fExternalSchemas},
  -                                          XMLErrorReporter.SEVERITY_WARNING);
  -        }
  -        if(fExternalNoNSSchema != null) {
  -            LocationArray noNs = new LocationArray();
  -            noNs.addLocation(fExternalNoNSSchema);
  -            locationPairs.put(XMLSymbols.EMPTY_STRING, noNs);
  -        }
  +        // Process external schema location properties.
  +        // We don't call tokenizeSchemaLocationStr here, because we also want
  +        // to check whether the values are valid URI.
  +        processExternalHints(fExternalSchemas, fExternalNoNSSchema,
  +                             locationPairs, fErrorReporter);
           SchemaGrammar grammar = loadSchema(desc, source, locationPairs);
           if(grammar != null && fGrammarPool != null) {
               fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, fGrammarBucket.getGrammars());
  @@ -541,12 +546,76 @@
                   loc = hints[0];
           }
   
  -        String expandedLoc = XMLEntityManager.expandSystemId(loc, desc.getBaseSystemId());
  +        String expandedLoc = XMLEntityManager.expandSystemId(loc, desc.getBaseSystemId(), false);
           desc.setLiteralSystemId(loc);
           desc.setExpandedSystemId(expandedLoc);
           return entityResolver.resolveEntity(desc);
       }
   
  +    // add external schema locations to the location pairs
  +    public static void processExternalHints(String sl, String nsl,
  +                                            Hashtable locations,
  +                                            XMLErrorReporter er) {
  +        if (sl != null) {
  +            try {
  +                // get the attribute decl for xsi:schemaLocation
  +                // because external schema location property has the same syntax
  +                // as xsi:schemaLocation
  +                XSAttributeDecl attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_SCHEMALOCATION);
  +                // validation the string value to get the list of URI's
  +                Object actualValue = attrDecl.fType.validate(sl, null, null);
  +                Object[] uris = (Object[])actualValue;
  +                // if there are even number of URI's
  +                // add them to the location pairs
  +                if (uris.length % 2 == 0) {
  +                    String namespace, location;
  +                    for (int i = 0; i < uris.length;) {
  +                        namespace = (String)uris[i++];
  +                        location = (String)uris[i++];
  +                        LocationArray la = ((LocationArray)locations.get(namespace));
  +                        if(la == null) {
  +                            la = new LocationArray();
  +                            locations.put(namespace, la);
  +                        }
  +                        la.addLocation(location);
  +                    }
  +                }
  +                else {
  +                    // report warning (odd number of items)
  +                    er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                   "SchemaLocation",
  +                                   new Object[]{sl},
  +                                   XMLErrorReporter.SEVERITY_WARNING);
  +                }
  +            }
  +            catch (InvalidDatatypeValueException ex) {
  +                // report warning (not list of URI's)
  +                er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                               ex.getKey(), ex.getArgs(),
  +                               XMLErrorReporter.SEVERITY_WARNING);
  +            }
  +        }
  +
  +        if (nsl != null) {
  +            try {
  +                // similarly for no ns schema location property
  +                XSAttributeDecl attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
  +                attrDecl.fType.validate(nsl, null, null);
  +                LocationArray la = ((LocationArray)locations.get(XMLSymbols.EMPTY_STRING));
  +                if(la == null) {
  +                    la = new LocationArray();
  +                    locations.put(XMLSymbols.EMPTY_STRING, la);
  +                }
  +                la.addLocation(nsl);
  +            }
  +            catch (InvalidDatatypeValueException ex) {
  +                // report warning (not a URI)
  +                er.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                               ex.getKey(), ex.getArgs(),
  +                               XMLErrorReporter.SEVERITY_WARNING);
  +            }
  +        }
  +    }
       // this method takes a SchemaLocation string.
       // If an error is encountered, false is returned;
       // otherwise, true is returned.  In either case, locations
  
  
  
  1.130     +24 -13    xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
  
  Index: XMLSchemaValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java,v
  retrieving revision 1.129
  retrieving revision 1.130
  diff -u -r1.129 -r1.130
  --- XMLSchemaValidator.java	16 Jan 2003 18:40:30 -0000	1.129
  +++ XMLSchemaValidator.java	16 Jan 2003 23:03:08 -0000	1.130
  @@ -184,6 +184,10 @@
       protected static final String ALLOW_JAVA_ENCODINGS =
       Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
   
  +    /** Feature identifier: standard uri conformant feature. */
  +    protected static final String STANDARD_URI_CONFORMANT_FEATURE =
  +        Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE;
  +
       /** Feature identifier: whether to continue parsing a schema after a fatal error is encountered */
       protected static final String CONTINUE_AFTER_FATAL_ERROR =
       Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
  @@ -238,6 +242,7 @@
           SCHEMA_FULL_CHECKING,
           ALLOW_JAVA_ENCODINGS,
           CONTINUE_AFTER_FATAL_ERROR,
  +        STANDARD_URI_CONFORMANT_FEATURE
       };
   
       /** Feature defaults. */
  @@ -254,6 +259,7 @@
           null, //Boolean.FALSE,
           null, //Boolean.FALSE,
           null, //Boolean.FALSE,
  +        null
       };
   
       /** Recognized properties. */
  @@ -443,7 +449,6 @@
       /** Schema Grammar Description passed,  to give a chance to application to supply the Grammar */
       protected final XSDDescription fXSDDescription = new XSDDescription() ;
       protected final Hashtable fLocationPairs = new Hashtable() ;
  -    protected final XMLSchemaLoader.LocationArray fNoNamespaceLocationArray = new XMLSchemaLoader.LocationArray();
   
       /** Base URI for the DOM revalidation*/
       protected String fBaseURI = null;
  @@ -1321,7 +1326,6 @@
   
           //reset XSDDescription
           fLocationPairs.clear();
  -        fNoNamespaceLocationArray.resize(0 , 2) ;
   
           // get schema location properties
           try {
  @@ -1338,7 +1342,8 @@
           // so any other schemaLocation declaration for the same namespace will be
           // effectively ignored. becuase we choose to take first location hint
           // available for a particular namespace.
  -        storeLocations(fExternalSchemas, fExternalNoNamespaceSchema) ;
  +        XMLSchemaLoader.processExternalHints(fExternalSchemas, fExternalNoNamespaceSchema,
  +                                             fLocationPairs, fXSIErrorReporter.fErrorReporter);
   
           try {
               fJaxpSchemaSource = componentManager.getProperty(JAXP_SCHEMA_SOURCE);
  @@ -1367,6 +1372,12 @@
           }
           catch (XMLConfigurationException e){
           }
  +        try {
  +            boolean strictURI = componentManager.getFeature(STANDARD_URI_CONFORMANT_FEATURE);
  +            fSchemaLoader.setFeature(STANDARD_URI_CONFORMANT_FEATURE, strictURI);
  +        }
  +        catch (XMLConfigurationException e){
  +        }
   
           // get continue-after-fatal-error feature
           try {
  @@ -2288,8 +2299,12 @@
               }
           }
           if (nsLocation != null) {
  -            fNoNamespaceLocationArray.addLocation(nsLocation);
  -            fLocationPairs.put(XMLSymbols.EMPTY_STRING, fNoNamespaceLocationArray);
  +            XMLSchemaLoader.LocationArray la = ((XMLSchemaLoader.LocationArray)fLocationPairs.get(XMLSymbols.EMPTY_STRING));
  +            if(la == null) {
  +                la = new XMLSchemaLoader.LocationArray();
  +                fLocationPairs.put(XMLSymbols.EMPTY_STRING, la);
  +            }
  +            la.addLocation(nsLocation);
           }
   
       }//storeLocations
  @@ -2314,13 +2329,9 @@
               }
   
               String[] temp = null ;
  -            if( namespace != null){
  -                Object locationArray = fLocationPairs.get(namespace) ;
  -                if(locationArray != null)
  -                    temp = ((XMLSchemaLoader.LocationArray)locationArray).getLocationArray() ;
  -            }else{
  -                temp = fNoNamespaceLocationArray.getLocationArray() ;
  -            }
  +            Object locationArray = fLocationPairs.get(namespace == null ? XMLSymbols.EMPTY_STRING : namespace) ;
  +            if(locationArray != null)
  +                temp = ((XMLSchemaLoader.LocationArray)locationArray).getLocationArray() ;
               if (temp != null && temp.length != 0) {
                   fXSDDescription.fLocationHints = new String [temp.length] ;
                   System.arraycopy(temp, 0 , fXSDDescription.fLocationHints, 0, temp.length );
  
  
  
  1.60      +23 -7     xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
  
  Index: XSDHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- XSDHandler.java	13 Dec 2002 17:33:02 -0000	1.59
  +++ XSDHandler.java	16 Jan 2003 23:03:08 -0000	1.60
  @@ -130,6 +130,10 @@
       protected static final String CONTINUE_AFTER_FATAL_ERROR =
           Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
   
  +    /** Feature identifier:  allow java encodings */
  +    protected static final String STANDARD_URI_CONFORMANT_FEATURE =
  +        Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE;
  +
       /** Property identifier: error handler. */
       protected static final String ERROR_HANDLER =
           Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
  @@ -169,6 +173,9 @@
   
       // are java encodings allowed?
       private boolean fAllowJavaEncodings = false;
  +    
  +    // enforcing strict uri?
  +    private boolean fStrictURI = false;
   
       // These tables correspond to the symbol spaces defined in the
       // spec.
  @@ -341,7 +348,8 @@
       // this object (i.e., clean the registries, etc.).
   
       public SchemaGrammar parseSchema(XMLInputSource is, XSDDescription desc,
  -                Hashtable locationPairs) {
  +                                     Hashtable locationPairs)
  +            throws IOException {
   
           fLocationPairs = locationPairs;
   
  @@ -379,7 +387,7 @@
               if(schemaNamespace != null && schemaNamespace.length() > 0) {
                   schemaNamespace = fSymbolTable.addSymbol(schemaNamespace);
                   desc.setTargetNamespace(schemaNamespace);
  -                String schemaId = XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId());
  +                String schemaId = XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false);
                   XSDKey key = new XSDKey(schemaId, referType, schemaNamespace);
                   fTraversed.put(key, schemaRoot );
                   if (schemaId != null) {
  @@ -1344,7 +1352,7 @@
                   // expand it, and check whether the same document has been
                   // parsed before. If so, return the document corresponding to
                   // that system id.
  -                String schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId());
  +                String schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false);
                   XSDKey key = new XSDKey(schemaId, referType, schemaNamespace);
                   if ((schemaDoc = (Document)fTraversed.get(key)) != null) {
                       fLastSchemaWasDuplicate = true;
  @@ -1485,13 +1493,15 @@
                         XMLEntityResolver entityResolver,
                         SymbolTable symbolTable,
                         XMLGrammarPool grammarPool,
  -                      boolean allowJavaEncodings) {
  +                      boolean allowJavaEncodings,
  +                      boolean strictURI) {
   
           fErrorReporter = errorReporter;
           fEntityResolver = entityResolver;
           fSymbolTable = symbolTable;
           fGrammarPool = grammarPool;
           fAllowJavaEncodings = allowJavaEncodings;
  +        fStrictURI = strictURI;
   
           resetSchemaParserErrorHandler();
           
  @@ -1511,14 +1521,20 @@
                   }
               } catch (Exception e) {
               }
  -            // make sure continue-after-fatal-error and
  -            // allow-java-encodings set correctly:
  +            // make sure the following are set correctly:
  +            // continue-after-fatal-error
  +            // allow-java-encodings
  +            // standard-uri-conformant
               try {
                   fSchemaParser.setFeature(CONTINUE_AFTER_FATAL_ERROR, fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR));
               } catch (Exception e) {
               }
               try {
                   fSchemaParser.setFeature(ALLOW_JAVA_ENCODINGS, fAllowJavaEncodings);
  +            } catch (Exception e) {
  +            }
  +            try {
  +                fSchemaParser.setFeature(STANDARD_URI_CONFORMANT_FEATURE, fStrictURI);
               } catch (Exception e) {
               }
               try {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org