Revision 712 org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.lib/org.gvsig.topology.lib.api/src/main/java/org/gvsig/topology/lib/spi/RuleResourceLoaderUtils.java

View differences:

RuleResourceLoaderUtils.java
5 5
 */
6 6
package org.gvsig.topology.lib.spi;
7 7

  
8
import java.io.File;
8 9
import java.io.InputStream;
10
import java.net.MalformedURLException;
9 11
import java.net.URL;
10 12
import java.util.List;
11 13
import java.util.Locale;
14
import java.util.logging.Level;
12 15
import org.apache.commons.io.IOUtils;
13 16
import org.apache.commons.lang3.StringUtils;
14 17
import org.json.JSONArray;
......
37 40
        return url;
38 41
    }
39 42
    
40
    public static JSONObject getRule(String idRule) {
41
        URL url = getRuleURL(idRule);
43
    public static JSONObject getRule(URL url) {
42 44
        if( url == null ) {
43 45
            return null;
44 46
        }
......
57 59
        return json;
58 60
    }
59 61

  
62
    public static JSONObject getRule(String idRuleOrPathname) {
63
        if( idRuleOrPathname==null ) {
64
            return null;
65
        }
66
        if( idRuleOrPathname.endsWith(".json") ) {
67
            // Asumimos que es una ruta al fichero json.
68
            return getRule(new File(idRuleOrPathname));
69
        }
70
        // Asumimos que es un ID de regla
71
        URL url = getRuleURL(idRuleOrPathname);
72
        if( url == null ) {
73
            return null;
74
        }
75
        return getRule(url);
76
    }
77
    
78
    public static JSONObject getRule(File jsonfile) {
79
        if( jsonfile == null || !jsonfile.exists() ) {
80
            return null;
81
        }
82
        try {
83
            return getRule(jsonfile.toURI().toURL());
84
        } catch (MalformedURLException ex) {
85
            LOGGER.warn("Can't load resource from json file '"+jsonfile.toString()+"'.", ex);
86
            return null;
87
        }
88
    }
89

  
60 90
    public static String getDescription(String idRule, JSONObject json) {
61 91
        String description = null;
62 92
        

Also available in: Unified diff