List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:com.fujitsu.dc.test.jersey.bar.BarInstallTest.java
/** * bar?????????./*from ww w . jav a2 s .c o m*/ */ private void checkRegistData() { final String token = AbstractCase.MASTER_TOKEN_NAME; final String colName = "odatacol1"; final String roleName = "../__/role1"; final String nameSpace = "http://www.w3.com/standards/z39.50/"; List<String> rolList = new ArrayList<String>(); rolList.add("read"); rolList.add("write"); String resorce = UrlUtils.box(Setup.TEST_CELL1, INSTALL_TARGET); StringBuffer sb = new StringBuffer(resorce); // UrlUtil???URL??? String boxUrl = sb.deleteCharAt(resorce.length() - 1).toString(); // ? BoxUtils.get(Setup.TEST_CELL1, token, INSTALL_TARGET, HttpStatus.SC_OK); RelationUtils.get(Setup.TEST_CELL1, token, "relation1", INSTALL_TARGET, HttpStatus.SC_OK); RelationUtils.get(Setup.TEST_CELL1, token, "relation2", INSTALL_TARGET, HttpStatus.SC_OK); RelationUtils.get(Setup.TEST_CELL1, token, "relation3", INSTALL_TARGET, HttpStatus.SC_OK); RoleUtils.get(Setup.TEST_CELL1, token, "role1", INSTALL_TARGET, HttpStatus.SC_OK); RoleUtils.get(Setup.TEST_CELL1, token, "role2", INSTALL_TARGET, HttpStatus.SC_OK); RoleUtils.get(Setup.TEST_CELL1, token, "role3", INSTALL_TARGET, HttpStatus.SC_OK); // ComplexType? checkComplexType(Setup.TEST_CELL1, INSTALL_TARGET, colName, "complex1"); checkComplexType(Setup.TEST_CELL1, INSTALL_TARGET, colName, "complex2"); // EntityType? checkEntityType(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity1"); checkEntityType(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity2"); // AssociationEnd? checkAssocEnd(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity1", "entity1-entity2"); checkAssocEnd(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity2", "entity2-entity1"); // AssociationEnd?$links? checkAssocEndLinks(colName); // Property?? checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity1", null, "property1", true); checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity1", null, "property2", true); checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity2", null, "property3", false); // ComplexTypeProperty?? checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, null, "complex1", "compProp1", true); checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, null, "complex1", "compProp2", true); checkProperty(Setup.TEST_CELL1, INSTALL_TARGET, colName, null, "complex2", "compProp3", false); // ?? checkUserData(Setup.TEST_CELL1, INSTALL_TARGET, colName, "entity3", "barInstallTest"); // OdataCollection?ACL? TResponse res = BarInstallTestUtils.propfind(Setup.TEST_CELL1, INSTALL_TARGET, colName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_MULTI_STATUS); Element root = res.bodyAsXml().getDocumentElement(); // DavCollection?ACL? checkAcl(root, rolList, roleName, boxUrl + "/" + colName); // DavCollection DavResourceUtils.getWebDavFile(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, "box/dav-get.txt", INSTALL_TARGET, "webdavcol1", HttpStatus.SC_OK); // DavCollection?PROPFIND res = BarInstallTestUtils.propfind(Setup.TEST_CELL1, INSTALL_TARGET, "webdavcol1", "0", AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_MULTI_STATUS); root = res.bodyAsXml().getDocumentElement(); // DavCollection?ACL? checkAcl(root, rolList, roleName, boxUrl + "/webdavcol1"); // DavCollection?Author? String author = root.getElementsByTagNameNS(nameSpace, "Author").item(0).getFirstChild().getNodeValue(); assertEquals("Test User2", author); // DavFile DavResourceUtils.getWebDavFile(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, "box/dav-get.txt", INSTALL_TARGET, "webdavcol1/testdavfile.txt", HttpStatus.SC_OK); // ServiceCollection BarInstallTestUtils.propfind(Setup.TEST_CELL1, INSTALL_TARGET, "svccol1", AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_MULTI_STATUS); // ServiceFile DavResourceUtils.getWebDavFile(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, "box/dav-get.txt", INSTALL_TARGET, "svccol1/__src/test.js", HttpStatus.SC_OK); // Box?? res = DavResourceUtils.propfind("box/propfind-box-allprop.txt", token, HttpStatus.SC_MULTI_STATUS, INSTALL_TARGET); root = res.bodyAsXml().getDocumentElement(); // BOX?ACL? checkAcl(root, rolList, roleName, boxUrl); // Box Author?? author = root.getElementsByTagNameNS(nameSpace, "Author").item(0).getFirstChild().getNodeValue(); assertEquals("Test User1", author); }
From source file:eu.europa.ec.markt.dss.applet.view.validationpolicy.EditView.java
private void nodeActionAdd(MouseEvent mouseEvent, final int selectedRow, final TreePath selectedPath, final XmlDomAdapterNode clickedItem, final JTree tree) { final Element clickedElement = (Element) clickedItem.node; // popup menu for list -> add final JPopupMenu popup = new JPopupMenu(); //delete node final JMenuItem menuItemToDelete = new JMenuItem(ResourceUtils.getI18n("DELETE")); menuItemToDelete.addActionListener(new ActionListener() { @Override//from www. java2 s .com public void actionPerformed(ActionEvent actionEvent) { // find the order# of the child to delete final int index = clickedItem.getParent().index(clickedItem); Node oldChild = clickedElement.getParentNode().removeChild(clickedElement); if (index > -1) { validationPolicyTreeModel.fireTreeNodesRemoved(selectedPath.getParentPath(), index, oldChild); } } }); popup.add(menuItemToDelete); //Add node/value final Map<XsdNode, Object> xsdTree = validationPolicyTreeModel.getXsdTree(); final List<XsdNode> children = getChildrenToAdd(clickedElement, xsdTree); for (final XsdNode xsdChild : children) { final String xmlName = xsdChild.getLastNameOfPath(); final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("ADD") + " (" + xmlName + " " + xsdChild.getType().toString().toLowerCase() + ")"); popup.add(menuItem); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Document document = getModel().getValidationPolicy().getDocument(); final Node newElement; if (xsdChild.getType() == XsdNodeType.TEXT) { // TEXT element always appended (last child) newElement = clickedElement.appendChild(document.createTextNode("VALUE")); } else if (xsdChild.getType() == XsdNodeType.ATTRIBUTE) { newElement = document.createAttributeNS(null, xmlName); ((Attr) newElement).setValue("VALUE"); clickedElement.setAttributeNode((Attr) newElement); } else if (xsdChild.getType() == XsdNodeType.ELEMENT) { final Element childToAdd = document .createElementNS("http://dss.markt.ec.europa.eu/validation/diagnostic", xmlName); // find the correct possition to add the child // Get all allowed children Map<XsdNode, Object> childrenMap = getChild(getXPath(clickedElement), xsdTree); boolean toAddSeen = false; Element elementIsToAddBeforeThisOne = null; for (final XsdNode allowed : childrenMap.keySet()) { if (!toAddSeen && allowed == xsdChild) { toAddSeen = true; continue; } if (toAddSeen) { final NodeList elementsByTagNameNS = clickedElement.getElementsByTagNameNS( "http://dss.markt.ec.europa.eu/validation/diagnostic", allowed.getLastNameOfPath()); if (elementsByTagNameNS.getLength() > 0) { // we found an element that is supposed to be after the one to add elementIsToAddBeforeThisOne = (Element) elementsByTagNameNS.item(0); break; } } } if (elementIsToAddBeforeThisOne != null) { newElement = clickedElement.insertBefore(childToAdd, elementIsToAddBeforeThisOne); } else { newElement = clickedElement.appendChild(childToAdd); } } else { throw new IllegalArgumentException("Unknow XsdNode NodeType " + xsdChild.getType()); } document.normalizeDocument(); int indexOfAddedItem = 0; final int childCount = clickedItem.childCount(); for (int i = 0; i < childCount; i++) { if (clickedItem.child(i).node == newElement) { indexOfAddedItem = i; break; } } TreeModelEvent event = new TreeModelEvent(validationPolicyTreeModel, selectedPath, new int[] { indexOfAddedItem }, new Object[] { newElement }); validationPolicyTreeModel.fireTreeNodesInserted(event); tree.expandPath(selectedPath); //Update model getModel().getValidationPolicy().setXmlDom(new XmlDom(document)); } }); } popup.show(tree, mouseEvent.getX(), mouseEvent.getY()); }
From source file:eu.europa.esig.dss.applet.view.validationpolicy.EditView.java
private void nodeActionAdd(MouseEvent mouseEvent, final int selectedRow, final TreePath selectedPath, final XmlDomAdapterNode clickedItem, final JTree tree) { final Element clickedElement = (Element) clickedItem.node; // popup menu for list -> add final JPopupMenu popup = new JPopupMenu(); //delete node final JMenuItem menuItemToDelete = new JMenuItem(ResourceUtils.getI18n("DELETE")); menuItemToDelete.addActionListener(new ActionListener() { @Override//from w w w .jav a 2 s. c o m public void actionPerformed(ActionEvent actionEvent) { // find the order# of the child to delete final int index = clickedItem.getParent().index(clickedItem); Node oldChild = clickedElement.getParentNode().removeChild(clickedElement); if (index > -1) { validationPolicyTreeModel.fireTreeNodesRemoved(selectedPath.getParentPath(), index, oldChild); } } }); popup.add(menuItemToDelete); //Add node/value final Map<XsdNode, Object> xsdTree = validationPolicyTreeModel.getXsdTree(); final List<XsdNode> children = getChildrenToAdd(clickedElement, xsdTree); for (final XsdNode xsdChild : children) { final String xmlName = xsdChild.getLastNameOfPath(); final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("ADD") + " (" + xmlName + " " + xsdChild.getType().toString().toLowerCase() + ")"); popup.add(menuItem); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Document document = getModel().getValidationPolicy().getDocument(); final Node newElement; if (xsdChild.getType() == XsdNodeType.TEXT) { // TEXT element always appended (last child) newElement = clickedElement.appendChild(document.createTextNode("VALUE")); } else if (xsdChild.getType() == XsdNodeType.ATTRIBUTE) { newElement = document.createAttributeNS(null, xmlName); ((Attr) newElement).setValue("VALUE"); clickedElement.setAttributeNode((Attr) newElement); } else if (xsdChild.getType() == XsdNodeType.ELEMENT) { final Element childToAdd = document .createElementNS("http://dss.esig.europa.eu/validation/diagnostic", xmlName); // find the correct possition to add the child // Get all allowed children Map<XsdNode, Object> childrenMap = getChild(getXPath(clickedElement), xsdTree); boolean toAddSeen = false; Element elementIsToAddBeforeThisOne = null; for (final XsdNode allowed : childrenMap.keySet()) { if (!toAddSeen && (allowed == xsdChild)) { toAddSeen = true; continue; } if (toAddSeen) { final NodeList elementsByTagNameNS = clickedElement.getElementsByTagNameNS( "http://dss.esig.europa.eu/validation/diagnostic", allowed.getLastNameOfPath()); if (elementsByTagNameNS.getLength() > 0) { // we found an element that is supposed to be after the one to add elementIsToAddBeforeThisOne = (Element) elementsByTagNameNS.item(0); break; } } } if (elementIsToAddBeforeThisOne != null) { newElement = clickedElement.insertBefore(childToAdd, elementIsToAddBeforeThisOne); } else { newElement = clickedElement.appendChild(childToAdd); } } else { throw new IllegalArgumentException("Unknow XsdNode NodeType " + xsdChild.getType()); } document.normalizeDocument(); int indexOfAddedItem = 0; final int childCount = clickedItem.childCount(); for (int i = 0; i < childCount; i++) { if (clickedItem.child(i).node == newElement) { indexOfAddedItem = i; break; } } TreeModelEvent event = new TreeModelEvent(validationPolicyTreeModel, selectedPath, new int[] { indexOfAddedItem }, new Object[] { newElement }); validationPolicyTreeModel.fireTreeNodesInserted(event); tree.expandPath(selectedPath); //Update model getModel().getValidationPolicy().setXmlDom(new XmlDom(document)); } }); } popup.show(tree, mouseEvent.getX(), mouseEvent.getY()); }
From source file:org.jdal.vaadin.beans.TableBeanDefinitionParser.java
/** * {@inheritDoc}/* w w w .ja v a 2 s .co m*/ */ @SuppressWarnings("rawtypes") public BeanDefinition parse(Element element, ParserContext parserContext) { // Defaults String entity = null; if (element.hasAttribute(ENTITY)) entity = element.getAttribute(ENTITY); String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, ".")); if (element.hasAttribute(ID)) name = element.getAttribute(ID); parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Bean names String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX; String tableBeanName = name + TABLE_SUFFIX; String dataSource = name + SERVICE_SUFFIX; String paginator = PAGINATOR_VIEW; String editor = name + EDITOR_SUFFIX; String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS; String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY; String scope = BeanDefinition.SCOPE_PROTOTYPE; String pageableTableClass = DEFAULT_PAGEABLE_TABLE_CLASS; String tableClass = DEFAULT_TABLE_CLASS; if (element.hasAttribute(DATA_SOURCE)) dataSource = element.getAttribute(DATA_SOURCE); if (element.hasAttribute(PAGINATOR)) paginator = element.getAttribute(PAGINATOR); if (element.hasAttribute(ACTIONS)) actions = element.getAttribute(ACTIONS); if (element.hasAttribute(GUI_FACTORY)) guiFactory = element.getAttribute(GUI_FACTORY); if (element.hasAttribute(EDITOR)) editor = element.getAttribute(EDITOR); if (element.hasAttribute(SCOPE)) scope = element.getAttribute(SCOPE); if (element.hasAttribute(PAGEABLE_TABLE_CLASS)) pageableTableClass = element.getAttribute(PAGEABLE_TABLE_CLASS); if (element.hasAttribute(TABLE_CLASS)) tableClass = element.getAttribute(TABLE_CLASS); // create PageableTable BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(pageableTableClass); bdb.setScope(scope); bdb.addPropertyReference(DATA_SOURCE, dataSource); bdb.addPropertyReference(PAGINATOR_VIEW, paginator); bdb.addPropertyValue(NAME, pageableTableBeanName); bdb.addPropertyReference(TABLE, tableBeanName); bdb.addPropertyReference(GUI_FACTORY, guiFactory); bdb.addPropertyValue(EDITOR_NAME, editor); bdb.addPropertyValue(ENTITY_CLASS, entity); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, TABLE_SERVICE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, MESSAGE_SOURCE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER_FORM); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, SORT_PROPERTY); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, ORDER); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PAGE_SIZE); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, NATIVE_BUTTONS); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PROPAGATE_SERVICE); if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS))) bdb.addPropertyReference(ACTIONS, actions); parserContext.getDelegate().parseBeanDefinitionAttributes(element, pageableTableBeanName, null, bdb.getBeanDefinition()); BeanDefinitionHolder holder = new BeanDefinitionHolder(bdb.getBeanDefinition(), pageableTableBeanName); // Test Decorators like aop:scoped-proxy NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node n = childNodes.item(i); if (Node.ELEMENT_NODE != n.getNodeType() || COLUMNS.equals(n.getLocalName())) continue; NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(n.getNamespaceURI()); if (handler != null) { holder = handler.decorate(n, holder, parserContext); } } parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); // create ConfigurableTable bdb = BeanDefinitionBuilder.genericBeanDefinition(tableClass); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FIELD_FACTORY); BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, MULTISELECT); if (element.hasAttribute(SELECTABLE)) { bdb.addPropertyValue(SELECTABLE, element.getAttribute(SELECTABLE)); } else { // set selectable by default bdb.addPropertyValue(SELECTABLE, true); } // parse columns NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS); if (nl.getLength() > 0) { List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0), bdb.getRawBeanDefinition()); bdb.addPropertyValue(COLUMNS, columns); } registerBeanDefinition(element, parserContext, tableBeanName, bdb); parserContext.popAndRegisterContainingComponent(); return null; }
From source file:nl.b3p.ogc.utils.OgcWfsClient.java
/** Haal de elementen uit de describefeaturetype request *///from ww w. j a v a2 s .c o m public static ArrayList getDescribeFeatureElements(Element el) throws Exception { //Haal eerst de complexTypes type elementen op en de prefix. String namespaceUri = el.getNamespaceURI(); NodeList childs = el.getChildNodes(); String prefix = ""; for (int i = 0; i < childs.getLength() && prefix.length() == 0; i++) { Node n = childs.item(i); if (n instanceof DeferredElementNSImpl) { Element e = (Element) n; if (e.getLocalName().equalsIgnoreCase("element")) { if (e.getAttribute("type") != null && e.getAttribute("type").contains(":")) { prefix = e.getAttribute("type").split(":")[0]; } } } } String featureNameSpace = null; if (prefix.length() > 0) { featureNameSpace = el.getAttribute("xmlns:" + prefix); } String s = elementToString(el); if (el == null) { return null; } NodeList nlist = el.getElementsByTagNameNS(namespaceUri, "complexType"); if (!(nlist.getLength() > 0)) { log.error("no complexType element found"); return null; } ArrayList returnValue = new ArrayList(); for (int i = 0; i < nlist.getLength(); i++) { Element e = (Element) nlist.item(i); NodeList nl = e.getElementsByTagNameNS(namespaceUri, "element"); for (int b = 0; b < nl.getLength(); b++) { Element element = (Element) nl.item(b); if (featureNameSpace != null && featureNameSpace.length() > 0) { element.setAttribute("name", "{" + featureNameSpace + "}" + element.getAttribute("name")); } returnValue.add(element); } } return returnValue; }
From source file:nl.nn.adapterframework.util.SoapConfigManager.java
public void loadRegistry() throws SOAPException { URL servicesRegistry;//from ww w.ja v a 2 s . c o m String message; try { servicesRegistry = context.getResource(filename); } catch (MalformedURLException e) { message = "cannot find URL for registry from resource-name '" + filename + "'"; log.error(message, e); throw new SOAPException(Constants.FAULT_CODE_SERVER, message, e); } if (servicesRegistry == null) { message = "cannot find registry from resource-name '" + filename + "'"; log.error(message); throw new SOAPException(Constants.FAULT_CODE_SERVER, message); } Element element = null; try { Document document = xdb.parse(servicesRegistry.openStream()); element = document.getDocumentElement(); } catch (Exception e) { message = "exception while reading servicesRegistry from " + servicesRegistry; log.error(message, e); throw new SOAPException(Constants.FAULT_CODE_SERVER, message, e); } log.info("loading servicesRegistry from " + servicesRegistry); ; NodeList nodelist = element.getElementsByTagNameNS("http://xml.apache.org/xml-soap/deployment", "service"); int i = nodelist.getLength(); dds = new Hashtable(); for (int j = 0; j < i; j++) { Element element1 = (Element) nodelist.item(j); DeploymentDescriptor deploymentdescriptor = DeploymentDescriptor.fromXML(element1); String s = deploymentdescriptor.getID(); log.info("deploying service " + s); dds.put(s, deploymentdescriptor); } }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
private void addAttributeSet(final Document xformsDocument, final Element modelSection, final Element defaultInstanceElement, final Element formSection, final XSModel schema, final XSComplexTypeDefinition controlType, final XSElementDeclaration owner, final String pathToRoot, final boolean checkIfExtension, final ResourceBundle resourceBundle) throws FormBuilderException { XSObjectList attrUses = controlType.getAttributeUses(); if (attrUses == null) { return;/*from w w w . j a v a 2 s . c om*/ } for (int i = 0; i < attrUses.getLength(); i++) { final XSAttributeUse currentAttributeUse = (XSAttributeUse) attrUses.item(i); final XSAttributeDeclaration currentAttribute = currentAttributeUse.getAttrDeclaration(); String attributeName = currentAttributeUse.getName(); if (attributeName == null || attributeName.length() == 0) { attributeName = currentAttributeUse.getAttrDeclaration().getName(); } //test if extended ! if (checkIfExtension && SchemaUtil.doesAttributeComeFromExtension(currentAttributeUse, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "[addAttributeSet] This attribute comes from an extension: recopy form controls. Model section =\n" + XMLUtil.toString(modelSection)); } //find the existing bind Id //(modelSection is the enclosing bind of the element) final NodeList binds = modelSection.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind"); String bindId = null; for (int j = 0; j < binds.getLength() && bindId == null; j++) { Element bind = (Element) binds.item(j); String nodeset = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"); if (nodeset != null) { //remove "@" in nodeset String name = nodeset.substring(1); if (name.equals(attributeName)) { bindId = bind.getAttributeNS(null, "id"); } } } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("[addAttributeSet] bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); final Pointer pointer = context .getPointer("//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']"); if (pointer != null) { control = (Element) pointer.getNode(); } else if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addAttributeSet] unable to resolve pointer for: //*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']"); } } if (LOGGER.isDebugEnabled()) { if (control == null) { LOGGER.debug("[addAttributeSet] control = <not found>"); } else { LOGGER.debug("[addAttributeSet] control = " + control.getTagName()); } } //copy it if (control == null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); formSection.appendChild(newControl); } } else { String attrNamespace = currentAttribute.getNamespace(); String namespacePrefix = ""; if (attrNamespace != null && attrNamespace.length() > 0) { String prefix = NamespaceResolver.getPrefix(xformsDocument.getDocumentElement(), attrNamespace); if (prefix != null && prefix.length() > 0) { namespacePrefix = prefix + ":"; } } final String newPathToRoot = (pathToRoot == null || pathToRoot.length() == 0 ? "@" + namespacePrefix + currentAttribute.getName() : (pathToRoot.endsWith("/") ? pathToRoot + "@" + namespacePrefix + currentAttribute.getName() : pathToRoot + "/@" + namespacePrefix + currentAttribute.getName())); if (LOGGER.isDebugEnabled()) LOGGER.debug("[addAttributeSet] adding attribute " + attributeName + " at " + newPathToRoot); try { String defaultValue = (currentAttributeUse.getConstraintType() == XSConstants.VC_NONE ? null : currentAttributeUse.getConstraintValue()); // make sure boolean attributes have a default value if (defaultValue == null && "boolean".equals(currentAttribute.getTypeDefinition().getName())) { defaultValue = "false"; } if (namespacePrefix.length() > 0) { defaultInstanceElement.setAttributeNS(this.targetNamespace, attributeName, defaultValue); } else { defaultInstanceElement.setAttribute(attributeName, defaultValue); } } catch (Exception e) { throw new FormBuilderException("error retrieving default value for attribute " + attributeName + " at " + newPathToRoot, e); } this.addSimpleType(xformsDocument, modelSection, formSection, schema, currentAttribute.getTypeDefinition(), currentAttributeUse, newPathToRoot, resourceBundle); } } }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
private Element addElementWithMultipleCompatibleTypes(final Document xformsDocument, Element modelSection, final Element defaultInstanceElement, final Element formSection, final XSModel schema, final XSElementDeclaration elementDecl, final TreeSet<XSTypeDefinition> compatibleTypes, final String pathToRoot, final ResourceBundle resourceBundle, final SchemaUtil.Occurrence occurs) throws FormBuilderException { if (LOGGER.isDebugEnabled()) LOGGER.debug("[addElementWithMultipleCompatibleTypes] adding element " + elementDecl + " at path " + pathToRoot);//w w w. ja va2 s. c o m // look for compatible types final XSTypeDefinition controlType = elementDecl.getTypeDefinition(); //get possible values final List<XSTypeDefinition> enumValues = new LinkedList<XSTypeDefinition>(); //add the type (if not abstract) if (!((XSComplexTypeDefinition) controlType).getAbstract()) { enumValues.add(controlType); } //add compatible types enumValues.addAll(compatibleTypes); // multiple compatible types for this element exist // in the schema - allow the user to choose from // between compatible non-abstract types boolean isRepeated = isRepeated(occurs, controlType); Element bindElement = this.createBind(xformsDocument, pathToRoot + "/@xsi:type"); String bindId = bindElement.getAttributeNS(null, "id"); modelSection.appendChild(bindElement); this.startBindElement(bindElement, schema, controlType, null, occurs); //add the "element" bind, in addition final Element bindElement2 = this.createBind(xformsDocument, pathToRoot + (isRepeated ? "[position() != last()]" : "")); modelSection.appendChild(bindElement2); this.startBindElement(bindElement2, schema, controlType, null, occurs); // add content to select1 final Map<String, Element> caseTypes = this.addChoicesForSelectSwitchControl(xformsDocument, formSection, enumValues, bindId); //add switch final Element switchElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":switch"); switchElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":bind", bindId); switchElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":appearance", "full"); formSection.appendChild(switchElement); if (!((XSComplexTypeDefinition) controlType).getAbstract()) { final Element firstCaseElement = caseTypes.get(controlType.getName()); switchElement.appendChild(firstCaseElement); final Element firstGroupElement = this.addComplexType(xformsDocument, modelSection, defaultInstanceElement, firstCaseElement, schema, (XSComplexTypeDefinition) controlType, elementDecl, pathToRoot, SchemaUtil.getOccurrence(elementDecl), true, false, resourceBundle); firstGroupElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":appearance", ""); } defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":type", (((XSComplexTypeDefinition) controlType).getAbstract() ? compatibleTypes.first().getName() : controlType.getName())); defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil", "true"); /////////////// add sub types ////////////// // add each compatible type within // a case statement for (final XSTypeDefinition type : compatibleTypes) { final String compatibleTypeName = type.getName(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(type == null ? ("[addElementWithMultipleCompatibleTypes] compatible type is null!! type = " + compatibleTypeName + ", targetNamespace = " + this.targetNamespace) : ("[addElementWithMultipleCompatibleTypes] adding compatible type " + type.getName())); } if (type == null || type.getTypeCategory() != XSTypeDefinition.COMPLEX_TYPE) { continue; } final Element caseElement = caseTypes.get(type.getName()); switchElement.appendChild(caseElement); // ALF-9524 fix, add an extra element to the instance for each type that extends the abstract parent Element newDefaultInstanceElement = xformsDocument.createElement(getElementName(type, xformsDocument)); Attr nodesetAttr = modelSection.getAttributeNodeNS(NamespaceConstants.XFORMS_NS, "nodeset"); // construct the nodeset that is used in bind for abstract type String desiredBindNodeset = getElementName(elementDecl, xformsDocument) + (isRepeated ? "[position() != last()]" : ""); // check the current bind if (nodesetAttr == null || !nodesetAttr.getValue().equals(desiredBindNodeset)) { // look for desired bind in children Element newModelSection = DOMUtil.getElementByAttributeValueNS(modelSection, NamespaceConstants.XFORMS_NS, "bind", NamespaceConstants.XFORMS_NS, "nodeset", desiredBindNodeset); if (newModelSection == null) { // look for absolute path desiredBindNodeset = "/" + desiredBindNodeset; newModelSection = DOMUtil.getElementByAttributeValueNS(modelSection, NamespaceConstants.XFORMS_NS, "bind", NamespaceConstants.XFORMS_NS, "nodeset", desiredBindNodeset); } modelSection = newModelSection; } // create the extra bind for each child of abstract type Element bindElement3 = this.createBind(xformsDocument, getElementName(type, xformsDocument)); modelSection.appendChild(bindElement3); bindElement3 = this.startBindElement(bindElement3, schema, controlType, elementDecl, occurs); // add the relevant attribute that checks the value of parent' @xsi:type bindElement3.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":relevant", "../@xsi:type='" + type.getName() + "'"); final Element groupElement = this.addComplexType(xformsDocument, modelSection, newDefaultInstanceElement, caseElement, schema, (XSComplexTypeDefinition) type, elementDecl, pathToRoot, SchemaUtil.getOccurrence(elementDecl), true, true, resourceBundle); groupElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":appearance", ""); defaultInstanceElement.appendChild(newDefaultInstanceElement.cloneNode(true)); // modify bind to add a "relevant" attribute that checks the value of @xsi:type if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addElementWithMultipleCompatibleTypes] Model section =\n" + XMLUtil.toString(bindElement3)); } final NodeList binds = bindElement3.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind"); for (int i = 0; i < binds.getLength(); i++) { final Element subBind = (Element) binds.item(i); String name = subBind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"); // ETHREEOH-3308 fix name = repeatableNamePattern.matcher(name).replaceAll(""); if (!subBind.getParentNode().getAttributes().getNamedItem("id").getNodeValue() .equals(bindElement3.getAttribute("id"))) { continue; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addElementWithMultipleCompatibleTypes] Testing sub-bind with nodeset " + name); } Pair<String, String> parsed = parseName(name, xformsDocument); if (!SchemaUtil.isElementDeclaredIn(parsed.getFirst(), parsed.getSecond(), (XSComplexTypeDefinition) type, false) && !SchemaUtil.isAttributeDeclaredIn(parsed.getFirst(), parsed.getSecond(), (XSComplexTypeDefinition) type, false)) { continue; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addElementWithMultipleCompatibleTypes] Element/Attribute " + name + " declared in type " + type.getName() + ": adding relevant attribute"); } //test sub types of this type //TreeSet subCompatibleTypes = (TreeSet) typeTree.get(type); String newRelevant = "../../@xsi:type='" + type.getName() + "'"; if (this.typeTree.containsKey(type.getName())) { for (XSTypeDefinition otherType : this.typeTree.get(type.getName())) { newRelevant = newRelevant + " or ../../@xsi:type='" + otherType.getName() + "'"; } } //change relevant attribute final String relevant = subBind.getAttributeNS(NamespaceConstants.XFORMS_NS, "relevant"); if (relevant != null && relevant.length() != 0) { newRelevant = ("(" + relevant + ") and " + newRelevant); } subBind.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":relevant", newRelevant); } } return switchElement; }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
/** *//*from w w w .j a v a2 s . c om*/ private void addGroup(final Document xformsDocument, final Element modelSection, final Element defaultInstanceElement, final Element formSection, final XSModel schema, final XSModelGroup group, final XSComplexTypeDefinition controlType, final XSElementDeclaration owner, final String pathToRoot, final SchemaUtil.Occurrence occurs, final boolean checkIfExtension, final ResourceBundle resourceBundle) throws FormBuilderException { if (group == null) { return; } if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addGroup] Start of addGroup, from owner = " + owner.getName() + " and controlType = " + controlType.getName()); LOGGER.debug("[addGroup] group before =\n" + XMLUtil.toString(formSection)); } final Element repeatSection = this.addRepeatIfNecessary(xformsDocument, modelSection, formSection, owner.getTypeDefinition(), pathToRoot, occurs); final XSObjectList particles = group.getParticles(); for (int counter = 0; counter < particles.getLength(); counter++) { final XSParticle currentNode = (XSParticle) particles.item(counter); XSTerm term = currentNode.getTerm(); final SchemaUtil.Occurrence childOccurs = new SchemaUtil.Occurrence(currentNode); if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addGroup] next term = " + term.getName() + ", occurs = " + childOccurs); } if (term instanceof XSModelGroup) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addGroup] term is a group"); } this.addGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection, schema, ((XSModelGroup) term), controlType, owner, pathToRoot, childOccurs, checkIfExtension, resourceBundle); } else if (term instanceof XSElementDeclaration) { XSElementDeclaration element = (XSElementDeclaration) term; if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addGroup] term is an element declaration: " + term.getName()); } //special case for types already added because used in an extension //do not add it when it comes from an extension !!! //-> make a copy from the existing form control if (checkIfExtension && SchemaUtil.doesElementComeFromExtension(element, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "[addGroup] This element comes from an extension: recopy form controls. Model Section =\n" + XMLUtil.toString(modelSection)); } //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind"); String bindId = null; for (int i = 0; i < binds.getLength() && bindId == null; i++) { Element bind = (Element) binds.item(i); String nodeset = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"); Pair<String, String> parsed = parseName(nodeset, xformsDocument); if (nodeset != null && EqualsHelper.nullSafeEquals(parsed.getSecond(), element.getNamespace()) && parsed.getFirst().equals(element.getName())) { bindId = bind.getAttributeNS(null, "id"); } } if (LOGGER.isDebugEnabled()) LOGGER.debug("[addGroup] found bindId " + bindId + " for element " + element.getName()); //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addGroup] bindId found: " + bindId); } final JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); final Pointer pointer = context .getPointer("//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']"); if (pointer != null) { control = (Element) pointer.getNode(); } else if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addGroup] unable to resolve pointer for: //*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']"); } } if (LOGGER.isDebugEnabled()) { if (control == null) { LOGGER.debug("[addGroup] control = <not found>"); } else { LOGGER.debug("[addGroup] control = " + control.getTagName()); } } //copy it if (control == null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Corresponding control not found"); this.addElementToGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection, schema, element, pathToRoot, childOccurs, resourceBundle); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); repeatSection.appendChild(newControl); } } else { this.addElementToGroup(xformsDocument, modelSection, defaultInstanceElement, repeatSection, schema, element, pathToRoot, childOccurs, resourceBundle); } } else { LOGGER.warn("Unhandled term " + term + " found in group from " + owner.getName() + " for pathToRoot = " + pathToRoot); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("[addGroup] group after =\n" + XMLUtil.toString(formSection)); LOGGER.debug("[addGroup] End of addGroup, from owner = " + owner.getName() + " and controlType = " + controlType.getName()); } }
From source file:org.apache.axis.message.MessageElement.java
/** * helper method for recusively getting the element that has namespace URI and localname * @param parentElement parent element/*from w w w. j ava 2 s . co m*/ * @param namespace namespace * @param localName local name of element * @return (potentially empty) list of elements that match the (namespace,localname) tuple */ protected NodeList getElementsNS(org.w3c.dom.Element parentElement, String namespace, String localName) { NodeList children = parentElement.getChildNodes(); NodeListImpl matches = new NodeListImpl(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i) instanceof Text) { continue; } Element child = (Element) children.item(i); if (namespace.equals(child.getNamespaceURI()) && localName.equals(child.getLocalName())) { matches.addNode(child); } // search the grand-children. matches.addNodeList(child.getElementsByTagNameNS(namespace, localName)); } return matches; }