Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / FLyrVectLinkProperties.java @ 21574

History | View | Annotate | Download (4.61 KB)

1
package org.gvsig.fmap.mapcontext.layers;
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
import java.util.Iterator;
9

    
10
import org.gvsig.data.ReadException;
11
import org.gvsig.data.vectorial.Feature;
12
import org.gvsig.data.vectorial.FeatureCollection;
13
import org.gvsig.data.vectorial.FeatureStore;
14
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
15
import org.opengis.filter.Filter;
16

    
17

    
18
/**
19
 * This class extends AbstractLinkProperties and implements the method to get an array of URI
20
 * using a point2D and a tolerance. This class extends AstractLinkProperties to add HyperLink
21
 * to Vectorial Layer(FLyrVect)
22
 */
23

    
24
public class FLyrVectLinkProperties extends AbstractLinkProperties{
25

    
26
    /**
27
     * Default Constructor. Costructs a LinkProperties with the necessary information
28
     *
29
     */
30
    public FLyrVectLinkProperties(){
31
        setType(0);
32
        setField(null);
33
        setExt(null);
34
    }
35

    
36
    /**
37
     * Constructor. Constructs a LinkProperties with the information that receives
38
     * @param tipo
39
     * @param fieldName
40
     * @param extension
41
     */
42
    public FLyrVectLinkProperties(int tipo, String fieldName, String extension){
43
        setType(tipo);
44
        setField(fieldName);
45
        setExt(extension);
46
    }
47

    
48
    /**
49
     * Creates an array of URI. With the point and the tolerance makes a query to the layer
50
     * and gets the geometries that contains the point with a certain error (tolerance).
51
     * For each one of this geometries creates one URI and adds it to the array
52
     * @param layer
53
     * @param point
54
     * @param tolerance
55
     * @return Array of URI
56
     * @throws ReadException
57
     */
58
    public URI[] getLink(FLayer layer, Point2D point, double tolerance) throws ReadException{
59
            //Sacado de la clase LinkListener
60
                FLyrVect lyrVect = (FLyrVect) layer;
61
                FeatureStore fStore = null;
62
                FeatureCollection fCollection=null;
63

    
64
            try {
65
                    fStore = lyrVect.getFeatureStore();
66
                    URI uri[]=null;
67

    
68
                    //Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que
69
                    //hacemos a la capa.
70
                    //String filter = "true = false"; //FIXME: Funcion!!!
71
                    Filter filter = null; //FIXME: Funcion!!!
72
                    
73
                    try {
74
                            fCollection = (FeatureCollection)fStore.getDataCollection(fStore.getDefaultFeatureType(), filter, null);
75
                    } catch (ReadException e) {
76
                            return null;
77
                    }
78

    
79
                    Iterator iter = null;
80
                    //Si el bitset creado no est? vac?o creamos el vector de URLS correspondientes
81
                    //a la consulta que hemos hecho.
82

    
83
                    ArrayList tmpUris=new ArrayList();
84
                    String auxext="";
85
                    int idField = fStore.getDefaultFeatureType().getFieldIndex(this.getField());
86

    
87

    
88

    
89

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

    
120

    
121
                    }
122

    
123
                    if (tmpUris.size()==0){
124
                            return null;
125
                    }
126

    
127
                    //Creo el vector de URL?s con la misma longitud que el bitset
128
                    uri = new URI[tmpUris.size()];
129
                    iter = tmpUris.iterator();
130
                    int i=0;
131
                    while (iter.hasNext()){
132
                            uri[i]=(URI) iter.next();
133
                            i++;
134
                    }
135

    
136
                    return uri;
137

    
138
            } catch (ReadException e) {
139
                    throw new ReadException(lyrVect.getName(),e);
140
            } catch (URISyntaxException e) {
141
                    throw new ReadException(lyrVect.getName(),e);
142
                }finally{
143
                        fCollection.dispose();
144
                }
145

    
146
    }
147

    
148
        public String getClassName() {
149
                // TODO Auto-generated method stub
150
                return null;
151
        }
152

    
153

    
154
}