Revision 21110
branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/mapcontext/layers/FLyrVectLinkProperties.java | ||
---|---|---|
4 | 4 |
import java.io.File; |
5 | 5 |
import java.net.URI; |
6 | 6 |
import java.net.URISyntaxException; |
7 |
import java.util.BitSet; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.Iterator; |
|
8 | 9 |
|
9 | 10 |
import org.gvsig.data.ReadException; |
10 |
import org.gvsig.fmap.mapcontext.layers.operations.AlphanumericData; |
|
11 |
import org.gvsig.data.vectorial.Feature; |
|
12 |
import org.gvsig.data.vectorial.FeatureCollection; |
|
13 |
import org.gvsig.data.vectorial.FeatureStore; |
|
11 | 14 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
15 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
12 | 16 |
|
13 | 17 |
|
14 | 18 |
/** |
... | ... | |
50 | 54 |
* @param tolerance |
51 | 55 |
* @return Array of URI |
52 | 56 |
*/ |
53 |
public URI[] getLink(FLayer layer, Point2D point, double tolerance) { |
|
54 |
//Sacado de la clase LinkListener |
|
55 |
FLyrVect lyrVect = (FLyrVect) layer; |
|
56 |
FBitSet newBitSet; |
|
57 |
BitSet bitset; |
|
58 |
URI uri[]=null; |
|
57 |
public URI[] getLink(FLayer layer, Point2D point, double tolerance) throws BehaviorException { |
|
58 |
//Sacado de la clase LinkListener |
|
59 |
FLyrVect lyrVect = (FLyrVect) layer; |
|
60 |
FeatureStore fStore = null; |
|
61 |
FeatureCollection fCollection=null; |
|
59 | 62 |
|
60 |
//Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que |
|
61 |
//hacemos a la capa. |
|
62 |
try { |
|
63 |
newBitSet = lyrVect.queryByPoint(point, tolerance); |
|
64 |
bitset = newBitSet; |
|
65 |
} catch (ReadException e) { |
|
66 |
return null; |
|
67 |
} |
|
63 |
try { |
|
64 |
fStore = lyrVect.getFeatureStore(); |
|
65 |
URI uri[]=null; |
|
68 | 66 |
|
69 |
//Si el bitset creado no est? vac?o creamos el vector de URLS correspondientes |
|
70 |
//a la consulta que hemos hecho. |
|
67 |
//Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que |
|
68 |
//hacemos a la capa. |
|
69 |
String filter = "true = false"; //FIXME: Funcion!!! |
|
70 |
try { |
|
71 |
fCollection = (FeatureCollection)fStore.getDataCollection(fStore.getDefaultFeatureType(), filter, null); |
|
72 |
} catch (ReadException e) { |
|
73 |
return null; |
|
74 |
} |
|
71 | 75 |
|
72 |
if (bitset!=null){
|
|
73 |
try {
|
|
74 |
if (layer instanceof AlphanumericData) {
|
|
76 |
Iterator iter = null;
|
|
77 |
//Si el bitset creado no est? vac?o creamos el vector de URLS correspondientes
|
|
78 |
//a la consulta que hemos hecho.
|
|
75 | 79 |
|
76 |
DataSource ds = ((AlphanumericData) layer).getRecordset(); |
|
77 |
ds.start(); |
|
78 |
//boolean exist=false; |
|
79 |
int idField; |
|
80 |
//Creo el vector de URL?s con la misma longitud que el bitset |
|
81 |
uri = new URI[bitset.length()]; |
|
80 |
ArrayList tmpUris=new ArrayList(); |
|
81 |
String auxext=""; |
|
82 |
int idField = fStore.getDefaultFeatureType().getFieldIndex(this.getField()); |
|
82 | 83 |
|
83 |
//Consigo el identificador del campo pasandole como par?metro el |
|
84 |
//nombre del campo del ?nlace |
|
85 |
idField = ds.getFieldIndexByName(this.getField()); |
|
86 |
if (idField != -1){ |
|
87 |
//Recorremos el BitSet siguiendo el ejmplo de la clase que se |
|
88 |
//proporciona en la API |
|
89 |
for (int j = bitset.nextSetBit(0); j >= 0; |
|
90 |
j = bitset.nextSetBit(j + 1)){ |
|
91 |
//TODO |
|
92 |
//Sacado de la clase LinkPanel, decidir como pintar la URL le |
|
93 |
//corresponde a LinkPanel, aqu? solo creamos el vector de URL?s |
|
94 |
String auxext=""; |
|
95 |
if (!super.getExt().equals("")){ |
|
96 |
auxext="."+this.getExt(); |
|
97 |
} |
|
98 |
// ds.start(); |
|
99 |
//Creamos el fichero con el nombre del campo y la extensi?n. |
|
100 |
String auxField=ds.getFieldValue(j, idField).toString(); |
|
101 |
if(auxField.startsWith("http:/")){ |
|
102 |
try { |
|
103 |
uri[j]=new URI(auxField); |
|
104 |
} catch (URISyntaxException e) { |
|
105 |
// TODO Auto-generated catch block |
|
106 |
e.printStackTrace(); |
|
107 |
} |
|
108 |
} |
|
109 |
else{ |
|
110 | 84 |
|
111 |
File file =new File(ds.getFieldValue(j, idField).toString()+auxext); |
|
112 |
uri[j]= file.toURI(); |
|
113 |
} |
|
114 |
System.out.println(uri[j].toString()); |
|
115 |
//System.out.println(uri[j]); |
|
116 | 85 |
|
117 | 86 |
|
118 |
} |
|
119 |
return uri; |
|
120 |
} |
|
87 |
//Consigo el identificador del campo pasandole como par?metro el |
|
88 |
//nombre del campo del ?nlace |
|
89 |
if (idField == -1){ |
|
90 |
throw new BehaviorException(lyrVect.getName()+": '"+this.getField()+"' not found"); |
|
91 |
} |
|
92 |
//Recorremos el BitSet siguiendo el ejmplo de la clase que se |
|
93 |
//proporciona en la API |
|
94 |
iter = fCollection.iterator(); |
|
95 |
while (iter.hasNext()){ |
|
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 |
if (!super.getExt().equals("")){ |
|
100 |
auxext="."+this.getExt(); |
|
101 |
} |
|
102 |
// ds.start(); |
|
103 |
//Creamos el fichero con el nombre del campo y la extensi?n. |
|
104 |
Feature feature = (Feature) iter.next(); |
|
105 |
String auxField=feature.getString(idField); |
|
106 |
URI tmpUri = null; |
|
107 |
if(auxField.startsWith("http:/")){ |
|
108 |
tmpUri= new URI(auxField); |
|
109 |
}else{ |
|
110 |
File file =new File(feature.getString(idField)+auxext); |
|
111 |
tmpUri = file.toURI(); |
|
112 |
} |
|
113 |
tmpUris.add(tmpUri); |
|
114 |
System.out.println(tmpUri.toString()); |
|
115 |
//System.out.println(uri[j]); |
|
121 | 116 |
|
122 |
ds.stop(); |
|
123 |
}else { |
|
124 |
//Posible error |
|
125 |
System.out.println("Error"); |
|
126 |
} |
|
127 | 117 |
|
128 |
} catch (ReadException e) { |
|
129 |
//Posible error |
|
130 |
System.out.println("Error"); |
|
131 |
} |
|
118 |
} |
|
132 | 119 |
|
120 |
if (tmpUris.size()==0){ |
|
121 |
return null; |
|
122 |
} |
|
133 | 123 |
|
134 |
} |
|
135 |
return null; |
|
136 |
} |
|
124 |
//Creo el vector de URL?s con la misma longitud que el bitset |
|
125 |
uri = new URI[tmpUris.size()]; |
|
126 |
iter = tmpUris.iterator(); |
|
127 |
int i=0; |
|
128 |
while (iter.hasNext()){ |
|
129 |
uri[i]=(URI) iter.next(); |
|
130 |
i++; |
|
131 |
} |
|
137 | 132 |
|
133 |
return uri; |
|
134 |
|
|
135 |
} catch (ReadException e) { |
|
136 |
throw new BehaviorException(lyrVect.getName(),e); |
|
137 |
} catch (URISyntaxException e) { |
|
138 |
throw new BehaviorException(lyrVect.getName(),e); |
|
139 |
}finally{ |
|
140 |
fCollection.dispose(); |
|
141 |
} |
|
142 |
|
|
143 |
} |
|
144 |
|
|
138 | 145 |
public String getClassName() { |
139 | 146 |
// TODO Auto-generated method stub |
140 | 147 |
return null; |
Also available in: Unified diff