List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:org.kalypsodeegree.xml.XMLTools.java
/** * Returns the first child element of the submitted node that matches the given namespace and name. *//*from w w w. j av a2 s. c om*/ public static Element getNamedChild(final Node node, final String namespace, final String name) { // Debug.debugMethodBegin( "XMLTools", "getNamedChild" ); final NodeList nl = node.getChildNodes(); Element element = null; Element return_ = null; if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof Element) { element = (Element) nl.item(i); final String s = element.getNamespaceURI(); if (namespace == null && s == null || namespace.equals(s)) { if (element.getLocalName().equals(name)) { return_ = element; break; } } } } } // Debug.debugMethodEnd(); return return_; }
From source file:org.kalypsodeegree_impl.filterencoding.AbstractFilter.java
/** * Builds a filter from the contents of a 'xs:anyType' element. Tries to interpret the given object either as filter * element, or, if not, it's direct nodes as filter. The first filter encountered wins. *//*from w w w. j a v a 2 s.c om*/ public static Filter buildFromAnyType(final Object anyType) throws FilterConstructionException { if (!(anyType instanceof Element)) return null; // Is the element itself the filter? final Element filterElement = (Element) anyType; if (filterElement.getLocalName().equals("Filter")) return buildFromDOM(filterElement); // Try the direct children final NodeList childNodes = filterElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { final Node item = childNodes.item(i); if (item instanceof Element && item.getLocalName().equals("Filter")) return AbstractFilter.buildFromDOM((Element) item); } return null; }
From source file:org.kalypsodeegree_impl.filterencoding.AbstractFilter.java
/** * Given a DOM-fragment, a corresponding Filter-object is built. This method recursively calls other buildFromDOM () - * methods to validate the structure of the DOM-fragment. * //from w w w . j a v a2s . com * @throws FilterConstructionException * if the structure of the DOM-fragment is invalid */ public static Filter buildFromDOM(final Element element) throws FilterConstructionException { // check if root element's name equals 'filter' if (!"Filter".equals(element.getLocalName())) throw new FilterConstructionException("Name of element does not equal 'Filter'!"); // determine type of Filter (FeatureFilter / ComplexFilter) Element firstElement = null; NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { firstElement = (Element) children.item(i); } } if (firstElement == null) throw new FilterConstructionException("Filter Node is empty!"); Filter filter = null; if ("FeatureId".equals(firstElement.getLocalName())) { // must be a FeatureFilter final FeatureFilter fFilter = new FeatureFilter(); children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { final Element fid = (Element) children.item(i); if (!"FeatureId".equals(fid.getLocalName())) throw new FilterConstructionException( "Unexpected Element encountered: " + fid.getLocalName()); fFilter.addFeatureId(FeatureId.buildFromDOM(fid)); } } filter = fFilter; } else { // must be a ComplexFilter children = element.getChildNodes(); boolean justOne = false; for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { final Element operator = (Element) children.item(i); if (justOne) throw new FilterConstructionException( "Unexpected element encountered: " + operator.getLocalName()); final ComplexFilter cFilter = new ComplexFilter(AbstractOperation.buildFromDOM(operator)); filter = cFilter; justOne = true; } } } return filter; }
From source file:org.kalypsodeegree_impl.filterencoding.PropertyIsCOMPOperation.java
/** * Given a DOM-fragment, a corresponding Operation-object is built. This method recursively calls other buildFromDOM * () - methods to validate the structure of the DOM-fragment. * //from w ww . j a v a 2s .c o m * @throws FilterConstructionException * if the structure of the DOM-fragment is invalid */ public static Operation buildFromDOM(final Element element) throws FilterConstructionException { // check if root element's name is a known operator final String name = element.getLocalName(); final int operatorId = OperationDefines.getIdByName(name); switch (operatorId) { case OperationDefines.PROPERTYISEQUALTO: case OperationDefines.PROPERTYISNOTEQUALTO: case OperationDefines.PROPERTYISLESSTHAN: case OperationDefines.PROPERTYISGREATERTHAN: case OperationDefines.PROPERTYISLESSTHANOREQUALTO: case OperationDefines.PROPERTYISGREATERTHANOREQUALTO: break; default: throw new FilterConstructionException("'" + name + "' is not a PropertyIsOperator!"); } final ElementList children = XMLTools.getChildElements(element); if (children.getLength() != 2) { throw new FilterConstructionException("'" + name + "' requires exactly 2 elements!"); } final Expression expr1 = Expression_Impl.buildFromDOM(children.item(0)); final Expression expr2 = Expression_Impl.buildFromDOM(children.item(1)); return new PropertyIsCOMPOperation(operatorId, expr1, expr2); }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
/** * Reads an sld file from an {@link InputStream}.<br> * The type of the returned element may be any of the top-level types defined in the sld-schema. * /*from w w w . j av a 2 s . c o m*/ * @throws XMLParsingException * if a syntactic or semantic error in the XML document is encountered * @return The read top-Level element */ public static Object readSLD(final IUrlResolver2 urlResolver, final InputStream is) throws XMLParsingException { try { final Document doc = XMLTools.parse(is); final Element element = doc.getDocumentElement(); final String namespaceURI = element.getNamespaceURI(); if (!NS_SLD.equals(namespaceURI)) throw new XMLParsingException(String.format("Root-Element must be of namespace '%s'", NS_SLD)); final String localName = element.getLocalName(); if ("StyledLayerDescriptor".equals(localName))//$NON-NLS-1$ return SLDFactory.createStyledLayerDescriptor(urlResolver, element); if ("NamedLayer".equals(localName))//$NON-NLS-1$ return SLDFactory.createNamedLayer(urlResolver, element); if ("UserLayer".equals(localName))//$NON-NLS-1$ return SLDFactory.createUserLayer(urlResolver, element); if ("UserStyle".equals(localName))//$NON-NLS-1$ return SLDFactory.createUserStyle(urlResolver, element); if ("FeatureTypeStyle".equals(localName))//$NON-NLS-1$ return SLDFactory.createFeatureTypeStyle(urlResolver, element); throw new XMLParsingException(String.format("Unable to parse Root-Element: '%s'", localName)); } catch (final IOException e) { throw new XMLParsingException("IOException encountered while parsing SLD-Document: " + e.getMessage(), e); } catch (final SAXException e) { throw new XMLParsingException("SAXException encountered while parsing SLD-Document: " + e.getMessage(), e); } }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
/** * Creates a <tt>LabelPlacement</tt> -instance according to the contents of the DOM-subtree starting at the given * 'LabelPlacement'- <tt>Element</tt>. * <p>/*w ww . ja va2 s . c om*/ * * @param element * the 'LabelPlacement'- <tt>Element</tt> * @throws XMLParsingException * if a syntactic or semantic error in the DOM-subtree is encountered * @return the constructed <tt>LabelPlacement</tt> -instance */ private static LabelPlacement createLabelPlacement(final Element element) throws XMLParsingException { LabelPlacement labelPlacement = null; // required: <PointPlacement> / <LinePlacement> final NodeList nodelist = element.getChildNodes(); PointPlacement pPlacement = null; LinePlacement lPlacement = null; for (int i = 0; i < nodelist.getLength(); i++) if (nodelist.item(i) instanceof Element) { final Element child = (Element) nodelist.item(i); final String namespace = child.getNamespaceURI(); if (!NS.SLD.equals(namespace)) { continue; } final String childName = child.getLocalName(); if ("PointPlacement".equals(childName))//$NON-NLS-1$ { pPlacement = SLDFactory.createPointPlacement(child); } else if ("LinePlacement".equals(childName))//$NON-NLS-1$ { lPlacement = SLDFactory.createLinePlacement(child); } } if (pPlacement != null && lPlacement == null) { labelPlacement = new LabelPlacement_Impl(pPlacement); } else if (pPlacement == null && lPlacement != null) { labelPlacement = new LabelPlacement_Impl(lPlacement); } else throw new XMLParsingException("Element 'LabelPlacement' must contain exactly one " + "'PointPlacement'- or one 'LinePlacement'-element!"); return labelPlacement; }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
/** * Creates a <tt>StyledLayerDescriptor</tt> -instance according to the contents of the DOM-subtree starting at the * given 'StyledLayerDescriptor'- <tt>Element</tt>. * <p>//from ww w . j ava 2s . co m * * @param element * the 'StyledLayerDescriptor'- <tt>Element</tt> * @throws XMLParsingException * if a syntactic or semantic error in the DOM-subtree is encountered * @return the constructed <tt>StyledLayerDescriptor</tt> -instance */ public static StyledLayerDescriptor createStyledLayerDescriptor(final IUrlResolver2 urlResolver, final Element element) throws XMLParsingException { // optional: <Name> final String name = XMLTools.getStringValue("Name", NS.SLD, element, null);//$NON-NLS-1$ // optional: <Title> final String title = XMLTools.getStringValue("Title", NS.SLD, element, null);//$NON-NLS-1$ // optional: <Abstract> final String description = XMLTools.getStringValue("Abstract", NS.SLD, element, null);//$NON-NLS-1$ // required: version-Attribute // final String version = XMLTools.getRequiredAttrValue( "version", element ); // TODO: check for correct version here...; must be "1.0.0", but i have seen many wrong .sld's // optional: <NamedLayer>(s) / <UserLayer>(s) final NodeList nodelist = element.getChildNodes(); final List<Layer> layerList = new ArrayList<>(100); for (int i = 0; i < nodelist.getLength(); i++) { if (nodelist.item(i) instanceof Element) { final Element child = (Element) nodelist.item(i); final String namespace = child.getNamespaceURI(); if (!NS.SLD.equals(namespace)) { continue; } final String childName = child.getLocalName(); if ("NamedLayer".equals(childName))//$NON-NLS-1$ { layerList.add(SLDFactory.createNamedLayer(urlResolver, child)); } else if ("UserLayer".equals(childName))//$NON-NLS-1$ { layerList.add(SLDFactory.createUserLayer(urlResolver, child)); } } } final Layer[] layers = layerList.toArray(new Layer[layerList.size()]); return new StyledLayerDescriptor_Impl(name, title, description, layers); }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
/** * Creates a <tt>NamedLayer</tt> -instance according to the contents of the DOM-subtree starting at the given * 'UserLayer'- <tt>Element</tt>. * <p>/*from ww w . j a v a2s .c o m*/ * * @param element * the 'NamedLayer'- <tt>Element</tt> * @throws XMLParsingException * if a syntactic or semantic error in the DOM-subtree is encountered * @return the constructed <tt>NamedLayer</tt> -instance */ private static NamedLayer createNamedLayer(final IUrlResolver2 urlResolver, final Element element) throws XMLParsingException { // required: <Name> final String name = XMLTools.getRequiredStringValue("Name", NS.SLD, element);//$NON-NLS-1$ // optional: <LayerFeatureConstraints> LayerFeatureConstraints lfc = null; final Element lfcElement = XMLTools.getChildByName("LayerFeatureConstraints", NS.SLD, element);//$NON-NLS-1$ if (lfcElement != null) { lfc = SLDFactory.createLayerFeatureConstraints(lfcElement); } // optional: <NamedStyle>(s) / <UserStyle>(s) final NodeList nodelist = element.getChildNodes(); final List<Style> styleList = new ArrayList<>(); for (int i = 0; i < nodelist.getLength(); i++) if (nodelist.item(i) instanceof Element) { final Element child = (Element) nodelist.item(i); final String namespace = child.getNamespaceURI(); if (!NS.SLD.equals(namespace)) { continue; } final String childName = child.getLocalName(); if ("NamedStyle".equals(childName)) { styleList.add(SLDFactory.createNamedStyle(child)); } else if ("UserStyle".equals(childName)) { styleList.add(SLDFactory.createUserStyle(urlResolver, child)); } } final Style[] styles = styleList.toArray(new Style[styleList.size()]); return new NamedLayer_Impl(name, lfc, styles); }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
private static void parseRuleOrSemanticTypeIdentifier(final IUrlResolver2 urlResolver, final List<Rule> ruleList, final List<String> typeIdentifierList, final List<Filter> filters, final List<Rule> elseRules, final Node item) throws XMLParsingException { if (item instanceof Element) { final Element child = (Element) item; final String namespace = child.getNamespaceURI(); if (!NS.SLD.equals(namespace)) { return; }/*from ww w .ja v a2s. co m*/ final String childName = child.getLocalName(); if ("Rule".equals(childName)) { final Rule rule = SLDFactory.createRule(urlResolver, child); if (rule.hasElseFilter()) { elseRules.add(rule); } else if (rule.getFilter() == null || rule.getFilter() instanceof ComplexFilter) { filters.add(rule.getFilter()); } ruleList.add(rule); } else if ("SemanticTypeIdentifier".equals(childName))//$NON-NLS-1$ { typeIdentifierList.add(XMLTools.getStringValue(child)); } } }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
public static Symbolizer createSymbolizer(final IUrlResolver2 urlResolver, final Element symbolizerElement) throws XMLParsingException { final String namespace = symbolizerElement.getNamespaceURI(); if (!(NS.SLD.equals(namespace) || SLDNS_EXT.equals(namespace))) return null; final UOM uom = readUOM(symbolizerElement); final String symbolizerName = symbolizerElement.getLocalName(); if ("LineSymbolizer".equals(symbolizerName))//$NON-NLS-1$ return SLDFactory.createLineSymbolizer(urlResolver, symbolizerElement, uom); if ("PointSymbolizer".equals(symbolizerName))//$NON-NLS-1$ return SLDFactory.createPointSymbolizer(urlResolver, symbolizerElement, uom); if ("PolygonSymbolizer".equals(symbolizerName))//$NON-NLS-1$ return SLDFactory.createPolygonSymbolizer(urlResolver, symbolizerElement, uom); if ("TextSymbolizer".equals(symbolizerName))//$NON-NLS-1$ return SLDFactory.createTextSymbolizer(urlResolver, symbolizerElement, uom); if ("RasterSymbolizer".equals(symbolizerName))//$NON-NLS-1$ return SLDFactory.createRasterSymbolizer(urlResolver, symbolizerElement, uom); if ("SurfaceLineSymbolizer".equals(symbolizerName))//$NON-NLS-1$ return SLDFactory.createSurfaceLineSymbolizer(urlResolver, symbolizerElement, uom); if ("SurfacePolygonSymbolizer".equals(symbolizerName)) //$NON-NLS-1$ return SLDFactory.createSurfacePolygonSymbolizer(urlResolver, symbolizerElement, uom); return null;/*from www .j a v a 2 s . com*/ }