Project

Profile

Help

Revision bd65cae9

Added by Michael Kay 5 months ago

Fix Feature #4838 - Configuration property for ZIP file URIs

View differences:

latest10/hej/net/sf/saxon/Configuration.java
160 160
    private transient DynamicLoader dynamicLoader = new DynamicLoader();
161 161

  
162 162
    private IntSet enabledProperties = new IntHashSet(64);
163

  
163
    private String zipUriPattern = null;
164 164
    private List<ExternalObjectModel> externalObjectModels = new ArrayList<>(4);
165 165
    protected IndependentContext staticContextForSystemFunctions;
166 166

  
......
4812 4812
                    //getDefaultXsltCompilerInfo().setXsltVersion(v);
4813 4813
                    break;
4814 4814

  
4815
                case FeatureCode.ZIP_URI_PATTERN:
4816
                    zipUriPattern = (String)value;
4817
                    break;
4818

  
4815 4819
                default:
4816 4820
                    throw new IllegalArgumentException("Unknown configuration property " + name);
4817 4821
            }
......
5280 5284
            case FeatureCode.XSLT_VERSION:
5281 5285
                return (T) Integer.valueOf(30);
5282 5286

  
5287
            case FeatureCode.ZIP_URI_PATTERN:
5288
                return zipUriPattern == null ? (T)Feature.ZIP_URI_PATTERN.defaultValue : (T)zipUriPattern;
5289

  
5283 5290
        }
5284 5291
        throw new IllegalArgumentException("Unknown configuration property " + feature.name);
5285 5292
    }
latest10/hej/net/sf/saxon/lib/Feature.java
8 8

  
9 9
package net.sf.saxon.lib;
10 10

  
11
import net.sf.saxon.trans.RecoveryPolicy;
12

  
13 11
import java.util.Iterator;
14 12
import java.util.Map;
15 13
import java.util.TreeMap;
......
2231 2229

  
2232 2230
// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE
2233 2231

  
2234
            
2232
    /**
2233
     *
2234
     *             <p>A regular expression used to decide whether a collection URI is to
2235
     *                 be treated as representing a ZIP file. The default pattern is
2236
     *                 "^jar:|\.jar$|\.zip$" which matches a URI that starts with "jar:"
2237
     *                 or that ends with ".jar" or ".zip".</p>
2238
     *
2239
     *
2240
     *             <p>This is used by the standard Collection Finder and may not be relevant
2241
     *                 if a custom Collection Finder is in use.
2242
     *             </p>
2243
     *             <p>If the absolutized URI passed to the collection() function matches
2244
     *             this pattern, then the URI will be treated as a reference to a ZIP file
2245
     *             (and will therefore fail if the URI does not resolve to a resource that can
2246
     *             be opened as a ZIP file).</p>
2247
     *
2248
     *
2249
     */
2250

  
2251
    public final static Feature<String> ZIP_URI_PATTERN = new Feature<>(
2252
            "http://saxon.sf.net/feature/zipUriPattern", 127, HE, String.class, "^jar:|\\.jar$|\\.zip$");
2253

  
2254

  
2235 2255
}
2236 2256
        
latest10/hej/net/sf/saxon/lib/FeatureCode.java
270 270
    public final static int RETAIN_NODE_FOR_DIAGNOSTICS = 125;
271 271
    /** @see Feature#ALLOW_UNRESOLVED_SCHEMA_COMPONENTS  */
272 272
    public final static int ALLOW_UNRESOLVED_SCHEMA_COMPONENTS = 126;
273
    /**
274
     * @see Feature#ZIP_URI_PATTERN
275
     */
276
    public final static int ZIP_URI_PATTERN = 127;
273 277

  
274 278

  
275
    public final static int MAX = 127;
279
    public final static int MAX = 128;
276 280

  
277 281
}
278 282
        
