Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVectLinkProperties.java @ 27525

History | View | Annotate | Download (4.59 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.DisposableIterator;
12
import org.gvsig.fmap.dal.feature.Feature;
13
import org.gvsig.fmap.dal.feature.FeatureSet;
14
import org.gvsig.fmap.dal.feature.FeatureStore;
15
import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties;
16
import org.gvsig.fmap.mapcontext.layers.FLayer;
17

    
18

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

    
25
public class FLyrVectLinkProperties extends AbstractLinkProperties{
26

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

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

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

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

    
69
                    //Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que
70
                    try {
71
                            fSet = lyrVect.queryByPoint(point, tolerance, fStore.getDefaultFeatureType());//fStore.getFeatureSet(featureQuery);
72
                    } catch (ReadException e) {
73
                            return null;
74
                    } catch (DataException e) {
75
                            return null;
76
                        }
77

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

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

    
86

    
87

    
88

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

    
119

    
120
                    }
121
                    iter.dispose();
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

    
129
                    return (URI[]) tmpUris.toArray(new URI[0]);
130

    
131
            } catch (ReadException e) {
132
                    throw new ReadException(lyrVect.getName(),e);
133
            } catch (URISyntaxException e) {
134
                    throw new ReadException(lyrVect.getName(),e);
135
                } catch (DataException e) {
136
                        throw new ReadException(lyrVect.getName(),e);
137
                }finally{
138
                        fSet.dispose();
139
                }
140

    
141
    }
142

    
143
        public String getClassName() {
144
                // TODO Auto-generated method stub
145
                return null;
146
        }
147

    
148

    
149
}