@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { try { String srsName = parentElement.getChild(SRS_NAME).getValue(); double minX = Double.parseDouble(parentElement.getChild(MIN_X).getValue()); double minY = Double.parseDouble(parentElement.getChild(MIN_Y).getValue()); double maxX = Double.parseDouble(parentElement.getChild(MAX_X).getValue()); double maxY = Double.parseDouble(parentElement.getChild(MAX_Y).getValue()); value = new CRSEnvelope(srsName, minX, minY, maxX, maxY); } catch (Exception e) { throw new IllegalArgumentException(e); } return value; }
@Override public final T convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { final DomElement refNoElement = parentElement.getChild("refNo"); if (refNoElement == null) { throw new ConversionException(String.format( "In parent element '%s': no child element 'refNo'", parentElement.getName())); } final Integer refNo; try { refNo = Integer.valueOf(refNoElement.getValue()); } catch (NumberFormatException e) { throw new ConversionException(String.format( "In parent element '%s': %s", parentElement.getName(), e.getMessage())); } final Product product = productManager.getProductByRefNo(refNo); if (product == null) { throw new ConversionException(String.format( "In parent element '%s': no product with refNo = %d", parentElement.getName(), refNo)); } return getProductNode(parentElement, product); }
@Override protected void convertProductNodeToDom(RasterDataNode raster, DomElement parentElement) { final DomElement rasterName = parentElement.createChild("rasterName"); rasterName.setValue(raster.getName()); } }
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); } }
final int count = config.getChildCount(); for (int i = 0; i < count; ++i) { final DomElement child = config.getChild(i); final String name = child.getName(); final String value = child.getValue(); if (name == null || value == null) continue; if (child.getChildCount() == 0) { final Converter converter = getConverter(valueContainer, name); if (converter == null) { final Object[] objArray = new Object[child.getChildCount()]; int c = 0; for (DomElement ch : child.getChildren()) { final String v = ch.getValue();
private ProductSetData[] findProductSets(final String readerName) { final List<ProductSetData> productSetDataList = new ArrayList<>(); for (Node n : graph.getNodes()) { if (n.getOperatorName().equalsIgnoreCase(readerName)) { final ProductSetData psData = new ProductSetData(); psData.nodeID = n.getId(); final DomElement config = n.getConfiguration(); final DomElement[] params = config.getChildren(); for (DomElement p : params) { if (p.getName().equals("fileList") && p.getValue() != null) { final StringTokenizer st = new StringTokenizer(p.getValue(), ProductSetHandler.SEPARATOR); int length = st.countTokens(); for (int i = 0; i < length; i++) { final String str = st.nextToken().replace(ProductSetHandler.SEPARATOR_ESC, ProductSetHandler.SEPARATOR); psData.fileList.add(str); } break; } } productSetDataList.add(psData); } } return productSetDataList.toArray(new ProductSetData[productSetDataList.size()]); }
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; }
private static void appendXmlUsage(StringBuilder usageText, OperatorDescriptor operatorDescriptor) { final DomElement graphElem = new XppDomElement("graph"); graphElem.setAttribute("id", "someGraphId"); final DomElement versionElem = graphElem.createChild("version"); versionElem.setValue("1.0"); final DomElement nodeElem = graphElem.createChild("node"); nodeElem.setAttribute("id", "someNodeId"); final DomElement operatorElem = nodeElem.createChild("operator"); operatorElem.setValue(operatorDescriptor.getAlias()); DomElement sourcesElem = nodeElem.createChild("sources"); for (SourceProductDescriptor sourceProduct : operatorDescriptor.getSourceProductDescriptors()) { convertSourceProductFieldToDom(sourceProduct, sourcesElem); } if (operatorDescriptor.getSourceProductsDescriptor() != null) { String name = getName(operatorDescriptor.getSourceProductsDescriptor()); final DomElement child = sourcesElem.createChild(name); child.setValue(String.format("${%s}", name)); } DomElement parametersElem = nodeElem.createChild("parameters"); for (ParameterDescriptor parameter : operatorDescriptor.getParameterDescriptors()) { if (!parameter.isDeprecated()) { convertParameterFieldToDom(parameter, parametersElem); } } final StringTokenizer st = new StringTokenizer(graphElem.toXml().replace('\r', ' '), "\n"); while (st.hasMoreElements()) { appendLine(usageText, " ", st.nextToken()); } }
return null; DomElement resolvedElement = new XppDomElement(domElement.getName()); Set<OperatorConfiguration.Reference> references = new HashSet<>(17); DomElement[] children = domElement.getChildren(); String reference = child.getAttribute("refid"); if (reference != null) { String parameterName = child.getName(); if (reference.contains(".")) { String[] referenceParts = reference.split("\\."); resolvedElement.addChild(child);
public void setIO(final File srcFile, final File tgtFile, final String format) { final String readOperatorAlias = OperatorSpi.getOperatorAlias(ReadOp.class); final Node readerNode = findNode(graph, readOperatorAlias); if (readerNode != null) { final DomElement param = new DefaultDomElement("parameters"); param.createChild("file").setValue(srcFile.getAbsolutePath()); readerNode.setConfiguration(param); } final String writeOperatorAlias = OperatorSpi.getOperatorAlias(WriteOp.class); final Node writerNode = findNode(graph, writeOperatorAlias); if (writerNode != null && tgtFile != null) { final DomElement origParam = writerNode.getConfiguration(); origParam.getChild("file").setValue(tgtFile.getAbsolutePath()); if (format != null) origParam.getChild("formatName").setValue(format); } }
private static void addDomToMetadata(DomElement parentDE, MetadataElement parentME) { final HashMap<String, List<DomElement>> map = new HashMap<>( parentDE.getChildCount() + 5); for (DomElement childDE : parentDE.getChildren()) { final String name = childDE.getName(); List<DomElement> elementList = map.get(name); if (elementList == null) { elementList = new ArrayList<>(3); map.put(name, elementList); } elementList.add(childDE); } for (Entry<String, List<DomElement>> entry : map.entrySet()) { String name = entry.getKey(); final List<DomElement> elementList = entry.getValue(); if (elementList.size() > 1) { for (int i = 0; i < elementList.size(); i++) { addDomToMetadata(elementList.get(i), name + '.' + i, parentME); } } else { addDomToMetadata(elementList.get(0), name, parentME); } } }
public void setOperatorParam(final String id, final String paramName, final String value) { final Node node = graph.getNode(id); DomElement xml = node.getConfiguration().getChild(paramName); if (xml == null) { xml = new XppDomElement(paramName); node.getConfiguration().addChild(xml); } xml.setValue(value); }
@Override public void convertValueToDom(Object value, DomElement parentElement) throws ConversionException { final Class<?> valueType = value.getClass(); parentElement.setAttribute("class", valueType.getName()); AbstractFigure figure = (AbstractFigure) value; final Shape figureShape = figure.getShape(); convertShapeToDom(figureShape, parentElement); final Map<String, Object> attributes = figure.getAttributes(); convertAttributesToDom(attributes, parentElement); if (valueType == ShapeFigure.class) { ShapeFigure shapeFigure = (ShapeFigure) value; final DomElement dimensionalChild = parentElement.createChild("oneDimensional"); dimensionalChild.setValue(String.valueOf(shapeFigure.isOneDimensional())); } }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { int childCount = parentElement.getChildCount(); AggregatorConfig[] aggregatorConfigs = new AggregatorConfig[childCount]; for (int i = 0; i < childCount; i++) { DomElement child = parentElement.getChild(i); aggregatorConfigs[i] = (AggregatorConfig) super.convertDomToValue(child, null); } return aggregatorConfigs; }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { final DomElement child = parentElement.getChild(0); SLDParser s = new SLDParser(CommonFactoryFinder.getStyleFactory(null), new StringReader(child.toXml())); final Style[] styles = s.readXML(); return styles[0]; }
@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")); } }
private void convertShapeToDom(Shape figureShape, DomElement parentElement) throws ConversionException { final DomElement shapeChild = parentElement.createChild("shape"); shapeChild.setAttribute("class", figureShape.getClass().getName()); final DefaultDomConverter domConverter = new DefaultDomConverter(Shape.class); domConverter.convertValueToDom(figureShape, shapeChild); }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { try { value = CRS.parseWKT(parentElement.getValue()); } catch (FactoryException e) { throw new IllegalArgumentException(e); } return value; }
@Override public void actionPerformed(ActionEvent event) { String parameterXml; try { DomElement domElement = parameterSupport.toDomElement(); parameterXml = domElement.toXml(); } catch (Exception e) { Debug.trace(e); Dialogs.showError(TITLE, "Failed to convert parameters to XML." + e.getMessage()); return; } JTextArea textArea = new JTextArea(parameterXml); textArea.setEditable(false); JScrollPane textAreaScrollPane = new JScrollPane(textArea); textAreaScrollPane.setPreferredSize(new Dimension(360, 360)); showInformationDialog(getOperatorName() + " Parameters", textAreaScrollPane); }