latest10/hej/net/sf/saxon/lib/FeatureKeys.java
8 8

  
9 9
package net.sf.saxon.lib;
10 10

  
11
import net.sf.saxon.trans.RecoveryPolicy;
12

  
13 11
// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE
14 12

  
15 13
/**
......
2204 2202

  
2205 2203
// AUTO-GENERATED FROM FeatureKeys.xml - DO NOT EDIT THIS FILE
2206 2204

  
2205
    /**
2206
     * <p>A regular expression used to decide whether a collection URI is to
2207
     * be treated as representing a ZIP file. The default pattern is
2208
     * "^jar:|\.jar$|\.zip$" which matches a URI that starts with "jar:"
2209
     * or that ends with ".jar" or ".zip".</p>
2210
     *
2211
     *
2212
     * <p>This is used by the standard Collection Finder and may not be relevant
2213
     * if a custom Collection Finder is in use.
2214
     * </p>
2215
     * <p>If the absolutized URI passed to the collection() function matches
2216
     * this pattern, then the URI will be treated as a reference to a ZIP file
2217
     * (and will therefore fail if the URI does not resolve to a resource that can
2218
     * be opened as a ZIP file).</p>
2219
     */
2220

  
2221
    public final static String ZIP_URI_PATTERN =
2222
            "http://saxon.sf.net/feature/zipUriPattern";
2223

  
2207 2224

  
2208 2225
}
2209 2226
        
latest10/hej/net/sf/saxon/lib/StandardEntityResolver.java
30 30
 */
31 31
public class StandardEntityResolver implements EntityResolver {
32 32

  
33
    private static HashMap<String, String> publicIds = new HashMap<>(30);
34
    private static HashMap<String, String> systemIds = new HashMap<>(30);
33
    private static HashMap<String, String> publicIds = new HashMap<>(150);
34
    private static HashMap<String, String> systemIds = new HashMap<>(250);
35 35

  
36 36
    public Configuration config;
37 37

  
latest10/hej/net/sf/saxon/resource/StandardCollectionFinder.java
12 12
import net.sf.saxon.functions.ResolveURI;
13 13
import net.sf.saxon.functions.URIQueryParameters;
14 14
import net.sf.saxon.lib.CollectionFinder;
15
import net.sf.saxon.lib.Feature;
15 16
import net.sf.saxon.lib.ResourceCollection;
17
import net.sf.saxon.regex.JavaRegularExpression;
16 18
import net.sf.saxon.trans.Err;
17 19
import net.sf.saxon.trans.XPathException;
18 20

  
......
114 116

  
115 117
        // check if file is a zip file
116 118

  
117
        if (isJarFileURI(collectionURI)) {
119
        String regex = context.getConfiguration().getConfigurationProperty(Feature.ZIP_URI_PATTERN);
120
        if (isJarFileURI(collectionURI) || new JavaRegularExpression(regex, "").containsMatch(collectionURI)) {
118 121
            return new JarCollection(context, collectionURI, params);
119 122
        }
120 123

  
......
144 147
     * This method is provided so that it can be overridden in subclasses. The default implementation
145 148
     * returns true if the collection URI ends with the extension ".jar" or ".zip", or if it
146 149
     * is a URI using the "jar" scheme.
150
     * <p>This method is retained for compatibility, as it can be overridden in a subclass.
151
     * The preferred mechanism now is to set the configuration property {@link Feature#ZIP_URI_PATTERN}.</p>
147 152
     * @param collectionURI the requested absolute collection URI
148 153
     * @return true if the collection URI should be interpreted as a JAR or ZIP file
149 154
     */
150 155

  
151 156
    protected boolean isJarFileURI(String collectionURI) {
152
        return collectionURI.endsWith(".jar") ||
153
            collectionURI.endsWith(".zip") ||
154
            collectionURI.startsWith("jar:");
157
        return false;
158
//        return collectionURI.endsWith(".jar") ||
159
//            collectionURI.endsWith(".zip") ||
160
//            collectionURI.startsWith("jar:");
155 161
    }
156 162

  
157 163

  
latest10/hej/net/sf/saxon/trans/ConfigurationReader.java
402 402
        applyProperty(props, "validationWarnings", Feature.VALIDATION_WARNINGS);
403 403
        applyProperty(props, "versionOfXml", Feature.XML_VERSION);
404 404
        applyProperty(props, "xInclude", Feature.XINCLUDE);
405
        applyProperty(props, "zipUriPattern", Feature.ZIP_URI_PATTERN);
405 406
    }
406 407

  
407 408
    private void applyProperty(Properties props, String attributeName, Feature feature) {

Also available in: Unified diff