List of usage examples for org.w3c.dom Element getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:org.opendatakit.aggregate.parser.SubmissionParser.java
/** * Recursive function that prints the nodes from an XML tree * //from w w w . ja v a2 s.c o m * @param node * xml node to be recursively printed */ @SuppressWarnings("unused") private void printNode(Element node) { System.out.println(ParserConsts.NODE_FORMATTED + node.getTagName()); if (node.hasAttributes()) { NamedNodeMap attributes = node.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attr = attributes.item(i); System.out.println(ParserConsts.ATTRIBUTE_FORMATTED + attr.getNodeName() + BasicConsts.EQUALS + attr.getNodeValue()); } } if (node.hasChildNodes()) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { printNode((Element) child); } else if (child.getNodeType() == Node.TEXT_NODE) { String value = child.getNodeValue().trim(); if (value.length() > 0) { System.out.println(ParserConsts.VALUE_FORMATTED + value); } } } } }
From source file:org.openestate.io.core.XmlUtils.java
private static void printNode(Element node, int indent) { String prefix = (indent > 0) ? StringUtils.repeat(">", indent) + " " : ""; LOGGER.debug(prefix + "<" + node.getTagName() + "> / " + node.getNamespaceURI() + " / " + node.getPrefix()); prefix = StringUtils.repeat(">", indent + 1) + " "; NamedNodeMap attribs = node.getAttributes(); for (int i = 0; i < attribs.getLength(); i++) { Attr attrib = (Attr) attribs.item(i); LOGGER.debug(prefix + "@" + attrib.getName() + " / " + attrib.getNamespaceURI() + " / " + attrib.getPrefix());/*from w w w. ja va 2 s .c o m*/ } NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { XmlUtils.printNode((Element) child, indent + 1); } } }
From source file:org.opensingular.internal.lib.commons.xml.TestMElement.java
License:asdf
/** * Verifica se ambos os nos so iguais fazendo uma comparao em * profundidade.//from www.j a va 2 s .co m * * @param n1 - * @param n2 - * @throws Exception Se nbo forem iguais */ public static void isIgual(Node n1, Node n2) throws Exception { if (n1 == n2) { return; } isIgual(n1, n2, "NodeName", n1.getNodeName(), n2.getNodeName()); isIgual(n1, n2, "NodeValue", n1.getNodeValue(), n2.getNodeValue()); isIgual(n1, n2, "Namespace", n1.getNamespaceURI(), n2.getNamespaceURI()); isIgual(n1, n2, "Prefix", n1.getPrefix(), n2.getPrefix()); isIgual(n1, n2, "LocalName", n1.getLocalName(), n2.getLocalName()); if (isMesmaClasse(Element.class, n1, n2)) { Element e1 = (Element) n1; Element e2 = (Element) n2; //Verifica se possuem os mesmos atributos NamedNodeMap nn1 = e1.getAttributes(); NamedNodeMap nn2 = e2.getAttributes(); if (nn1.getLength() != nn2.getLength()) { fail("O nmero atributos em " + XPathToolkit.getFullPath(n1) + " (qtd=" + nn1.getLength() + " diferente de n2 (qtd=" + nn2.getLength() + ")"); } for (int i = 0; i < nn1.getLength(); i++) { isIgual((Attr) nn1.item(i), (Attr) nn2.item(i)); } //Verifica se possuem os mesmos filhos Node filho1 = e1.getFirstChild(); Node filho2 = e2.getFirstChild(); int count = 0; while ((filho1 != null) && (filho2 != null)) { isIgual(filho1, filho2); filho1 = filho1.getNextSibling(); filho2 = filho2.getNextSibling(); count++; } if (filho1 != null) { fail("H mais node [" + count + "] " + XPathToolkit.getNomeTipo(filho1) + " (" + XPathToolkit.getFullPath(filho1) + ") em n1:" + XPathToolkit.getFullPath(n1)); } if (filho2 != null) { fail("H mais node [" + count + "] " + XPathToolkit.getNomeTipo(filho2) + " (" + XPathToolkit.getFullPath(filho2) + ") em n2:" + XPathToolkit.getFullPath(n2)); } } else if (isMesmaClasse(Attr.class, n1, n2)) { //Ok } else if (isMesmaClasse(Text.class, n1, n2)) { //Ok } else { fail("Tipo de n " + n1.getClass() + " no tratado"); } }
From source file:org.openspaces.core.config.LocalTxManagerBeanDefinitionParser.java
protected void doParse(Element element, BeanDefinitionBuilder builder) { log.warn(//from w ww . ja v a2 s. c o m "Local transaction manager is deprecated, use distributed transaction manager instead ('distributed-tx-manager')"); super.doParse(element, builder); NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); String name = attribute.getLocalName(); if (ID_ATTRIBUTE.equals(name)) { continue; } String propertyName = extractPropertyName(name); if (SPACE.equals(name)) { continue; } if (CLUSTERED.equals(name)) { continue; } Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); builder.addPropertyValue(propertyName, attribute.getValue()); } }
From source file:org.osaf.cosmo.xml.DomWriter.java
private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException { //if (log.isDebugEnabled()) //log.debug("Writing element " + e.getNodeName()); String local = e.getLocalName(); if (local == null) local = e.getNodeName();//from w w w . j a v a 2 s . c o m String ns = e.getNamespaceURI(); if (ns != null) { String prefix = e.getPrefix(); if (prefix != null) { writer.writeStartElement(prefix, local, ns); writer.writeNamespace(prefix, ns); } else { writer.setDefaultNamespace(ns); writer.writeStartElement(ns, local); writer.writeDefaultNamespace(ns); } } else { writer.writeStartElement(local); } NamedNodeMap attributes = e.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) writeAttribute((Attr) attributes.item(i), writer); NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) writeNode(children.item(i), writer); writer.writeEndElement(); }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
private boolean isDigested(NodeList nodes, VerifyReference[] references) { for (int idx = 0; idx < nodes.getLength(); idx++) { Node node = nodes.item(idx); //this._logger.log(Level.FINE, "node name: {0}", node.getLocalName()); boolean changed = false; if (node.getNodeType() == Node.TEXT_NODE) { String originalTextValue = node.getNodeValue(); String changedTextValue = originalTextValue + "foobar"; node.setNodeValue(changedTextValue); changed = false; // need to have impact anyway for (int referenceIdx = 0; referenceIdx < references.length; referenceIdx++) { VerifyReference reference = references[referenceIdx]; changed |= reference.hasChanged(); }//from w ww. jav a 2 s . co m if (false == changed) { return false; } node.setNodeValue(originalTextValue); } else if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; NamedNodeMap attributes = element.getAttributes(); for (int attributeIdx = 0; attributeIdx < attributes.getLength(); attributeIdx++) { Node attributeNode = attributes.item(attributeIdx); String originalAttributeValue = attributeNode.getNodeValue(); String changedAttributeValue = originalAttributeValue + "foobar"; attributeNode.setNodeValue(changedAttributeValue); for (int referenceIdx = 0; referenceIdx < references.length; referenceIdx++) { VerifyReference reference = references[referenceIdx]; changed |= reference.hasChanged(); } attributeNode.setNodeValue(originalAttributeValue); } changed |= isDigested(element.getChildNodes(), references); } else if (node.getNodeType() == Node.COMMENT_NODE) { // not always digested by the ds:References } else { throw new RuntimeException("unsupported node type: " + node.getNodeType()); } if (false == changed) { return false; } } return true; }
From source file:org.paxle.tools.ieporter.cm.impl.ConfigurationIEPorter.java
@SuppressWarnings("unchecked") public Dictionary<String, Object> importConfiguration(Document doc) { if (doc == null) return null; Dictionary<String, Object> props = new Hashtable<String, Object>(); try {/* w ww. j av a2 s. c o m*/ Element configElement = doc.getDocumentElement(); // getting the service-pid Element pidElement = (Element) configElement.getElementsByTagName(Constants.SERVICE_PID).item(0); props.put(Constants.SERVICE_PID, pidElement.getFirstChild().getNodeValue()); // loop through all properties Element propsElement = (Element) configElement.getElementsByTagName(ELEM_PROPERTIES).item(0); NodeList propsList = propsElement.getElementsByTagName(ELEM_PROPERTY); for (int i = 0; i < propsList.getLength(); i++) { Element propertyElement = (Element) propsList.item(i); Object value = null; String key = propertyElement.getAttributes().getNamedItem(ATTRIBUTE_PROPERTY_KEY).getNodeValue(); String type = propertyElement.getAttributes().getNamedItem(ATTRIB_PROPERTY_TYPE).getNodeValue(); if (type.endsWith("[]") || type.equals(Vector.class.getSimpleName())) { Element valueElements = (Element) propertyElement.getElementsByTagName(ELEM_VALUES).item(0); NodeList valueElementList = valueElements.getElementsByTagName(ELEM_VALUE); if (type.endsWith("[]")) { // get type class Class clazz = NAMELOOKUP.get(type.substring(0, type.length() - 2)); // create a new array value = Array.newInstance(clazz, valueElementList.getLength()); } else { // create a new vector value = new Vector(); } // append all values to the array/vector for (int j = 0; j < valueElementList.getLength(); j++) { Element valueElement = (Element) valueElementList.item(j); Object valueObj = this.valueOf(type, valueElement); if (type.endsWith("[]")) { Array.set(value, j, valueObj); } else { ((Vector<Object>) value).add(valueObj); } } } else { Element valueElement = (Element) propertyElement.getElementsByTagName(ELEM_VALUE).item(0); // get concrete value value = this.valueOf(type, valueElement); } // add value props.put(key, value); } } catch (Exception e) { e.printStackTrace(); } return props; }
From source file:org.pentaho.platform.repository.solution.SolutionRepositoryServiceImpl.java
protected void processRepositoryFile(IPentahoSession session, boolean isAdministrator, ISolutionRepository repository, Node parentNode, ISolutionFile file, String[] filters) { final String name = file.getFileName(); // MDD 10/16/2008 Not always.. what about 'system' if (name.startsWith("system") || name.startsWith("tmp") || name.startsWith(".")) { //$NON-NLS-1$ // slip hidden files (starts with .) // skip the system & tmp dir, we DO NOT ever want this to hit the client return;//w w w .j av a2s . c o m } if (!accept(isAdministrator, repository, file)) { // we don't want this file, skip to the next one return; } if (file.isDirectory()) { // we always process directories // maintain legacy behavior if (repository.getRootFolder(ISolutionRepository.ACTION_EXECUTE).getFullPath() .equals(file.getFullPath())) { // never output the root folder as part of the repo doc; skip root and process its children ISolutionFile[] children = file.listFiles(); for (ISolutionFile childSolutionFile : children) { processRepositoryFile(session, isAdministrator, repository, parentNode, childSolutionFile, filters); } return; } Element child = null; final String key = file.getFullPath() + file.getLastModified() + LocaleHelper.getLocale(); ICacheManager cacheManager = PentahoSystem.getCacheManager(null); if (cacheManager != null && cacheManager.cacheEnabled(ISolutionRepository.REPOSITORY_SERVICE_CACHE_REGION)) { child = (Element) cacheManager .getFromRegionCache(ISolutionRepository.REPOSITORY_SERVICE_CACHE_REGION, key); } if (child == null) { child = parentNode instanceof Document ? ((Document) parentNode).createElement("file") //$NON-NLS-1$ : parentNode.getOwnerDocument().createElement("file"); //$NON-NLS-1$ try { String localizedName = repository.getLocalizedFileProperty(file, "name", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); child.setAttribute("localized-name", //$NON-NLS-1$ localizedName == null || "".equals(localizedName) ? name : localizedName); //$NON-NLS-1$ } catch (Exception e) { child.setAttribute("localized-name", name); //$NON-NLS-1$ } try { String visible = repository.getLocalizedFileProperty(file, "visible", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); child.setAttribute("visible", visible == null || "".equals(visible) ? "false" : visible); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } catch (Exception e) { e.printStackTrace(); child.setAttribute("visible", "false"); //$NON-NLS-1$ //$NON-NLS-2$ } String description = repository.getLocalizedFileProperty(file, "description", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); child.setAttribute("description", //$NON-NLS-1$ description == null || "".equals(description) ? name : description); //$NON-NLS-1$ child.setAttribute("name", name); //$NON-NLS-1$ child.setAttribute("isDirectory", "true"); //$NON-NLS-1$ //$NON-NLS-2$ child.setAttribute("lastModifiedDate", "" + file.getLastModified()); //$NON-NLS-1$ //$NON-NLS-2$ if (cacheManager != null && cacheManager.cacheEnabled(ISolutionRepository.REPOSITORY_SERVICE_CACHE_REGION)) { cacheManager.putInRegionCache(ISolutionRepository.REPOSITORY_SERVICE_CACHE_REGION, key, child); } } else { Element newChild = parentNode instanceof Document ? ((Document) parentNode).createElement("file") //$NON-NLS-1$ : parentNode.getOwnerDocument().createElement("file"); //$NON-NLS-1$ NamedNodeMap attributes = child.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); newChild.setAttribute(attribute.getNodeName(), attribute.getNodeValue()); } child = newChild; } parentNode.appendChild(child); ISolutionFile[] children = file.listFiles(); for (ISolutionFile childSolutionFile : children) { processRepositoryFile(session, isAdministrator, repository, child, childSolutionFile, filters); } } else { InputStream pluginInputStream = null; try { int lastPoint = name.lastIndexOf('.'); String extension = ""; //$NON-NLS-1$ if (lastPoint != -1) { // ignore anything with no extension extension = name.substring(lastPoint + 1).toLowerCase(); } // xaction and URL support are built in boolean addFile = acceptFilter(name, filters) || "xaction".equals(extension) //$NON-NLS-1$ || "url".equals(extension); //$NON-NLS-1$ boolean isPlugin = false; // see if there is a plugin for this file type IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, session); if (pluginManager != null) { Set<String> types = pluginManager.getContentTypes(); isPlugin = types != null && types.contains(extension); addFile |= isPlugin; } if (addFile) { ICacheManager cacheManager = PentahoSystem.getCacheManager(null); Element child = null; final String key = file.getFullPath() + file.getLastModified() + LocaleHelper.getLocale(); if (cacheManager != null && cacheManager.cacheEnabled(ISolutionRepository.REPOSITORY_SERVICE_CACHE_REGION)) { child = (Element) cacheManager .getFromRegionCache(ISolutionRepository.REPOSITORY_SERVICE_CACHE_REGION, key); } if (child == null) { child = parentNode instanceof Document ? ((Document) parentNode).createElement("file") //$NON-NLS-1$ : parentNode.getOwnerDocument().createElement("file"); //$NON-NLS-1$ if (cacheManager != null && cacheManager.cacheEnabled(ISolutionRepository.REPOSITORY_SERVICE_CACHE_REGION)) { cacheManager.putInRegionCache(ISolutionRepository.REPOSITORY_SERVICE_CACHE_REGION, key, child); } } else { Element newChild = parentNode instanceof Document ? ((Document) parentNode).createElement("file") //$NON-NLS-1$ : parentNode.getOwnerDocument().createElement("file"); //$NON-NLS-1$ NamedNodeMap attributes = child.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); newChild.setAttribute(attribute.getNodeName(), attribute.getNodeValue()); } parentNode.appendChild(newChild); return; } parentNode.appendChild(child); IFileInfo fileInfo = null; if (name.endsWith(".xaction")) { //$NON-NLS-1$ // add special props? // localization.. String solution = file.getSolutionPath(); String path = ""; //$NON-NLS-1$ if (solution.startsWith(ISolutionRepository.SEPARATOR + "")) { //$NON-NLS-1$ solution = solution.substring(1); } final int pos = solution.indexOf(ISolutionRepository.SEPARATOR); if (pos != -1) { path = solution.substring(pos + 1); solution = solution.substring(0, pos); } IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); String contextPath = requestContext.getContextPath(); final String paramServiceUrl = contextPath + "ServiceAction?solution=" //$NON-NLS-1$ + URLEncoder.encode(solution, URL_ENCODING) + "&path=" + URLEncoder.encode(path, URL_ENCODING) + "&action=" + URLEncoder.encode(name, URL_ENCODING) + "&component=xaction-parameter"; child.setAttribute("param-service-url", paramServiceUrl); final String url = contextPath + "ViewAction?solution=" //$NON-NLS-1$ + URLEncoder.encode(solution, URL_ENCODING) + "&path=" + URLEncoder.encode(path, URL_ENCODING) + "&action=" + URLEncoder.encode(name, URL_ENCODING); child.setAttribute("url", url); } else if (name.endsWith(".url")) { //$NON-NLS-1$ // add special props String props = new String(file.getData()); StringTokenizer tokenizer = new StringTokenizer(props, "\n"); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken(); int pos = line.indexOf('='); if (pos > 0) { String propname = line.substring(0, pos); String value = line.substring(pos + 1); if ((value != null) && (value.length() > 0) && (value.charAt(value.length() - 1) == '\r')) { value = value.substring(0, value.length() - 1); } if ("URL".equalsIgnoreCase(propname)) { //$NON-NLS-1$ child.setAttribute("url", value); //$NON-NLS-1$ } } } } else if (isPlugin) { // must be a plugin - make it look like a URL try { // get the file info object for this file // not all plugins are going to actually use the inputStream, so we have a special // wrapper inputstream so that we can pay that price when we need to (2X speed boost) pluginInputStream = new PluginFileInputStream(repository, file); fileInfo = pluginManager.getFileInfo(extension, session, file, pluginInputStream); String handlerId = pluginManager.getContentGeneratorIdForType(extension, session); String fileUrl = pluginManager.getContentGeneratorUrlForType(extension, session); String solution = file.getSolutionPath(); String path = ""; //$NON-NLS-1$ IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); String contextPath = requestContext.getContextPath(); if (solution.startsWith(ISolutionRepository.SEPARATOR + "")) { //$NON-NLS-1$ solution = solution.substring(1); } int pos = solution.indexOf(ISolutionRepository.SEPARATOR); if (pos != -1) { path = solution.substring(pos + 1); solution = solution.substring(0, pos); } String url = null; if (!"".equals(fileUrl)) { //$NON-NLS-1$ url = contextPath + fileUrl + "?solution=" + URLEncoder.encode(solution, URL_ENCODING) + "&path=" + URLEncoder.encode(path, URL_ENCODING) + "&action=" //$NON-NLS-1$ + URLEncoder.encode(name, URL_ENCODING); //$NON-NLS-2$ //$NON-NLS-3$ } else { IContentInfo info = pluginManager.getContentInfoFromExtension(extension, session); for (IPluginOperation operation : info.getOperations()) { if (operation.getId().equalsIgnoreCase("RUN")) { //$NON-NLS-1$ String command = operation.getCommand(); command = command.replaceAll("\\{solution\\}", //$NON-NLS-1$ URLEncoder.encode(solution, URL_ENCODING)); command = command.replaceAll("\\{path\\}", //$NON-NLS-1$ URLEncoder.encode(path, URL_ENCODING)); command = command.replaceAll("\\{name\\}", //$NON-NLS-1$ URLEncoder.encode(name, URL_ENCODING)); url = contextPath + command; break; } } if (url == null) { url = contextPath + "content/" + handlerId + "?solution=" + URLEncoder.encode(solution, URL_ENCODING) + "&path=" + URLEncoder.encode(path, URL_ENCODING) + "&action=" //$NON-NLS-1$ + URLEncoder.encode(name, URL_ENCODING); //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } child.setAttribute("url", url); //$NON-NLS-1$ // do not come up with fantasy values for a non-existing service. // if there is no param-service then do not claim that there is one. String paramUrl = null; final IContentInfo info = pluginManager.getContentInfoFromExtension(extension, session); for (final IPluginOperation operation : info.getOperations()) { if (operation.getId().equals("PARAMETER")) { //$NON-NLS-1$ String command = operation.getCommand(); command = command.replaceAll("\\{solution\\}", //$NON-NLS-1$ URLEncoder.encode(solution, URL_ENCODING)); command = command.replaceAll("\\{path\\}", //$NON-NLS-1$ URLEncoder.encode(path, URL_ENCODING)); command = command.replaceAll("\\{name\\}", //$NON-NLS-1$ URLEncoder.encode(name, URL_ENCODING)); paramUrl = contextPath + command; break; } } if (StringUtil.isEmpty(paramUrl) == false) { child.setAttribute("param-service-url", paramUrl); //$NON-NLS-1$ } } catch (Throwable t) { t.printStackTrace(); } } if (fileInfo != null) { if ("none".equals(fileInfo.getDisplayType())) // $NON-NLS-1$ { child.setAttribute("visible", "false"); //$NON-NLS-1$ //$NON-NLS-2$ } else { child.setAttribute("visible", "true"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { try { // the visibility flag for action-sequences is controlled by // /action-sequence/documentation/result-type // and we should no longer be looking at 'visible' because it was // never actually used! String visible = "none".equals(repository.getLocalizedFileProperty(file, //$NON-NLS-1$ "documentation/result-type", ISolutionRepository.ACTION_EXECUTE)) ? "false" //$NON-NLS-1$//$NON-NLS-2$ : "true"; //$NON-NLS-1$ child.setAttribute("visible", //$NON-NLS-1$ (visible == null || "".equals(visible) || "true".equals(visible)) ? "true" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ : "false"); //$NON-NLS-1$ } catch (Exception e) { child.setAttribute("visible", "true"); //$NON-NLS-1$ //$NON-NLS-2$ } } // localization try { String localizedName = null; if (name.endsWith(".url")) { //$NON-NLS-1$ localizedName = repository.getLocalizedFileProperty(file, "url_name", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); } else if (fileInfo != null) { localizedName = fileInfo.getTitle(); } else { localizedName = repository.getLocalizedFileProperty(file, "title", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); } child.setAttribute("localized-name", //$NON-NLS-1$ localizedName == null || "".equals(localizedName) ? name : localizedName); //$NON-NLS-1$ } catch (Exception e) { child.setAttribute("localized-name", name); //$NON-NLS-1$ } try { // only folders, urls and xactions have descriptions if (name.endsWith(".url")) { //$NON-NLS-1$ String url_description = repository.getLocalizedFileProperty(file, "url_description", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); String description = repository.getLocalizedFileProperty(file, "description", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); if (url_description == null && description == null) { child.setAttribute("description", name); //$NON-NLS-1$ } else { child.setAttribute("description", //$NON-NLS-1$ url_description == null || "".equals(url_description) ? description //$NON-NLS-1$ : url_description); } } else if (name.endsWith(".xaction")) { //$NON-NLS-1$ String description = repository.getLocalizedFileProperty(file, "description", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); child.setAttribute("description", //$NON-NLS-1$ description == null || "".equals(description) ? name : description); //$NON-NLS-1$ } else if (fileInfo != null) { child.setAttribute("description", fileInfo.getDescription()); //$NON-NLS-1$ } else { child.setAttribute("description", name); //$NON-NLS-1$ } } catch (Exception e) { child.setAttribute("description", "xxxxxxx"); //$NON-NLS-1$ //$NON-NLS-2$ } // add permissions for each file/folder child.setAttribute("name", name); //$NON-NLS-1$ child.setAttribute("isDirectory", "" + file.isDirectory()); //$NON-NLS-1$ //$NON-NLS-2$ child.setAttribute("lastModifiedDate", "" + file.getLastModified()); //$NON-NLS-1$ //$NON-NLS-2$ } } catch (UnsupportedEncodingException e) { // if that happens, you are running on a JDK without UTF-8 support. Get a proper JDK! throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(pluginInputStream); } } // else isfile }
From source file:org.pentaho.platform.repository.solution.SolutionRepositoryServiceImplFast.java
protected void processRepositoryFile(IPentahoSession session, boolean isAdministrator, ISolutionRepository repository, Node parentNode, ISolutionFile file, String[] filters) { final String name = file.getFileName(); // MDD 10/16/2008 Not always.. what about 'system' if (name.startsWith("system") || name.startsWith("tmp") || name.startsWith(".")) { //$NON-NLS-1$ // slip hidden files (starts with .) // skip the system & tmp dir, we DO NOT ever want this to hit the client return;//ww w . ja v a 2 s. c o m } if (!accept(isAdministrator, repository, file)) { // we don't want this file, skip to the next one return; } if (file.isDirectory()) { // we always process directories // maintain legacy behavior if (repository.getRootFolder(ISolutionRepository.ACTION_EXECUTE).getFullPath() .equals(file.getFullPath())) { // never output the root folder as part of the repo doc; skip root and process its children ISolutionFile[] children = file.listFiles(); for (ISolutionFile childSolutionFile : children) { processRepositoryFile(session, isAdministrator, repository, parentNode, childSolutionFile, filters); } return; } Element child = null; final String key = file.getFullPath() + file.getLastModified() + LocaleHelper.getLocale(); ICacheManager cacheManager = PentahoSystem.getCacheManager(null); if (cacheManager != null && cacheManager.cacheEnabled(REPOSITORY_SERVICE_FILEINFO_CACHE_REGION)) { child = (Element) cacheManager.getFromRegionCache(REPOSITORY_SERVICE_FILEINFO_CACHE_REGION, key); } if (child == null) { child = parentNode instanceof Document ? ((Document) parentNode).createElement("file") //$NON-NLS-1$ : parentNode.getOwnerDocument().createElement("file"); //$NON-NLS-1$ try { String localizedName = repository.getLocalizedFileProperty(file, "name", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); child.setAttribute("localized-name", //$NON-NLS-1$ localizedName == null || "".equals(localizedName) ? name : localizedName); //$NON-NLS-1$ } catch (Exception e) { child.setAttribute("localized-name", name); //$NON-NLS-1$ } try { String visible = repository.getLocalizedFileProperty(file, "visible", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); child.setAttribute("visible", visible == null || "".equals(visible) ? "false" : visible); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } catch (Exception e) { e.printStackTrace(); child.setAttribute("visible", "false"); //$NON-NLS-1$ //$NON-NLS-2$ } String description = repository.getLocalizedFileProperty(file, "description", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); child.setAttribute("description", //$NON-NLS-1$ description == null || "".equals(description) ? name : description); //$NON-NLS-1$ child.setAttribute("name", name); //$NON-NLS-1$ child.setAttribute("isDirectory", "true"); //$NON-NLS-1$ //$NON-NLS-2$ child.setAttribute("lastModifiedDate", "" + file.getLastModified()); //$NON-NLS-1$ //$NON-NLS-2$ if (cacheManager != null && cacheManager.cacheEnabled(REPOSITORY_SERVICE_FILEINFO_CACHE_REGION)) { cacheManager.putInRegionCache(REPOSITORY_SERVICE_FILEINFO_CACHE_REGION, key, child); } } else { Element newChild = parentNode instanceof Document ? ((Document) parentNode).createElement("file") //$NON-NLS-1$ : parentNode.getOwnerDocument().createElement("file"); //$NON-NLS-1$ NamedNodeMap attributes = child.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); newChild.setAttribute(attribute.getNodeName(), attribute.getNodeValue()); } child = newChild; } parentNode.appendChild(child); ISolutionFile[] children = file.listFiles(); for (ISolutionFile childSolutionFile : children) { processRepositoryFile(session, isAdministrator, repository, child, childSolutionFile, filters); } } else { InputStream pluginInputStream = null; try { int lastPoint = name.lastIndexOf('.'); String extension = ""; //$NON-NLS-1$ if (lastPoint != -1) { // ignore anything with no extension extension = name.substring(lastPoint + 1).toLowerCase(); } // xaction and URL support are built in boolean addFile = acceptFilter(name, filters) || "xaction".equals(extension) //$NON-NLS-1$ || "url".equals(extension); //$NON-NLS-1$ boolean isPlugin = false; // see if there is a plugin for this file type IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, session); if (pluginManager != null) { Set<String> types = pluginManager.getContentTypes(); isPlugin = types != null && types.contains(extension); addFile |= isPlugin; } if (addFile) { ICacheManager cacheManager = PentahoSystem.getCacheManager(null); Element child = null; final String key = file.getFullPath() + file.getLastModified() + LocaleHelper.getLocale(); if (cacheManager != null && cacheManager.cacheEnabled(REPOSITORY_SERVICE_FILEINFO_CACHE_REGION)) { child = (Element) cacheManager.getFromRegionCache(REPOSITORY_SERVICE_FILEINFO_CACHE_REGION, key); } if (child == null) { child = parentNode instanceof Document ? ((Document) parentNode).createElement("file") //$NON-NLS-1$ : parentNode.getOwnerDocument().createElement("file"); //$NON-NLS-1$ if (cacheManager != null && cacheManager.cacheEnabled(REPOSITORY_SERVICE_FILEINFO_CACHE_REGION)) { cacheManager.putInRegionCache(REPOSITORY_SERVICE_FILEINFO_CACHE_REGION, key, child); } } else { Element newChild = parentNode instanceof Document ? ((Document) parentNode).createElement("file") //$NON-NLS-1$ : parentNode.getOwnerDocument().createElement("file"); //$NON-NLS-1$ NamedNodeMap attributes = child.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); newChild.setAttribute(attribute.getNodeName(), attribute.getNodeValue()); } parentNode.appendChild(newChild); return; } parentNode.appendChild(child); IFileInfo fileInfo = null; try { // the visibility flag for action-sequences is controlled by // /action-sequence/documentation/result-type // and we should no longer be looking at 'visible' because it was // never actually used! String visible = "none".equals(repository.getLocalizedFileProperty(file, //$NON-NLS-1$ "documentation/result-type", ISolutionRepository.ACTION_EXECUTE)) ? "false" //$NON-NLS-1$//$NON-NLS-2$ : "true"; //$NON-NLS-1$ child.setAttribute("visible", //$NON-NLS-1$ (visible == null || "".equals(visible) || "true".equals(visible)) ? "true" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ : "false"); //$NON-NLS-1$ } catch (Exception e) { child.setAttribute("visible", "true"); //$NON-NLS-1$ //$NON-NLS-2$ } if (name.endsWith(".xaction")) { //$NON-NLS-1$ // add special props? // localization.. } else if (name.endsWith(".url")) { //$NON-NLS-1$ // add special props String props = new String(file.getData()); StringTokenizer tokenizer = new StringTokenizer(props, "\n"); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken(); int pos = line.indexOf('='); if (pos > 0) { String propname = line.substring(0, pos); String value = line.substring(pos + 1); if ((value != null) && (value.length() > 0) && (value.charAt(value.length() - 1) == '\r')) { value = value.substring(0, value.length() - 1); } if ("URL".equalsIgnoreCase(propname)) { //$NON-NLS-1$ child.setAttribute("url", value); //$NON-NLS-1$ } } } } else if (isPlugin) { // must be a plugin - make it look like a URL try { // get the file info object for this file // not all plugins are going to actually use the inputStream, so we have a special // wrapper inputstream so that we can pay that price when we need to (2X speed boost) pluginInputStream = new PluginFileInputStream(repository, file); fileInfo = pluginManager.getFileInfo(extension, session, file, pluginInputStream); String handlerId = pluginManager.getContentGeneratorIdForType(extension, session); String fileUrl = pluginManager.getContentGeneratorUrlForType(extension, session); String solution = file.getSolutionPath(); String path = ""; //$NON-NLS-1$ IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); String contextPath = requestContext.getContextPath(); if (solution.startsWith(ISolutionRepository.SEPARATOR + "")) { //$NON-NLS-1$ solution = solution.substring(1); } int pos = solution.indexOf(ISolutionRepository.SEPARATOR); if (pos != -1) { path = solution.substring(pos + 1); solution = solution.substring(0, pos); } String url = null; if (!"".equals(fileUrl)) { //$NON-NLS-1$ url = contextPath + fileUrl //$NON-NLS-1$ + "?solution=" + solution + "&path=" + path + "&action=" + name; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else { IContentInfo info = pluginManager.getContentInfoFromExtension(extension, session); for (IPluginOperation operation : info.getOperations()) { if (operation.getId().equalsIgnoreCase("RUN")) { //$NON-NLS-1$ String command = operation.getCommand(); command = command.replaceAll("\\{solution\\}", solution); //$NON-NLS-1$ command = command.replaceAll("\\{path\\}", path); //$NON-NLS-1$ command = command.replaceAll("\\{name\\}", name); //$NON-NLS-1$ url = contextPath + command; //$NON-NLS-1$ break; } } if (url == null) { url = contextPath + "content/" + handlerId + "?solution=" + solution + "&path=" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + path + "&action=" + name; //$NON-NLS-1$ } } child.setAttribute("url", url); //$NON-NLS-1$ String paramServiceUrl = contextPath + "content/" + handlerId + "?solution=" + solution //$NON-NLS-1$//$NON-NLS-2$ + "&path=" + path + "&action=" + name; //$NON-NLS-1$ //$NON-NLS-2$ child.setAttribute("param-service-url", paramServiceUrl); //$NON-NLS-1$ } catch (Throwable t) { t.printStackTrace(); } } // localization try { String localizedName = null; if (name.endsWith(".url")) { //$NON-NLS-1$ localizedName = repository.getLocalizedFileProperty(file, "url_name", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); } else if (fileInfo != null) { localizedName = fileInfo.getTitle(); } else { localizedName = repository.getLocalizedFileProperty(file, "title", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); } child.setAttribute("localized-name", //$NON-NLS-1$ localizedName == null || "".equals(localizedName) ? name : localizedName); //$NON-NLS-1$ } catch (Exception e) { child.setAttribute("localized-name", name); //$NON-NLS-1$ } try { // only folders, urls and xactions have descriptions if (name.endsWith(".url")) { //$NON-NLS-1$ String url_description = repository.getLocalizedFileProperty(file, "url_description", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); String description = repository.getLocalizedFileProperty(file, "description", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); if (url_description == null && description == null) { child.setAttribute("description", name); //$NON-NLS-1$ } else { child.setAttribute("description", //$NON-NLS-1$ url_description == null || "".equals(url_description) ? description //$NON-NLS-1$ : url_description); } } else if (name.endsWith(".xaction")) { //$NON-NLS-1$ String description = repository.getLocalizedFileProperty(file, "description", //$NON-NLS-1$ ISolutionRepository.ACTION_EXECUTE); child.setAttribute("description", //$NON-NLS-1$ description == null || "".equals(description) ? name : description); //$NON-NLS-1$ } else if (fileInfo != null) { child.setAttribute("description", fileInfo.getDescription()); //$NON-NLS-1$ } else { child.setAttribute("description", name); //$NON-NLS-1$ } } catch (Exception e) { child.setAttribute("description", "xxxxxxx"); //$NON-NLS-1$ //$NON-NLS-2$ } // add permissions for each file/folder child.setAttribute("name", name); //$NON-NLS-1$ child.setAttribute("isDirectory", "" + file.isDirectory()); //$NON-NLS-1$ //$NON-NLS-2$ child.setAttribute("lastModifiedDate", "" + file.getLastModified()); //$NON-NLS-1$ //$NON-NLS-2$ } } finally { IOUtils.closeQuietly(pluginInputStream); } } // else isfile }
From source file:org.pepstock.jem.jbpm.XmlParser.java
/** * Scans all children of PROCESS element, all BPMN tasks * @param list list of task, children of process * @return collection of tasks// www . j a va 2 s.c o m */ private static List<TaskDescription> getTasks(NodeList list) { // creates list of tasks to return List<TaskDescription> result = new ArrayList<TaskDescription>(); // scans all nodes for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); // gets tagname String tagName = getElementName(node); // checks if is TASK element if (tagName != null && TASK_ELEMENT.equalsIgnoreCase(tagName)) { Element element = (Element) node; boolean isJemWorkItem = false; // scans attributes to check if is a JEM node for (int k = 0; k < element.getAttributes().getLength(); k++) { // gets attribute and value String attrName = element.getAttributes().item(k).getNodeName(); String value = element.getAttributes().item(k).getTextContent(); // checks if the task is a JEM task. // chekcs if there is a namespace also if (value != null && (attrName.endsWith(":" + TASK_NAME_ATTRIBUTE) || attrName.equalsIgnoreCase(TASK_NAME_ATTRIBUTE))) { isJemWorkItem = value.equalsIgnoreCase(JBpmKeys.JBPM_JEM_WORKITEM_NAME); } } // if it has found JEM task, loads information to task if (isJemWorkItem && element.hasChildNodes()) { // loads data TaskDescription task = new TaskDescription(); task.setId(element.getAttribute(ID_ATTRIBUTE)); task.setName(element.getAttribute(NAME_ATTRIBUTE)); // gets IOSPECIFICATION, where all IO information are written task.setIoSpecification(getIoSpecification(element.getChildNodes())); result.add(task); } } } return result; }