public String cacheAgeMax() { Element cacheInfo = ReaderUtils.getChildElement(featureType, "cacheinfo"); if (cacheInfo != null) { try { return ReaderUtils.getAttribute(cacheInfo, "maxage", false); } catch (Exception e) { } } return null; }
public Envelope nativeBoundingBox() throws Exception { Element box = ReaderUtils.getChildElement(featureType, "nativeBBox"); boolean dynamic = ReaderUtils.getBooleanAttribute(box, "dynamic", false, true); if (dynamic) { return null; } double minx = ReaderUtils.getDoubleAttribute(box, "minx", true); double miny = ReaderUtils.getDoubleAttribute(box, "miny", true); double maxx = ReaderUtils.getDoubleAttribute(box, "maxx", true); double maxy = ReaderUtils.getDoubleAttribute(box, "maxy", true); return new Envelope(minx, maxx, miny, maxy); }
/** * Returns a particular attribute value of a specified child of an element. * * @param root The element. * @param childName The child element. * @param attName The attribute of the child to obtain. * @return The attribute value or null if it does not exist. */ public static String getChildAttribute(Element root, String childName, String attName) { try { return getChildAttribute(root, childName, attName, false); } catch (Exception e) { return null; } }
public Envelope latLonBoundingBox() throws Exception { Element box = ReaderUtils.getChildElement(featureType, "latLonBoundingBox"); double minx = ReaderUtils.getDoubleAttribute(box, "minx", true); double miny = ReaderUtils.getDoubleAttribute(box, "miny", true); double maxx = ReaderUtils.getDoubleAttribute(box, "maxx", true); double maxy = ReaderUtils.getDoubleAttribute(box, "maxy", true); return new Envelope(minx, maxx, miny, maxy); }
<T> void value(String parameter, Element element, Map map, Class<T> clazz, boolean man, T def) throws Exception { Element valueElement = ReaderUtils.getChildElement(element, parameter); if (valueElement == null) { if (man) { throw new RuntimeException("No such element: " + parameter); } else { map.put(parameter, def); return; } } Object value = null; if (Boolean.class.equals(clazz)) { value = Boolean.valueOf( ReaderUtils.getBooleanAttribute(valueElement, "value", true, false)); } else if (Integer.class.equals(clazz)) { value = Integer.valueOf(ReaderUtils.getIntAttribute(valueElement, "value", true, -1)); } else if (Double.class.equals(clazz)) { value = new Double(ReaderUtils.getDoubleAttribute(valueElement, "value", true)); } else { value = ReaderUtils.getAttribute(valueElement, "value", true); } map.put(parameter, value); }
public Map<String, Object> grid() throws Exception { Element gridElement = ReaderUtils.getChildElement(coverage, "grid"); if (gridElement == null) { return null; Integer.parseInt(ReaderUtils.getAttribute(gridElement, "dimension", true))); Element lowElement = ReaderUtils.getChildElement(gridElement, "low"); String[] lows = lowElement.getFirstChild().getTextContent().trim().split(" "); int[] low = new int[lows.length]; Element highElement = ReaderUtils.getChildElement(gridElement, "high"); String[] highs = highElement.getFirstChild().getTextContent().trim().split(" "); int[] high = new int[highs.length]; Element[] axisNameElements = ReaderUtils.getChildElements(gridElement, "axisName"); String[] axisName = new String[axisNameElements.length]; for (int i = 0; i < axisName.length; i++) { Element geoTransformElement = ReaderUtils.getChildElement(gridElement, "geoTransform"); if (geoTransformElement != null) { Map<String, Double> geoTransform = new HashMap<String, Double>(); String scaleX = ReaderUtils.getChildText(geoTransformElement, "scaleX"); String scaleY = ReaderUtils.getChildText(geoTransformElement, "scaleY"); String shearX = ReaderUtils.getChildText(geoTransformElement, "shearX"); String shearY = ReaderUtils.getChildText(geoTransformElement, "shearY"); String translateX = ReaderUtils.getChildText(geoTransformElement, "translateX"); String translateY = ReaderUtils.getChildText(geoTransformElement, "translateY");
/** * getChildElement purpose. * * <p>Used to help with XML manipulations. Returns the first child element of the specified * name. * * @param root The root element to look for children in. * @param name The name of the child element to look for. * @return The child element found, null if not found. * @see #getChildElement(Element,String,boolean) */ public static Element getChildElement(Element root, String name) { try { return getChildElement(root, name, false); } catch (Exception e) { // will never be here. return null; } }
Element formatsElement = ReaderUtils.getChildElement(catalog, "formats", true); format.put("id", ReaderUtils.getAttribute(formatElement, "id", true)); format.put("namespace", ReaderUtils.getAttribute(formatElement, "namespace", false)); format.put( "enabled", Boolean.valueOf( ReaderUtils.getBooleanAttribute( formatElement, "enabled", false, true))); format.put("type", ReaderUtils.getChildText(formatElement, "type", true)); format.put("url", ReaderUtils.getChildText(formatElement, "url", false)); format.put("title", ReaderUtils.getChildText(formatElement, "title", false)); format.put( "description", ReaderUtils.getChildText(formatElement, "description", false));
public List<String> supportedFormats() throws Exception { Element supportedFormats = ReaderUtils.getChildElement(coverage, "supportedFormats"); String[] formats = ReaderUtils.getChildText(supportedFormats, "formats").split(","); return Arrays.asList(formats); }
public Map<String, Serializable> parameters() { Element parameters = ReaderUtils.getChildElement(coverage, "parameters"); if (parameters == null) { return Collections.EMPTY_MAP; } HashMap<String, Serializable> map = new HashMap<String, Serializable>(); Element[] parameter = ReaderUtils.getChildElements(parameters, "parameter"); for (int i = 0; i < parameter.length; i++) { String name = parameter[i].getAttribute("name"); String value = parameter[i].getAttribute("value"); map.put(name, value); } return map; }
Map<String, Object> readService(Element serviceElement) throws Exception { HashMap<String, Object> service = new HashMap<String, Object>(); service.put( "enabled", ReaderUtils.getBooleanAttribute(serviceElement, "enabled", false, true)); text("abstract", serviceElement, service, String.class); Element mlElement = ReaderUtils.getChildElement(serviceElement, "metadataLink"); if (mlElement != null) { HashMap metadataLink = new HashMap(); metadataLink.put("about", ReaderUtils.getAttribute(mlElement, "about", false)); metadataLink.put("type", ReaderUtils.getAttribute(mlElement, "type", false)); metadataLink.put( "metadataType", ReaderUtils.getAttribute(mlElement, "metadataType", false)); service.put("metadataLink", metadataLink); Element keywordsElement = ReaderUtils.getChildElement(serviceElement, "keywords"); Element[] keywordElements = ReaderUtils.getChildElements(keywordsElement, "keyword"); ArrayList keywords = new ArrayList(); if (keywordElements != null) {
public List<Map> coverageDimensions() throws Exception { Element[] cdElements = ReaderUtils.getChildElements(coverage, "CoverageDimension"); List<Map> cds = new ArrayList<Map>(); for (int i = 0; i < cdElements.length; i++) { HashMap cd = new HashMap(); cd.put("name", ReaderUtils.getChildText(cdElements[i], "name")); cd.put("description", ReaderUtils.getChildText(cdElements[i], "description")); Element intervalElement = ReaderUtils.getChildElement(cdElements[i], "interval"); double min = Double.parseDouble(ReaderUtils.getChildText(intervalElement, "min")); double max = Double.parseDouble(ReaderUtils.getChildText(intervalElement, "max")); cd.put("min", min); cd.put("max", max); cds.add(cd); } return cds; }
public Map<String, Object> legendURL() throws Exception { Element legendURL = ReaderUtils.getChildElement(featureType, "LegendURL"); if (legendURL != null) { HashMap map = new HashMap(); map.put("width", Integer.parseInt(ReaderUtils.getAttribute(legendURL, "width", true))); map.put( "height", Integer.parseInt(ReaderUtils.getAttribute(legendURL, "height", true))); map.put("format", ReaderUtils.getChildText(legendURL, "Format", true)); map.put( "onlineResource", ReaderUtils.getAttribute( ReaderUtils.getChildElement(legendURL, "OnlineResource", true), "xlink:href", true)); return map; } return null; }
public Map<String, Object> envelope() throws Exception { Element envelopeElement = ReaderUtils.getChildElement(coverage, "envelope"); HashMap<String, Object> e = new HashMap<String, Object>(); String nativeCrsWkt = ReaderUtils.getAttribute(envelopeElement, "crs", false); nativeCrsWkt = nativeCrsWkt.replaceAll("'", "\""); e.put("crs", nativeCrsWkt); e.put("srsName", ReaderUtils.getAttribute(envelopeElement, "srsName", false)); Element[] posElements = ReaderUtils.getChildElements(envelopeElement, "pos"); String[] pos1 = posElements[0].getFirstChild().getTextContent().split(" "); String[] pos2 = posElements[1].getFirstChild().getTextContent().split(" "); e.put("x1", Double.parseDouble(pos1[0])); e.put("y1", Double.parseDouble(pos1[1])); e.put("x2", Double.parseDouble(pos2[0])); e.put("y2", Double.parseDouble(pos2[1])); return e; }
Element dataStoresElement = ReaderUtils.getChildElement(catalog, "datastores", true); String id = ReaderUtils.getAttribute(dataStoreElement, "id", true); dataStore.put("id", id); dataStore.put( "namespace", ReaderUtils.getAttribute(dataStoreElement, "namespace", false)); dataStore.put( "enabled", Boolean.valueOf( ReaderUtils.getBooleanAttribute( dataStoreElement, "enabled", false, true))); try {
@RunTestSetup @Test public void testGeoServerReload() throws Exception { Catalog cat = getCatalog(); FeatureTypeInfo lakes = cat.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertFalse("foo".equals(lakes.getTitle())); GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader()); File info = dd.findResourceFile(lakes); // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml"); FileReader in = new FileReader(info); Element dom = ReaderUtils.parse(in); Element title = ReaderUtils.getChildElement(dom, "title"); title.getFirstChild().setNodeValue("foo"); OutputStream output = new FileOutputStream(info); try { TransformerFactory.newInstance() .newTransformer() .transform(new DOMSource(dom), new StreamResult(output)); } finally { output.close(); } getGeoServer().reload(); lakes = cat.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertEquals("foo", lakes.getTitle()); }
/** * Parses the info.xml file into a DOM. * * <p>This method *must* be called before any other methods. * * @param file The info.xml file. * @throws IOException In event of a parser error. */ public void read(File file) throws IOException { parentDirectory = file.getParentFile(); Reader reader = XmlCharsetDetector.getCharsetAwareReader(new FileInputStream(file)); try { coverage = ReaderUtils.parse(reader); } finally { reader.close(); } }
/** * getChildText purpose. * * <p>Used to help with XML manipulations. Returns the first child text value of the specified * element name. An exception occurs when the node is required and not found. * * @param root The root element to look for children in. * @param childName The name of the attribute to look for. * @param mandatory true when an exception should be thrown if the text does not exist. * @return The value if the child was found, the null otherwise. * @throws Exception When a child attribute is required and not found. */ public static String getChildText(Element root, String childName, boolean mandatory) throws Exception { Element elem = getChildElement(root, childName, mandatory); if (elem != null) { return getElementText(elem, mandatory); } else { if (mandatory) { String msg = "Mandatory child " + childName + "not found in " + " element: " + root; throw new Exception(msg); } return null; } }
public String name() { return ReaderUtils.getChildText(featureType, "name"); }
Element service(Element servicesElement, String id) throws Exception { Element[] serviceElements = ReaderUtils.getChildElements(servicesElement, "service"); for (int i = 0; i < serviceElements.length; i++) { String serviceId = ReaderUtils.getAttribute(serviceElements[i], "type", false); if (id.equals(serviceId)) { return serviceElements[i]; } } throw new Exception("No service element: " + id); }