Example usage for org.dom4j Node getStringValue

List of usage examples for org.dom4j Node getStringValue

Introduction

In this page you can find the example usage for org.dom4j Node getStringValue.

Prototype

String getStringValue();

Source Link

Document

Returns the XPath string-value of this node.

Usage

From source file:org.openadaptor.auxil.connector.jdbc.writer.XMLTableWriterTestCase.java

License:Open Source License

protected Object[] setupWriteBatchDataAndExpectationsBatchingDisabled() {
    Object[] data = new Object[] { SampleXMLOne, SampleXMLTwo, SampleXMLThree };
    preparedStatementMock.expects(atLeastOnce()).method("clearParameters");
    for (int dataIndex = 0; dataIndex < data.length; dataIndex++) {
        Document dataElement = (Document) data[dataIndex];
        for (int i = 0; i < ColumnNames.length; i++) {
            Node node = dataElement.getRootElement().selectSingleNode(ColumnNames[i]);
            if (node != null) {
                preparedStatementMock.expects(once()).method("setObject").with(eq(i + 1),
                        eq(node.getStringValue()), eq(Types.NUMERIC));
            } else {
                preparedStatementMock.expects(once()).method("setNull").with(eq(i + 1), eq(Types.NUMERIC));
            }/*from   ww  w. ja v a2s  . c  o  m*/
        }
    }
    preparedStatementMock.expects(never()).method("addBatch");
    preparedStatementMock.expects(never()).method("executeBatch");
    preparedStatementMock.expects(atLeastOnce()).method("executeUpdate").will(returnValue(1));
    return data;
}

From source file:org.orbeon.oxf.processor.serializer.legacy.JFreeChartSerializer.java

License:Open Source License

protected CategoryDataset createDataset(ChartConfig chartConfig, Document data) {
    ItemPaintCategoryDataset ds = new ItemPaintCategoryDataset();
    for (Iterator i = chartConfig.getValueIterator(); i.hasNext();) {
        Value value = (Value) i.next();//  w  ww  .  j a va 2s .  c  o  m
        Iterator cats = XPathUtils.selectIterator(data, value.getCategories());
        Iterator series = XPathUtils.selectIterator(data, value.getSeries());

        Iterator colors = null;
        if (value.getColors() != null)
            colors = XPathUtils.selectIterator(data, value.getColors());

        while (cats.hasNext() && series.hasNext()) {
            Node s = (Node) series.next();
            Node c = (Node) cats.next();
            Double d = new Double(s.getStringValue());
            if (colors != null) {
                Node col = (Node) colors.next();
                Color color = getRGBColor(col.getStringValue());
                ds.addValue(d, color, value.getTitle(), c.getStringValue());
            } else
                ds.addValue(d, value.getTitle(), c.getStringValue());
        }
    }
    return ds;
}

From source file:org.orbeon.oxf.processor.serializer.legacy.JFreeChartSerializer.java

License:Open Source License

protected XYSeriesCollection createXYDataset(ChartConfig chartConfig, Document data) {
    XYSeriesCollection ds = new XYSeriesCollection();
    for (Iterator i = chartConfig.getValueIterator(); i.hasNext();) {
        Value value = (Value) i.next();/*from   w ww  .j a v  a 2s .c  om*/
        String title = value.getTitle();
        Iterator x = XPathUtils.selectIterator(data, value.getCategories());
        Iterator y = XPathUtils.selectIterator(data, value.getSeries());

        XYSeries xyseries = new XYSeries(title);
        while (x.hasNext() && y.hasNext()) {
            Node s = (Node) y.next();
            Node c = (Node) x.next();
            Double abcissa = new Double(c.getStringValue());
            Double ordinate = new Double(s.getStringValue());
            xyseries.add(abcissa, ordinate);
        }
        ds.addSeries(xyseries);
    }
    return ds;
}

From source file:org.orbeon.oxf.processor.serializer.legacy.JFreeChartSerializer.java

License:Open Source License

protected TimeSeriesCollection createTimeSeriesDataset(ChartConfig chartConfig, Document data) {
    TimeSeriesCollection ds = new TimeSeriesCollection();
    for (Iterator i = chartConfig.getValueIterator(); i.hasNext();) {
        Value value = (Value) i.next();//from w w  w . ja v a  2 s.  com
        String title = value.getTitle();
        Iterator x = XPathUtils.selectIterator(data, value.getCategories());
        Iterator y = XPathUtils.selectIterator(data, value.getSeries());

        TimeSeries timeSeries = new TimeSeries(title, FixedMillisecond.class);
        while (x.hasNext() && y.hasNext()) {
            Node s = (Node) y.next();
            Node c = (Node) x.next();
            SimpleDateFormat sdf = new SimpleDateFormat(chartConfig.getDateFormat());
            FixedMillisecond fm;
            try {
                fm = new FixedMillisecond(sdf.parse(c.getStringValue()).getTime());
            } catch (java.text.ParseException pe) {
                throw new OXFException(
                        "Date Format " + chartConfig.getDateFormat() + " does not match with the date data",
                        pe);
            }
            Double ordinate = new Double(s.getStringValue());
            timeSeries.add(fm, ordinate);
        }
        ds.addSeries(timeSeries);
    }
    return ds;
}

