Project

Profile

Help

Revision ab669bec

Added by O'Neil Delpratt over 7 years ago

Bug fix relating to issue #2051. Added specific XML parser features and properties

View differences:

latest9.5/hej/net/sf/saxon/Configuration.java
3807 3807
        } else if (name.equals(FeatureKeys.XINCLUDE)) {
3808 3808
            setXIncludeAware(requireBoolean(name, value));
3809 3809

  
3810
        } else if(name.startsWith(FeatureKeys.XML_PARSER_FEATURE)){
3811
             defaultParseOptions.addParserFeature(name, requireBoolean(name, value));
3812

  
3813
        } else if (name.startsWith(FeatureKeys.XML_PARSER_PROPERTY)) {
3814
            defaultParseOptions.addParserProperties(name, requireString(name, value));
3815

  
3810 3816
        } else if (name.equals(FeatureKeys.XQUERY_ALLOW_UPDATE)) {
3811 3817
            getDefaultStaticQueryContext().setUpdatingEnabled(requireBoolean(name, value));
3812 3818

  
......
4290 4296
        } else if (name.equals(FeatureKeys.XSLT_STATIC_URI_RESOLVER_CLASS)) {
4291 4297
            return getDefaultXsltCompilerInfo().getURIResolver().getClass().getName();
4292 4298

  
4299
        } else if (name.startsWith(FeatureKeys.XML_PARSER_FEATURE)) {
4300
             String uri = name.substring(FeatureKeys.XML_PARSER_FEATURE.length());
4301
             return defaultParseOptions.getParserFeature(uri);
4302
        } else if (name.startsWith(FeatureKeys.XML_PARSER_PROPERTY)) {
4303
             String uri = name.substring(FeatureKeys.XML_PARSER_PROPERTY.length());
4304
             return defaultParseOptions.getParserProperty(uri);
4293 4305
        } else if (name.equals(FeatureKeys.XSLT_VERSION)) {
4294 4306
            return getDefaultXsltCompilerInfo().getXsltVersion().toString();
4295 4307

  
latest9.5/hej/net/sf/saxon/event/Sender.java
33 33
import javax.xml.transform.stream.StreamSource;
34 34
import java.lang.reflect.Method;
35 35
import java.util.List;
36
import java.util.Map;
36 37

  
37 38
/**
38 39
* Sender is a helper class that sends events to a Receiver from any kind of Source object
......
333 334
            }
334 335
        }
335 336

  
337
        Map<String, Boolean> parserFeatures = options.getParserFeatures();
338
        Map<String, String> parserProperties = options.getParserProperties();
339

  
340
        if(parserFeatures != null) {
341
            for(Map.Entry<String, Boolean> entry : parserFeatures.entrySet()){
342
                try {
343
                    parser.setFeature(entry.getKey(), entry.getValue());
344
                } catch (SAXNotRecognizedException err) {
345
                    config.getStandardErrorOutput().println("XML Parser does not recognize the feature "+entry.getKey());
346
                } catch (SAXNotSupportedException err) {
347
                    config.getStandardErrorOutput().println("XML Parser does not support the feature "+entry.getKey());
348
                }
349
            }
350
        }
351

  
352
        if(parserProperties != null) {
353
           for(Map.Entry<String, String> entry : parserProperties.entrySet()) {
354
               try {
355
                   parser.setProperty(entry.getKey(), entry.getValue());
356
               } catch (SAXNotRecognizedException err) {
357
                   config.getStandardErrorOutput().println("XML Parser does not recognize the property "+entry.getKey());
358
               } catch (SAXNotSupportedException err) {
359
                   config.getStandardErrorOutput().println("XML Parser does not support the property "+entry.getKey());
360
               }
361

  
362
           }
363

  
364

  
365

  
366
        }
367

  
336 368
        boolean xInclude = options.isXIncludeAware();
337 369
        if (xInclude) {
338 370
            boolean tryAgain = false;
latest9.5/hej/net/sf/saxon/lib/FeatureKeys.java
23 23
 
24 24
 public abstract class FeatureKeys {
25 25

  
26
 public final static String XML_PARSER_FEATURE =
27
"http://saxon.sf.net/feature/parserFeature?uri";
28

  
29
public final static String XML_PARSER_PROPERTY =
30
"http://saxon.sf.net/feature/parserProperty?uri";
31

  
26 32
        
27 33
/**
28 34
*            <p>ALLOW_EXTERNAL_FUNCTIONS determines whether calls to reflexive external functions are
latest9.5/hej/net/sf/saxon/lib/ParseOptions.java
27 27
import java.io.IOException;
28 28
import java.io.Serializable;
29 29
import java.util.ArrayList;
30
import java.util.HashMap;
30 31
import java.util.List;
32
import java.util.Map;
31 33

  
32 34

  
33 35
/**
......
62 64
    private int validationErrorLimit = Integer.MAX_VALUE;
63 65
    /*@Nullable*/ private ValidationParams validationParams = null;
64 66
    /*@Nullable*/ private ValidationStatisticsRecipient validationStatisticsRecipient = null;
67
    private Map<String, Boolean> parserFeatures = null;
68
    private Map<String, String> parserProperties = null;
65 69

  
66 70
    /**
67 71
     * Create a ParseOptions object with default options set
......
101 105
        validationErrorLimit = p.validationErrorLimit;
102 106
        continueAfterValidationErrors = p.continueAfterValidationErrors;
103 107
        addCommentsAfterValidationErrors = p.addCommentsAfterValidationErrors;
108
        if(p.parserFeatures != null){
109
            parserFeatures = new HashMap<String, Boolean>(p.parserFeatures);
110
        }
111
        if(p.parserProperties != null){
112
            parserProperties = new HashMap<String, String>(p.parserProperties);
113
        }
104 114
    }
105 115

  
106 116
    /**
......
155 165
            }
156 166
            filters.addAll(options.filters);
157 167
        }
168
        if(options.parserFeatures != null) {
169
            if(parserFeatures == null) {
170
                parserFeatures = new HashMap<String, Boolean>();
171
            }
172
            parserFeatures.putAll(options.parserFeatures);
173
        }
174
        if(options.parserProperties != null) {
175
            if(parserProperties == null) {
176
                parserProperties = new HashMap<String, String>();
177
            }
178
            parserProperties.putAll(options.parserProperties);
179
        }
158 180
        if (options.sourceIsXQJ) {
159 181
            sourceIsXQJ = true;
160 182
        }
......
173 195
        validationErrorLimit = java.lang.Math.min(validationErrorLimit, options.validationErrorLimit);
174 196
    }
175 197

  
198
    public void addParserFeature(String uri, boolean value){
199
        if(parserFeatures == null) {
200
            parserFeatures = new HashMap<String, Boolean>();
201
        }
202
         parserFeatures.put(uri, new Boolean(value));
203
    }
204

  
205
    public void addParserProperties(String uri, String value){
206
        if(parserProperties == null) {
207
            parserProperties = new HashMap<String, String>();
208
        }
209
         parserProperties.put(uri, value);
210
    }
211

  
212
    public boolean getParserFeature(String uri){
213
        return parserFeatures.get(uri).booleanValue();
214
    }
215

  
216
    public String getParserProperty(String name){
217
        return parserProperties.get(name);
218
    }
219

  
220
    public Map<String, Boolean> getParserFeatures(){
221
        return parserFeatures;
222
    }
223

  
224
    public Map<String, String> getParserProperties(){
225
        return parserProperties;
226
    }
227

  
228

  
229

  
176 230
    /**
177 231
     * Merge settings from the Configuration object into these parseOptions
178 232
     * @param config the Configuration. Settings from the Configuration are

Also available in: Unified diff