Example usage for org.apache.commons.lang3 StringEscapeUtils unescapeXml

List of usage examples for org.apache.commons.lang3 StringEscapeUtils unescapeXml

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils unescapeXml.

Prototype

public static final String unescapeXml(final String input) 

Source Link

Document

Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Supports only the five basic XML entities (gt, lt, quot, amp, apos).

Usage

From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java

protected RangeConfiguration parseRange(NodeList rangeNodes) {
    RangeConfiguration rangeConfig = new RangeConfiguration();
    for (int k = 0; k < rangeNodes.getLength(); k++) {
        Node item = rangeNodes.item(k);
        if (item.getNodeName().equals("propertyid") && item.hasChildNodes()) {
            rangeConfig.setPropertyId(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }//  ww w.  ja  v a  2 s  .  co m
        if (item.getNodeName().equals("name") && item.hasChildNodes()) {
            String name = item.getFirstChild().getNodeValue();
            Locale locale = LocaleManager.currentLocale();
            Node languageNode = item.getAttributes().getNamedItem("language");
            if (languageNode != null)
                locale = new Locale(languageNode.getNodeValue());
            rangeConfig.setName(StringEscapeUtils.unescapeXml(name), locale);
        }
        if (item.getNodeName().equals("scalarfunction") && item.hasChildNodes()) {
            rangeConfig
                    .setScalarFunctionCode(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("unit") && item.hasChildNodes()) {
            String unit = item.getFirstChild().getNodeValue();
            Locale locale = LocaleManager.currentLocale();
            Node languageNode = item.getAttributes().getNamedItem("language");
            if (languageNode != null)
                locale = new Locale(languageNode.getNodeValue());
            rangeConfig.setUnit(StringEscapeUtils.unescapeXml(unit), locale);
        }
    }
    return rangeConfig;
}

From source file:org.jboss.dashboard.displayer.chart.ChartDisplayerXMLFormat.java

protected void parseDisplayer(AbstractChartDisplayer displayer, Node item, ImportResults results)
        throws Exception {
    // Domain./*from   w  w w .j a  v  a2 s  .c  om*/
    if (item.getNodeName().equals("domain") && item.hasChildNodes()) {
        NodeList domainNodes = item.getChildNodes();
        displayer.setDomainConfiguration(parseDomain(domainNodes));
    }
    // Range.
    else if (item.getNodeName().equals("range") && item.hasChildNodes()) {
        NodeList rangeNodes = item.getChildNodes();
        displayer.setRangeConfiguration(parseRange(rangeNodes));
    } else if (item.getNodeName().equals("type") && item.hasChildNodes()) {
        displayer.setType(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("showlabelsxaxis") && item.hasChildNodes()) {
        displayer.setShowLabelsXAxis(
                Boolean.parseBoolean(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("labelanglexaxis") && item.hasChildNodes()
            && displayer instanceof AbstractXAxisDisplayer) {
        AbstractXAxisDisplayer xAxisDisplayer = (AbstractXAxisDisplayer) displayer;
        xAxisDisplayer.setLabelAngleXAxis(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("showlinesarea") && item.hasChildNodes()
            && displayer instanceof AbstractXAxisDisplayer) {
        AbstractXAxisDisplayer xAxisDisplayer = (AbstractXAxisDisplayer) displayer;
        xAxisDisplayer.setShowLinesArea(
                Boolean.parseBoolean(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("intervalsortcriteria") && item.hasChildNodes()) {
        displayer.setIntervalsSortCriteria(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("intervalsortorder") && item.hasChildNodes()) {
        displayer.setIntervalsSortOrder(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("color") && item.hasChildNodes()) {
        displayer.setColor(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("backgroundcolor") && item.hasChildNodes()) {
        displayer.setBackgroundColor(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("width") && item.hasChildNodes()) {
        displayer
                .setWidth(Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("height") && item.hasChildNodes()) {
        displayer.setHeight(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("showlegend") && item.hasChildNodes()) {
        displayer.setShowLegend(Boolean
                .valueOf(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())).booleanValue());
    } else if (item.getNodeName().equals("axisinteger") && item.hasChildNodes()) {
        displayer.setAxisInteger(Boolean
                .valueOf(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())).booleanValue());
    } else if (item.getNodeName().equals("legendanchor") && item.hasChildNodes()) {
        displayer.setLegendAnchor(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("showtitle") && item.hasChildNodes()) {
        displayer.setShowTitle(Boolean
                .valueOf(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())).booleanValue());
    } else if (item.getNodeName().equals("align") && item.hasChildNodes()) {
        displayer.setGraphicAlign(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("marginleft") && item.hasChildNodes()) {
        displayer.setMarginLeft(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("marginright") && item.hasChildNodes()) {
        displayer.setMarginRight(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("margintop") && item.hasChildNodes()) {
        displayer.setMarginTop(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("marginbottom") && item.hasChildNodes()) {
        displayer.setMarginBottom(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    }
}

From source file:org.jboss.dashboard.displayer.chart.MeterChartDisplayerXMLFormat.java

protected void parseMeterProperties(DataDisplayer displayer, Node item, ImportResults results)
        throws Exception {
    Locale locale = LocaleManager.currentLocale();
    NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
    MeterChartDisplayer meterDisplayer = (MeterChartDisplayer) displayer;
    if (item.getNodeName().equals("meter") && item.hasChildNodes()) {
        NodeList meterNodes = item.getChildNodes();
        for (int k = 0; k < meterNodes.getLength(); k++) {
            Node meterItem = meterNodes.item(k);
            if (meterItem.getNodeName().equals("positionType") && meterItem.hasChildNodes()) {
                meterDisplayer.setPositionType(
                        StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()));
            }/*w w  w  .  j a  v a2 s. co  m*/
            if (meterItem.getNodeName().equals("minValue") && meterItem.hasChildNodes()) {
                meterDisplayer.setMinValue(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (meterItem.getNodeName().equals("maxValue") && meterItem.hasChildNodes()) {
                meterDisplayer.setMaxValue(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (meterItem.getNodeName().equals("maxMeterTicks") && meterItem.hasChildNodes()) {
                meterDisplayer.setMaxMeterTicks(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .intValue());
            }
            // Thresholds.
            if (meterItem.getNodeName().equals("warningThreshold") && meterItem.hasChildNodes()) {
                meterDisplayer.setWarningThreshold(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (meterItem.getNodeName().equals("criticalThreshold") && meterItem.hasChildNodes()) {
                meterDisplayer.setCriticalThreshold(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            // Critical interval.
            if (meterItem.getNodeName().equals("descripCriticalInterval") && meterItem.hasChildNodes()) {
                String descripCriticalInterval = meterItem.getFirstChild().getNodeValue();
                Node languageNode = meterItem.getAttributes().getNamedItem("language");
                if (languageNode != null)
                    locale = new Locale(languageNode.getNodeValue());
                meterDisplayer.setDescripCriticalInterval(
                        StringEscapeUtils.unescapeXml(descripCriticalInterval), locale);
            }
            // Warning interval.
            if (meterItem.getNodeName().equals("descripWarningInterval") && meterItem.hasChildNodes()) {
                String descripWarningInterval = meterItem.getFirstChild().getNodeValue();
                Node languageNode = meterItem.getAttributes().getNamedItem("language");
                if (languageNode != null)
                    locale = new Locale(languageNode.getNodeValue());
                meterDisplayer.setDescripWarningInterval(StringEscapeUtils.unescapeXml(descripWarningInterval),
                        locale);
            }
            // Normal interval.
            if (meterItem.getNodeName().equals("descripNormalInterval") && meterItem.hasChildNodes()) {
                String descripNormalInterval = meterItem.getFirstChild().getNodeValue();
                Node languageNode = meterItem.getAttributes().getNamedItem("language");
                if (languageNode != null)
                    locale = new Locale(languageNode.getNodeValue());
                meterDisplayer.setDescripNormalInterval(StringEscapeUtils.unescapeXml(descripNormalInterval),
                        locale);
            }
        }
    } else if (item.getNodeName().equals("thermometer") && item.hasChildNodes()) {
        NodeList thermoNodes = item.getChildNodes();
        for (int k = 0; k < thermoNodes.getLength(); k++) {
            Node thermoItem = thermoNodes.item(k);
            if (thermoItem.getNodeName().equals("positionType") && thermoItem.hasChildNodes()) {
                meterDisplayer.setPositionType(
                        StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()));
            }
            if (thermoItem.getNodeName().equals("thermoLowerBound") && thermoItem.hasChildNodes()) {
                meterDisplayer.setThermoLowerBound(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (thermoItem.getNodeName().equals("thermoUpperBound") && thermoItem.hasChildNodes()) {
                meterDisplayer.setThermoUpperBound(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            // Thresholds.
            if (thermoItem.getNodeName().equals("warningThermoThreshold") && thermoItem.hasChildNodes()) {
                meterDisplayer.setWarningThermoThreshold(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (thermoItem.getNodeName().equals("criticalThermoThreshold") && thermoItem.hasChildNodes()) {
                meterDisplayer.setCriticalThermoThreshold(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
        }
    } else if (item.getNodeName().equals("dial")) {
        NodeList dialNodes = item.getChildNodes();
        for (int k = 0; k < dialNodes.getLength(); k++) {
            Node dialItem = dialNodes.item(k);
            if (dialItem.getNodeName().equals("positionType") && dialItem.hasChildNodes()) {
                meterDisplayer.setPositionType(
                        StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()));
            }
            if (dialItem.getNodeName().equals("pointerType") && dialItem.hasChildNodes()) {
                meterDisplayer
                        .setPointerType(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()));
            }
            if (dialItem.getNodeName().equals("dialLowerBound") && dialItem.hasChildNodes()) {
                meterDisplayer.setDialLowerBound(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (dialItem.getNodeName().equals("dialUpperBound") && dialItem.hasChildNodes()) {
                meterDisplayer.setDialUpperBound(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (dialItem.getNodeName().equals("maxTicks") && dialItem.hasChildNodes()) {
                meterDisplayer.setMaxTicks(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()))
                        .intValue());
            }
            if (dialItem.getNodeName().equals("minorTickCount") && dialItem.hasChildNodes()) {
                meterDisplayer.setMinorTickCount(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()))
                        .intValue());
            }
        }
    }
}

From source file:org.jboss.dashboard.displayer.table.TableDisplayerXMLFormat.java

protected void parseDisplayer(DataDisplayer dd, NodeList subNodes, ImportResults results) throws Exception {
    TableDisplayer displayer = (TableDisplayer) dd;
    DataSetTable table = displayer.getTable();

    // First of all look if group by is enabled.
    for (int j = 0; j < subNodes.getLength(); j++) {
        Node item = subNodes.item(j);
        if (item.getNodeName().equals("groupby") && item.hasChildNodes()) {
            NodeList groupByNodes = item.getChildNodes();
            table.setGroupByConfiguration(parseDomain(groupByNodes));
            for (int k = 0; k < groupByNodes.getLength(); k++) {
                item = groupByNodes.item(k);
                if (item.getNodeName().equals("showtotals") && item.hasChildNodes()) {
                    table.setGroupByShowTotals(
                            Boolean.valueOf(item.getFirstChild().getNodeValue()).booleanValue());
                }/* w ww .  jav a2  s . c om*/
                if (item.getNodeName().equals("totalshtmlstyle") && item.hasChildNodes()) {
                    table.setGroupByTotalsHtmlStyle(item.getFirstChild().getNodeValue());
                }
            }
        }
    }
    // Parse the rest.
    for (int j = 0; j < subNodes.getLength(); j++) {
        Node item = subNodes.item(j);
        if (item.getNodeName().equals("rowsperpage") && item.hasChildNodes()) {
            table.setMaxRowsPerPage(Integer.parseInt(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("headerposition") && item.hasChildNodes()) {
            table.setHeaderPosition(item.getFirstChild().getNodeValue());
        }
        if (item.getNodeName().equals("htmlstyle") && item.hasChildNodes()) {
            table.setHtmlStyle(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("rowevenstyle") && item.hasChildNodes()) {
            table.setRowEvenStyle(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("rowoddstyle") && item.hasChildNodes()) {
            table.setRowOddStyle(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("rowhoverstyle") && item.hasChildNodes()) {
            table.setRowHoverStyle(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("rowevenstyle") && item.hasChildNodes()) {
            table.setRowEvenStyle(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("htmlclass") && item.hasChildNodes()) {
            table.setHtmlClass(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("rowevenclass") && item.hasChildNodes()) {
            table.setRowEventClass(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("rowoddclass") && item.hasChildNodes()) {
            table.setRowOddClass(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("rowhoverclass") && item.hasChildNodes()) {
            table.setRowHoverClass(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        } else if (item.getNodeName().equals("column") && item.hasChildNodes()) {
            NodeList columnNodes = item.getChildNodes();
            TableColumn column = table.createColumn();
            int columnIndex = table.getColumnCount();
            for (int k = 0; k < columnNodes.getLength(); k++) {
                item = columnNodes.item(k);
                if (item.getNodeName().equals("name") && item.hasChildNodes()) {
                    String name = item.getFirstChild().getNodeValue();
                    Locale locale = LocaleManager.currentLocale();
                    Node languageNode = item.getAttributes().getNamedItem("language");
                    if (languageNode != null)
                        locale = new Locale(languageNode.getNodeValue());
                    column.setName(StringEscapeUtils.unescapeXml(name), locale);
                }
                if (item.getNodeName().equals("hint") && item.hasChildNodes()) {
                    String name = item.getFirstChild().getNodeValue();
                    Locale locale = LocaleManager.currentLocale();
                    Node languageNode = item.getAttributes().getNamedItem("language");
                    if (languageNode != null)
                        locale = new Locale(languageNode.getNodeValue());
                    column.setHint(StringEscapeUtils.unescapeXml(name), locale);
                }
                if (item.getNodeName().equals("modelproperty") && item.hasChildNodes()) {
                    column.setPropertyId(item.getFirstChild().getNodeValue());
                } else if (item.getNodeName().equals("headerhtmlstyle") && item.hasChildNodes()) {
                    column.setHeaderHtmlStyle(
                            StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                } else if (item.getNodeName().equals("cellhtmlstyle") && item.hasChildNodes()) {
                    column.setCellHtmlStyle(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                } else if (item.getNodeName().equals("htmlvalue") && item.hasChildNodes()) {
                    column.setHtmlValue(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                } else if (item.getNodeName().equals("selectable") && item.hasChildNodes()) {
                    column.setSelectable(false);
                    if ("true".equals(item.getFirstChild().getNodeValue().trim().toLowerCase()))
                        column.setSelectable(true);
                } else if (item.getNodeName().equals("selectable") && item.hasChildNodes()) {
                    column.setSelectable(false);
                    if ("true".equals(item.getFirstChild().getNodeValue().trim().toLowerCase()))
                        column.setSelectable(true);
                } else if (item.getNodeName().equals("sortable") && item.hasChildNodes()) {
                    column.setSortable(false);
                    if ("true".equals(item.getFirstChild().getNodeValue().trim().toLowerCase()))
                        column.setSortable(true);
                } else if (item.getNodeName().equals("groupbyfunction") && item.hasChildNodes()) {
                    table.setGroupByFunctionCode(columnIndex,
                            StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                }
            }
            table.addColumn(column);
        }
    }
}

From source file:org.jboss.dashboard.export.ImportManagerImpl.java

protected void parseKPIs(NodeList xmlNodes, ImportResults results) throws Exception {
    for (int i = 0; i < xmlNodes.getLength(); i++) {
        Node item = xmlNodes.item(i);
        if (item.getNodeName().equals("kpi")) {
            try {
                KPI kpi = DataDisplayerServices.lookup().getKPIManager().createKPI();
                Node codeNode = item.getAttributes().getNamedItem("code");
                if (codeNode != null)
                    kpi.setCode(StringEscapeUtils.unescapeXml(codeNode.getNodeValue()));

                NodeList subNodes = item.getChildNodes();
                for (int j = 0; j < subNodes.getLength(); j++) {
                    item = subNodes.item(j);

                    // Description
                    if (item.getNodeName().equals("description") && item.hasChildNodes()) {
                        String description = item.getFirstChild().getNodeValue();
                        Locale locale = LocaleManager.currentLocale();
                        Node languageNode = item.getAttributes().getNamedItem("language");
                        if (languageNode != null)
                            locale = new Locale(languageNode.getNodeValue());
                        kpi.setDescription(StringEscapeUtils.unescapeXml(description), locale);
                    }//from  w  w  w  .j a  v  a 2s.c om

                    // Provider
                    if (item.getNodeName().equals("provider") && item.hasAttributes()) {
                        String providerCode = item.getAttributes().getNamedItem("code").getNodeValue();
                        DataProvider provider = results.getDataProviderByCode(providerCode);
                        if (provider == null)
                            provider = DataDisplayerServices.lookup().getDataProviderManager()
                                    .getDataProviderByCode(providerCode);
                        if (provider == null) {
                            results.getMessages()
                                    .add(new ImportExportMessage(ImportExportMessage.PROVIDER_CODE_NOT_FOUND,
                                            new Object[] { providerCode }));
                            throw new RuntimeException("Continue with the next KPI...");
                        }
                        kpi.setDataProvider(provider);
                    }

                    // Displayer
                    if (item.getNodeName().equals("displayer") && item.hasAttributes()
                            && item.hasChildNodes()) {
                        String typeUid = item.getAttributes().getNamedItem("type").getNodeValue();
                        DataDisplayerType type = dataDisplayerManager.getDisplayerTypeByUid(typeUid);
                        if (type == null) {
                            results.getMessages().add(new ImportExportMessage(
                                    ImportExportMessage.DISPLAYER_TYPE_NOT_FOUND, new Object[] { typeUid }));
                            throw new RuntimeException("Continue with the next KPI...");
                        }
                        DataDisplayerRenderer renderer = null;
                        Node rendererNode = item.getAttributes().getNamedItem("renderer");
                        if (rendererNode != null) {
                            String rendUid = rendererNode.getNodeValue();
                            renderer = dataDisplayerManager.getDisplayerRendererByUid(rendUid);
                            if (renderer == null) {
                                results.getMessages()
                                        .add(new ImportExportMessage(
                                                ImportExportMessage.DISPLAYER_RENDERER_NOT_FOUND,
                                                new Object[] { rendUid }));
                                throw new RuntimeException("Continue with the next KPI...");
                            }
                        }
                        DataDisplayer displayer = type.getXmlFormat().parse(subNodes, results);
                        if (results.getMessages().hasErrors()) {
                            throw new Exception(results.getMessages().get(0).toString());
                        }

                        displayer.setDataDisplayerType(type);
                        displayer.setDataDisplayerRenderer(renderer);
                        kpi.setDataDisplayer(displayer);
                    }
                }
                results.addKPI(kpi);
            } catch (Exception e) {
                log.error("Error parsing KPI", e);
                // Continue with the next KPI...
            }
        }
    }
}

From source file:org.jboss.dashboard.export.ImportManagerImpl.java

public void parseProviders(NodeList xmlNodes, ImportResults results) throws Exception {
    for (int i = 0; i < xmlNodes.getLength(); i++) {
        Node item = xmlNodes.item(i);
        if (item.getNodeName().equals("dataprovider")) {

            // Get the provider type module by class.
            String uid = item.getAttributes().getNamedItem("type").getNodeValue();
            DataProviderType type = DataDisplayerServices.lookup().getDataProviderManager()
                    .getProviderTypeByUid(uid);
            if (type == null) {
                results.getMessages().add(new ImportExportMessage(ImportExportMessage.PROVIDER_TYPE_NOT_FOUND,
                        new Object[] { uid }));
                continue;
            }//w w w  .ja  v  a 2 s .c  o  m

            // Parse the provider instance custom part.
            NodeList subNodes = item.getChildNodes();
            DataLoader loader = type.getXmlFormat().parse(subNodes);
            if (results.getMessages().hasErrors()) {
                throw new Exception(results.getMessages().get(0).toString());
            }
            loader.setDataProviderType(type);

            // Get the provider instance common properties.
            DataProviderImpl provider = new DataProviderImpl();
            provider.setDataLoader(loader);
            Node codeNode = item.getAttributes().getNamedItem("code");
            if (codeNode != null)
                provider.setCode(StringEscapeUtils.unescapeXml(codeNode.getNodeValue()));
            for (int j = 0; j < subNodes.getLength(); j++) {
                item = subNodes.item(j);

                if (item.getNodeName().equals("canEdit") && item.hasChildNodes()) {
                    String canEditStr = item.getFirstChild().getNodeValue();
                    if ("false".equalsIgnoreCase(canEditStr))
                        provider.canEdit = false;
                }

                if (item.getNodeName().equals("canEditProperties") && item.hasChildNodes()) {
                    String canEditPropertiesStr = item.getFirstChild().getNodeValue();
                    if ("false".equalsIgnoreCase(canEditPropertiesStr))
                        provider.canEditProperties = false;
                }

                if (item.getNodeName().equals("canDelete") && item.hasChildNodes()) {
                    String canDelete = item.getFirstChild().getNodeValue();
                    if ("false".equalsIgnoreCase(canDelete))
                        provider.canDelete = false;
                }

                if (item.getNodeName().equals("description") && item.hasChildNodes()) {
                    String description = item.getFirstChild().getNodeValue();
                    Locale locale = LocaleManager.currentLocale();
                    Node languageNode = item.getAttributes().getNamedItem("language");
                    if (languageNode != null)
                        locale = new Locale(languageNode.getNodeValue());
                    provider.setDescription(StringEscapeUtils.unescapeXml(description), locale);
                }

                if (item.getNodeName().equals("dataproperties") && item.hasChildNodes()) {
                    provider.getDataSet().parseXMLProperties(item.getChildNodes());
                }
            }

            // Register the imported provider.
            results.addDataProvider(provider);
        }
    }
}

From source file:org.jboss.dashboard.provider.csv.CSVDataLoaderXMLFormat.java

public DataLoader parse(NodeList xmlNodes) throws Exception {
    for (int i = 0; i < xmlNodes.getLength(); i++) {
        Node item = xmlNodes.item(i);
        if (item.getNodeName().equals("csvprovider")) {
            CSVDataLoader loader = new CSVDataLoader();
            NodeList subNodes = item.getChildNodes();
            for (int j = 0; j < subNodes.getLength(); j++) {
                item = subNodes.item(j);

                if (item.getNodeName().equals("csvSeparatedBy") && item.hasChildNodes()) {
                    loader.setCsvSeparatedBy(
                            StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                }//ww w  . j a va2  s  .c o  m
                if (item.getNodeName().equals("csvQuoteChar") && item.hasChildNodes()) {
                    loader.setCsvQuoteChar(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                }
                if (item.getNodeName().equals("csvEscapeChar") && item.hasChildNodes()) {
                    loader.setCsvEscapeChar(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                }
                if (item.getNodeName().equals("csvDatePattern") && item.hasChildNodes()) {
                    loader.setCsvDatePattern(
                            StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                }
                if (item.getNodeName().equals("csvNumberPattern") && item.hasChildNodes()) {
                    loader.setCsvNumberPattern(
                            StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                }
                if (item.getNodeName().equals("fileURL") && item.hasChildNodes()) {
                    loader.setFileURL(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                }
            }
            return loader;
        }
    }
    return null;
}

From source file:org.jboss.dashboard.provider.sql.SQLDataLoaderXMLFormat.java

public DataLoader parse(NodeList xmlNodes) throws Exception {
    for (int i = 0; i < xmlNodes.getLength(); i++) {
        Node item = xmlNodes.item(i);
        if (item.getNodeName().equals("sqlprovider")) {
            SQLDataLoader loader = new SQLDataLoader();
            NodeList subNodes = item.getChildNodes();
            for (int j = 0; j < subNodes.getLength(); j++) {
                item = subNodes.item(j);
                if (item.getNodeName().equals("datasource") && item.hasChildNodes()) {
                    loader.setDataSource(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
                }/* w w w.  j a va  2 s . c  o m*/
                if (item.getNodeName().equals("query") && item.hasChildNodes()) {
                    Node typeNode = item.getAttributes().getNamedItem("type");
                    String dataBaseName = SQLDataLoader.PARAM_DEFAULT_QUERY;
                    if (typeNode != null)
                        dataBaseName = typeNode.getNodeValue().toLowerCase();
                    loader.setSQLQuery(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()),
                            dataBaseName);
                }
            }
            return loader;
        }
    }
    return null;
}

From source file:org.jbpm.formModeler.core.config.FormSerializationManagerImpl.java

public Form deserializeForm(Node nodeForm, String path, Map<String, Properties> resources) throws Exception {
    if (!nodeForm.getNodeName().equals(NODE_FORM))
        return null;

    Form form = formManager.createForm("");
    form.setId(Long.valueOf(//from www.  jav  a 2 s  . co  m
            StringEscapeUtils.unescapeXml(nodeForm.getAttributes().getNamedItem(ATTR_ID).getNodeValue())));

    Set<Field> fields = new TreeSet<Field>();
    NodeList childNodes = nodeForm.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeName().equals(NODE_PROPERTY)) {
            String propName = node.getAttributes().getNamedItem(ATTR_NAME).getNodeValue();
            String value = StringEscapeUtils
                    .unescapeXml(node.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());
            if ("subject".equals(propName)) {
                form.setSubject(value);
            } else if ("name".equals(propName)) {
                form.setName(value);
            } else if ("displayMode".equals(propName)) {
                form.setDisplayMode(value);
            } else if ("labelMode".equals(propName)) {
                form.setLabelMode(value);
            } else if ("showMode".equals(propName)) {
                form.setShowMode(value);
            } else if ("status".equals(propName)) {
                form.setStatus(Long.valueOf(value));
            } else if ("formTemplate".equals(propName)) {
                form.setFormTemplate(value);
            }
        } else if (node.getNodeName().equals(NODE_FIELD)) {
            Field field = deserializeField(form, node, resources);
            field.setForm(form);
            fields.add(field);
        } else if (node.getNodeName().equals(NODE_DATA_HOLDER)) {
            String holderId = getNodeAttributeValue(node, ATTR_ID);
            String holderInputId = getNodeAttributeValue(node, ATTR_INPUT_ID);
            String holderOutId = getNodeAttributeValue(node, ATTR_OUT_ID);
            String holderType = getNodeAttributeValue(node, ATTR_TYPE);
            String holderValue = getNodeAttributeValue(node, ATTR_VALUE);
            String holderRenderColor = getNodeAttributeValue(node, ATTR_NAME);
            String holderSupportedType = getNodeAttributeValue(node, ATTR_SUPPORTED_TYPE);

            if (!StringUtils.isEmpty(holderId) && !StringUtils.isEmpty(holderType)
                    && !StringUtils.isEmpty(holderValue)) {

                DataHolderBuildConfig config = new DataHolderBuildConfig(holderId, holderInputId, holderOutId,
                        holderRenderColor, holderValue);
                config.addAttribute("path", path);
                if (!StringUtils.isEmpty(holderSupportedType))
                    config.addAttribute(ATTR_SUPPORTED_TYPE, holderSupportedType);

                DataHolder holder = dataHolderManager.createDataHolderByType(holderType, config);

                if (!StringUtils.isEmpty(holderId))
                    form.setDataHolder(holder);
            }
        }
    }
    if (fields != null)
        form.setFormFields(fields);
    return form;
}

From source file:org.jbpm.formModeler.core.config.FormSerializationManagerImpl.java

public Field deserializeField(Form form, Node nodeField, Map<String, Properties> resources) throws Exception {
    if (!nodeField.getNodeName().equals(NODE_FIELD))
        return null;

    Field field = new Field();
    field.setId(Long.valueOf(nodeField.getAttributes().getNamedItem(ATTR_ID).getNodeValue()));
    field.setFieldName(nodeField.getAttributes().getNamedItem(ATTR_NAME).getNodeValue());
    field.setPosition(Integer.parseInt(nodeField.getAttributes().getNamedItem(ATTR_POSITION).getNodeValue()));
    field.setFieldType(/*  w w w  . j  a v  a 2  s  .c  o  m*/
            fieldTypeManager.getTypeByCode(nodeField.getAttributes().getNamedItem(ATTR_TYPE).getNodeValue()));

    Node bag = nodeField.getAttributes().getNamedItem(ATTR_BAG_TYPE);

    if (bag != null) {
        field.setBag(bag.getNodeValue());
    }

    NodeList fieldPropsNodes = nodeField.getChildNodes();
    for (int j = 0; j < fieldPropsNodes.getLength(); j++) {
        Node nodeFieldProp = fieldPropsNodes.item(j);
        if (nodeFieldProp.getNodeName().equals(NODE_PROPERTY)) {
            String propName = nodeFieldProp.getAttributes().getNamedItem(ATTR_NAME).getNodeValue();
            String value = StringEscapeUtils
                    .unescapeXml(nodeFieldProp.getAttributes().getNamedItem(ATTR_VALUE).getNodeValue());
            if (propName != null && value != null) {
                if ("fieldRequired".equals(propName)) {
                    field.setFieldRequired(Boolean.valueOf(value));
                } else if ("groupWithPrevious".equals(propName)) {
                    field.setGroupWithPrevious(Boolean.valueOf(value));
                } else if ("height".equals(propName)) {
                    field.setHeight(value);
                } else if ("labelCSSClass".equals(propName)) {
                    field.setLabelCSSClass(value);
                } else if ("labelCSSStyle".equals(propName)) {
                    field.setLabelCSSStyle(value);
                } else if ("label".equals(propName)) {
                    field.setLabel(deserializeI18nEntrySet(value));
                } else if ("errorMessage".equals(propName)) {
                    field.setErrorMessage(deserializeI18nEntrySet(value));
                } else if ("title".equals(propName)) {
                    field.setTitle(deserializeI18nEntrySet(value));
                } else if ("readonly".equals(propName)) {
                    field.setReadonly(Boolean.valueOf(value));
                } else if ("size".equals(propName)) {
                    if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value))
                        field.setSize(Long.valueOf(value));
                } else if ("formula".equals(propName)) {
                    field.setFormula(value);
                } else if ("rangeFormula".equals(propName)) {
                    field.setRangeFormula(value);
                } else if ("pattern".equals(propName)) {
                    field.setPattern(value);
                } else if ("maxlength".equals(propName)) {
                    if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value))
                        field.setMaxlength(Long.valueOf(value));
                } else if ("styleclass".equals(propName)) {
                    field.setStyleclass(value);
                } else if ("cssStyle".equals(propName)) {
                    field.setCssStyle(value);
                } else if ("tabindex".equals(propName)) {
                    if (!StringUtils.isEmpty(value) && StringUtils.isNumeric(value))
                        field.setTabindex(Long.valueOf(value));
                } else if ("accesskey".equals(propName)) {
                    field.setAccesskey(value);
                } else if ("isHTML".equals(propName)) {
                    field.setIsHTML(Boolean.valueOf(value));
                } else if ("htmlContent".equals(propName)) {
                    field.setHtmlContent(deserializeHMLI18nEntrySet(value));
                } else if ("hideContent".equals(propName)) {
                    field.setHideContent(Boolean.valueOf(value));
                } else if ("defaultValueFormula".equals(propName)) {
                    field.setDefaultValueFormula(value);
                } else if ("defaultSubform".equals(propName)) {
                    field.setDefaultSubform(value);
                } else if ("previewSubform".equals(propName)) {
                    field.setPreviewSubform(value);
                } else if ("tableSubform".equals(propName)) {
                    field.setTableSubform(value);
                } else if ("newItemText".equals(propName)) {
                    field.setNewItemText(deserializeI18nEntrySet(value));
                } else if ("addItemText".equals(propName)) {
                    field.setAddItemText(deserializeI18nEntrySet(value));
                } else if ("cancelItemText".equals(propName)) {
                    field.setCancelItemText(deserializeI18nEntrySet(value));
                } else if ("deleteItems".equals(propName)) {
                    field.setDeleteItems(Boolean.valueOf(value));
                } else if ("updateItems".equals(propName)) {
                    field.setUpdateItems(Boolean.valueOf(value));
                } else if ("visualizeItems".equals(propName)) {
                    field.setVisualizeItem(Boolean.valueOf(value));
                } else if ("hideCreateItem".equals(propName)) {
                    field.setHideCreateItem(Boolean.valueOf(value));
                } else if ("expanded".equals(propName)) {
                    field.setExpanded(Boolean.valueOf(value));
                } else if ("enableTableEnterData".equals(propName)) {
                    field.setEnableTableEnterData(Boolean.valueOf(value));
                } else if ("inputBinding".equals(propName)) {
                    field.setInputBinding(value);
                } else if ("outputBinding".equals(propName)) {
                    field.setOutputBinding(value);
                } else if ("customFieldType".equals(propName)) {
                    field.setCustomFieldType(value);
                } else if ("param1".equals(propName)) {
                    field.setParam1(value);
                } else if ("param2".equals(propName)) {
                    field.setParam2(value);
                } else if ("param3".equals(propName)) {
                    field.setParam3(value);
                } else if ("param4".equals(propName)) {
                    field.setParam4(value);
                } else if ("param5".equals(propName)) {
                    field.setParam5(value);
                } else if ("fieldClass".equals(propName)) {
                    field.getFieldType().setFieldClass(value);
                } else if ("onChangeScript".equals(propName)) {
                    field.setOnChangeScript(value);
                }
            }
        }
    }

    if (resources != null) {
        field.setTitle(new I18nSet());
        field.setLabel(new I18nSet());
        field.setErrorMessage(new I18nSet());
        if (resources.containsKey("default")) {
            resources.put(localeManager.getDefaultLang(), resources.remove("default"));
        }
        for (String lang : resources.keySet()) {
            Properties props = resources.get(lang);
            String value = getFieldProperty(form.getName(), field.getFieldName(), "title", props);
            if (!StringUtils.isEmpty(value))
                field.getTitle().setValue(lang, value);

            value = getFieldProperty(form.getName(), field.getFieldName(), "label", props);
            if (!StringUtils.isEmpty(value))
                field.getLabel().setValue(lang, value);

            value = getFieldProperty(form.getName(), field.getFieldName(), "errorMessage", props);
            if (!StringUtils.isEmpty(value))
                field.getErrorMessage().setValue(lang, value);
        }
    }
    return field;
}