Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVectLinkProperties.java @ 13664

History | View | Annotate | Download (5.05 KB)

1 13558 evercher
package com.iver.cit.gvsig.fmap.layers;
2
3
import java.awt.geom.Point2D;
4
import java.io.File;
5
import java.net.MalformedURLException;
6
import java.net.URI;
7
import java.net.URISyntaxException;
8
import java.net.URL;
9
import java.util.BitSet;
10
11
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
12
import com.hardcode.gdbms.engine.data.DataSource;
13
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
14
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
15
import com.iver.utiles.XMLEntity;
16
17
/**
18
 * This class extends AbstractLinkProperties and implements the method to get an array of URI
19
 * using a point2D and a tolerance. This class extends AstractLinkProperties to add HyperLink
20
 * to Vectorial Layer(FLyrVect)
21
 */
22
23
public class FLyrVectLinkProperties extends AbstractLinkProperties{
24
25
    /**
26
     * Default Constructor. Costructs a LinkProperties with the necessary information
27
     *
28
     */
29
    public FLyrVectLinkProperties(){
30
        setType(0);
31
        setField(null);
32
        setExt(null);
33
    }
34
35
    /**
36
     * Constructor. Constructs a LinkProperties with the information that receives
37
     * @param tipo
38
     * @param fieldName
39
     * @param extension
40
     */
41
    public FLyrVectLinkProperties(int tipo, String fieldName, String extension){
42
        setType(tipo);
43
        setField(fieldName);
44
        setExt(extension);
45
    }
46
47
    /**
48
     * Creates an array of URI. With the point and the tolerance makes a query to the layer
49
     * and gets the geometries that contains the point with a certain error (tolerance).
50
     * For each one of this geometries creates one URI and adds it to the array
51
     * @param layer
52
     * @param point
53
     * @param tolerance
54
     * @return Array of URI
55
     */
56
    public URI[] getLink(FLayer layer, Point2D point, double tolerance)  {
57
        //Sacado de la clase LinkListener
58
        FLyrVect lyrVect = (FLyrVect) layer;
59
        FBitSet newBitSet;
60
        BitSet bitset;
61
        URI uri[]=null;
62
63
        //Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que
64
        //hacemos a la capa.
65
        try {
66
            newBitSet = lyrVect.queryByPoint(point, tolerance);
67
            bitset = newBitSet;
68
        } catch (ReadDriverException e) {
69
            return null;
70
        } catch (VisitorException e) {
71
            return null;
72
        }
73
74
        //Si el bitset creado no est? vac?o creamos el vector de URLS correspondientes
75
        //a la consulta que hemos hecho.
76
77
        if (bitset!=null){
78
            try {
79
                if (layer instanceof AlphanumericData) {
80
81
                    DataSource ds = ((AlphanumericData) layer).getRecordset();
82
                    ds.start();
83
                    //boolean exist=false;
84
                    int idField;
85
                    //Creo el vector de URL?s con la misma longitud que el bitset
86
                    uri = new URI[bitset.length()];
87
88
                    //Consigo el identificador del campo pasandole como par?metro el
89
                    //nombre del campo del ?nlace
90
                    idField = ds.getFieldIndexByName(this.getField());
91
                    if (idField != -1){
92
                        //Recorremos el BitSet siguiendo el ejmplo de la clase que se
93
                        //proporciona en la API
94
                        for (int j = bitset.nextSetBit(0); j >= 0;
95
                            j = bitset.nextSetBit(j + 1)){
96
                            //TODO
97
                            //Sacado de la clase LinkPanel, decidir como pintar la URL le
98
                            //corresponde a LinkPanel, aqu? solo creamos el vector de URL?s
99
                            String auxext="";
100
                            if (!super.getExt().equals("")){
101
                                auxext="."+this.getExt();
102
                            }
103
//                                                ds.start();
104
                            //Creamos el fichero con el nombre del campo y la extensi?n.
105
                            String auxField=ds.getFieldValue(j, idField).toString();
106
                            if(auxField.startsWith("http:/")){
107
                                    try {
108
                                                                        uri[j]=new URI(auxField);
109
                                                                } catch (URISyntaxException e) {
110
                                                                        // TODO Auto-generated catch block
111
                                                                        e.printStackTrace();
112
                                                                }
113
                            }
114
                            else{
115
116
                                    File file =new File(ds.getFieldValue(j, idField).toString()+auxext);
117
                                    uri[j]= file.toURI();
118
                            }
119
                            System.out.println(uri[j].toString());
120
                            //System.out.println(uri[j]);
121
122
123
                        }
124
                        return uri;
125
                    }
126
127
                    ds.stop();
128
                }else {
129
                    //Posible error
130
                    System.out.println("Error");
131
                }
132
133
            } catch (ReadDriverException e) {
134
                //Posible error
135
                System.out.println("Error");
136
            }
137
138
139
            }
140
            return null;
141
     }
142
143
        public String getClassName() {
144
                // TODO Auto-generated method stub
145
                return null;
146
        }
147
148
149
}