List of usage examples for org.w3c.dom Node hasChildNodes
public boolean hasChildNodes();
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()); }//from w w w .j a v a2s.c o m 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 va2s. c o m*/ // 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; }/*from w w w. jav a 2s .co 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())); }/*from ww w .j ava 2s .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())); }//from w w w.j av a 2s . c om 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.jboss.pressgang.ccms.contentspec.builder.DocBookBuilder.java
/** * Adds a revision element to the list of revisions in a revhistory element. This method ensures that the new revision is at * the top of the revhistory list.//from www.j av a 2 s . c o m * * @param revHistory The revhistory element to add the revision to. * @param revision The revision element to be added into the revisionhistory element. */ private void addRevisionToRevHistory(final Node revHistory, final Node revision) { if (revHistory.hasChildNodes()) { revHistory.insertBefore(revision, revHistory.getFirstChild()); } else { revHistory.appendChild(revision); } }
From source file:org.jbpm.designer.server.RdfJsonTransformation.java
public static JSONObject toJson(Document rdfDoc, String requestUrl) { canvas = new JSONObject(); objects = new HashMap<String, JSONObject>(); parents = new HashMap<String, String>(); hostUrl = requestUrl;// w ww. j a v a 2 s . c om Node root = getRootNode(rdfDoc); if (root == null) return canvas; if (root.hasChildNodes()) { for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) { if (node instanceof Text) continue; // Does this make any sense??? it just don't parse xml docs with no new lines!!! //String type = getType(node); //if (type == null) // continue; Node rdfTypeNode = getChild(node, "rdf:type"); if (rdfTypeNode != null) { String rdfType = getAttributeValue(rdfTypeNode, "rdf:resource"); if ((rdfType != null) && rdfType.equals("http://oryx-editor.org/canvas")) { handleCanvas(node); continue; } } handleShape(node); } } setupParentRelationships(); return canvas; }
From source file:org.jbpm.designer.server.RdfJsonTransformation.java
/** * Evaluates if given node can be a shape. E.g., it looks for an resource id, if there are any * children and if it have a node named generatorAgent (which provides only meta info about the rdf) * @param n Node/*from ww w.ja v a 2 s .c o m*/ * @return true if given node seems to be a shape */ private static boolean isValidShapeNode(Node n) { if (getResourceId(n).length() == 0) //if there isn't a resource id return false; if (n.hasChildNodes()) { //if there is the generatorAgent node if (n.getFirstChild().getLocalName() != null && n.getFirstChild().getLocalName().equals("generatorAgent")) return false; } else { //if there isn't any child node return false; } return true; }
From source file:org.jbpm.designer.server.RdfJsonTransformation.java
private static void handleProperties(Node n, JSONObject object) throws JSONException { JSONObject properties = new JSONObject(); object.put("properties", properties); if (n.hasChildNodes()) { for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) { if (!isReservedNodeName(child.getNodeName())) { String content = getContent(child); if (content == null) { properties.put(child.getNodeName(), content); } else { try { // try to parse property value to JSON object (for complex properties) JSONObject jsonObj = new JSONObject(content); properties.put(child.getNodeName(), jsonObj); } catch (JSONException e) { // non-JSON content log.info("conversion error"); log.info(content); log.info(e.toString()); properties.put(child.getNodeName(), content); }/*from w w w. j a va 2 s . co m*/ } } else { handleReservedNodeName(child, object); } } } // if((!object.has("target")||"{}".equals(object.getString("target"))||"".equals(object.getString("target")))&& object.has("outgoing")){ // if(object.getJSONArray("outgoing").length()>0) // object.put("target", object.getJSONArray("outgoing").get(0)); // } }
From source file:org.jbpm.designer.server.RdfJsonTransformation.java
private static String getContent(Node node) { if (node != null && node.hasChildNodes()) return node.getFirstChild().getNodeValue(); return null;/* w w w . ja v a2s . c om*/ }