Revision 44276

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.lib/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/impl/DefaultFilesystemServerExplorer.java
23 23
package org.gvsig.fmap.dal.serverexplorer.filesystem.impl;
24 24

  
25 25
import java.io.File;
26
import java.io.FileInputStream;
27
import java.io.FileOutputStream;
28
import java.io.InputStream;
29
import java.io.OutputStream;
30
import java.net.MalformedURLException;
31
import java.net.URL;
32 26
import java.util.ArrayList;
33 27
import java.util.HashSet;
34 28
import java.util.Iterator;
35 29
import java.util.List;
36 30
import java.util.Set;
37
import java.util.logging.Level;
38
import java.util.logging.Logger;
39 31
import org.apache.commons.io.FilenameUtils;
40
import org.apache.commons.io.IOUtils;
41
import org.gvsig.fmap.dal.AbstractDataResource;
42 32

  
43 33
import org.gvsig.fmap.dal.DALFileLocator;
44 34
import org.gvsig.fmap.dal.DALLocator;
......
66 56
import org.gvsig.fmap.dal.spi.FileMultiResource;
67 57
import org.gvsig.tools.exception.BaseException;
68 58
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
59
import org.gvsig.tools.util.ResourcesStorage;
60
import org.gvsig.tools.util.SimpleFileResource;
69 61

  
70 62
@SuppressWarnings("UseSpecificCatch")
71 63
public class DefaultFilesystemServerExplorer extends AbstractDataServerExplorer
72 64
        implements FilesystemServerExplorerProviderServices,
