Revision 42792 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/DefaultFeatureTypeDefinitionsManager.java

View differences:

DefaultFeatureTypeDefinitionsManager.java
2 2

  
3 3
import java.io.File;
4 4
import java.io.FileInputStream;
5
import java.io.FileOutputStream;
5 6
import java.io.IOException;
6 7
import java.io.InputStream;
7 8
import java.nio.charset.Charset;
......
9 10
import java.util.Map;
10 11
import java.util.Properties;
11 12
import java.util.zip.CRC32;
13

  
12 14
import org.apache.commons.io.FileUtils;
13 15
import org.apache.commons.io.IOUtils;
14 16
import org.gvsig.andami.PluginServices;
......
96 98
        if (f.exists()) {
97 99
            return f;
98 100
        }
101
        f = new File(s);
102
        if (f.exists()) {
103
            return f;
104
        }
99 105
        return null;
100 106
    }
101 107

  
......
113 119
        DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
114 120
        try {
115 121
            String xml = FileUtils.readFileToString(definitionFile);
122
            xml = xml.replaceAll("@@@",definitionFile.getParentFile().getAbsolutePath());
123

  
116 124
            InputStream is = IOUtils.toInputStream(xml, Charset.forName("UTF-8"));
117 125
            Map<String, DynClass> dynClasses = dynObjectManager.importDynClassDefinitions(is, this.getClass().getClassLoader());
118 126
            for (DynClass aDynClass : dynClasses.values()) {
......
157 165
    }
158 166
    
159 167
    public void addModel(File model) {
160
        //  TODO:
168
    	  DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager();
169
          try {
170
              String xml = FileUtils.readFileToString(model);
171
              InputStream is = IOUtils.toInputStream(xml, Charset.forName("UTF-8"));
172
              Map<String, DynClass> dynClasses = dynObjectManager.importDynClassDefinitions(is, this.getClass().getClassLoader());
173
              
174
              File folder;
175
              try {
176
                  folder = getDefinitionsFolder();
177
              } catch (IOException ex) {
178
                  return ;
179
              }
180
              Properties prop = new Properties();
181
              FileInputStream fin = null;
182
              try {
183
                  fin = new FileInputStream(new File(folder, "index.properties"));
184
                  prop.load(fin);
185
              } catch (IOException ex) {
186
              } finally {
187
                  IOUtils.closeQuietly(fin);
188
              }
189
              for (DynClass aDynClass : dynClasses.values()) {
190
            	  String className = aDynClass.getName();
191
            	  prop.setProperty(className, model.getAbsolutePath());
192
              }
193
              FileOutputStream fout = null;
194
              try {
195
            	  fout = new FileOutputStream(new File(folder, "index.properties"));
196
                  prop.store(fout, "");
197
              } catch (IOException ex) {
198
              } finally {
199
                  IOUtils.closeQuietly(fout);
200
              }
201
              
202
          } catch (Exception ex) {
203
              logger.warn("Can't parse xml definition.", ex);
204
          }
161 205
    }
162 206

  
163 207
}

Also available in: Unified diff