@Override public PlacemarkDescriptor convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { final String type = parentElement.getAttribute("class"); PlacemarkDescriptor placemarkDescriptor = PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(type); if (placemarkDescriptor == null) { throw new ConversionException(String.format("Unknown placemark descriptor class '%s'", type)); } return placemarkDescriptor; }
static void escapeXmlElements(DomElement domElement) { domElement.setValue(StringEscapeUtils.escapeXml(domElement.getValue())); String[] attributeNames = domElement.getAttributeNames(); for (String attributeName : attributeNames) { domElement.setAttribute(attributeName, StringEscapeUtils.escapeXml(domElement.getAttribute(attributeName))); } DomElement[] children = domElement.getChildren(); for (DomElement child : children) { escapeXmlElements(child); } }
@Override public PlacemarkDescriptor convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { final String type = parentElement.getAttribute("class"); PlacemarkDescriptor placemarkDescriptor = PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(type); if (placemarkDescriptor == null) { throw new ConversionException(String.format("Unknown placemark descriptor class '%s'", type)); } return placemarkDescriptor; }
private static void addDomToMetadata(DomElement childDE, String name, MetadataElement parentME) { if (childDE.getChildCount() > 0 || childDE.getAttributeNames().length > 0) { final MetadataElement childME = new MetadataElement(name); addDomToMetadata(childDE, childME); parentME.addElement(childME); if (childDE.getAttributeNames().length != 0) { String[] attributeNames = childDE.getAttributeNames(); for (String attributeName : attributeNames) { String attributeValue = childDE.getAttribute(attributeName); final ProductData valueMEAtrr = ProductData.createInstance(attributeValue); final MetadataAttribute mdAttribute = new MetadataAttribute(attributeName, valueMEAtrr, true); childME.addAttribute(mdAttribute); } } } else { String valueDE = childDE.getValue(); if (valueDE == null) { valueDE = ""; } final ProductData valueME = ProductData.createInstance(valueDE); final MetadataAttribute attribute = new MetadataAttribute(name, valueME, true); parentME.addAttribute(attribute); } }
@Override public AbstractFigure convertDomToValue(DomElement parentElement, Object figure) throws ConversionException, ValidationException { final String className = parentElement.getAttribute("class"); final Shape shapeObject = convertDomToShape(parentElement); Map<String, Object> attributes = convertDomToAttributes(parentElement); if (LineFigure.class.getName().equals(className)) { return new LineFigure(shapeObject, attributes); } else if (AreaFigure.class.getName().equals(className)) { return new AreaFigure(shapeObject, attributes); } else if (ShapeFigure.class.getName().equals(className)) { final DomElement dimensionalChild = parentElement.getChild("oneDimensional"); final boolean oneDimensional = Boolean.valueOf(dimensionalChild.getValue()); return new ShapeFigure(shapeObject, oneDimensional, attributes); } return null; }
String reference = child.getAttribute("refid"); if (reference != null) { String parameterName = child.getName();
@Test public void testEscapingXmlParameters() throws Exception { DefaultDomElement domElement = new DefaultDomElement("parameter"); String unescapedString = "12 < 13 && 56 > 42 & \"true\" + 'a name'"; String escapedString = "12 < 13 && 56 > 42 & "true" + 'a name'"; domElement.addChild(new DefaultDomElement("expression", unescapedString)); DefaultDomElement withAttribute = new DefaultDomElement("withAttribute"); withAttribute.setAttribute("attrib", unescapedString); domElement.addChild(withAttribute); OperatorMenu.escapeXmlElements(domElement); assertEquals(escapedString, domElement.getChild("expression").getValue()); assertEquals(escapedString, domElement.getChild("withAttribute").getAttribute("attrib")); String xmlString = domElement.toXml(); XppDom readDomElement = OperatorMenu.createDom(xmlString); assertEquals(unescapedString, readDomElement.getChild("expression").getValue()); assertEquals(unescapedString, readDomElement.getChild("withAttribute").getAttribute("attrib")); } }