From source file:org.rundeck.api.parser.OutputEntryParserV5.java

License:Apache License

@Override
protected String parseMessage(Node entryNode) {
    return StringUtils.trimToNull(entryNode.getStringValue());
}

From source file:org.rundeck.api.parser.StringParser.java

License:Apache License

@Override
public String parse(Node strNode) {

    return StringUtils.trimToNull(strNode.getStringValue());
}

From source file:org.saiku.plugin.PentahoDatasourceManager.java

License:Apache License

private void loadDatasourcesFromXml(String dataSources) {
    EntityResolver loader = new PentahoEntityResolver();
    Document doc = null;/*from ww w  .ja v a2s . com*/
    try {
        doc = XmlDom4JHelper.getDocFromFile(dataSources, loader);
        String modified = doc.asXML();
        doc = XmlDom4JHelper.getDocFromString(modified, loader);

        List<Node> nodes = doc.selectNodes("/DataSources/DataSource/Catalogs/Catalog"); //$NON-NLS-1$
        int nr = 0;
        for (Node node : nodes) {
            nr++;
            String name = "PentahoDs" + nr;
            Element e = (Element) node;
            List<Attribute> list = e.attributes();
            for (Attribute attribute : list) {
                String aname = attribute.getName();
                if ("name".equals(aname)) {
                    name = attribute.getStringValue();
                }
            }

            Node ds = node.selectSingleNode("DataSourceInfo");
            Node cat = node.selectSingleNode("Definition");
            String connectStr = ds.getStringValue();
            PropertyList pl = Util.parseConnectString(connectStr);
            String dynProcName = pl.get(RolapConnectionProperties.DynamicSchemaProcessor.name());
            if (StringUtils.isNotBlank(dynamicSchemaProcessor) && StringUtils.isBlank(dynProcName)) {
                pl.put(RolapConnectionProperties.DynamicSchemaProcessor.name(), dynamicSchemaProcessor);

            }
            LOG.debug("NAME: " + name + " DSINFO: " + pl.toString() + "  ###CATALOG: "
                    + (cat != null ? cat.getStringValue() : "NULL"));
            Properties props = new Properties();
            props.put("driver", "mondrian.olap4j.MondrianOlap4jDriver");
            props.put("location", "jdbc:mondrian:" + pl.toString() + ";Catalog=" + cat.getStringValue());
            if (saikuDatasourceProcessor != null) {
                props.put(ISaikuConnection.DATASOURCE_PROCESSORS, saikuDatasourceProcessor);
            }
            if (saikuConnectionProcessor != null) {
                props.put(ISaikuConnection.CONNECTION_PROCESSORS, saikuConnectionProcessor);
            }
            props.list(System.out);

            SaikuDatasource sd = new SaikuDatasource(name, SaikuDatasource.Type.OLAP, props);
            datasources.put(name, sd);

        }
    } catch (Exception e) {
        e.printStackTrace();
        LOG.error(e);
    }
    if (LOG.isDebugEnabled()) {
        if (doc == null) {
            LOG.debug("Original Document is null");
        } else {
            LOG.debug("Original Document:" + doc.asXML()); //$NON-NLS-1$
        }
    }

}

From source file:org.sigimera.frontends.android.tablet.CrisisEntryActivity.java

