Revision 34056
tags/v2_0_0_Build_2021/applications/appCatalog/src-test/org/gvsig/catalog/catalog/drivers/ExampleNewDriver.java | ||
---|---|---|
1 |
package org.gvsig.catalog.catalog.drivers; |
|
2 |
|
|
3 |
import java.net.URI; |
|
4 |
|
|
5 |
import org.gvsig.catalog.CatalogLocator; |
|
6 |
import org.gvsig.catalog.CatalogManager; |
|
7 |
import org.gvsig.catalog.drivers.AbstractCatalogServiceDriver; |
|
8 |
import org.gvsig.catalog.drivers.CatalogCapabilities; |
|
9 |
import org.gvsig.catalog.drivers.DiscoveryServiceCapabilities; |
|
10 |
import org.gvsig.catalog.drivers.GetRecordsReply; |
|
11 |
import org.gvsig.catalog.querys.CatalogQuery; |
|
12 |
import org.gvsig.catalog.schemas.Record; |
|
13 |
import org.gvsig.catalog.ui.search.SearchAditionalPropertiesPanel; |
|
14 |
|
|
15 |
|
|
16 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
17 |
* |
|
18 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
19 |
* |
|
20 |
* This program is free software; you can redistribute it and/or |
|
21 |
* modify it under the terms of the GNU General Public License |
|
22 |
* as published by the Free Software Foundation; either version 2 |
|
23 |
* of the License, or (at your option) any later version. |
|
24 |
* |
|
25 |
* This program is distributed in the hope that it will be useful, |
|
26 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
27 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
28 |
* GNU General Public License for more details. |
|
29 |
* |
|
30 |
* You should have received a copy of the GNU General Public License |
|
31 |
* along with this program; if not, write to the Free Software |
|
32 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
33 |
* |
|
34 |
* For more information, contact: |
|
35 |
* |
|
36 |
* Generalitat Valenciana |
|
37 |
* Conselleria d'Infraestructures i Transport |
|
38 |
* Av. Blasco Ib??ez, 50 |
|
39 |
* 46010 VALENCIA |
|
40 |
* SPAIN |
|
41 |
* |
|
42 |
* +34 963862235 |
|
43 |
* gvsig@gva.es |
|
44 |
* www.gvsig.gva.es |
|
45 |
* |
|
46 |
* or |
|
47 |
* |
|
48 |
* IVER T.I. S.A |
|
49 |
* Salamanca 50 |
|
50 |
* 46005 Valencia |
|
51 |
* Spain |
|
52 |
* |
|
53 |
* +34 963163400 |
|
54 |
* dac@iver.es |
|
55 |
*/ |
|
56 |
/* CVS MESSAGES: |
|
57 |
* |
|
58 |
* $Id: ExampleNewDriver.java 537 2007-07-26 11:21:10Z jpiera $ |
|
59 |
* $Log$ |
|
60 |
* Revision 1.1.2.1 2007/07/13 12:00:35 jorpiell |
|
61 |
* Add the posibility to add a new panel |
|
62 |
* |
|
63 |
* |
|
64 |
*/ |
|
65 |
/** |
|
66 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
67 |
*/ |
|
68 |
public class ExampleNewDriver extends AbstractCatalogServiceDriver { |
|
69 |
private static final CatalogManager catalogManager = CatalogLocator.getCatalogManager(); |
|
70 |
|
|
71 |
/* |
|
72 |
* (non-Javadoc) |
|
73 |
* @see es.gva.cit.catalogClient.drivers.IDiscoveryServiceDriver#getCapabilities(java.net.URI) |
|
74 |
*/ |
|
75 |
public DiscoveryServiceCapabilities getCapabilities(URI uri) { |
|
76 |
return new CatalogCapabilities(); |
|
77 |
} |
|
78 |
|
|
79 |
/* |
|
80 |
* (non-Javadoc) |
|
81 |
* @see es.gva.cit.catalog.drivers.ICatalogServiceDriver#getRecords(java.net.URI, es.gva.cit.catalog.querys.CatalogQuery, int) |
|
82 |
*/ |
|
83 |
public GetRecordsReply getRecords(URI uri, CatalogQuery query, |
|
84 |
int firstRecord) { |
|
85 |
GetRecordsReply reply = new GetRecordsReply(1); |
|
86 |
Record record = catalogManager.createRecord(uri, null); |
|
87 |
record.setTitle("Record example"); |
|
88 |
record.setAbstract_("Just for testing"); |
|
89 |
reply.addRecord(record); |
|
90 |
return reply; |
|
91 |
} |
|
92 |
|
|
93 |
/* |
|
94 |
* (non-Javadoc) |
|
95 |
* @see es.gva.cit.catalog.drivers.IDiscoveryServiceDriver#getServiceName() |
|
96 |
*/ |
|
97 |
public String getServiceName() { |
|
98 |
return "My catalog service"; |
|
99 |
} |
|
100 |
|
|
101 |
/* |
|
102 |
* (non-Javadoc) |
|
103 |
* @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getAditionalSearchPanel() |
|
104 |
*/ |
|
105 |
public SearchAditionalPropertiesPanel getAditionalSearchPanel(){ |
|
106 |
return new ExampleNewPanel(); |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
} |
|
0 | 113 |
tags/v2_0_0_Build_2021/applications/appCatalog/src-test/org/gvsig/catalog/catalog/drivers/ExampleNewDriverTest.java | ||
---|---|---|
1 |
package org.gvsig.catalog.catalog.drivers; |
|
2 |
|
|
3 |
import javax.swing.UIManager; |
|
4 |
import javax.swing.UnsupportedLookAndFeelException; |
|
5 |
|
|
6 |
import org.gvsig.catalog.CatalogLocator; |
|
7 |
import org.gvsig.catalog.ui.serverconnect.ServerConnectDialog; |
|
8 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
9 |
|
|
10 |
|
|
11 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
12 |
* |
|
13 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
14 |
* |
|
15 |
* This program is free software; you can redistribute it and/or |
|
16 |
* modify it under the terms of the GNU General Public License |
|
17 |
* as published by the Free Software Foundation; either version 2 |
|
18 |
* of the License, or (at your option) any later version. |
|
19 |
* |
|
20 |
* This program is distributed in the hope that it will be useful, |
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23 |
* GNU General Public License for more details. |
|
24 |
* |
|
25 |
* You should have received a copy of the GNU General Public License |
|
26 |
* along with this program; if not, write to the Free Software |
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
28 |
* |
|
29 |
* For more information, contact: |
|
30 |
* |
|
31 |
* Generalitat Valenciana |
|
32 |
* Conselleria d'Infraestructures i Transport |
|
33 |
* Av. Blasco Ib??ez, 50 |
|
34 |
* 46010 VALENCIA |
|
35 |
* SPAIN |
|
36 |
* |
|
37 |
* +34 963862235 |
|
38 |
* gvsig@gva.es |
|
39 |
* www.gvsig.gva.es |
|
40 |
* |
|
41 |
* or |
|
42 |
* |
|
43 |
* IVER T.I. S.A |
|
44 |
* Salamanca 50 |
|
45 |
* 46005 Valencia |
|
46 |
* Spain |
|
47 |
* |
|
48 |
* +34 963163400 |
|
49 |
* dac@iver.es |
|
50 |
*/ |
|
51 |
/* CVS MESSAGES: |
|
52 |
* |
|
53 |
* $Id: ExampleNewDriverTest.java 512 2007-07-24 11:25:43Z jorpiell $ |
|
54 |
* $Log$ |
|
55 |
* Revision 1.1.2.2 2007/07/24 11:25:42 jorpiell |
|
56 |
* The registers has been refactorized |
|
57 |
* |
|
58 |
* Revision 1.1.2.1 2007/07/13 12:00:35 jorpiell |
|
59 |
* Add the posibility to add a new panel |
|
60 |
* |
|
61 |
* |
|
62 |
*/ |
|
63 |
/** |
|
64 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
65 |
*/ |
|
66 |
public class ExampleNewDriverTest { |
|
67 |
|
|
68 |
/** |
|
69 |
* @param args |
|
70 |
*/ |
|
71 |
public static void main(String[] args) { |
|
72 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
73 |
// DefaultCatalogLibrary library = new DefaultCatalogLibrary(); |
|
74 |
// library.initialize(); |
|
75 |
// library.postInitialize(); |
|
76 |
|
|
77 |
CatalogLocator.getCatalogManager().register("My catalog service", ExampleNewDriver.class); |
|
78 |
//Get the currently installed look and feel |
|
79 |
UIManager.getLookAndFeel(); |
|
80 |
// Install a different look and feel; specifically, the Windows look and feel |
|
81 |
try { |
|
82 |
UIManager.setLookAndFeel( |
|
83 |
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); |
|
84 |
} catch (InstantiationException e) { |
|
85 |
} catch (ClassNotFoundException e) { |
|
86 |
} catch (UnsupportedLookAndFeelException e) { |
|
87 |
} catch (IllegalAccessException e) { |
|
88 |
} |
|
89 |
|
|
90 |
new ServerConnectDialog(); |
|
91 |
} |
|
92 |
|
|
93 |
} |
|
0 | 94 |
tags/v2_0_0_Build_2021/applications/appCatalog/src-test/org/gvsig/catalog/catalog/drivers/ExampleNewPanel.java | ||
---|---|---|
1 |
package org.gvsig.catalog.catalog.drivers; |
|
2 |
|
|
3 |
import java.util.Properties; |
|
4 |
|
|
5 |
import javax.swing.JLabel; |
|
6 |
import javax.swing.JTextField; |
|
7 |
|
|
8 |
import org.gvsig.catalog.ui.search.SearchAditionalPropertiesPanel; |
|
9 |
|
|
10 |
|
|
11 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
12 |
* |
|
13 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
14 |
* |
|
15 |
* This program is free software; you can redistribute it and/or |
|
16 |
* modify it under the terms of the GNU General Public License |
|
17 |
* as published by the Free Software Foundation; either version 2 |
|
18 |
* of the License, or (at your option) any later version. |
|
19 |
* |
|
20 |
* This program is distributed in the hope that it will be useful, |
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23 |
* GNU General Public License for more details. |
|
24 |
* |
|
25 |
* You should have received a copy of the GNU General Public License |
|
26 |
* along with this program; if not, write to the Free Software |
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
28 |
* |
|
29 |
* For more information, contact: |
|
30 |
* |
|
31 |
* Generalitat Valenciana |
|
32 |
* Conselleria d'Infraestructures i Transport |
|
33 |
* Av. Blasco Ib??ez, 50 |
|
34 |
* 46010 VALENCIA |
|
35 |
* SPAIN |
|
36 |
* |
|
37 |
* +34 963862235 |
|
38 |
* gvsig@gva.es |
|
39 |
* www.gvsig.gva.es |
|
40 |
* |
|
41 |
* or |
|
42 |
* |
|
43 |
* IVER T.I. S.A |
|
44 |
* Salamanca 50 |
|
45 |
* 46005 Valencia |
|
46 |
* Spain |
|
47 |
* |
|
48 |
* +34 963163400 |
|
49 |
* dac@iver.es |
|
50 |
*/ |
|
51 |
/* CVS MESSAGES: |
|
52 |
* |
|
53 |
* $Id: ExampleNewPanel.java 537 2007-07-26 11:21:10Z jpiera $ |
|
54 |
* $Log$ |
|
55 |
* Revision 1.1.2.1 2007/07/13 12:00:35 jorpiell |
|
56 |
* Add the posibility to add a new panel |
|
57 |
* |
|
58 |
* |
|
59 |
*/ |
|
60 |
/** |
|
61 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
62 |
*/ |
|
63 |
public class ExampleNewPanel extends SearchAditionalPropertiesPanel{ |
|
64 |
JLabel label = null; |
|
65 |
JTextField text = null; |
|
66 |
|
|
67 |
public ExampleNewPanel(){ |
|
68 |
label = new JLabel(); |
|
69 |
text = new JTextField(); |
|
70 |
setLayout(new java.awt.BorderLayout()); |
|
71 |
label.setText("Label"); |
|
72 |
add(label, java.awt.BorderLayout.WEST); |
|
73 |
add(text, java.awt.BorderLayout.CENTER); |
|
74 |
} |
|
75 |
|
|
76 |
/* |
|
77 |
* (non-Javadoc) |
|
78 |
* @see es.gva.cit.gazetteer.ui.search.SearchAditionalPropertiesPanel#getProperties() |
|
79 |
*/ |
|
80 |
public Properties getProperties() { |
|
81 |
Properties properties = new Properties(); |
|
82 |
properties.put("PROP1", text.getText()); |
|
83 |
return properties; |
|
84 |
} |
|
85 |
|
|
86 |
} |
|
0 | 87 |
tags/v2_0_0_Build_2021/applications/appCatalog/src-test/org/gvsig/catalog/catalog/utils/URIUtilsTest.java | ||
---|---|---|
1 |
package org.gvsig.catalog.catalog.utils; |
|
2 |
|
|
3 |
import java.net.URI; |
|
4 |
import java.net.URISyntaxException; |
|
5 |
|
|
6 |
import junit.framework.TestCase; |
|
7 |
|
|
8 |
import org.gvsig.catalog.utils.URIUtils; |
|
9 |
|
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
11 |
* |
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or |
|
15 |
* modify it under the terms of the GNU General Public License |
|
16 |
* as published by the Free Software Foundation; either version 2 |
|
17 |
* of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
27 |
* |
|
28 |
* For more information, contact: |
|
29 |
* |
|
30 |
* Generalitat Valenciana |
|
31 |
* Conselleria d'Infraestructures i Transport |
|
32 |
* Av. Blasco Ib??ez, 50 |
|
33 |
* 46010 VALENCIA |
|
34 |
* SPAIN |
|
35 |
* |
|
36 |
* +34 963862235 |
|
37 |
* gvsig@gva.es |
|
38 |
* www.gvsig.gva.es |
|
39 |
* |
|
40 |
* or |
|
41 |
* |
|
42 |
* IVER T.I. S.A |
|
43 |
* Salamanca 50 |
|
44 |
* 46005 Valencia |
|
45 |
* Spain |
|
46 |
* |
|
47 |
* +34 963163400 |
|
48 |
* dac@iver.es |
|
49 |
*/ |
|
50 |
/* CVS MESSAGES: |
|
51 |
* |
|
52 |
* $Id: URIUtilsTest.java,v 1.1.2.1 2007/07/10 11:18:04 jorpiell Exp $ |
|
53 |
* $Log: URIUtilsTest.java,v $ |
|
54 |
* Revision 1.1.2.1 2007/07/10 11:18:04 jorpiell |
|
55 |
* Added the registers |
|
56 |
* |
|
57 |
* |
|
58 |
*/ |
|
59 |
/** |
|
60 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
61 |
*/ |
|
62 |
public class URIUtilsTest extends TestCase { |
|
63 |
|
|
64 |
public void test1() throws URISyntaxException{ |
|
65 |
URI uri = URIUtils.createUri("http://www.upv.es", "http", 80); |
|
66 |
assertEquals(uri.getHost(), "www.upv.es"); |
|
67 |
assertEquals(uri.getScheme(), "http"); |
|
68 |
assertEquals(uri.getPort(), 80); |
|
69 |
assertEquals(uri.getPath(), ""); |
|
70 |
} |
|
71 |
|
|
72 |
public void test2() throws URISyntaxException{ |
|
73 |
URI uri = URIUtils.createUri("www.upv.es", "http", 80); |
|
74 |
assertEquals(uri.getHost(), "www.upv.es"); |
|
75 |
assertEquals(uri.getScheme(), "http"); |
|
76 |
assertEquals(uri.getPort(), 80); |
|
77 |
assertEquals(uri.getPath(), ""); |
|
78 |
} |
|
79 |
|
|
80 |
public void test3() throws URISyntaxException{ |
|
81 |
URI uri = URIUtils.createUri("www.upv.es", "z3950", 2100); |
|
82 |
assertEquals(uri.getHost(), "www.upv.es"); |
|
83 |
assertEquals(uri.getScheme(), "z3950"); |
|
84 |
assertEquals(uri.getPort(), 2100); |
|
85 |
assertEquals(uri.getPath(), ""); |
|
86 |
} |
|
87 |
|
|
88 |
public void test4() throws URISyntaxException{ |
|
89 |
URI uri = URIUtils.createUri("http://193.144.250.29/webservices/services/IDEC_GeoServeisPort", "http", 80); |
|
90 |
assertEquals(uri.getHost(), "193.144.250.29"); |
|
91 |
assertEquals(uri.getScheme(), "http"); |
|
92 |
assertEquals(uri.getPort(), 80); |
|
93 |
assertEquals(uri.getPath(), "/webservices/services/IDEC_GeoServeisPort"); |
|
94 |
} |
|
95 |
} |
|
0 | 96 |
tags/v2_0_0_Build_2021/applications/appCatalog/config/ApplicationContextAlone.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> |
|
3 |
|
|
4 |
<beans> |
|
5 |
|
|
6 |
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> |
|
7 |
<property name="location"><value>config/TestContext.properties</value></property> |
|
8 |
</bean> |
|
9 |
|
|
10 |
<!-- ========================= GENERAL DEFINITIONS ========================= --> |
|
11 |
|
|
12 |
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> |
|
13 |
<property name="basename"><value>messages</value></property> |
|
14 |
</bean> |
|
15 |
|
|
16 |
|
|
17 |
<!-- ========================= PERSISTENCE DEFINITIONS ========================= --> |
|
18 |
|
|
19 |
<!-- ========================= BUSINESS DEFINITIONS ========================= --> |
|
20 |
|
|
21 |
<bean id="OIDRegister" class="org.jzkit.a2j.codec.util.OIDRegister"> |
|
22 |
<constructor-arg index="0"><value>/es/gva/cit/catalog/protocols/context/a2j.properties</value></constructor-arg> |
|
23 |
</bean> |
|
24 |
|
|
25 |
<!-- conversion rules --> |
|
26 |
<bean id="RPNToInternalRules" class="org.jzkit.util.PropsHolder"> |
|
27 |
<constructor-arg index="0"><value>/es/gva/cit/catalog/protocols/context/InternalAttrTypes.properties</value></constructor-arg> |
|
28 |
</bean> |
|
29 |
|
|
30 |
<bean id="InternalToType1ConversionRules" class="org.jzkit.z3950.QueryModel.PropsBasedInternalToType1ConversionRules"> |
|
31 |
<constructor-arg index="0"><value>/es/gva/cit/catalog/protocols/context/InternalToType1Rules.properties</value></constructor-arg> |
|
32 |
</bean> |
|
33 |
|
|
34 |
</beans> |
tags/v2_0_0_Build_2021/applications/appCatalog/config/ApplicationContext.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> |
|
3 |
<beans> |
|
4 |
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> |
|
5 |
<property name="location"><value>gvSIG/extensiones/es.gva.cit.gvsig.catalogClient/config/TestContext.properties</value></property> |
|
6 |
</bean> |
|
7 |
<!-- ========================= GENERAL DEFINITIONS ========================= --> |
|
8 |
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> |
|
9 |
<property name="basename"><value>messages</value></property> |
|
10 |
</bean> |
|
11 |
<!-- ========================= PERSISTENCE DEFINITIONS ========================= --> |
|
12 |
|
|
13 |
<!-- ========================= BUSINESS DEFINITIONS ========================= --> |
|
14 |
|
|
15 |
<bean id="OIDRegister" class="org.jzkit.a2j.codec.util.OIDRegister"> |
|
16 |
<constructor-arg index="0"><value>/es/gva/cit/catalog/protocols/context/a2j.properties</value></constructor-arg> |
|
17 |
</bean> |
|
18 |
|
|
19 |
<!-- conversion rules --> |
|
20 |
<bean id="RPNToInternalRules" class="org.jzkit.util.PropsHolder"> |
|
21 |
<constructor-arg index="0"><value>/es/gva/cit/catalog/protocols/context/InternalAttrTypes.properties</value></constructor-arg> |
|
22 |
</bean> |
|
23 |
|
|
24 |
<bean id="InternalToType1ConversionRules" class="org.jzkit.z3950.QueryModel.PropsBasedInternalToType1ConversionRules"> |
|
25 |
<constructor-arg index="0"><value>/es/gva/cit/catalog/protocols/context/InternalToType1Rules.properties</value></constructor-arg> |
|
26 |
</bean> |
|
27 |
</beans> |
tags/v2_0_0_Build_2021/applications/appCatalog/src/org/gvsig/catalog/impl/DefaultCatalogLibrary.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.catalog.impl; |
|
29 |
|
|
30 |
import org.gvsig.catalog.CatalogLocator; |
|
31 |
import org.gvsig.catalog.CatalogManager; |
|
32 |
import org.gvsig.catalog.csw.drivers.CSWISO19115CatalogServiceDriver; |
|
33 |
import org.gvsig.catalog.csw.drivers.CSWebRIMCatalogServiceDriver; |
|
34 |
import org.gvsig.catalog.schemas.DeegreeISO19115Record; |
|
35 |
import org.gvsig.catalog.schemas.DublinCoreRecord; |
|
36 |
import org.gvsig.catalog.schemas.GeonetworkISO19115Record; |
|
37 |
import org.gvsig.catalog.schemas.IdecISO19115Record; |
|
38 |
import org.gvsig.catalog.schemas.IdeeISO19115Record; |
|
39 |
import org.gvsig.catalog.schemas.Iso19139Record; |
|
40 |
import org.gvsig.catalog.schemas.LaitsGmuEbRIMRecord; |
|
41 |
import org.gvsig.catalog.schemas.LaitsGmuISO19115Record; |
|
42 |
import org.gvsig.catalog.schemas.LaitsGmuServicesRecord; |
|
43 |
import org.gvsig.catalog.srw.drivers.SRWCatalogServiceDriver; |
|
44 |
import org.gvsig.catalog.z3950.drivers.Z3950CatalogServiceDriver; |
|
45 |
import org.gvsig.tools.library.AbstractLibrary; |
|
46 |
import org.gvsig.tools.library.Library; |
|
47 |
import org.gvsig.tools.library.LibraryException; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
51 |
*/ |
|
52 |
public class DefaultCatalogLibrary extends AbstractLibrary { |
|
53 |
|
|
54 |
public DefaultCatalogLibrary() { |
|
55 |
super(DefaultCatalogLibrary.class,Library.TYPE.API); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
protected void doInitialize() throws LibraryException { |
|
60 |
//Register the default CatalogManager |
|
61 |
CatalogLocator.registerCatalogManager(DefaultCatalogManager.class); |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
protected void doPostInitialize() throws LibraryException { |
|
66 |
CatalogManager catalogManager = CatalogLocator.getCatalogManager(); |
|
67 |
|
|
68 |
//Register the default catalog drivers |
|
69 |
catalogManager.register("z3950", Z3950CatalogServiceDriver.class); |
|
70 |
catalogManager.register("srw", SRWCatalogServiceDriver.class); |
|
71 |
catalogManager.register("csw/iso 19115", CSWISO19115CatalogServiceDriver.class); |
|
72 |
catalogManager.register("csw/ebrim", CSWebRIMCatalogServiceDriver.class); |
|
73 |
|
|
74 |
//Default the records |
|
75 |
catalogManager.addRecord(new GeonetworkISO19115Record()); |
|
76 |
catalogManager.addRecord(new DeegreeISO19115Record()); |
|
77 |
catalogManager.addRecord(new DublinCoreRecord()); |
|
78 |
catalogManager.addRecord(new IdecISO19115Record()); |
|
79 |
catalogManager.addRecord(new IdeeISO19115Record()); |
|
80 |
catalogManager.addRecord(new Iso19139Record()); |
|
81 |
catalogManager.addRecord(new LaitsGmuISO19115Record()); |
|
82 |
catalogManager.addRecord(new LaitsGmuServicesRecord()); |
|
83 |
catalogManager.addRecord(new LaitsGmuEbRIMRecord()); |
|
84 |
} |
|
85 |
} |
|
0 | 86 |
tags/v2_0_0_Build_2021/applications/appCatalog/src/org/gvsig/catalog/impl/DefaultCatalogManager.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.catalog.impl; |
|
29 |
|
|
30 |
import java.lang.reflect.InvocationTargetException; |
|
31 |
import java.net.URI; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.Iterator; |
|
34 |
import java.util.TreeMap; |
|
35 |
|
|
36 |
import org.gvsig.catalog.CatalogManager; |
|
37 |
import org.gvsig.catalog.drivers.ICatalogServiceDriver; |
|
38 |
import org.gvsig.catalog.loaders.LayerLoader; |
|
39 |
import org.gvsig.catalog.metadataxml.XMLNode; |
|
40 |
import org.gvsig.catalog.schemas.Record; |
|
41 |
import org.gvsig.catalog.schemas.Resource; |
|
42 |
import org.gvsig.catalog.schemas.UnknownRecord; |
|
43 |
import org.gvsig.tools.ToolsLocator; |
|
44 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
45 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
46 |
import org.slf4j.Logger; |
|
47 |
import org.slf4j.LoggerFactory; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
51 |
*/ |
|
52 |
public class DefaultCatalogManager implements CatalogManager { |
|
53 |
private static final Logger logger = LoggerFactory.getLogger(DefaultCatalogManager.class); |
|
54 |
private static final String DRIVER_REGISTER_NAME = "CatalogDrivers"; |
|
55 |
private ArrayList records = null; |
|
56 |
private static TreeMap loadersPool = null; |
|
57 |
|
|
58 |
public DefaultCatalogManager() { |
|
59 |
super(); |
|
60 |
records = new ArrayList(); |
|
61 |
loadersPool = new TreeMap(); |
|
62 |
} |
|
63 |
|
|
64 |
/* (non-Javadoc) |
|
65 |
* @see org.gvsig.catalog.CatalogManager#getDriver(java.lang.String) |
|
66 |
*/ |
|
67 |
public ICatalogServiceDriver getDriver(String protocol) { |
|
68 |
ExtensionPointManager extensionPointManager = ToolsLocator |
|
69 |
.getExtensionPointManager(); |
|
70 |
ExtensionPoint extensionPoint = extensionPointManager.add(DRIVER_REGISTER_NAME); |
|
71 |
|
|
72 |
Iterator extensions = extensionPoint.iterator(); |
|
73 |
while (extensions.hasNext()){ |
|
74 |
ExtensionPoint.Extension extension = (ExtensionPoint.Extension)extensions.next(); |
|
75 |
ICatalogServiceDriver driver; |
|
76 |
try { |
|
77 |
driver = (ICatalogServiceDriver)extension.create(); |
|
78 |
if (driver.getServiceName().toLowerCase().compareTo(protocol.toLowerCase()) == 0){ |
|
79 |
return driver; |
|
80 |
} |
|
81 |
} catch (InstantiationException e) { |
|
82 |
logger.error("Impossible to create a catalog driver", e); |
|
83 |
} catch (IllegalAccessException e) { |
|
84 |
logger.error("Impossible to create a catalog driver", e); |
|
85 |
} |
|
86 |
} |
|
87 |
return null; |
|
88 |
} |
|
89 |
|
|
90 |
/* (non-Javadoc) |
|
91 |
* @see org.gvsig.catalog.CatalogManager#getDrivers() |
|
92 |
*/ |
|
93 |
public ICatalogServiceDriver[] getDrivers() { |
|
94 |
ICatalogServiceDriver[] drivers = null; |
|
95 |
ExtensionPointManager extensionPointManager = ToolsLocator |
|
96 |
.getExtensionPointManager(); |
|
97 |
ExtensionPoint extensionPoint = extensionPointManager.add(DRIVER_REGISTER_NAME); |
|
98 |
drivers = new ICatalogServiceDriver[extensionPoint.getCount()]; |
|
99 |
Iterator extensions = extensionPoint.iterator(); |
|
100 |
int i = 0; |
|
101 |
while (extensions.hasNext()){ |
|
102 |
ExtensionPoint.Extension extension = (ExtensionPoint.Extension)extensions.next(); |
|
103 |
ICatalogServiceDriver driver; |
|
104 |
try { |
|
105 |
driver = (ICatalogServiceDriver)extension.create(); |
|
106 |
drivers[i] = driver; |
|
107 |
} catch (InstantiationException e) { |
|
108 |
logger.error("Impossible to create a catalog driver", e); |
|
109 |
} catch (IllegalAccessException e) { |
|
110 |
logger.error("Impossible to create a catalog driver", e); |
|
111 |
} |
|
112 |
|
|
113 |
i++; |
|
114 |
} |
|
115 |
return drivers; |
|
116 |
} |
|
117 |
|
|
118 |
/* (non-Javadoc) |
|
119 |
* @see org.gvsig.catalog.CatalogManager#register(java.lang.String, java.lang.Class) |
|
120 |
*/ |
|
121 |
public void register(String name, Class driver) { |
|
122 |
ExtensionPointManager extensionPointManager = ToolsLocator |
|
123 |
.getExtensionPointManager(); |
|
124 |
ExtensionPoint extensionPoint = extensionPointManager.add(DRIVER_REGISTER_NAME); |
|
125 |
extensionPoint.append(name.toLowerCase(), "", driver); |
|
126 |
} |
|
127 |
|
|
128 |
/* (non-Javadoc) |
|
129 |
* @see org.gvsig.catalog.CatalogManager#addRecord(org.gvsig.catalog.schemas.Record) |
|
130 |
*/ |
|
131 |
public void addRecord(Record record) { |
|
132 |
records.add(record); |
|
133 |
} |
|
134 |
|
|
135 |
/* (non-Javadoc) |
|
136 |
* @see org.gvsig.catalog.CatalogManager#createRecord(java.net.URI, org.gvsig.catalog.metadataxml.XMLNode) |
|
137 |
*/ |
|
138 |
public Record createRecord(URI uri, XMLNode node) { |
|
139 |
for (int i=0 ; i<records.size() ; i++){ |
|
140 |
Record record = (Record)records.get(i); |
|
141 |
if (node != null){ |
|
142 |
if (record.accept(uri, node)){ |
|
143 |
Object[] values = {uri, node}; |
|
144 |
Class[] types = {URI.class, XMLNode.class}; |
|
145 |
try { |
|
146 |
return (Record)record.getClass().getConstructor(types).newInstance(values); |
|
147 |
} catch (Exception e) { |
|
148 |
//It the instance can be created the |
|
149 |
//default record has to be returned |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
} |
|
154 |
return new UnknownRecord(uri,node); |
|
155 |
} |
|
156 |
|
|
157 |
/* (non-Javadoc) |
|
158 |
* @see org.gvsig.catalog.CatalogManager#addLayerLoader(java.lang.String, java.lang.Class) |
|
159 |
*/ |
|
160 |
public void addLayerLoader(String key, Class loader) { |
|
161 |
loadersPool.put(key, loader); |
|
162 |
} |
|
163 |
|
|
164 |
/* (non-Javadoc) |
|
165 |
* @see org.gvsig.catalog.CatalogManager#getLayerLoader(org.gvsig.catalog.schemas.Resource) |
|
166 |
*/ |
|
167 |
public LayerLoader getLayerLoader(Resource resource) |
|
168 |
throws IllegalArgumentException, SecurityException, |
|
169 |
InstantiationException, IllegalAccessException, |
|
170 |
InvocationTargetException, NoSuchMethodException { |
|
171 |
if (loadersPool.containsKey(resource.getType())) { |
|
172 |
Class llClass = (Class) loadersPool.get(resource.getType()); |
|
173 |
Class [] args = {Resource.class}; |
|
174 |
Object [] params = {resource}; |
|
175 |
return (LayerLoader) llClass.getConstructor(args).newInstance(params); |
|
176 |
} |
|
177 |
return null; |
|
178 |
} |
|
179 |
|
|
180 |
} |
|
181 |
|
|
0 | 182 |
tags/v2_0_0_Build_2021/applications/appCatalog/src/org/gvsig/catalog/metadataxml/XMLNode.java | ||
---|---|---|
1 |
package org.gvsig.catalog.metadataxml; |
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* Generalitat Valenciana |
|
23 |
* Conselleria d'Infraestructures i Transport |
|
24 |
* Av. Blasco Ib??ez, 50 |
|
25 |
* 46010 VALENCIA |
|
26 |
* SPAIN |
|
27 |
* |
|
28 |
* +34 963862235 |
|
29 |
* gvsig@gva.es |
|
30 |
* www.gvsig.gva.es |
|
31 |
* |
|
32 |
* or |
|
33 |
* |
|
34 |
* IVER T.I. S.A |
|
35 |
* Salamanca 50 |
|
36 |
* 46005 Valencia |
|
37 |
* Spain |
|
38 |
* |
|
39 |
* +34 963163400 |
|
40 |
* dac@iver.es |
|
41 |
*/ |
|
42 |
import java.io.File; |
|
43 |
import java.io.FileWriter; |
|
44 |
import java.io.InputStream; |
|
45 |
import java.io.Writer; |
|
46 |
import java.util.Hashtable; |
|
47 |
import java.util.Vector; |
|
48 |
|
|
49 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
50 |
|
|
51 |
import org.w3c.dom.Document; |
|
52 |
import org.w3c.dom.Element; |
|
53 |
import org.w3c.dom.NamedNodeMap; |
|
54 |
import org.w3c.dom.Node; |
|
55 |
import org.w3c.dom.NodeList; |
|
56 |
|
|
57 |
/** |
|
58 |
* Esta clase representa un XMLNode simplificado |
|
59 |
* Contiene una lista de subnodos y una lista de atributos. |
|
60 |
* Tambi?n tiene una cadena. |
|
61 |
* Soporta la lectura y escritura de y desde un fichero XML. |
|
62 |
* Tambi?n soporta la lectura desde Internet |
|
63 |
* Modificado por jaume |
|
64 |
* |
|
65 |
*/ |
|
66 |
public class XMLNode { |
|
67 |
public static final String ISNOTXML = "NOTXML"; |
|
68 |
private Vector subNodes = new Vector(); |
|
69 |
private String cdata = null; |
|
70 |
private Hashtable attr = new Hashtable(); |
|
71 |
private String nodeName; |
|
72 |
private String text = null; |
|
73 |
private Vector attrKeys = new Vector(); |
|
74 |
private String header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
|
75 |
|
|
76 |
/** |
|
77 |
* Constructor, lee de un fichero |
|
78 |
* @param file |
|
79 |
* @author jaume - jaume.dominguez@iver.es |
|
80 |
* Modified by Jorge Piera Llodra - piera_jor@gva.es |
|
81 |
*/ |
|
82 |
public XMLNode(File file) throws Exception { |
|
83 |
this(factory.newDocumentBuilder().parse(file)); |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Constructor. Usando url.openStream() se puede usar |
|
88 |
* para leer info descargada de internet. |
|
89 |
* |
|
90 |
* |
|
91 |
* @param inputstream |
|
92 |
* @throws Exception |
|
93 |
*/ |
|
94 |
public XMLNode(InputStream inputstream) throws Exception { |
|
95 |
this(factory.newDocumentBuilder().parse(inputstream)); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Contructor, constructor desde un documento DOM |
|
100 |
* |
|
101 |
* |
|
102 |
* @param dom |
|
103 |
* @author jaume - jaume.dominguez@iver.es |
|
104 |
*/ |
|
105 |
public XMLNode(Document dom) throws Exception { |
|
106 |
this((Element)dom.getFirstChild()); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Contructor, crea un nodo con su nombre |
|
111 |
* |
|
112 |
* |
|
113 |
* @param name |
|
114 |
*/ |
|
115 |
public XMLNode(String name) throws Exception { |
|
116 |
nodeName = name; |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* Contructor, crea un nodo con su nombre y el texto |
|
121 |
* |
|
122 |
* |
|
123 |
* @param name |
|
124 |
* @param text |
|
125 |
*/ |
|
126 |
public XMLNode(String name, String text) throws Exception { |
|
127 |
nodeName = name; |
|
128 |
this.text = text; |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Contructor, desde un elemento DOM |
|
133 |
* |
|
134 |
* |
|
135 |
* @param dom |
|
136 |
*/ |
|
137 |
public XMLNode(Element dom) throws Exception { |
|
138 |
nodeName = dom.getNodeName(); |
|
139 |
NamedNodeMap map = dom.getAttributes(); |
|
140 |
for (int i = 0; i < map.getLength(); i++) { |
|
141 |
Node att = map.item(i); |
|
142 |
addAtrribute(att.getNodeName(), att.getNodeValue()); |
|
143 |
|
|
144 |
} |
|
145 |
NodeList nodeList = dom.getChildNodes(); |
|
146 |
for (int i = 0; i < nodeList.getLength(); i++) { |
|
147 |
Node sub = nodeList.item(i); |
|
148 |
if (sub.getNodeType() == Node.ELEMENT_NODE) { |
|
149 |
addSubNode(new XMLNode((Element)sub)); |
|
150 |
}else if (sub.getNodeType() == Node.CDATA_SECTION_NODE){ |
|
151 |
String sCdata = sub.getNodeValue().trim(); |
|
152 |
if (sCdata.length() > 0) { |
|
153 |
cdata = sCdata; |
|
154 |
} |
|
155 |
}else if (sub.getNodeType() == Node.TEXT_NODE) { |
|
156 |
String s = sub.getNodeValue().trim(); |
|
157 |
if (s.length() > 0) { |
|
158 |
if (text != null) { |
|
159 |
throw new Exception("XMLNode '" + nodeName + "' has 2 Textblocks"); |
|
160 |
} |
|
161 |
text = s; |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* |
|
169 |
* |
|
170 |
* |
|
171 |
* @param s |
|
172 |
*/ |
|
173 |
public void setText(String s) { |
|
174 |
text = s; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* |
|
179 |
* |
|
180 |
* |
|
181 |
* @param s |
|
182 |
*/ |
|
183 |
public void addSubNode(XMLNode s) { |
|
184 |
subNodes.add(s); |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* |
|
189 |
* |
|
190 |
* |
|
191 |
* @param name |
|
192 |
* @param value |
|
193 |
*/ |
|
194 |
public void addAtrribute(String name, String value) throws Exception { |
|
195 |
if (attr.containsKey(name)) { |
|
196 |
throw new Exception( |
|
197 |
"XMLNode '" + nodeName + "' already contains Attribute '" + name + "'"); |
|
198 |
} |
|
199 |
attr.put(name, value); |
|
200 |
attrKeys.add(name); |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* |
|
205 |
* |
|
206 |
* |
|
207 |
* @return |
|
208 |
*/ |
|
209 |
public int getNumSubNodes() { |
|
210 |
return subNodes.size(); |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* |
|
215 |
* |
|
216 |
* |
|
217 |
* @return |
|
218 |
*/ |
|
219 |
public String getName() { |
|
220 |
return nodeName; |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* |
|
225 |
* |
|
226 |
* |
|
227 |
* @return |
|
228 |
*/ |
|
229 |
public String getText() { |
|
230 |
return text; |
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* |
|
235 |
* |
|
236 |
* |
|
237 |
* @return |
|
238 |
*/ |
|
239 |
public String getCdata() { |
|
240 |
return cdata; |
|
241 |
} |
|
242 |
|
|
243 |
/** |
|
244 |
* |
|
245 |
* |
|
246 |
* |
|
247 |
* @return |
|
248 |
* @param index |
|
249 |
*/ |
|
250 |
public XMLNode getSubNode(int index) { |
|
251 |
return (XMLNode)subNodes.get(index); |
|
252 |
} |
|
253 |
|
|
254 |
/** |
|
255 |
* |
|
256 |
* |
|
257 |
* |
|
258 |
* @return |
|
259 |
*/ |
|
260 |
public XMLNode[] getSubnodes() { |
|
261 |
XMLNode[] xmlNodes = new XMLNode[getNumSubNodes()]; |
|
262 |
for (int i=0 ; i<getNumSubNodes() ; i++){ |
|
263 |
xmlNodes[i] = getSubNode(i); |
|
264 |
} |
|
265 |
return xmlNodes; |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* |
|
270 |
* |
|
271 |
* |
|
272 |
* @return |
|
273 |
*/ |
|
274 |
public Vector getAttributeNames() { |
|
275 |
return attrKeys; |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* |
|
280 |
* |
|
281 |
* |
|
282 |
* @param wr |
|
283 |
*/ |
|
284 |
public void write(Writer wr) throws Exception { |
|
285 |
wwrite("", wr); |
|
286 |
} |
|
287 |
|
|
288 |
/** |
|
289 |
* Escribe el c?digo XML de este objeto con su identaci?n |
|
290 |
* |
|
291 |
* |
|
292 |
* @param pre |
|
293 |
* @param wr |
|
294 |
*/ |
|
295 |
private void wwrite(String pre, Writer wr) throws Exception { |
|
296 |
wr.write(pre + "<" + nodeName); |
|
297 |
for (int i = 0; i < attrKeys.size(); i++) { |
|
298 |
String name = (String)attrKeys.get(i); |
|
299 |
String val = (String)attr.get(name); |
|
300 |
wr.write(" " + name + "='" + val + "'"); |
|
301 |
} |
|
302 |
if (getNumSubNodes() == 0 && text == null) { |
|
303 |
wr.write("/>\n"); |
|
304 |
} |
|
305 |
else { |
|
306 |
wr.write(">"); |
|
307 |
if (text != null) { |
|
308 |
wr.write(text); |
|
309 |
} |
|
310 |
if (getNumSubNodes() > 0) { |
|
311 |
wr.write("\n"); |
|
312 |
for (int i = 0; i < subNodes.size(); i++) { |
|
313 |
if (getSubNode(i) != null) { |
|
314 |
getSubNode(i).wwrite(pre + " ", wr); |
|
315 |
} |
|
316 |
} |
|
317 |
wr.write(pre + "</" + nodeName + ">\n"); |
|
318 |
} |
|
319 |
else { |
|
320 |
wr.write("</" + nodeName + ">\n"); |
|
321 |
} |
|
322 |
} |
|
323 |
} |
|
324 |
|
|
325 |
/** |
|
326 |
* |
|
327 |
* |
|
328 |
* |
|
329 |
* @return |
|
330 |
* @param key |
|
331 |
*/ |
|
332 |
public String getAttribute(String key) { |
|
333 |
return (String)attr.get(key); |
|
334 |
} |
|
335 |
|
|
336 |
/** |
|
337 |
* |
|
338 |
* |
|
339 |
* |
|
340 |
* @return |
|
341 |
* @param key |
|
342 |
*/ |
|
343 |
public double getDoubleAttribute(String key) { |
|
344 |
return Double.parseDouble((String)attr.get(key)); |
|
345 |
} |
|
346 |
|
|
347 |
/** |
|
348 |
* |
|
349 |
* |
|
350 |
* |
|
351 |
* @return |
|
352 |
* @param key |
|
353 |
*/ |
|
354 |
public boolean getBoolAttribute(String key) { |
|
355 |
if (!hasAttribute(key)) { |
|
356 |
return false; |
|
357 |
} |
|
358 |
return new Boolean((String)attr.get(key)).booleanValue(); |
|
359 |
} |
|
360 |
|
|
361 |
/** |
|
362 |
* |
|
363 |
* |
|
364 |
* |
|
365 |
* @return |
|
366 |
* @param key |
|
367 |
*/ |
|
368 |
public int getIntAttribute(String key) { |
|
369 |
return Integer.parseInt((String)attr.get(key)); |
|
370 |
} |
|
371 |
|
|
372 |
/** |
|
373 |
* |
|
374 |
* |
|
375 |
* |
|
376 |
* @return |
|
377 |
* @param key |
|
378 |
*/ |
|
379 |
public boolean hasAttribute(String key) { |
|
380 |
return attr.containsKey(key); |
|
381 |
} |
|
382 |
// escribe al fichero |
|
383 |
|
|
384 |
/** |
|
385 |
* |
|
386 |
* |
|
387 |
* |
|
388 |
* @param f |
|
389 |
*/ |
|
390 |
public void write(File f) throws Exception { |
|
391 |
FileWriter fw = new FileWriter(f); |
|
392 |
fw.write(header); |
|
393 |
write(fw); |
|
394 |
fw.flush(); |
|
395 |
fw.close(); |
|
396 |
} |
|
397 |
|
|
398 |
/** |
|
399 |
* @return |
|
400 |
*/ |
|
401 |
public String toString() { |
|
402 |
return this.getName(); |
|
403 |
} |
|
404 |
|
|
405 |
static DocumentBuilderFactory factory; |
|
406 |
static { |
|
407 |
factory = DocumentBuilderFactory.newInstance(); |
|
408 |
factory.setValidating(false); |
|
409 |
factory.setNamespaceAware(false); |
|
410 |
factory.setIgnoringComments(true); |
|
411 |
} |
|
412 |
|
|
413 |
/** |
|
414 |
* @param header |
|
415 |
*/ |
|
416 |
public void setHeader(String header) { |
|
417 |
this.header = header; |
|
418 |
} |
|
419 |
|
|
420 |
/** |
|
421 |
* This method prints all the child nodes. It is used only for |
|
422 |
* fixing bugs. |
|
423 |
* |
|
424 |
*/ |
|
425 |
public void printSubNodes() { |
|
426 |
for (int i=0 ; i<getNumSubNodes() ; i++){ |
|
427 |
System.out.println(getSubNode(i).getName() + " = " + getSubNode(i).getText()); |
|
428 |
} |
|
429 |
} |
|
430 |
|
|
431 |
/** |
|
432 |
* This method prints a node in the standard output. Just for degug |
|
433 |
* @param node |
|
434 |
*/ |
|
435 |
public void printNode() { |
|
436 |
printNode(this); |
|
437 |
} |
|
438 |
|
|
439 |
/** |
|
440 |
* Busca un Nodo dado una ruta de nodo del tipo "nodoRaiz:nodoPrimerNivel:...:nodoNivelN": |
|
441 |
* @return Devuelve el Nodo que corresponde a la ruta correcta o 'null' si no |
|
442 |
* lo encuentra |
|
443 |
* @param etiqueta Ruta del campo que queremos buscar, separando los niveles por ':' |
|
444 |
*/ |
|
445 |
public XMLNode searchNode(String etiqueta) { |
|
446 |
return XMLTree.searchNode(this, etiqueta); |
|
447 |
} |
|
448 |
|
|
449 |
/** |
|
450 |
* Hace una busqueda de un atributo de un nodo |
|
451 |
* |
|
452 |
* @param nombreAtributo Nombre del atributo |
|
453 |
* @return Valor del atributo, o null si no lo ha encontrado |
|
454 |
* @param attributeName |
|
455 |
*/ |
|
456 |
public String searchAtribute(String attributeName) { |
|
457 |
return XMLTree.searchAtribute(this, attributeName); |
|
458 |
} |
|
459 |
|
|
460 |
/** |
|
461 |
* Hace una busqueda de una etiqueta en un nodo y devuelve |
|
462 |
* su valor |
|
463 |
* @return Valor de la etiqueta |
|
464 |
* @param etiqueta Nombre de la etiqueta |
|
465 |
*/ |
|
466 |
public String searchNodeValue(String etiqueta) { |
|
467 |
return XMLTree.searchNodeValue(this,etiqueta); |
|
468 |
} |
|
469 |
|
|
470 |
/** |
|
471 |
* Hace una busqueda de una etiqueta en un nodo y devuelve |
|
472 |
* el valor del atributo correspondiente |
|
473 |
* @return Valor del atributo de la etiqueta o null |
|
474 |
* @param etiqueta Nombre de la etiqueta |
|
475 |
* @param atributo |
|
476 |
*/ |
|
477 |
public String searchNodeAtribute(XMLNode node, String etiqueta, String atributo) { |
|
478 |
return XMLTree.searchNodeAtribute(this, etiqueta, atributo); |
|
479 |
} |
|
480 |
|
|
481 |
/** |
|
482 |
* Hace una busqueda de nodos que se llaman igual y devuleve el valor |
|
483 |
* @return Un vector con valores de las etiquetas |
|
484 |
* @param rootNode Nodo a partir del cual se quiere hacer la b?squeda |
|
485 |
* @param label Node label |
|
486 |
*/ |
|
487 |
public String[] searchMultipleNodeValue(String label) { |
|
488 |
return XMLTree.searchMultipleNodeValue(this, label); |
|
489 |
} |
|
490 |
|
|
491 |
/** |
|
492 |
* Hace una busqueda de nodos que se llaman igual desde uno dado(sin recursividad) |
|
493 |
* @return Un vector con los nodos que ha encontrado |
|
494 |
* @param nodoRaiz Nodo a partir del cual se quiere hacer la b?squeda |
|
495 |
* @param label |
|
496 |
*/ |
|
497 |
public XMLNode[] searchMultipleNode(String label) { |
|
498 |
return XMLTree.searchMultipleNode(this, label); |
|
499 |
} |
|
500 |
|
|
501 |
/** |
|
502 |
* @return The XML tree like a String |
|
503 |
*/ |
|
504 |
public String getXmlTree(){ |
|
505 |
StringBuffer buffer = new StringBuffer(); |
|
506 |
buffer.append("<" + getName()); |
|
507 |
for (int i = 0; i < getAttributeNames().size(); i++) { |
|
508 |
String name = (String)getAttributeNames().get(i); |
|
509 |
String val = (String)getAttribute(name); |
|
510 |
buffer.append(" " + name + "='" + val + "'"); |
|
511 |
} |
|
512 |
if (getNumSubNodes() == 0 && getText() == null) { |
|
513 |
buffer.append("/>\n"); |
|
514 |
} |
|
515 |
else { |
|
516 |
buffer.append(">"); |
|
517 |
if (getText() != null) { |
|
518 |
buffer.append(getText()); |
|
519 |
} |
|
520 |
if (getNumSubNodes() > 0) { |
|
521 |
buffer.append("\n"); |
|
522 |
for (int i = 0; i < getSubnodes().length; i++) { |
|
523 |
if (getSubnodes()[i] != null) { |
|
524 |
buffer.append(getSubnodes()[i].getXmlTree()); |
|
525 |
} |
|
526 |
} |
|
527 |
buffer.append("</" + getName() + ">\n"); |
|
528 |
} |
|
529 |
else { |
|
530 |
buffer.append("</" + getName() + ">\n"); |
|
531 |
} |
|
532 |
} |
|
533 |
return buffer.toString(); |
|
534 |
} |
|
535 |
|
|
536 |
/** |
|
537 |
* Print a node by the default exit |
|
538 |
* @param node |
|
539 |
*/ |
|
540 |
private void printNode(XMLNode node){ |
|
541 |
System.out.print(getXmlTree()); |
|
542 |
} |
|
543 |
} |
|
0 | 544 |
tags/v2_0_0_Build_2021/applications/appCatalog/src/org/gvsig/catalog/metadataxml/XMLTree.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
Also available in: Unified diff