Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2021 / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVectLinkProperties.java @ 34093

History | View | Annotate | Download (5.21 KB)

1
package org.gvsig.fmap.mapcontext.layers.vectorial;
2

    
3
import java.awt.geom.Point2D;
4
import java.io.File;
5
import java.net.URI;
6
import java.net.URISyntaxException;
7
import java.util.ArrayList;
8

    
9
import org.gvsig.fmap.dal.exception.DataException;
10
import org.gvsig.fmap.dal.exception.ReadException;
11
import org.gvsig.fmap.dal.feature.Feature;
12
import org.gvsig.fmap.dal.feature.FeatureSet;
13
import org.gvsig.fmap.dal.feature.FeatureStore;
14
import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties;
15
import org.gvsig.fmap.mapcontext.layers.FLayer;
16
import org.gvsig.tools.ToolsLocator;
17
import org.gvsig.tools.dispose.DisposableIterator;
18
import org.gvsig.tools.dynobject.DynStruct;
19
import org.gvsig.tools.persistence.PersistenceManager;
20

    
21

    
22
/**
23
 * This class extends AbstractLinkProperties and implements the method to get an array of URI
24
 * using a point2D and a tolerance. This class extends AstractLinkProperties to add HyperLink
25
 * to Vectorial Layer(FLyrVect)
26
 * 
27
 * @deprecated this functionality has extracted of the core form gvSIG 2.0 
28
 */
29

    
30
public class FLyrVectLinkProperties extends AbstractLinkProperties {
31

    
32
    /**
33
     * Default Constructor. Costructs a LinkProperties with the necessary information
34
     *
35
     */
36
    public FLyrVectLinkProperties(){
37
        setType(0);
38
        setField(null);
39
        setExt(null);
40
    }
41

    
42
    /**
43
     * Constructor. Constructs a LinkProperties with the information that receives
44
     * @param tipo
45
     * @param fieldName
46
     * @param extension
47
     */
48
    public FLyrVectLinkProperties(int tipo, String fieldName, String extension){
49
        setType(tipo);
50
        setField(fieldName);
51
        setExt(extension);
52
    }
53

    
54
    /**
55
     * Creates an array of URI. With the point and the tolerance makes a query to the layer
56
     * and gets the geometries that contains the point with a certain error (tolerance).
57
     * For each one of this geometries creates one URI and adds it to the array
58
     * @param layer
59
     * @param point
60
     * @param tolerance
61
     * @return Array of URI
62
     * @throws ReadException
63
     */
64
    public URI[] getLink(FLayer layer, Point2D point, double tolerance) throws ReadException{
65
            //Sacado de la clase LinkListener
66
                FLyrVect lyrVect = (FLyrVect) layer;
67
                FeatureStore fStore = null;
68
                FeatureSet fSet=null;
69
                DisposableIterator iter = null;
70

    
71
            try {
72
                    fStore = lyrVect.getFeatureStore();
73
                    //URI uri[]=null;
74

    
75
                    //Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que
76
                    try {
77
                            fSet = lyrVect.queryByPoint(point, tolerance, fStore.getDefaultFeatureType());//fStore.getFeatureSet(featureQuery);
78
                    } catch (ReadException e) {
79
                            return null;
80
                    } catch (DataException e) {
81
                            return null;
82
                        }
83

    
84
                    //Si el bitset creado no est? vac?o creamos el vector de URLS correspondientes
85
                    //a la consulta que hemos hecho.
86

    
87
                    ArrayList tmpUris=new ArrayList();
88
                    String auxext="";
89
                    int idField = fStore.getDefaultFeatureType().getIndex(this.getField());
90

    
91

    
92

    
93

    
94
                    //Consigo el identificador del campo pasandole como par?metro el
95
                    //nombre del campo del ?nlace
96
                    if (idField == -1){
97
                        throw new ReadException(lyrVect.getName()+": '"+this.getField()+"' not found",new Exception());
98
                    }
99
                    //Recorremos el BitSet siguiendo el ejmplo de la clase que se
100
                    //proporciona en la API
101
                    iter = fSet.iterator();
102
                    while (iter.hasNext()){
103
                            //TODO
104
                            //Sacado de la clase LinkPanel, decidir como pintar la URL le
105
                            //corresponde a LinkPanel, aqu? solo creamos el vector de URL?s
106
                            if (!super.getExt().equals("")){
107
                                    auxext="."+this.getExt();
108
                            }
109
                            //Creamos el fichero con el nombre del campo y la extensi?n.
110
                            Feature feature = (Feature) iter.next();
111
                            String auxField=feature.getString(idField);
112
                            URI tmpUri = null;
113
                            if(auxField.startsWith("http:/")){
114
                                    tmpUri= new URI(auxField);
115
                            }else{
116
                                    File file =new File(feature.getString(idField)+auxext);
117
                                    tmpUri = file.toURI();
118
                            }
119
                            tmpUris.add(tmpUri);
120
                            System.out.println(tmpUri.toString());
121

    
122

    
123
                    }
124

    
125
                    if (tmpUris.size()==0){
126
                            return null;
127
                    }
128

    
129
                    // Creo el vector de URL?s con la misma longitud que el bitset
130

    
131
                    return (URI[]) tmpUris.toArray(new URI[0]);
132

    
133
            } catch (ReadException e) {
134
                    throw new ReadException(lyrVect.getName(),e);
135
            } catch (URISyntaxException e) {
136
                    throw new ReadException(lyrVect.getName(),e);
137
                } catch (DataException e) {
138
                        throw new ReadException(lyrVect.getName(),e);
139
                }finally{
140
                        if (iter != null) {
141
                                iter.dispose();
142
                        }
143
                        if (fSet != null) {
144
                                fSet.dispose();
145
                        }
146
                }
147

    
148
    }
149

    
150
        public static void registerPersistent() {
151
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
152
                DynStruct definition = manager.addDefinition(
153
                                FLyrVectLinkProperties.class,
154
                                "FLyrVectLinkProperties",
155
                                "FLyrVectLinkProperties Persistence definition",
156
                                null, 
157
                                null
158
                );
159
                definition.addDynFieldInt("typeLink").setMandatory(true);
160
                definition.addDynFieldString("fieldName").setMandatory(true);
161
                definition.addDynFieldString("extName").setMandatory(true);
162
        }
163

    
164

    
165
}