List of usage examples for org.dom4j Element getStringValue
String getStringValue();
From source file:org.pentaho.platform.uifoundation.component.StaticFilterDefinition.java
License:Open Source License
@Override protected IPentahoResultSet getResultSet(final Map parameterProviders) { List headers = node.selectNodes("static-lov/headers/header"); //$NON-NLS-1$ List colHeaders = new LinkedList(); for (Iterator it = headers.iterator(); it.hasNext();) { Element header = (Element) it.next(); String value = header.getStringValue(); colHeaders.add(value);/* w ww.ja v a2s . c o m*/ } List rows = node.selectNodes("static-lov/rows/row"); //$NON-NLS-1$ List data = new LinkedList(); for (Iterator it = rows.iterator(); it.hasNext();) { Element rowItem = (Element) it.next(); List items = rowItem.selectNodes("item"); List row = new LinkedList(); for (Iterator itt = items.iterator(); itt.hasNext();) { Element item = (Element) itt.next(); String value = item.getStringValue(); row.add(value); } data.add(row); } IPentahoResultSet resultSet = MemoryResultSet.createFromLists(colHeaders, data); return resultSet; }
From source file:org.ploin.web.flow.FlowControl.java
License:Apache License
/** * This method read the "ploinFlows.xml" and build an object-graph. * The object-graph is a List of Flow-Ojbects. * * @see Flow/*ww w .j a v a2s . c o m*/ * @return List<Flow>, object-graph */ public List<Flow> readFlows() { List<Flow> flows = new ArrayList<Flow>(); try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) loader = ClassLoader.getSystemClassLoader(); URL url = loader.getResource("ploinFlows.xml"); SAXReader reader = new SAXReader(); Document document = reader.read(url); Element root = document.getRootElement(); String authSource = null; // authoritiySource String appName = null; // applicationName String acceddDeniedPage = null; Boolean disableUrlNavigation = Boolean.FALSE; Set<String> viewsForAllFlows = new HashSet<String>(); Set<String> ignoreFlows = new HashSet<String>(); for (Iterator<Element> i = root.elementIterator(); i.hasNext();) { Element flow = (Element) i.next(); if ("ignoreViews".equalsIgnoreCase(flow.getName())) { for (Iterator<Element> e = flow.elementIterator(); e.hasNext();) { Element view = (Element) e.next(); if ("view".equalsIgnoreCase(view.getName())) { ignoreFlows.add(view.getStringValue()); } } } else if ("viewsForAllFlows".equalsIgnoreCase(flow.getName())) { for (Iterator<Element> e = flow.elementIterator(); e.hasNext();) { Element view = (Element) e.next(); if ("view".equalsIgnoreCase(view.getName())) { viewsForAllFlows.add(view.getStringValue()); } } } else if ("disableUrlNavigation".equalsIgnoreCase(flow.getName())) { try { disableUrlNavigation = Boolean.parseBoolean(flow.getStringValue()); } catch (Exception e) { log.error("ERROR by parsing boolean. ", e); } } else if ("accessDeniedPage".equalsIgnoreCase(flow.getName())) { acceddDeniedPage = flow.getStringValue(); } else if ("appName".equalsIgnoreCase(flow.getName())) { appName = flow.getStringValue(); } else if ("authoritySource".equalsIgnoreCase(flow.getName())) { authSource = flow.getStringValue(); } else if ("flow".equalsIgnoreCase(flow.getName())) { Flow flowItem = new Flow(); flowItem.setFlowId(flow.attribute("id").getValue()); log.debug("read ID: " + flow.attribute("id").getValue()); for (Iterator<Element> e = flow.elementIterator(); e.hasNext();) { Element flowChild = (Element) e.next(); if ("views".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element view = (Element) t.next(); if ("view".equalsIgnoreCase(view.getName())) { flowItem.addView(view.getStringValue()); } } } else if ("attributes".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element attribute = (Element) t.next(); if ("attribute".equalsIgnoreCase(attribute.getName())) { flowItem.addAttribute(attribute.getStringValue()); } } } else if ("includeAuthorities".equalsIgnoreCase(flowChild.getName()) || "includeAuthoritys".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element auth = (Element) t.next(); if ("authority".equalsIgnoreCase(auth.getName())) { flowItem.addIncludeAuthority(auth.getStringValue()); } } } else if ("excludeAuthorities".equalsIgnoreCase(flowChild.getName()) || "excludeAuthoritys".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element auth = (Element) t.next(); if ("authority".equalsIgnoreCase(auth.getName())) { flowItem.addExcludeAuthority(auth.getStringValue()); } } } else if ("beforeFlowAction".equalsIgnoreCase(flowChild.getName())) { flowItem.setBeforeFlowAction(flowChild.getStringValue()); } else if ("afterFlowAction".equalsIgnoreCase(flowChild.getName())) { flowItem.setAfterFlowAction(flowChild.getStringValue()); } else if ("beforeLifecycleAction".equalsIgnoreCase(flowChild.getName())) { flowItem.setBeforeLifecycleAction(flowChild.getStringValue()); } else if ("afterLifecycleAction".equalsIgnoreCase(flowChild.getName())) { flowItem.setAfterLifecycleAction(flowChild.getStringValue()); } else if ("subFlows".equalsIgnoreCase(flowChild.getName())) { for (Iterator<Element> t = flowChild.elementIterator(); t.hasNext();) { Element flowId = (Element) t.next(); if ("flowId".equalsIgnoreCase(flowId.getName())) { flowItem.addSubFlow(flowId.getStringValue()); } } } } flowItem.setAuthoritySource(authSource); flowItem.setAppName(appName); flowItem.setAccessDeniedPage(acceddDeniedPage); if (viewsForAllFlows.size() > 0) { for (String view : viewsForAllFlows) { flowItem.addView(view); } } flowItem.setIgnoreViews(ignoreFlows); flowItem.setDisableUrlNavigation(disableUrlNavigation); flows.add(flowItem); } } } catch (Exception e) { log.error("ERROR in ploinFlow ", e); } return flows; }
From source file:org.soyatec.windowsazure.blob.internal.BlobContainerRest.java
License:Apache License
/** * Retrieve the blob meta-data from the response body in XML format. * * @param stream/*from w ww . ja va 2s . c om*/ * HTTP response body * @return an ListBlobsResult * @throws StorageServerException */ @SuppressWarnings("unchecked") private ListBlobsResult parseBlobFromResponse(InputStream stream) throws StorageServerException { List<IBlobProperties> blobs = new ArrayList<IBlobProperties>(); List<String> commonPrefixes = new ArrayList<String>(); String nextMarker = null; Document document = XmlUtil.load(stream); // Get the commonPrefixes List xmlNodes = document.selectNodes(XPathQueryHelper.CommonPrefixQuery); for (Iterator iterator = xmlNodes.iterator(); iterator.hasNext();) { Element element = (Element) iterator.next(); String blobPrefix = XPathQueryHelper.loadSingleChildStringValue(element, XmlElementNames.BlobPrefixName, false); commonPrefixes.add(blobPrefix); } // Get all the blobs returned as the listing results xmlNodes = document.getRootElement().element("Blobs").elements("Blob"); //xmlNodes = document.selectNodes(XPathQueryHelper.BlobQuery); for (Iterator iterator = xmlNodes.iterator(); iterator.hasNext();) { /* * Parse the Blob meta-data from response XML content. */ Element blobNode = (Element) iterator.next(); // @Note: update for new version Element propNode = blobNode.element(XmlElementNames.BlobProperties); if (propNode == null) blobs.add(parseBlobInfo(blobNode)); else blobs.add(parseBlobInfo2(blobNode, propNode)); } // Get the nextMarker Element nextMarkerNode = (Element) document.selectSingleNode(XPathQueryHelper.NextMarkerQuery); if (nextMarkerNode != null && nextMarkerNode.hasContent()) { nextMarker = nextMarkerNode.getStringValue(); } return new ListBlobsResult(blobs, commonPrefixes, nextMarker); }
From source file:org.soyatec.windowsazure.blob.internal.BlobStorageRest.java
License:Apache License
@SuppressWarnings("unchecked") private ListContainersResult listContainersResultFromResponse(InputStream stream) { List<ContainerProperties> props = new ArrayList<ContainerProperties>(); String nextMarker = null;// w w w .j a va 2 s . com Document document = XmlUtil.load(stream); // Get all the containers returned as the listing results List xmlNodes = document.selectNodes(XPathQueryHelper.ContainerQuery); for (Iterator iterator = xmlNodes.iterator(); iterator.hasNext();) { /* * Parse the container meta-data from response XML content. */ Element containerNode = (Element) iterator.next(); Timestamp lastModified = XPathQueryHelper.loadSingleChildDateTimeValue(containerNode, XmlElementNames.LastModified, false); String eTag = XPathQueryHelper.loadSingleChildStringValue(containerNode, XmlElementNames.Etag, false); String containerUri = XPathQueryHelper.loadSingleChildStringValue(containerNode, XmlElementNames.Url, true); String containerName = XPathQueryHelper.loadSingleChildStringValue(containerNode, XmlElementNames.Name, true); ContainerProperties properties = new ContainerProperties(containerName); if (lastModified != null) { properties.setLastModifiedTime(lastModified); } properties.setETag(eTag); if (!Utilities.isNullOrEmpty(containerUri)) { properties.setUri(URI.create(containerUri)); } props.add(properties); } // Get the nextMarker Element nextMarkerNode = (Element) document.selectSingleNode(XPathQueryHelper.NextMarkerQuery); if (nextMarkerNode != null && nextMarkerNode.hasContent()) { nextMarker = nextMarkerNode.getStringValue(); } ListContainersResult result = new ListContainersResult(); result.setContains(props); result.setNextMarker(nextMarker); return result; }
From source file:org.soyatec.windowsazure.internal.util.xml.XPathQueryHelper.java
License:Apache License
/** * Load single child dateTime value by given blobNode,childName and boolean * throwIfNotFound//from w ww .j a v a2s.co m * * @param blobNode * @param childName * @param throwIfNotFound * @return a Timestamp object */ public static Timestamp loadSingleChildDateTimeValue(Element blobNode, String childName, boolean throwIfNotFound) { Element childNode = (Element) blobNode.selectSingleNode(childName); if (childNode != null && childNode.hasContent()) { Timestamp date; try { date = Utilities.tryGetDateTimeFromHttpString(childNode.getStringValue()); return date; } catch (ParseException e) { throw new StorageServerException(StorageErrorCode.ServiceBadResponse, "Date time value returned from server " + childNode.getStringValue() + " can't be parsed.", HttpStatusConstant.DEFAULT_STATUS, null); } } else if (!throwIfNotFound) { return null; } else { return null; } }
From source file:org.soyatec.windowsazure.internal.util.xml.XPathQueryHelper.java
License:Apache License
/** * Load single child long value by given blobNode,childName and boolean * throwIfNotFound//from ww w . j a v a 2 s . co m * * @param blobNode * @param childName * @param throwIfNotFound * @return a long object * @throws StorageServerException * Server exceptions are those due to server side problems. * These may be transient and requests resulting in such * exceptions can be retried with the same parameters. */ public static Long loadSingleChildLongValue(Element blobNode, String childName, boolean throwIfNotFound) throws StorageServerException { Element childNode = (Element) blobNode.selectSingleNode(childName); if (childNode != null && childNode.hasContent()) { try { return Long.parseLong(childNode.getStringValue()); } catch (Exception e) { throw new StorageServerException( StorageErrorCode.ServiceBadResponse, "Reponse size field is not a valid long number." + childNode.getStringValue() + " can't be parsed.", HttpStatusConstant.DEFAULT_STATUS, null); } } else if (!throwIfNotFound) { return null; } else { return null; } }
From source file:org.soyatec.windowsazure.queue.internal.QueueStorageRest.java
License:Apache License
/** * Internal method for creating ListQueueResult from input stream. *//* w ww . jav a2 s . co m*/ @SuppressWarnings("unchecked") private ListQueueResult getQueuesResultFromResponse(InputStream stream) throws StorageException { List<String> names = new ArrayList<String>(); List<String> urls = new ArrayList<String>(); String nextMarker = null; Document document = XmlUtil.load(stream, "The result of a ListQueue operation could not be parsed"); // get queue names and urls List xmlNodes = document.selectNodes(XPathQueryHelper.QueueListQuery); for (Iterator iterator = xmlNodes.iterator(); iterator.hasNext();) { Element queueNameNode = (Element) iterator.next(); String queueName = XPathQueryHelper.loadSingleChildStringValue(queueNameNode, XmlElementNames.QueueName, true); names.add(queueName); String url = XPathQueryHelper.loadSingleChildStringValue(queueNameNode, XmlElementNames.Url, true); urls.add(url); } // Get the nextMarker Element nextMarkerNode = (Element) document.selectSingleNode(XPathQueryHelper.NextMarkerQuery); if (nextMarkerNode != null && nextMarkerNode.hasContent()) { nextMarker = nextMarkerNode.getStringValue(); } assert names.size() == urls.size(); // Make this useful, you shoule open // the -enableassertions when run. return new ListQueueResult(names, urls, nextMarker); }
From source file:org.soyatec.windowsazure.table.internal.CloudTableRest.java
License:Apache License
/** * All response for table request is represents in xml format. Parse xml and * compose entities with the content in xml. * * @param stream/*w w w . j a va 2 s .c o m*/ * @return A list of {@link AbstractTableServiceEntity} */ @SuppressWarnings("unchecked") private List<AbstractTableServiceEntity> getTableEntitiesFromResponse(InputStream stream) { final List<AbstractTableServiceEntity> result = new ArrayList<AbstractTableServiceEntity>(); Document document = XmlUtil.load(stream, "The result of a ListTableEntities operation could not be parsed"); // get queue names and urls List xmlNodes = XPathQueryHelper.parseEntryFromFeed(document); for (Iterator iterator = xmlNodes.iterator(); iterator.hasNext();) { Element tableEntryNode = (Element) iterator.next(); String partitionKey = XPathQueryHelper.loadTableEntryPropertyValue(tableEntryNode, XmlElementNames.TableEntryPropertyPartitionKey); String rowKey = XPathQueryHelper.loadTableEntryPropertyValue(tableEntryNode, XmlElementNames.TableEntryPropertyRowKey); // Retrieve ETag value from the entry attribute [m:etag] String eTag = XPathQueryHelper.loadTableEntryValueFromAttribute(tableEntryNode, XmlElementNames.TableEntryPropertyETag); String timestamp = XPathQueryHelper.loadTableEntryPropertyValue(tableEntryNode, XmlElementNames.TableEntryPropertyTimestamp); Element element = XPathQueryHelper.loadTableEntryProperties(tableEntryNode); List<ICloudTableColumn> values = new ArrayList<ICloudTableColumn>(); for (Iterator iter = element.elementIterator(); iter.hasNext();) { Element next = (Element) iter.next(); String xmlNodeName = next.getName(); String xmlType = next.attributeValue(XmlElementNames.TableEntryPropertyType); String stringValue = AtomUtil.unescapeXml(next.getStringValue().trim()); CloudTableColumn column = new CloudTableColumn(); column.setName(xmlNodeName); column.setValue(stringValue); column.setType(ETableColumnType.getTypebyLiteral(xmlType)); values.add(column); } if (getModelClass() != null) { try { AbstractTableServiceEntity targetObject = (AbstractTableServiceEntity) createObjectByModelClass( partitionKey, rowKey, eTag, timestamp, values); if (targetObject != null) { result.add(targetObject); } } catch (Exception e) { Logger.error("Compose table entity error!", e); } } else { // If have no targerObject given, use SimpleTableServiceEntity AbstractTableServiceEntity entity = null; try { entity = new SimpleTableServiceEntity(partitionKey, rowKey, Utilities.tryGetDateTimeFromTableEntry(timestamp)); entity.setValues(values); result.add(entity); } catch (ParseException e) { Logger.error("Parse timestamp error!", e); } } } return result; }
From source file:org.soyatec.windowsazure.table.internal.TableStorageRest.java
License:Apache License
private ListTableResult getTableResultFromResponse(InputStream stream) { List<String> names = new ArrayList<String>(); String nextMarker = null;/*from ww w . j a v a2s .c o m*/ Document document = XmlUtil.load(stream, "The result of a ListTable operation could not be parsed"); // get queue names and urls List xmlNodes = XPathQueryHelper.parseEntryFromFeed(document); for (Iterator iterator = xmlNodes.iterator(); iterator.hasNext();) { Element tableEntryNode = (Element) iterator.next(); String queueName = XPathQueryHelper.loadTableNameFromTableEntry(tableEntryNode); names.add(queueName); } // Get the nextMarker Element nextMarkerNode = (Element) document.selectSingleNode(XPathQueryHelper.NextMarkerQuery); // the -enableassertions when run. if (nextMarkerNode != null && nextMarkerNode.hasContent()) { nextMarker = nextMarkerNode.getStringValue(); } return new ListTableResult(names, nextMarker); }
From source file:org.talend.core.utils.TemplateFileUtils.java
License:Open Source License
public static String handleAssemblyJobTemplate(String content, String launcher) throws DocumentException { if (launcher == null || launcher.equalsIgnoreCase(LAUNCHER_ALL)) { return content; }/* w ww .jav a 2 s. co m*/ ByteArrayInputStream source = new ByteArrayInputStream(content.getBytes()); SAXReader reader = new SAXReader(); Document doc = reader.read(source); Element root = doc.getRootElement(); Element files = root.element("files"); //$NON-NLS-1$ if (files == null) { return content; } for (Iterator j = files.elementIterator("file"); j.hasNext();) { //$NON-NLS-1$ Element file = (Element) j.next(); Element destName = file.element("destName"); //$NON-NLS-1$ if (launcher.equalsIgnoreCase(UNIX_ENVIRONMENT)) { if (destName.getStringValue().endsWith(WINDOWS_LAUNCHER)) { files.remove(file); } if (destName.getStringValue().endsWith(POWER_SHELL)) { files.remove(file); } } else if (launcher.equalsIgnoreCase(WINDOWS_ENVIRONMENT)) { if (destName.getStringValue().endsWith(UNIX_LAUNCHER)) { files.remove(file); } } } return root.asXML(); }