/** * Encode the simpleContent property of a ComplexAttribute (if any) as an XML text node. * * <p>A property named simpleContent is a convention for representing XSD complexType with * simpleContent in GeoAPI. * * @param complex the ComplexAttribute to be searched for simpleContent * @param document the containing document * @param element the element to which text node should be added */ public static void encodeSimpleContent( ComplexAttribute complex, Document document, Element element) { Object value = getSimpleContent(complex); encodeAsText(document, element, value); }
/** Test VocabFunction in a mapping file */ @Test public void testVocabFunctionInMappingFile() { final Map<String, String> VALUE_MAP = new HashMap<String, String>() { { put("sc.1", "urn:cgi:classifier:CGI:SimpleLithology:2008:gravel"); put("sc.2", "urn:cgi:classifier:CGI:SimpleLithology:2008:diamictite"); put("sc.3", "urn:cgi:classifier:CGI:SimpleLithology:2008:sediment"); } }; FeatureIterator<Feature> features = exCollection.features(); try { while (features.hasNext()) { Feature feature = features.next(); String fId = feature.getIdentifier().getID(); // gml[2]: <OCQL>Vocab(URN_ID, // 'src/test/java/org/geotools/filter/test-data/minoc_lithology_mapping.properties')</OCQL> ComplexAttribute complexAttribute = (ComplexAttribute) ff.property("gml:name[2]").evaluate(feature); String value = Converters.convert( GML3EncodingUtils.getSimpleContent(complexAttribute), String.class); assertEquals(VALUE_MAP.get(fId), value); } } finally { features.close(); } }
String value = Converters.convert( GML3EncodingUtils.getSimpleContent(complexAttribute), String.class); assertEquals(expectedValues.get(fid), value);
String value = Converters.convert( GML3EncodingUtils.getSimpleContent(complexAttribute), String.class); assertEquals(recodedName, value);
assertEquals(1, values.size()); assertEquals( "Yaugher Volcanic Group 1", GML3EncodingUtils.getSimpleContent(complexAttribute)); assertEquals(1, values.size()); assertEquals( "Yaugher Volcanic Group 2", GML3EncodingUtils.getSimpleContent(complexAttribute)); assertEquals("-Py", GML3EncodingUtils.getSimpleContent(complexAttribute));
/** * Encode the simpleContent property of a ComplexAttribute (if any) as an XML text node. * * <p> * * A property named simpleContent is a convention for representing XSD complexType with * simpleContent in GeoAPI. * * @param complex * the ComplexAttribute to be searched for simpleContent * @param document * the containing document * @param element * the element to which text node should be added */ public static void encodeSimpleContent(ComplexAttribute complex, Document document, Element element) { Object value = getSimpleContent(complex); if (value != null) { Text text = document.createTextNode(Converters.convert(value, String.class)); element.appendChild(text); } }
/** * Test VocabFunction in a mapping file */ @Test public void testVocabFunctionInMappingFile() { final Map<String, String> VALUE_MAP = new HashMap<String, String>() { { put("sc.1", "urn:cgi:classifier:CGI:SimpleLithology:2008:gravel"); put("sc.2", "urn:cgi:classifier:CGI:SimpleLithology:2008:diamictite"); put("sc.3", "urn:cgi:classifier:CGI:SimpleLithology:2008:sediment"); } }; Iterator<Feature> features = exCollection.iterator(); while (features.hasNext()) { Feature feature = features.next(); String fId = feature.getIdentifier().getID(); // gml[2]: <OCQL>Vocab(URN_ID, // 'src/test/java/org/geotools/filter/test-data/minoc_lithology_mapping.properties')</OCQL> ComplexAttribute complexAttribute = (ComplexAttribute) ff.property("gml:name[2]") .evaluate(feature); String value = Converters.convert(GML3EncodingUtils.getSimpleContent(complexAttribute), String.class); assertEquals(VALUE_MAP.get(fId), value); } exCollection.close(features); }
/** * Test RecodeFunction * * @throws IOException */ @Test public void testRecodeFunction() throws IOException { final Map<String, String> VALUE_MAP = new HashMap<String, String>() { { put("sc.1", "a"); put("sc.2", "b"); put("sc.3", "c"); } }; Iterator<Feature> features = exCollection.iterator(); while (features.hasNext()) { Feature feature = features.next(); String fId = feature.getIdentifier().getID(); String recodedName = VALUE_MAP.get(fId); // gml[3]: <OCQL>Recode(STRING, 'string_one', 'a', 'string_two', 'b', 'string_three', // 'c')</OCQL> ComplexAttribute complexAttribute = (ComplexAttribute) ff.property("gml:name[3]") .evaluate(feature); String value = Converters.convert(GML3EncodingUtils.getSimpleContent(complexAttribute), String.class); assertEquals(recodedName, value); } exCollection.close(features); }
assertEquals(1, values.size()); assertEquals("Yaugher Volcanic Group 1", GML3EncodingUtils.getSimpleContent(complexAttribute)); assertEquals(1, values.size()); assertEquals("Yaugher Volcanic Group 2", GML3EncodingUtils.getSimpleContent(complexAttribute)); assertEquals(1, values.size()); assertEquals("-Py", GML3EncodingUtils.getSimpleContent(complexAttribute));