License:Open Source License

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.crisis_entry);

    View v = findViewById(R.id.crisisEntryMain);
    v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);

    this.crisisID = null;

    Bundle bundle = getIntent().getExtras();
    if (savedInstanceState != null) {
        this.crisisID = savedInstanceState.getString("crisisid");
        this.crisis = (CrisisEntity) savedInstanceState.getSerializable("crisisObj");
    } else if (bundle != null) {
        this.crisisID = bundle.getString("crisisid");
    }/*from   w  w  w  . j a  va2  s . c o m*/

    this.actionBar = getActionBar();

    this.actionBar.setTitle(this.crisisID);
    this.actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    this.actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    this.actionBar.setDisplayShowHomeEnabled(true);
    this.actionBar.setDisplayHomeAsUpEnabled(true);

    if (this.crisis == null) {
        try {
            this.crisis = new CrisisEntity(new URI(this.crisisID));

            Thread worker = new Thread() {
                @Override
                public void run() {
                    SAXReader reader = new SAXReader();
                    Document doc;
                    try {
                        doc = reader.read(new URL(crisisID));

                        Node title = selectNode("//rdf:Description/dc:title", doc);
                        if (title != null)
                            crisis.setTitle(title.getStringValue());

                        Node description = selectNode("//rdf:Description/dc:description", doc);
                        if (description != null)
                            crisis.setDescription(description.getStringValue());

                        Node issued = selectNode("//rdf:Description/dct:issued", doc);
                        if (issued != null)
                            crisis.setIssued(issued.getStringValue());

                        Node latitude = selectNode("//rdf:Description/geo:lat", doc);
                        if (latitude != null)
                            crisis.setLatitude(latitude.getStringValue());

                        Node longitude = selectNode("//rdf:Description/geo:long", doc);
                        if (longitude != null)
                            crisis.setLongitude(longitude.getStringValue());

                        Node crisisType = selectNode("//rdf:Description/crisis:hasCrisisType/@rdf:resource",
                                doc);
                        if (crisisType != null)
                            crisis.setCrisisType(crisisType.getStringValue());

                        Node crisisLevel = selectNode("//rdf:Description/crisis:alertLevelAsgard", doc);
                        if (crisisLevel == null)
                            crisisLevel = selectNode("//rdf:Description/crisis:alertLevelGdas", doc);
                        if (crisisLevel != null)
                            crisis.setRiskLevel(crisisLevel.getStringValue());

                        if (longitude != null && latitude != null) {
                            URL depictionURL = new URL("http://staticmap.openstreetmap.de/staticmap.php?center="
                                    + latitude.getStringValue() + "," + longitude.getStringValue()
                                    + "&zoom=4&markers=" + latitude.getStringValue() + ","
                                    + longitude.getStringValue()
                                    + ",ol-marker&size=470x230&maptype=osmarenderer");
                            if (depictionURL != null) {
                                crisis.setDepictionURL(depictionURL.toString());
                            }
                        }

                        /**
                         * TODO: Set more values, e.g. location, risk level, ...
                         */

                        guiHandler.post(updateCrisisEntry);
                    } catch (MalformedURLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (DocumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (JaxenException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            };
            worker.start();
        } catch (URISyntaxException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else {
        try {
            this.updateCrisisEntryInGUI();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

From source file:org.soyatec.windowsazure.internal.util.xml.XPathQueryHelper.java

License:Apache License

/**
 * Parse the response of the storage service properties.Construct a
 * StorageAccountProperties from the response content
 * /*  ww  w  . j a v  a  2  s.c o m*/
 * @param stream
 *            the inputStream
 * @return a StorageAccountProperties object
 */
public static StorageAccountProperties parseStorageServicePropertiesResponse(InputStream stream) {
    Document doc = XmlUtil.load(stream);
    Element storageServiceElement = doc.getRootElement();
    if (storageServiceElement == null) {
        return null;
    }

    String name = getStringValue(storageServiceElement, ServiceXmlElementNames.StorageService_Name);
    String url = getStringValue(storageServiceElement, ServiceXmlElementNames.StorageService_Url);
    Element element = (Element) selectSingleNode(storageServiceElement,
            addXmlnsNameSpace((ServiceXmlElementNames.StorageServiceProperties)));
    String description = getStringValue(element, ServiceXmlElementNames.AffinityGroupDescription);
    String label = getStringValue(element, ServiceXmlElementNames.Label);
    String location = getStringValue(element, ServiceXmlElementNames.AffinityGroupLocation);

    Node groupElement = selectSingleNode(element, addXmlnsNameSpace(ServiceXmlElementNames.AffinityGroup));
    String group = groupElement == null ? null : groupElement.getStringValue();

    if (label != null) {
        label = new String(Base64.decode(label));
    }

    StorageAccountProperties prop = new StorageAccountProperties(name, url, description, group, location,
            label);
    return prop;
}

From source file:org.soyatec.windowsazure.internal.util.xml.XPathQueryHelper.java

License:Apache License

private static String getStringValue(Node node, String query, boolean decodeBase64) {
    Node child = selectSingleNode(node, addXmlnsNameSpace(query));
    if (child == null) {
        return "";
    } else {//from  www  .j av a2  s.co  m
        String value = child.getStringValue();
        if (decodeBase64) {
            return new String(Base64.decode(value));
        } else {
            return value;
        }
    }

}