73 65
        FilesystemFileFilter {
74 66

  
75
    private class FileResource 
76
            extends AbstractDataResource
77
            implements DataResource 
78
        {
79

  
80
        private final File f;
81
        private FileInputStream in;
82
        private FileOutputStream out;
83
        
84
        public FileResource(File f) {
85
            this.f = f;
86
        }
87

  
88
        public URL getURL() {
89
            try {
90
                return this.f.toURI().toURL();
91
            } catch (MalformedURLException ex) {
92
                return null;
93
            }
94
        }
95
        
96
        public File getFile() {
97
            return this.f;
98
        }
99
        
100
        @Override
101
        public boolean exists() {
102
            return this.f.exists();
103
        }
104

  
105
        @Override
106
        public InputStream asInputStream() throws java.io.FileNotFoundException {
107
            if( this.out != null || this.in!=null ) {
108
                throw new IllegalStateException("Input already open");
109
            }
110
            this.in = new FileInputStream(this.f);
111
            return this.in;
112
        }
113

  
114
        @Override
115
        public OutputStream asOutputStream() throws java.io.FileNotFoundException {
116
            if( this.out != null || this.in!=null ) {
117
                throw new IllegalStateException("Input already open");
118
            }
119
            this.out = new FileOutputStream(this.f);
120
            return this.out;
121
        }
122

  
123
        @Override
124
        public void close() {
125
            IOUtils.closeQuietly(out);
126
            IOUtils.closeQuietly(in);
127
            this.in = null;
128
            this.out = null;
129
        }
130
    }
131

  
132 67
    private File root;
133 68
    private File current; // Current path
134 69
    private List<FilesystemServerExplorerProvider> serverProviders;
......
559 494
    @Deprecated
560 495
    @Override
561 496
    public File getResourcePath(DataStore dataStore, String resourceName) throws DataException {
562
        FileResource resource = (FileResource) this.getResource(dataStore, resourceName);
497
        SimpleFileResource resource = (SimpleFileResource) this.getResource(dataStore, resourceName);
563 498
        if( resource==null ) {
564 499
            return null;
565 500
        }
......
567 502
    }
568 503

  
569 504
    @Override
570
    public DataResource getResource(DataStore dataStore, String resourceName) throws DataException {
505
    public org.gvsig.tools.util.ResourcesStorage.Resource getResource(DataStore dataStore, String resourceName) throws DataException {
571 506
        FilesystemServerExplorerProvider provider = this.getProvider(dataStore.getProviderName());
572 507
        if (provider == null) {
573 508
            return null;
......
586 521
        }
587 522
        File f = new File(FilenameUtils.getFullPathNoEndSeparator(rootPathName),resourceName);
588 523
        if( f.exists() ) {
589
            return new FileResource(f);
524
            return new SimpleFileResource(f);
590 525
        }
591
        return new FileResource(new File(rootPathName + "." + resourceName));
526
        return new SimpleFileResource(new File(rootPathName + "." + resourceName));
592 527
    }
528

  
529
    @Override
530
    public List<ResourcesStorage.Resource> getResources(DataStore dataStore, String resourceName) throws DataException {
531
        FilesystemServerExplorerProvider provider = this.getProvider(dataStore.getProviderName());
532
        if (provider == null) {
533
            return null;
534
        }
535
        String rootPathName = provider.getResourceRootPathName(dataStore);
536
        if (rootPathName == null) {
537
            return null;
538
        }
539
        List<ResourcesStorage.Resource>ress = new ArrayList<>();
540
        int n = 0;
541
        while(true) {
542
            String multiresourceName;
543
            if( n==0 ) {
544
                multiresourceName = resourceName;
545
            } else {
546
                multiresourceName = String.valueOf(n)+"."+resourceName;
547
            }
548
            File f = new File(rootPathName + "." + multiresourceName);
549
            if( !f.exists() ) {
550
                break;
551
            }
552
            ress.add(new SimpleFileResource(f));
553
            n++;
554
        }
555
        if( ress.isEmpty() ) {
556
            return null;
557
        }
558
        return ress;
559
    }
593 560
    
561
    
594 562
    @Override
595 563
    public DataStoreParameters get(String name) throws DataException {
596 564
        File theFile = new File(this.current,name);
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java
52 52
import org.gvsig.fmap.dal.DataManager;
53 53
import org.gvsig.fmap.dal.DataQuery;
54 54
import org.gvsig.fmap.dal.DataServerExplorer;
55
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
56 55
import org.gvsig.fmap.dal.DataSet;
57 56
import org.gvsig.fmap.dal.DataStore;
58 57
import org.gvsig.fmap.dal.DataStoreNotification;
......
1587 1586
    
1588 1587

  
1589 1588
    private void saveDALFile() {       
1590
        DataResource resource = null;
1589
        org.gvsig.tools.util.ResourcesStorage.Resource resource = null;
1591 1590
        try {
1592 1591
            DataServerExplorer explorer = this.getExplorer();
1593 1592
            if( explorer == null ) {
......
1610 1609
    }
1611 1610
    
1612 1611
    private void loadDALFile() {
1613
        DataResource resource = null;
1612
        org.gvsig.tools.util.ResourcesStorage.Resource resource = null;
1614 1613
        try {
1615 1614
            DataServerExplorer explorer = this.getExplorer();
1616 1615
            if( explorer == null ) {
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DALFile.java
7 7
import java.util.List;
8 8
import org.apache.commons.collections4.CollectionUtils;
9 9
import org.apache.commons.lang3.StringUtils;
10
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
11 10
import org.gvsig.fmap.dal.exception.DataException;
12 11
import org.gvsig.fmap.dal.feature.FeatureType;
13 12
import org.gvsig.tools.ToolsLocator;
......
32 31
        return f;
33 32
    }
34 33

  
35
    public static DALFile getDALFile(DataResource resource) {
34
    public static DALFile getDALFile(org.gvsig.tools.util.ResourcesStorage.Resource resource) {
36 35
        DALFile df = new DALFile();
37 36
        df.read(resource);
38 37
        return df;
......
70 69
        return false;
71 70
    }
72 71
    
73
    public void write(DataResource resource) {
72
    public void write(org.gvsig.tools.util.ResourcesStorage.Resource resource) {
74 73
        try {
75 74
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
76 75
            PersistentState state = manager.getState(this);
......
81 80
        }
82 81
    }
83 82

  
84
    public void read(DataResource resource) {
83
    public void read(org.gvsig.tools.util.ResourcesStorage.Resource resource) {
85 84
        try {
86 85
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
87 86
            InputStream in = resource.asInputStream();
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DALResourcesStorage.java
1 1
package org.gvsig.fmap.dal.impl;
2 2

  
3
import java.util.List;
3 4
import org.gvsig.fmap.dal.DataServerExplorer;
4 5
import org.gvsig.fmap.dal.DataStore;
5 6
import org.gvsig.tools.util.ResourcesStorage;
......
31 32
    @Override
32 33
    public Resource getResource(String name) {
33 34
        try {
34
            DataServerExplorer.DataResource resource = explorer.getResource(store, name);
35
            Resource resource = explorer.getResource(store, name);
35 36
            return resource;
36 37
        } catch (Exception ex) {
37 38
            return null;
......
39 40
    }
40 41

  
41 42
    @Override
43
    public List<Resource> getResources(String name) {
44
        try {
45
            List<Resource> resources = explorer.getResources(store, name);
46
            return resources;
47
        } catch (Exception ex) {
48
            return null;
49
        }
50
    }
51

  
52
    
53
    @Override
42 54
    public boolean exists(String name) {
43 55
        try {
44
            DataServerExplorer.DataResource resource = explorer.getResource(store, name);
56
            Resource resource = explorer.getResource(store, name);
45 57
            return resource.exists();
46 58
        } catch (Exception ex) {
47 59
            return false;
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialExplorer.java
1 1
package org.gvsig.fmap.dal.store.h2;
2 2

  
3 3
import java.io.File;
4
import java.util.ArrayList;
5
import java.util.List;
4 6
import org.apache.commons.io.FilenameUtils;
5 7
import org.gvsig.fmap.dal.DataStore;
6 8
import org.gvsig.fmap.dal.exception.DataException;
......
10 12
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
11 13
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
12 14
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCServerExplorerBase;
15
import org.gvsig.tools.util.ResourcesStorage.Resource;
13 16

  
14 17
/**
15 18
 *
......
28 31
    }
29 32

  
30 33
    @Override
31
    public DataResource getResource(DataStore dataStore, String resourceName) throws DataException {
34
    public Resource getResource(DataStore dataStore, String resourceName) throws DataException {
32 35
        String zipPath = this.getParameters().getFile().getAbsolutePath();
33 36
        zipPath = FilenameUtils.removeExtension(zipPath);
34 37
        FileMultiResource resource = new FileMultiResource(new File(zipPath), dataStore.getName(),resourceName);
35 38
        return resource;
36 39
    }
37 40
    
41
    @Override
42
    public List<Resource> getResources(DataStore dataStore, String resourceName) throws DataException {
43
        String zipPath = this.getParameters().getFile().getAbsolutePath();
44
        zipPath = FilenameUtils.removeExtension(zipPath);
45
        List<Resource>ress = new ArrayList<>();
46
        int n = 0;
47
        while(true) {
48
            String multiresourceName;
49
            if( n==0 ) {
50
                multiresourceName = resourceName;
51
            } else {
52
                multiresourceName = String.valueOf(n)+"."+resourceName;
53
            }
54
            FileMultiResource resource = new FileMultiResource(new File(zipPath), dataStore.getName(),multiresourceName);
55
            if( !resource.exists() ) {
56
                break;
57
            }
58
            ress.add(resource);
59
            n++;
60
        }
61
        if( ress.isEmpty() ) {
62
            return null;
63
        }
64
        return ress;
65
    }
38 66
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataServerExplorer.java
23 23
 */
24 24
package org.gvsig.fmap.dal;
25 25

  
26
import java.io.Closeable;
27 26
import java.io.File;
28
import java.io.IOException;
29
import java.io.InputStream;
30
import java.io.OutputStream;
31
import java.net.URL;
32 27
import java.util.List;
33 28

  
34 29
import org.gvsig.fmap.dal.exception.DataException;
35
import static org.gvsig.tools.dataTypes.DataTypes.URL;
36 30
import org.gvsig.tools.dispose.Disposable;
37 31
import org.gvsig.tools.util.ResourcesStorage.Resource;
38 32

  
......
45 39
 */
46 40
public interface DataServerExplorer extends Disposable, DataFactoryUnit {
47 41

  
48
    public interface DataResource extends Resource {
49
        @Override
50
        public URL getURL();
51
        
52
        @Override
53
        public boolean exists();
54
        
55
        @Override
56
        public InputStream asInputStream() throws IOException;
57
        
58
        @Override
59
        public OutputStream asOutputStream() throws IOException;
60
        
61
        @Override
62
        public void close();
63
    }
64
    
42
//    public interface DataResource extends Resource {
43
//        @Override
44
//        public URL getURL();
45
//        
46
//        @Override
47
//        public boolean exists();
48
//        
49
//        @Override
50
//        public InputStream asInputStream() throws IOException;
51
//        
52
//        @Override
53
//        public OutputStream asOutputStream() throws IOException;
54
//        
55
//        @Override
56
//        public void close();
57
//    }
58
//    
65 59
    /**
66 60
     * Returns the DataServerExplorer's name
67 61
     *
......
197 191
     * @return the DataResource or null
198 192
     * @throws DataException
199 193
     */
200
    public DataResource getResource(DataStore dataStore, String resourceName) throws DataException;
194
    public Resource getResource(DataStore dataStore, String resourceName) throws DataException;
195

  
196
    public List<Resource> getResources(DataStore dataStore, String resourceName) throws DataException;
201 197
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/AbstractDataResource.java
4 4
import java.io.InputStream;
5 5
import java.io.OutputStream;
6 6
import java.net.URL;
7
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
7
import org.gvsig.tools.util.ResourcesStorage.Resource;
8 8

  
9

  
9 10
/**
10 11
 *
11 12
 * @author jjdelcerro
12 13
 */
13
public abstract class AbstractDataResource implements DataResource {
14
public abstract class AbstractDataResource implements Resource {
14 15

  
15 16
    @Override
16 17
    public URL getURL() {
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/FileMultiResource.java
21 21
import org.apache.commons.io.IOUtils;
22 22
import org.apache.commons.lang3.StringUtils;
23 23
import org.gvsig.fmap.dal.AbstractDataResource;
24
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
24
import org.gvsig.tools.util.ResourcesStorage.Resource;
25 25
import org.slf4j.LoggerFactory;
26 26

  
27 27
/**
......
31 31
@SuppressWarnings("UseSpecificCatch")
32 32
public class FileMultiResource
33 33
        extends AbstractDataResource
34
        implements DataResource {
34
        implements Resource {
35 35

  
36 36
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(FileMultiResource.class);
37 37

  
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/spi/AbstractDataServerExplorer.java
1 1
package org.gvsig.fmap.dal.spi;
2 2

  
3 3
import java.io.File;
4
import java.util.List;
4 5
import org.gvsig.fmap.dal.DataServerExplorerParameters;
5 6
import org.gvsig.fmap.dal.DataServerExplorer_v2;
6 7
import org.gvsig.fmap.dal.DataStore;
......
10 11
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
11 12
import org.gvsig.tools.dispose.impl.AbstractDisposable;
12 13
import org.gvsig.tools.exception.BaseException;
14
import org.gvsig.tools.util.ResourcesStorage.Resource;
13 15

  
14 16
public abstract class AbstractDataServerExplorer extends AbstractDisposable implements DataServerExplorer_v2 {
15 17

  
......
47 49
    }
48 50

  
49 51
    @Override
50
    public DataResource getResource(DataStore dataStore, String resourceName) throws DataException {
52
    public Resource getResource(DataStore dataStore, String resourceName) throws DataException {
51 53
        return null;
52 54
    }
53 55
    
54 56
    @Override
57
    public List<Resource> getResources(DataStore dataStore, String resourceName) throws DataException {
58
        return null;
59
    }
60
    
61
    @Override
55 62
    public SQLBuilder createSQLBuilder() {
56 63
        return new SQLBuilderBase();
57 64
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java
26 26
import java.awt.Font;
27 27
import java.io.File;
28 28
import java.io.FileFilter;
29
import java.io.FileInputStream;
30
import java.io.FileNotFoundException;
31
import java.io.IOException;
32 29
import java.io.InputStream;
33 30
import java.lang.reflect.InvocationTargetException;
34 31
import java.lang.reflect.Method;
35 32
import java.util.ArrayList;
36
import java.util.Collections;
37 33
import java.util.HashMap;
38 34
import java.util.Iterator;
39 35
import java.util.LinkedHashMap;
......
45 41
import org.cresques.cts.IProjection;
46 42
import org.gvsig.fmap.crs.CRSFactory;
47 43
import org.gvsig.fmap.dal.DataServerExplorer;
48
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
49 44
import org.gvsig.fmap.dal.DataStore;
50 45
import org.gvsig.fmap.dal.DataStoreParameters;
51 46
import org.gvsig.fmap.dal.exception.DataException;
......
85 80
import org.gvsig.tools.observer.ObservableHelper;
86 81
import org.gvsig.tools.observer.Observer;
87 82
import org.gvsig.tools.persistence.PersistenceManager;
83
import org.gvsig.tools.util.ResourcesStorage.Resource;
88 84
import org.slf4j.Logger;
89 85
import org.slf4j.LoggerFactory;
90 86

  
......
585 581
    public ILegend getLegend(DataStore dataStore) {
586 582
        ILegend legend = null;
587 583

  
588
        DataResource resource = getResource(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1));
584
        Resource resource = getResource(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1));
589 585
        try {
590 586
            if ((resource != null) && (resource.exists())) {
591 587
                PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
......
635 631
    public ILabelingStrategy getLabelingStrategy(DataStore dataStore) {
636 632
        ILabelingStrategy labelingStrategy = null;
637 633

  
638
        DataResource resource = getResource(dataStore, SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1));
634
        Resource resource = getResource(dataStore, SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1));
639 635
        try {
640 636
            if ((resource != null) && (resource.exists())) {
641 637
                PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
......
689 685
    }
690 686

  
691 687
    
692
    private DataResource getResource(DataStore dataStore, String resource) {
688
    private Resource getResource(DataStore dataStore, String resource) {
693 689
        DataServerExplorer explorer = null;
694 690
        try {
695 691
            explorer = dataStore.getExplorer();
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/DefaultFeatureTypeDefinitionsManager.java
18 18
import org.gvsig.andami.PluginsLocator;
19 19
import org.gvsig.andami.PluginsManager;
20 20
import org.gvsig.fmap.dal.DataServerExplorer;
21
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
22 21
import org.gvsig.fmap.dal.DataStoreParameters;
23 22
import org.gvsig.fmap.dal.complements.RelatedFeatures;
24
import org.gvsig.fmap.dal.exception.DataException;
25 23
import org.gvsig.fmap.dal.feature.AbstractFeatureTypeDefinitionsManager;
26 24
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
27 25
import org.gvsig.fmap.dal.feature.FeatureStore;
......
31 29
import org.gvsig.tools.dataTypes.DataTypes;
32 30
import org.gvsig.tools.dispose.DisposeUtils;
33 31
import org.gvsig.tools.dynform.JDynForm;
34
import static org.gvsig.tools.dynform.JDynForm.USE_PLAIN;
35
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
36 32
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.TAG_DYNFORM_LAYOUTMODE;
37
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.TAG_DYNFORM_LAYOUTMODE_VALUE_PLAIN;
38 33
import org.gvsig.tools.dynobject.DynClass;
39 34
import org.gvsig.tools.dynobject.DynClass_v2;
40 35
import org.gvsig.tools.dynobject.DynField_v2;
41 36
import org.gvsig.tools.dynobject.DynObjectManager;
42 37
import org.gvsig.tools.dynobject.Tags;
43 38
import org.gvsig.tools.util.HasAFile;
39
import org.gvsig.tools.util.ResourcesStorage.Resource;
44 40
import org.slf4j.Logger;
45 41
import org.slf4j.LoggerFactory;
46 42

  
......
153 149
        File definitionFile = getDefinitionFile(key);
154 150
        if (definitionFile == null) {
155 151
            DataServerExplorer explorer = null;
156
            DataResource resource = null;
152
            Resource resource = null;
157 153
            try {
158 154
                explorer = store.getExplorer();
159 155
                resource = explorer.getResource(store, FILE_EXTENSION);

Also available in: Unified diff