Project

General

Profile

« Previous | Next » 

Revision 4426

Added by daigle over 16 years ago

Look for schemaLocations in the document while initializing parser. If full schema validation is turned on in metacat.properties, and at least one schema is not registered locally, then turn on full schema validation in the parser.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
36 36
import java.io.InputStream;
37 37
import java.io.PrintWriter;
38 38
import java.io.Reader;
39
import java.io.StringReader;
39 40
import java.io.StringWriter;
40 41
import java.io.Writer;
41 42
import java.net.URL;
......
55 56

  
56 57
import edu.ucsb.nceas.metacat.service.DatabaseService;
57 58
import edu.ucsb.nceas.metacat.service.PropertyService;
59
import edu.ucsb.nceas.metacat.service.XMLSchema;
60
import edu.ucsb.nceas.metacat.service.XMLSchemaService;
58 61
import edu.ucsb.nceas.metacat.spatial.SpatialHarvester;
59 62
import edu.ucsb.nceas.metacat.util.LDAPUtil;
60 63
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
......
97 100
    public static final String LEXICALPROPERTY = "http://xml.org/sax/properties/lexical-handler";
98 101
    public static final String VALIDATIONFEATURE = "http://xml.org/sax/features/validation";
99 102
    public static final String SCHEMAVALIDATIONFEATURE = "http://apache.org/xml/features/validation/schema";
103
    public static final String FULLSCHEMAVALIDATIONFEATURE = "http://apache.org/xml/features/validation/schema-full-checking";
100 104
    public static final String NAMESPACEFEATURE = "http://xml.org/sax/features/namespaces";
101 105
    public static final String NAMESPACEPREFIXESFEATURE = "http://xml.org/sax/features/namespace-prefixes";
102 106
    
......
2394 2398
                     * XMLReader parser = initializeParser(conn, action, docid,
2395 2399
                     * updaterev, validate, user, groups, pub, serverCode, dtd);
2396 2400
                     */
2397
                    parser = initializeParser(conn, action, docid, updaterev,
2401
                    parser = initializeParser(conn, action, docid, xml, updaterev,
2398 2402
                            user, groups, pub, serverCode, dtd, ruleBase,
2399 2403
                            needValidation, false, null, null);// false means it is not a revision doc
2400 2404
                                   //null, null are createdate and updatedate
......
2465 2469
        }
2466 2470
        XMLReader parser = null;
2467 2471
        try {
2468
            parser = initializeParser(conn, action, docid, rev, user, groups,
2472
            parser = initializeParser(conn, action, docid, xml, rev, user, groups,
2469 2473
                    pub, serverCode, dtd, ruleBase, needValidation, false, null, null);
2470 2474
                    // null and null are createtime and updatetime
2471 2475
                    // null will create current time
......
2631 2635
            {
2632 2636
                isRevision = true;
2633 2637
            }
2634
            parser = initializeParser(conn, action, docid, rev, user, groups,
2638
            parser = initializeParser(conn, action, docid, xml, rev, user, groups,
2635 2639
                    pub, serverCode, dtd, ruleBase, needValidation, 
2636 2640
                    isRevision, createDate, updateDate);
2637 2641
         
......
3120 3124
     * Set up the parser handlers for writing the document to the database
3121 3125
     */
3122 3126
    private static XMLReader initializeParser(DBConnection dbconn,
3123
            String action, String docid, String rev, String user,
3127
            String action, String docid, Reader xml, String rev, String user,
3124 3128
            String[] groups, String pub, int serverCode, Reader dtd,
3125 3129
            String ruleBase, boolean needValidation, boolean isRevision,
3126 3130
            String createDate, String updateDate) throws Exception
......
3150 3154
                parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
3151 3155
                // From DB to find the register external schema location
3152 3156
                String externalSchemaLocation = null;
3153
                SchemaLocationResolver resolver = new SchemaLocationResolver();
3154
                externalSchemaLocation = resolver
3155
                        .getNameSpaceAndLocationString();
3157
//                SchemaLocationResolver resolver = new SchemaLocationResolver();
3158
                externalSchemaLocation = XMLSchemaService.getNameSpaceAndLocationString();
3156 3159
                // Set external schemalocation.
3157 3160
                if (externalSchemaLocation != null
3158 3161
                        && !(externalSchemaLocation.trim()).equals("")) {
......
3175 3178
                parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
3176 3179
                // From DB to find the register external schema location
3177 3180
                String externalSchemaLocation = null;
3178
                SchemaLocationResolver resolver = new SchemaLocationResolver();
3179
                externalSchemaLocation = resolver
3180
                        .getNameSpaceAndLocationString();
3181
                externalSchemaLocation = XMLSchemaService.getNameSpaceAndLocationString();
3181 3182
                // Set external schemalocation.
3182 3183
                if (externalSchemaLocation != null
3183 3184
                        && !(externalSchemaLocation.trim()).equals("")) {
......
3203 3204
                    parser.setFeature(NAMESPACEFEATURE, true);
3204 3205
                    //parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
3205 3206
                    parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
3207
                    
3208
                    Vector<XMLSchema> schemaList = XMLSchemaService.findSchemasInXML((StringReader)xml);
3209
                    boolean allSchemasRegistered = 
3210
                    	XMLSchemaService.areAllSchemasRegistered(schemaList);
3211
                    if (XMLSchemaService.useFullSchemaValidation() && !allSchemasRegistered) {
3212
                    	parser.setFeature(FULLSCHEMAVALIDATIONFEATURE, true);
3213
                    }
3206 3214
                    // From DB to find the register external schema location
3207 3215
                    String externalSchemaLocation = null;
3208
                    SchemaLocationResolver resolver =
3209
                        new SchemaLocationResolver();
3210
                    externalSchemaLocation = resolver
3211
                            .getNameSpaceAndLocationString();
3216
                    externalSchemaLocation = XMLSchemaService.getNameSpaceAndLocationString();
3212 3217
                    // Set external schemalocation.
3213 3218
                    if (externalSchemaLocation != null
3214 3219
                            && !(externalSchemaLocation.trim()).equals("")) {

Also available in: Unified diff