List of usage examples for org.w3c.dom Element hasAttribute
public boolean hasAttribute(String name);
true
when an attribute with a given name is specified on this element or has a default value, false
otherwise. From source file:eu.europa.ec.markt.dss.validation102853.xades.XAdESSignature.java
@Override public SignatureCryptographicVerification checkIntegrity(DSSDocument detachedDocument) { final SignatureCryptographicVerification scv = new SignatureCryptographicVerification(); final CertificateToken certToken = getSigningCertificate().getCertToken(); if (certToken != null) { final PublicKey publicKey = certToken.getCertificate().getPublicKey(); final KeySelector keySelector = KeySelector.singletonKeySelector(publicKey); /**//from ww w. jav a 2 s. com * Creating a Validation Context<br> * We create an XMLValidateContext instance containing input parameters for validating the signature. Since we * are using DOM, we instantiate a DOMValidateContext instance (a subclass of XMLValidateContext), and pass it * two parameters, a KeyValueKeySelector object and a reference to the Signature element to be validated (which * is the first entry of the NodeList we generated earlier): */ final DOMValidateContext valContext = new DOMValidateContext(keySelector, signatureElement); try { URIDereferencer dereferencer = new ExternalFileURIDereferencer(detachedDocument); valContext.setURIDereferencer(dereferencer); /** * This property controls whether or not the digested Reference objects will cache the dereferenced content * and pre-digested input for subsequent retrieval via the Reference.getDereferencedData and * Reference.getDigestInputStream methods. The default value if not specified is Boolean.FALSE. */ valContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE); /** * Unmarshalling the XML Signature<br> * We extract the contents of the Signature element into an XMLSignature object. This process is called * unmarshalling. The Signature element is unmarshalled using an XMLSignatureFactory object. An application * can obtain a DOM implementation of XMLSignatureFactory by calling the following line of code: */ // These providers do not support ECDSA algorithm // factory = XMLSignatureFactory.getInstance("DOM"); // factory = XMLSignatureFactory.getInstance("DOM", "XMLDSig"); // factory = XMLSignatureFactory.getInstance("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI()); // This provider support ECDSA signature /** * ApacheXMLDSig / Apache Santuario XMLDSig (DOM XMLSignatureFactory; DOM KeyInfoFactory; C14N 1.0, C14N * 1.1, Exclusive C14N, Base64, Enveloped, XPath, XPath2, XSLT TransformServices)<br> * If this library is used than the same library must be used for the URIDereferencer. */ final XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM", xmlProvider); /** * We then invoke the unmarshalXMLSignature method of the factory to unmarshal an XMLSignature object, and * pass it the validation context we created earlier: */ final XMLSignature signature = factory.unmarshalXMLSignature(valContext); //System.out.println("XMLSignature class: " + signature.getClass()); // Austrian specific signature //org.apache.xml.security.signature.XMLSignature signature_ = null; // try { // signature_ = new org.apache.xml.security.signature.XMLSignature(signatureElement, ""); // } catch (Exception e) { // // throw new DSSException(e); // } // signature.addResourceResolver(new XPointerResourceResolver(signatureElement)); //signature_.getSignedInfo().verifyReferences();//getVerificationResult(1); /** * In case of org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI() provider, the ID attributes need to be set * manually.<br> * The DSSXMLUtils.recursiveIdBrowse(...) method do not take into account the XML outside of the Signature * tag. It prevents some signatures to be validated.<br> * * Solution: the following lines where added: */ final Document document = signatureElement.getOwnerDocument(); final Element rootElement = document.getDocumentElement(); if (rootElement.hasAttribute(DSSXMLUtils.ID_ATTRIBUTE_NAME)) { valContext.setIdAttributeNS(rootElement, null, DSSXMLUtils.ID_ATTRIBUTE_NAME); } DSSXMLUtils.recursiveIdBrowse(valContext, rootElement); /** * Validating the XML Signature<br> * Now we are ready to validate the signature. We do this by invoking the validate method on the * XMLSignature object, and pass it the validation context as follows: */ boolean coreValidity = false; try { coreValidity = signature.validate(valContext); } catch (XMLSignatureException e) { scv.setErrorMessage("Signature validation: " + e.getMessage()); } boolean signatureValidity = coreValidity; boolean dataFound = true; boolean dataHashValid = true; /** * If the XMLSignature.validate method returns false, we can try to narrow down the cause of the failure. * There are two phases in core XML Signature validation: <br> * - Signature validation (the cryptographic verification of the signature)<br> * - Reference validation (the verification of the digest of each reference in the signature)<br> * Each phase must be successful for the signature to be valid. To check if the signature failed to * cryptographically validate, we can check the status, as follows: */ try { signatureValidity = signature.getSignatureValue().validate(valContext); } catch (XMLSignatureException e) { scv.setErrorMessage(e.getMessage()); } @SuppressWarnings("unchecked") final List<Reference> references = signature.getSignedInfo().getReferences(); for (Reference reference : references) { boolean refHashValidity = false; try { refHashValidity = reference.validate(valContext); } catch (XMLSignatureException e) { scv.setErrorMessage(reference.getURI() + ": " + e.getMessage()); } dataHashValid = dataHashValid && refHashValidity; if (LOG.isLoggable(Level.INFO)) { LOG.info("Reference hash validity checked: " + reference.getURI() + "=" + refHashValidity); } final Data data = reference.getDereferencedData(); dataFound = dataFound && (data != null); final InputStream digestInputStream = reference.getDigestInputStream(); if (data != null && digestInputStream != null) { // The references are saved for later treatment in -A level. try { IOUtils.copy(digestInputStream, referencesDigestOutputStream); } catch (IOException e) { } } } scv.setReferenceDataFound(dataFound); scv.setReferenceDataIntact(dataHashValid); scv.setSignatureIntegrity(signatureValidity); } catch (MarshalException e) { scv.setErrorMessage(e.getMessage()); } } else { scv.setErrorMessage( "Unable to proceed with the signature cryptographic verification. There is no signing certificate!"); } return scv; }
From source file:eap.config.ConfigBeanDefinitionParser.java
/** * Parses one of '{@code before}', '{@code after}', '{@code after-returning}', * '{@code after-throwing}' or '{@code around}' and registers the resulting * BeanDefinition with the supplied BeanDefinitionRegistry. * @return the generated advice RootBeanDefinition *//*w w w . ja v a 2 s. com*/ private AbstractBeanDefinition parseAdvice(String aspectName, int order, Element aspectElement, Element adviceElement, ParserContext parserContext, List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) { try { this.parseState.push(new AdviceEntry(parserContext.getDelegate().getLocalName(adviceElement))); // create the method factory bean RootBeanDefinition methodDefinition = new RootBeanDefinition(MethodLocatingFactoryBean.class); methodDefinition.getPropertyValues().add("targetBeanName", aspectName); methodDefinition.getPropertyValues().add("methodName", adviceElement.getAttribute("method")); methodDefinition.setSynthetic(true); // create instance factory definition RootBeanDefinition aspectFactoryDef = new RootBeanDefinition( SimpleBeanFactoryAwareAspectInstanceFactory.class); aspectFactoryDef.getPropertyValues().add("aspectBeanName", aspectName); aspectFactoryDef.setSynthetic(true); // register the pointcut AbstractBeanDefinition adviceDef = createAdviceDefinition(adviceElement, parserContext, aspectName, order, methodDefinition, aspectFactoryDef, beanDefinitions, beanReferences); // configure the advisor RootBeanDefinition advisorDefinition = new RootBeanDefinition(AspectJPointcutAdvisor.class); advisorDefinition.setSource(parserContext.extractSource(adviceElement)); advisorDefinition.getConstructorArgumentValues().addGenericArgumentValue(adviceDef); if (aspectElement.hasAttribute(ORDER_PROPERTY)) { advisorDefinition.getPropertyValues().add(ORDER_PROPERTY, aspectElement.getAttribute(ORDER_PROPERTY)); } // register the final advisor parserContext.getReaderContext().registerWithGeneratedName(advisorDefinition); return advisorDefinition; } finally { this.parseState.pop(); } }
From source file:com.twinsoft.convertigo.beans.core.Sequence.java
@Override public void parseInputDocument(Context context) throws EngineException { super.parseInputDocument(context); if (context.inputDocument != null && Engine.logContext.isInfoEnabled()) { Document printDoc = (Document) Visibility.Logs.replaceVariables(getVariablesList(), context.inputDocument);/*www. ja v a2 s. c o m*/ XMLUtils.logXml(printDoc, Engine.logContext, "Input document"); } NodeList variableNodes = context.inputDocument.getElementsByTagName("variable"); int len = variableNodes.getLength(); variables.clear(); for (int i = 0; i < len; i++) { Element variableNode = (Element) variableNodes.item(i); String variableName = variableNode.getAttribute("name"); String variableValue = (variableNode.hasAttribute("value") ? variableNode.getAttribute("value") : null); Attr valueAttrNode = variableNode.getAttributeNode("value"); // Test case for sequence if (variableName.indexOf(Parameter.Testcase.getName()) == 0) { TestCase testcase = getTestCaseByName(variableValue); if (testcase != null) { String testCaseVariableName; Object testCaseVariableValue; // Add test case variables default value(s) for (TestCaseVariable testCaseVariable : testcase.getVariables()) { testCaseVariableName = testCaseVariable.getName(); testCaseVariableValue = testcase.getVariableValue(testCaseVariableName); if (testCaseVariableValue != null) { variables.put(testCaseVariableName, testCaseVariableValue); } } } else { if (Engine.logBeans.isInfoEnabled()) Engine.logBeans.warn("Sequence: there's no testcase named '" + variableValue + "' for '" + getName() + "' sequence"); } continue; } // Standard variable case RequestableVariable variable = (RequestableVariable) getVariable(variableName); // Structured value? Object scopeValue = (variableValue != null) ? variableValue : variableNode.getChildNodes(); // Multivalued variable ? if ((variable != null) && (variable.isMultiValued())) { List<Object> current = GenericUtils.cast(variables.get(variableName)); if (current == null) { current = new LinkedList<Object>(); variables.put(variableName, current); } if (variableValue == null || valueAttrNode != null) { current.add(scopeValue); } } else { variables.put(variableName, scopeValue); } } // Enumeration of all sequence variables if (Engine.logBeans.isDebugEnabled()) Engine.logBeans.debug("Sequence variables: " + (variables == null ? "none" : Visibility.Logs.replaceVariables(getVariablesList(), variables))); }
From source file:autohit.creator.compiler.SimCompiler.java
/** * handle call./*from ww w .j ava 2 s .co m*/ * MICROCODE * 1- i.scope * 2- (SET)* * 3- i.call(name) * 4- i.rscope * 5- if (result exist) i.store(result) */ private void handleCall(Element en) { String name = en.getAttribute(ATTR_NAME); runtimeDebug("handleCall. call=" + name); // 1- i.scope this.emitScope(); // 2- (SET)* try { // recurse into the children processCode(en); // 3- i.call(name) this.emitCall(name); } catch (Exception e) { // Stop an error unravelling here. Close the scope and move on runtimeError("ERROR handleCall. Broken call." + name); runtimeError(e.toString()); this.emitRScope(); return; } // 4- i.rscope this.emitRScope(); // 5- if (result exist) i.store(result) if (en.hasAttribute(ATTR_RESULT)) { this.emitStore(en.getAttribute(ATTR_RESULT)); } }
From source file:autohit.creator.compiler.SimCompiler.java
/** * handle exec.//from ww w . j a v a 2 s . c o m * MICROCODE * 1- i.scope * 2- (INPUT)* * 3- i.exec(name) * 4- i.rscope * 5- if (result exist) i.store(result) */ private void handleExec(Element en) { String name = en.getAttribute(ATTR_NAME); runtimeDebug("handleExec. exec=" + name); // 1- i.scope this.emitScope(); // 2- (INPUT)* try { // recurse into the children processCode(en); // 3- i.call(name) this.emitExec(name); } catch (Exception e) { // Stop an error unravelling here. Close the scope and move on runtimeError("ERROR handleExec. Broken exec." + name); runtimeError(e.toString()); this.emitRScope(); return; } // 4- i.rscope this.emitRScope(); // 5- if (result exist) i.store(result) if (en.hasAttribute(ATTR_RESULT)) { this.emitStore(en.getAttribute(ATTR_RESULT)); } }
From source file:com.mtgi.analytics.aop.config.v11.BtPersisterChainBeanDefinitionParser.java
@Override @SuppressWarnings("unchecked") protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //propagate shared template factory into sub-components if necessary. this would not be //necessary if parserContext gave us access to the entire component stack instead of just the //top. In that case, deeply nested children could search up the stack until they found //the template. perhaps a future version of the Spring API will support this. DefaultListableBeanFactory template = findEnclosingTemplateFactory(parserContext); if (template != null) parserContext.pushContainingComponent(new TemplateComponentDefinition(element.getNodeName(), parserContext.extractSource(element), template)); try {//w ww . j a va 2s .c o m //parse delegate persister definitions ManagedList persisters = new ManagedList(); persisters.setSource(element); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); ++i) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String namespaceUri = node.getNamespaceURI(); NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(namespaceUri); Object def = handler == null ? parserContext.getDelegate().parsePropertySubElement((Element) node, builder.getRawBeanDefinition()) : handler.parse((Element) node, parserContext); persisters.add(def); } } builder.addPropertyValue("delegates", persisters); } finally { if (template != null) parserContext.popContainingComponent(); } //register persister implementation with parent. if (parserContext.isNested()) { AbstractBeanDefinition def = builder.getBeanDefinition(); String id = element.hasAttribute("id") ? element.getAttribute("id") : parserContext.getReaderContext().generateBeanName(def); BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id); BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext); } }
From source file:autohit.creator.compiler.SimCompiler.java
/** * handle subroutine./*from w ww . ja va 2 s .c o m*/ * MICROCODE * 1- i.scope * 2- (SET)* * 3- i.subr(name) * 4- i.rscope * 5- if (result exist) i.store(result) */ private void handleSubroutine(Element en) { String name = en.getAttribute(ATTR_NAME); runtimeDebug("handleSubroutine. name=" + name); // 1- i.scope this.emitScope(); // 2- (SET)* try { // recurse into the children processCode(en); // 3- i.call(name) this.emitSubr(name); } catch (Exception e) { // Stop an error unravelling here. Close the scope and move on runtimeError("ERROR handleCall. Broken call." + name); runtimeError(e.toString()); ob.emit(new VMIRScope()); return; } // 4- i.rscope this.emitRScope(); // 5- if (result exist) i.store(result) if (en.hasAttribute(ATTR_RESULT)) { this.emitStore(en.getAttribute(ATTR_RESULT)); } }
From source file:com.mtgi.analytics.aop.config.v11.BtManagerBeanDefinitionParser.java
@Override protected void transform(ConfigurableListableBeanFactory factory, BeanDefinition template, Element element, ParserContext parserContext) {/*from w w w .ja va 2s .c om*/ ManagerComponentDefinition def = (ManagerComponentDefinition) parserContext.getContainingComponent(); String managerId = overrideAttribute(ATT_ID, template, element); if (managerId == null) template.setAttribute(ATT_ID, managerId = "defaultTrackingManager"); if ("false".equals(element.getAttribute(ATT_ENABLED))) { //manager is disabled. replace definition with dummy instance. template.setBeanClassName(DisabledBehaviorTrackingManager.class.getName()); //clear properties and attributes. for (String att : template.attributeNames()) if (!ATT_ID.equals(att)) template.removeAttribute(att); template.getPropertyValues().clear(); //terminate immediately, do not parse any nested definitions (persisters, AOP config, context beans, etc) return; } overrideProperty(ATT_APPLICATION, template, element, false); overrideProperty(ATT_FLUSH_THRESHOLD, template, element, false); //wake up MBeanExporter if we're going to be doing MBean registration. if ("true".equalsIgnoreCase(element.getAttribute(ATT_REGISTER_MBEANS))) { AbstractBeanDefinition exporter = (AbstractBeanDefinition) factory .getBeanDefinition(CONFIG_MBEAN_EXPORTER); exporter.setLazyInit(false); //append manager ID to mbean name, in case of multiple managers in a single application. BeanDefinition naming = factory.getBeanDefinition(CONFIG_NAMING_STRATEGY); naming.getPropertyValues().addPropertyValue("value", managerId); } //prefer references to beans in the parent factory if they've been specified if (element.hasAttribute(ATT_MBEAN_SERVER)) factory.registerAlias(element.getAttribute(ATT_MBEAN_SERVER), CONFIG_MBEAN_SERVER); if (element.hasAttribute(ATT_SCHEDULER)) factory.registerAlias(element.getAttribute(ATT_SCHEDULER), CONFIG_SCHEDULER); if (element.hasAttribute(ATT_TASK_EXECUTOR)) factory.registerAlias(element.getAttribute(ATT_TASK_EXECUTOR), CONFIG_EXECUTOR); //make note of external persister element so that we don't activate log rotation. if (element.hasAttribute(ATT_PERSISTER)) { def.addNestedProperty(ATT_PERSISTER); MutablePropertyValues props = template.getPropertyValues(); props.removePropertyValue(ATT_PERSISTER); props.addPropertyValue(ATT_PERSISTER, new RuntimeBeanReference(element.getAttribute(ATT_PERSISTER))); } if (element.hasAttribute(ATT_SESSION_CONTEXT)) { //override default session context with reference def.addNestedProperty("sessionContext"); factory.registerAlias(element.getAttribute(ATT_SESSION_CONTEXT), CONFIG_SESSION_CONTEXT); } //handle AOP configuration if needed if (element.hasAttribute(ATT_METHOD_EXPRESSION)) { //activate global AOP proxying if it hasn't already been done (borrowed logic from AopNamespaceHandler / config element parser) activateAopProxies(parserContext, element); //register pointcut definition for the provided expression. RootBeanDefinition pointcut = new RootBeanDefinition(AspectJExpressionPointcut.class); //rely on deprecated method to maintain spring 2.0 support pointcut.setSingleton(false); pointcut.setSynthetic(true); pointcut.getPropertyValues().addPropertyValue("expression", element.getAttribute(ATT_METHOD_EXPRESSION)); //create implicit pointcut advice bean. RootBeanDefinition advice = new RootBeanDefinition(BehaviorTrackingAdvice.class); advice.getPropertyValues().addPropertyValue("trackingManager", new RuntimeBeanReference(managerId)); //register advice, pointcut, and advisor entry to bind the two together. XmlReaderContext ctx = parserContext.getReaderContext(); String pointcutId = ctx.registerWithGeneratedName(pointcut); String adviceId = ctx.registerWithGeneratedName(advice); RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class); advisorDefinition.getPropertyValues().addPropertyValue("adviceBeanName", new RuntimeBeanNameReference(adviceId)); advisorDefinition.getPropertyValues().addPropertyValue("pointcut", new RuntimeBeanReference(pointcutId)); ctx.registerWithGeneratedName(advisorDefinition); } //configure flush trigger and job to be globally unique based on manager name. BeanDefinition flushTrigger = factory.getBeanDefinition("com.mtgi.analytics.btFlushTrigger"); SchedulerActivationPostProcessor.configureTriggerDefinition(flushTrigger, element.getAttribute(ATT_FLUSH_SCHEDULE), managerId + "_flush"); //set up a post-processor to register the flush job with the selected scheduler instance. the job and scheduler //come from the template factory, but the post-processor runs when the currently-parsing factory is finished. SchedulerActivationPostProcessor.registerPostProcessor(parserContext, factory, CONFIG_SCHEDULER, CONFIG_NAMESPACE + ".btFlushTrigger"); //ManagerComponentDefinition is a flag to nested parsers that they should push their parsed bean definitions into //the manager bean definition. for example, see BtPersisterBeanDefinitionParser. //descend on nested child nodes to pick up persister and session context configuration NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String namespaceUri = node.getNamespaceURI(); NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(namespaceUri); ParserContext nestedCtx = new ParserContext(parserContext.getReaderContext(), parserContext.getDelegate(), template); nestedCtx.pushContainingComponent(def); handler.parse((Element) node, nestedCtx); } } if (!def.nestedProperties.contains(ATT_PERSISTER)) { //no persister registered. schedule default log rotation trigger. BtXmlPersisterBeanDefinitionParser.configureLogRotation(parserContext, factory, null); } if (!def.nestedProperties.contains("sessionContext")) { //custom session context not registered. select appropriate default class //depending on whether we are in a web context or not. if (parserContext.getReaderContext().getReader().getResourceLoader() instanceof WebApplicationContext) { BeanDefinition scDef = factory.getBeanDefinition(CONFIG_SESSION_CONTEXT); scDef.setBeanClassName(SpringSessionContext.class.getName()); } } }
From source file:autohit.creator.compiler.SimCompiler.java
/** * Processes info section tags. /*from w w w . j a v a 2 s . c om*/ */ private void processItem(Element en) throws Exception { String tempText; String name; //runtimeDebug("ENTER --- " + en.getTagName()); name = en.getTagName().toLowerCase(); NodeList itemTreeChildren; int idx; Node sNode; // Parse the token and call a handler if (name.charAt(0) == 'n') { if (name.charAt(1) == 'a') { //NAME tempText = getText(en.getFirstChild()); if (tempText == null) { runtimeError("Empty <name> tag."); } else { ob.exec.name = tempText; runtimeDebug("TAG <name> name= " + ob.exec.name); } // optional uid attribute if (en.hasAttribute(ATTR_UID)) { ob.exec.uid = en.getAttribute(ATTR_UID); localname = ob.exec.uid; runtimeDebug("TAG <name> uid= " + ob.exec.uid); } } else { // NOTE - optional tempText = getText(en.getFirstChild()); ob.exec.note = tempText; } } else if (name.charAt(0) == 'v') { // VERSION ob.exec.major = 0; try { if (en.hasAttribute(ATTR_VERSIONNUMBER)) { tempText = en.getAttribute(ATTR_VERSIONNUMBER); ob.exec.major = Integer.parseInt(tempText); runtimeDebug("TAG <version> num= " + ob.exec.major); } else { runtimeError("ERROR: TAG<version> Attr num not present."); } } catch (Exception e) { runtimeError("ERROR: TAG<version> Could not parse value for Attr num."); } } else if (name.charAt(0) == 'i') { if (name.charAt(1) == 'o') { // IO - Recurse with it's children. itemTreeChildren = en.getChildNodes(); for (idx = 0; idx < itemTreeChildren.getLength(); idx++) { sNode = itemTreeChildren.item(idx); if (sNode instanceof Element) { processItem((Element) sNode); } } } else { // INPUT - NOT SUPPORTED } } else if (name.charAt(0) == 'b') { // BUFFER - NOT SUPPORTED } else if (name.charAt(0) == 'o') { ob.exec.output = new NVPair(); // OUTPUT - Specifies the output variable ob.exec.output.name = en.getAttribute(ATTR_NAME); if (en.hasAttribute(ATTR_TYPE)) { ob.exec.output.value = en.getAttribute(ATTR_TYPE); } } else { runtimeError("Software Detected Fault: creator.compiler.SimCompiler.processItem(). The textual token [" + en.getNodeName() + "] should have NOT reached this code. Check the XML DTD associated with the SimCompiler."); throw (new Exception("Software Detected Fault in creator.compiler.SimCompiler.processItem().")); } //DEBUG //runtimeDebug("EXIT --- " + en.getTagName()); }
From source file:com.concursive.connect.cms.portal.dao.DashboardTemplateList.java
private void parseLibrary(XMLUtils library) { LOG.debug("objectType=" + objectType); LOG.debug("has xml? " + (library != null)); if (LOG.isTraceEnabled()) { LOG.trace(library.toString());/*from w w w .j a v a 2 s .c o m*/ } // Use XPath for querying xml elements XPath xpath = XPathFactory.newInstance().newXPath(); // Build a list of dashboard pages ArrayList<Element> pageElements = new ArrayList<Element>(); XMLUtils.getAllChildren(XMLUtils.getFirstChild(library.getDocumentElement(), objectType), "page", pageElements); Iterator i = pageElements.iterator(); int count = 0; while (i.hasNext()) { ++count; Element el = (Element) i.next(); DashboardTemplate thisTemplate = new DashboardTemplate(); thisTemplate.setId(count); thisTemplate.setName(el.getAttribute("name")); // Check for xml included fragments declaration // <xml-include fragment="portal-fragments-id"/> // NOTE: since the document is being read as a resource, xinclude and xpointer could not be used // mainly due to xpointer not being implemented try { NodeList includeList = (NodeList) xpath.evaluate("row/column/portlet/xml-include", el, XPathConstants.NODESET); // XML Include found, so find all the fragments for (int nodeIndex = 0; nodeIndex < includeList.getLength(); nodeIndex++) { Node xmlInclude = includeList.item(nodeIndex); String fragmentId = ((Element) xmlInclude).getAttribute("fragment"); NodeList fragmentNodeList = (NodeList) xpath.evaluate( "*/fragment[@id=\"" + fragmentId + "\"]/*", library.getDocumentElement(), XPathConstants.NODESET); if (LOG.isDebugEnabled() && fragmentNodeList.getLength() == 0) { LOG.error("Could not find fragment with id: " + fragmentId); } for (int prefIndex = 0; prefIndex < fragmentNodeList.getLength(); prefIndex++) { xmlInclude.getParentNode().appendChild(fragmentNodeList.item(prefIndex).cloneNode(true)); } // Remove the XML Include declaration xmlInclude.getParentNode().removeChild(xmlInclude); } } catch (Exception e) { LOG.error("Replace xml fragments", e); } // Set the completed xml layout thisTemplate.setXmlDesign(XMLUtils.toString(el)); // Check for properties that affect the rendering of the portal page if (el.hasAttribute("permission")) { thisTemplate.setPermission(el.getAttribute("permission")); } if (el.hasAttribute("title")) { thisTemplate.setTitle(el.getAttribute("title")); } if (el.hasAttribute("description")) { thisTemplate.setDescription(el.getAttribute("description")); } if (el.hasAttribute("keywords")) { thisTemplate.setKeywords(el.getAttribute("keywords")); } if (el.hasAttribute("category")) { thisTemplate.setCategory(el.getAttribute("category")); } this.add(thisTemplate); } }