@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 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 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 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 protected BitmaskDef getProductNode(DomElement parentElement, Product product) { final String bitmaskName = parentElement.getChild("bitmaskName").getValue(); return product.getBitmaskDef(bitmaskName); }
@Override protected RasterDataNode getProductNode(DomElement parentElement, Product product) { final DomElement rasterName = parentElement.getChild("rasterName"); return product.getRasterDataNode(rasterName.getValue()); }
@Override protected RasterDataNode getProductNode(DomElement parentElement, Product product) { final DomElement rasterName = parentElement.getChild("rasterName"); return product.getRasterDataNode(rasterName.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()]); }
public File[] getPotentialOutputFiles() { final List<File> fileList = new ArrayList<>(); final Node[] nodes = graph.getNodes(); for (Node n : nodes) { if (n.getOperatorName().startsWith(OperatorSpi.getOperatorAlias(WriteOp.class))) { final DomElement config = n.getConfiguration(); final DomElement fileParam = config.getChild("file"); if (fileParam != null) { final String filePath = fileParam.getValue(); if (filePath != null && !filePath.isEmpty()) { final File file = new File(filePath); fileList.add(file); } } } } return fileList.toArray(new File[fileList.size()]); }
@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 SubGraphData[] findSubGraphs(final String opName) throws GraphException { try { final List<SubGraphData> dataList = new ArrayList<>(); for (Node n : graph.getNodes()) { if (n.getOperatorName().equalsIgnoreCase(opName)) { final SubGraphData data = new SubGraphData(); data.nodeID = n.getId(); final DomElement config = n.getConfiguration(); final DomElement[] params = config.getChildren(); for (DomElement p : params) { if (p.getName().equals("graphFile") && p.getValue() != null) { data.subGraph = GraphIO.read(new FileReader(p.getValue())); break; } } dataList.add(data); } } return dataList.toArray(new SubGraphData[dataList.size()]); } catch (Exception e) { throw new GraphException(e.getMessage(), e); } }
@Override public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { ConverterRegistry registry = ConverterRegistry.getInstance(); DomElement widthElement = parentElement.getChild("width"); Float width = registry.getConverter(Float.class).parse(widthElement.getValue()); DomElement capElement = parentElement.getChild("cap"); Integer cap = registry.getConverter(Integer.class).parse(capElement.getValue()); DomElement joinElement = parentElement.getChild("join"); Integer join = registry.getConverter(Integer.class).parse(joinElement.getValue()); DomElement miterlimitElement = parentElement.getChild("miterlimit"); Float miterlimit = registry.getConverter(Float.class).parse(miterlimitElement.getValue()); DomElement dashElement = parentElement.getChild("dash"); float[] dash = null; if(dashElement != null) { dash = registry.getConverter(float[].class).parse(dashElement.getValue()); } DomElement dashPhaseElement = parentElement.getChild("dashPhase"); Float dashPhase = registry.getConverter(Float.class).parse(dashPhaseElement.getValue()); return new BasicStroke(width, cap, join, miterlimit, dash, dashPhase); }
@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 public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException, ValidationException { DomElement typeElement = parentElement.getChild("type"); if (typeElement == null) { throw new ConversionException(String.format("Missing element 'type' in parent element '%s'", parentElement.getName())); } String typeName = typeElement.getValue(); TC config; if (value == null) { config = createConfig(typeName); } else { config = (TC) value; } DomConverter childConverter = createChildConverter(config.getClass()); childConverter.convertDomToValue(parentElement, config); return config; }
@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); }
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); } }
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); } }
@Test public void testStoreAndLoadParameter() throws IOException, ValidationException, ConversionException { final OperatorParameterSupport support = new OperatorParameterSupport(new TestOpSpi().getOperatorDescriptor()); PropertySet container = support.getPropertySet(); container.setValue("paramDouble", 0.42); container.setValue("paramString", "A String!"); container.setValue("paramComplex", new Complex(25)); final DomElement domElement = support.toDomElement(); assertEquals("parameters", domElement.getName()); assertEquals(3, domElement.getChildCount()); assertNotNull(domElement.getChild("paramDouble")); assertEquals("0.42", domElement.getChild("paramDouble").getValue()); assertNotNull(domElement.getChild("paramString")); assertEquals("A String!", domElement.getChild("paramString").getValue()); assertNotNull(domElement.getChild("paramComplex")); assertNotNull(domElement.getChild("paramComplex").getChild("complexInt")); assertEquals("25", domElement.getChild("paramComplex").getChild("complexInt").getValue()); // change container container.setValue("paramDouble", 23.67); container.setValue("paramString", "Another String"); container.setValue("paramComplex", new Complex(17)); support.fromDomElement(domElement); assertEquals(0.42, (double)support.getPropertySet().getValue("paramDouble"), 1.0e-6); assertEquals("A String!", support.getPropertySet().getValue("paramString")); assertEquals(new Complex(25), support.getPropertySet().getValue("paramComplex")); }
@Test public void testStoreAndLoadParameter() throws IOException, ValidationException, ConversionException { final OperatorParameterSupport support = new OperatorParameterSupport(new TestOpSpi().getOperatorDescriptor()); PropertySet container = support.getPropertySet(); container.setValue("paramDouble", 0.42); container.setValue("paramString", "A String!"); container.setValue("paramComplex", new Complex(25)); final DomElement domElement = support.toDomElement(); assertEquals("parameters", domElement.getName()); assertEquals(3, domElement.getChildCount()); assertNotNull(domElement.getChild("paramDouble")); assertEquals("0.42", domElement.getChild("paramDouble").getValue()); assertNotNull(domElement.getChild("paramString")); assertEquals("A String!", domElement.getChild("paramString").getValue()); assertNotNull(domElement.getChild("paramComplex")); assertNotNull(domElement.getChild("paramComplex").getChild("complexInt")); assertEquals("25", domElement.getChild("paramComplex").getChild("complexInt").getValue()); // change container container.setValue("paramDouble", 23.67); container.setValue("paramString", "Another String"); container.setValue("paramComplex", new Complex(17)); support.fromDomElement(domElement); assertEquals(0.42, (double)support.getPropertySet().getValue("paramDouble"), 1.0e-6); assertEquals("A String!", support.getPropertySet().getValue("paramString")); assertEquals(new Complex(25), support.getPropertySet().getValue("paramComplex")); }
@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")); } }