List of usage examples for org.w3c.dom Element setAttributeNS
public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException;
From source file:org.apereo.portal.layout.dlm.FragmentActivator.java
/** * Recursive method that passes through a layout tree and changes all ids * from the regular format of sXX or nXX to the globally safe incorporated * id of form uXlXsXX or uXlXnXX indicating the user id and layout id from * which this node came.//from w w w. j av a2 s. co m */ private void setIdsAndAttribs(Element parent, String labelBase, String index, String precedence) { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { Element child = (Element) children.item(i); String id = child.getAttribute(Constants.ATT_ID); if (!id.equals("")) { String newId = labelBase + id; child.setAttribute(Constants.ATT_ID, newId); child.setIdAttribute(Constants.ATT_ID, true); child.setAttributeNS(Constants.NS_URI, Constants.ATT_FRAGMENT, index); child.setAttributeNS(Constants.NS_URI, Constants.ATT_PRECEDENCE, precedence); setIdsAndAttribs(child, labelBase, index, precedence); } } } }
From source file:org.apereo.portal.layout.dlm.ParameterEditManager.java
/** This method does the actual work of adding a newly created parameter edit and adding it to the parameter edits set. *//*from www .j a v a2 s.c o m*/ private static void addParmEditDirective(String targetID, String name, String value, IPerson person, Document plf, Element parmSet) throws PortalException { String ID = null; try { ID = getDLS().getNextStructDirectiveId(person); } catch (Exception e) { throw new PortalException("Exception encountered while " + "generating new parameter edit node " + "Id for userId=" + person.getID(), e); } Element parm = plf.createElement(Constants.ELM_PARM_EDIT); parm.setAttribute(Constants.ATT_TYPE, Constants.ELM_PARM_EDIT); parm.setAttribute(Constants.ATT_ID, ID); parm.setIdAttribute(Constants.ATT_ID, true); parm.setAttributeNS(Constants.NS_URI, Constants.ATT_TARGET, targetID); parm.setAttribute(Constants.ATT_NAME, name); parm.setAttribute(Constants.ATT_USER_VALUE, value); parmSet.appendChild(parm); }
From source file:org.apereo.portal.layout.dlm.PositionManager.java
/** Create, append to the passed in position set, and return a position element that references the passed in elementID. *///w ww .j a v a2 s .c om private static Element createAndAppendPosition(String elementID, Element positions, IPerson person) throws PortalException { if (LOG.isDebugEnabled()) LOG.debug("Adding Position Set entry " + elementID + "."); String ID = null; try { ID = getDLS().getNextStructDirectiveId(person); } catch (Exception e) { throw new PortalException("Exception encountered while " + "generating new position node " + "Id for userId=" + person.getID(), e); } Document plf = positions.getOwnerDocument(); Element position = plf.createElement(Constants.ELM_POSITION); position.setAttribute(Constants.ATT_TYPE, Constants.ELM_POSITION); position.setAttribute(Constants.ATT_ID, ID); position.setAttributeNS(Constants.NS_URI, Constants.ATT_NAME, elementID); positions.appendChild(position); return position; }
From source file:org.apereo.portal.layout.dlm.RDBMDistributedLayoutStore.java
/** * Returns the layout for a user. This method overrides the same * method in the superclass to return a composite layout for non * fragment owners and a regular layout for layout owners. A * composite layout is made up of layout pieces from potentially * multiple incorporated layouts. If no layouts are defined then * the composite layout will be the same as the user's personal * layout fragment or PLF, the one holding only those UI elements * that they own or incorporated elements that they have been * allowed to changed./* w w w .j av a 2 s. c o m*/ **/ private DistributedUserLayout _getUserLayout(IPerson person, IUserProfile profile) { final String userName = (String) person.getAttribute("username"); final FragmentDefinition ownedFragment = this.fragmentUtils.getFragmentDefinitionByOwner(person); final boolean isLayoutOwnerDefault = this.isLayoutOwnerDefault(person); final Set<String> fragmentNames = new LinkedHashSet<String>(); final Document ILF; final Document PLF = this.getPLF(person, profile); // If this user is an owner then ownedFragment will be non null. For // fragment owners and owners of any default layout from which a // fragment owners layout is copied there should not be any imported // distributed layouts. Instead, load their PLF, mark as an owned // if a fragment owner, and return. if (ownedFragment != null || isLayoutOwnerDefault) { ILF = (Document) PLF.cloneNode(true); final Element layoutNode = ILF.getDocumentElement(); final Element ownerDocument = layoutNode.getOwnerDocument().getDocumentElement(); final NodeList channelNodes = ownerDocument.getElementsByTagName("channel"); for (int i = 0; i < channelNodes.getLength(); i++) { Element channelNode = (Element) channelNodes.item(i); final Node chanIdNode = channelNode.getAttributeNode("chanID"); if (chanIdNode == null || MissingPortletDefinition.CHANNEL_ID.equals(chanIdNode.getNodeValue())) { channelNode.getParentNode().removeChild(channelNode); } } if (ownedFragment != null) { fragmentNames.add(ownedFragment.getName()); layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_FRAGMENT_NAME, ownedFragment.getName()); logger.debug("User '{}' is owner of '{}' fragment.", userName, ownedFragment.getName()); } else if (isLayoutOwnerDefault) { layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_IS_TEMPLATE_USER, "true"); layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_TEMPLATE_LOGIN_ID, (String) person.getAttribute("username")); } } else { final Locale locale = profile.getLocaleManager().getLocales()[0]; final List<FragmentDefinition> applicableFragmentDefinitions = this.fragmentUtils .getFragmentDefinitionsApplicableToPerson(person); final List<Document> applicableLayouts = this.fragmentUtils .getFragmentDefinitionUserViewLayouts(applicableFragmentDefinitions, locale); final IntegrationResult integrationResult = new IntegrationResult(); ILF = this.createCompositeILF(person, PLF, applicableLayouts, integrationResult); // push optimizations made during merge back into db. if (integrationResult.isChangedPLF()) { if (logger.isDebugEnabled()) { logger.debug("Saving PLF for {} due to changes during merge.", person.getAttribute(IPerson.USERNAME)); } super.setUserLayout(person, profile, PLF, false); } fragmentNames.addAll(this.fragmentUtils.getFragmentNames(applicableFragmentDefinitions)); } return this.createDistributedUserLayout(person, profile, ILF, fragmentNames); }
From source file:org.apereo.portal.layout.dlm.RDBMDistributedLayoutStore.java
@Override protected Element getStructure(Document doc, LayoutStructure ls) { Element structure = null; String type = ls.getType();/*w w w . j av a 2 s. c o m*/ if (ls.isChannel()) { final IPortletDefinition channelDef = this.portletDefinitionRegistry .getPortletDefinition(String.valueOf(ls.getChanId())); if (channelDef != null && channelApproved(channelDef.getApprovalDate())) { structure = this.getElementForChannel(doc, channelPrefix + ls.getStructId(), channelDef, ls.getLocale()); } else { structure = this.getElementForChannel(doc, channelPrefix + ls.getStructId(), MissingPortletDefinition.INSTANCE, null); } } else { // create folder objects including dlm new types in cp namespace if (type != null && type.startsWith(Constants.NS)) { structure = doc.createElementNS(Constants.NS_URI, type); } else { structure = doc.createElement("folder"); } structure.setAttribute("name", ls.getName()); structure.setAttribute("type", (type != null ? type : "regular")); } structure.setAttribute("hidden", (ls.isHidden() ? "true" : "false")); structure.setAttribute("immutable", (ls.isImmutable() ? "true" : "false")); structure.setAttribute("unremovable", (ls.isUnremovable() ? "true" : "false")); if (localeAware) { structure.setAttribute("locale", ls.getLocale()); // for i18n by Shoji } /* * Parameters from up_layout_param are loaded slightly differently for * folders and channels. For folders all parameters are added as attributes * of the Element. For channels only those parameters with names starting * with the dlm namespace Constants.NS are added as attributes to the Element. * Others are added as child parameter Elements. */ if (ls.getParameters() != null) { for (final Iterator itr = ls.getParameters().iterator(); itr.hasNext();) { final StructureParameter sp = (StructureParameter) itr.next(); String pName = sp.getName(); if (!ls.isChannel()) { // Folder if (pName.startsWith(Constants.NS)) { structure.setAttributeNS(Constants.NS_URI, pName, sp.getValue()); } else { structure.setAttribute(pName, sp.getValue()); } } else // Channel { // if dealing with a dlm namespace param add as attribute if (pName.startsWith(Constants.NS)) { structure.setAttributeNS(Constants.NS_URI, pName, sp.getValue()); itr.remove(); } else { /* * do traditional override processing. some explanation is in * order. The structure element was created by the * ChannelDefinition and only contains parameter children if the * definition had defined parameters. These are checked for each * layout loaded parameter as found in LayoutStructure.parameters. * If a name match is found then we need to see if overriding is * allowed and if so we set the value on the child parameter * element. At that point we are done with that version loaded * from the layout so we remove it from the in-memory set of * parameters that are being merged-in. Then, after all such have * been checked against those added by the channel definition we * add in any remaining as adhoc, unregulated parameters. */ final NodeList nodeListParameters = structure.getElementsByTagName("parameter"); for (int j = 0; j < nodeListParameters.getLength(); j++) { final Element parmElement = (Element) nodeListParameters.item(j); final NamedNodeMap nm = parmElement.getAttributes(); final String nodeName = nm.getNamedItem("name").getNodeValue(); if (nodeName.equals(pName)) { final Node override = nm.getNamedItem("override"); if (override != null && override.getNodeValue().equals("yes")) { final Node valueNode = nm.getNamedItem("value"); valueNode.setNodeValue(sp.getValue()); } itr.remove(); break; // found the corresponding one so skip the rest } } } } } // For channels, add any remaining parameter elements loaded with the // layout as adhoc, unregulated, parameter children that can be overridden. if (ls.isChannel()) { for (final Iterator itr = ls.getParameters().iterator(); itr.hasNext();) { final StructureParameter sp = (StructureParameter) itr.next(); final Element parameter = doc.createElement("parameter"); parameter.setAttribute("name", sp.getName()); parameter.setAttribute("value", sp.getValue()); parameter.setAttribute("override", "yes"); structure.appendChild(parameter); } } } // finish setting up elements based on loaded params final String origin = structure.getAttribute(Constants.ATT_ORIGIN); final String prefix = ls.isChannel() ? channelPrefix : folderPrefix; // if not null we are dealing with a node incorporated from another // layout and this node contains changes made by the user so handle // id swapping. if (!origin.equals("")) { structure.setAttributeNS(Constants.NS_URI, Constants.ATT_PLF_ID, prefix + ls.getStructId()); structure.setAttribute("ID", origin); } else if (!ls.isChannel()) // regular folder owned by this user, need to check if this is a // directive or ui element. If the latter then use traditional id // structure { if (type != null && type.startsWith(Constants.NS)) { structure.setAttribute("ID", Constants.DIRECTIVE_PREFIX + ls.getStructId()); } else { structure.setAttribute("ID", folderPrefix + ls.getStructId()); } } else { logger.debug("Adding identifier {}{}", folderPrefix, ls.getStructId()); structure.setAttribute("ID", channelPrefix + ls.getStructId()); } structure.setIdAttribute(Constants.ATT_ID, true); return structure; }
From source file:org.apereo.portal.layout.node.UserLayoutNodeDescription.java
/** * Add all of common node attributes to the <code>Element</code>. * * @param node an <code>Element</code> value */// w w w .j a v a2 s . co m public void addNodeAttributes(Element node) { node.setAttribute("ID", this.getId()); node.setAttribute("name", this.getName()); node.setAttribute("unremovable", (new Boolean(this.isUnremovable())).toString()); node.setAttribute("immutable", (new Boolean(this.isImmutable())).toString()); node.setAttribute("hidden", (new Boolean(this.isHidden())).toString()); if (!this.isDeleteAllowed()) node.setAttributeNS(Constants.NS_URI, Constants.ATT_DELETE_ALLOWED, "false"); if (!this.isMoveAllowed()) node.setAttributeNS(Constants.NS_URI, Constants.ATT_MOVE_ALLOWED, "false"); if (!this.isEditAllowed()) node.setAttributeNS(Constants.NS_URI, Constants.ATT_EDIT_ALLOWED, "false"); if (!this.isAddChildAllowed()) node.setAttributeNS(Constants.NS_URI, Constants.ATT_ADD_CHILD_ALLOWED, "false"); if (this.getPrecedence() != 0.0) node.setAttributeNS(Constants.NS_URI, Constants.ATT_PRECEDENCE, Double.toString(this.getPrecedence())); }
From source file:org.atricore.idbus.capabilities.sso.support.test.XmlDsigTest.java
/** * Sign a simple DOM document using the configured JSR 105 Provider *//*from ww w.ja v a2 s.c om*/ @Test public void simpleDocumentSign() throws Exception { //All the parameters for the keystore String keystoreType = "JKS"; String keystoreFile = "src/test/resources/keystore.jks"; String keystorePass = "xmlsecurity"; String privateKeyAlias = "test"; String privateKeyPass = "xmlsecurity"; String certificateAlias = "test"; File signatureFile = new File("target/signature.xml"); KeyStore ks = KeyStore.getInstance(keystoreType); FileInputStream fis = new FileInputStream(keystoreFile); //load the keystore ks.load(fis, keystorePass.toCharArray()); //get the private key for signing. PrivateKey privateKey = (PrivateKey) ks.getKey(privateKeyAlias, privateKeyPass.toCharArray()); X509Certificate cert = (X509Certificate) ks.getCertificate(certificateAlias); PublicKey publicKey = cert.getPublicKey(); // Create a DOM XMLSignatureFactory that will be used to generate the // enveloped signature String providerName = System.getProperty("jsr105Provider", "org.jcp.xml.dsig.internal.dom.XMLDSigRI"); XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM", (Provider) Class.forName(providerName).newInstance()); // Create a Reference to the enveloped document (in this case we are // signing the whole document, so a URI of "" signifies that) and // also specify the SHA1 digest algorithm and the ENVELOPED Transform. Reference ref = fac.newReference("#12345", fac.newDigestMethod(DigestMethod.SHA1, null), Collections.singletonList(fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)), null, null); // Create the SignedInfo SignedInfo si = fac.newSignedInfo( fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS, (C14NMethodParameterSpec) null), fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null), Collections.singletonList(ref)); // Instantiate the document to be signed javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); //XML Signature needs to be namespace aware dbf.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.newDocument(); //Build a sample document. It will look something like: //<!-- Comment before --> //<apache:RootElement xmlns:apache="http://www.apache.org/ns/#app1" ID="12345">Some simple text //</apache:RootElement> //<!-- Comment after --> doc.appendChild(doc.createComment(" Comment before ")); Element root = doc.createElementNS("http://www.apache.org/ns/#app1", "apache:RootElement"); root.setAttributeNS(null, "ID", "12345"); root.setAttributeNS(null, "attr1", "test1"); root.setAttributeNS(null, "attr2", "test2"); root.setAttributeNS(org.apache.xml.security.utils.Constants.NamespaceSpecNS, "xmlns:foo", "http://example.org/#foo"); root.setAttributeNS("http://example.org/#foo", "foo:attr1", "foo's test"); root.setAttributeNS(org.apache.xml.security.utils.Constants.NamespaceSpecNS, "xmlns:apache", "http://www.apache.org/ns/#app1"); doc.appendChild(root); root.appendChild(doc.createTextNode("Some simple text\n")); // Create a DOMSignContext and specify the DSA PrivateKey and // location of the resulting XMLSignature's parent element DOMSignContext dsc = new DOMSignContext(privateKey, doc.getDocumentElement()); // Create the XMLSignature (but don't sign it yet) KeyInfoFactory kif = fac.getKeyInfoFactory(); X509Data kv = kif.newX509Data(Collections.singletonList(cert)); // Create a KeyInfo and add the KeyValue to it KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv)); javax.xml.crypto.dsig.XMLSignature signature = fac.newXMLSignature(si, ki); signature.sign(dsc); // TODO : Verify signature ? // output the resulting document FileOutputStream f = new FileOutputStream(signatureFile); XMLUtils.outputDOMc14nWithComments(doc, f); f.close(); }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
/** * builds a form from a XML schema.// w w w .ja v a 2 s . c o m * * @param inputURI the URI of the Schema to be used * @return __UNDOCUMENTED__ * @throws FormBuilderException __UNDOCUMENTED__ */ public Document buildForm(String inputURI) throws FormBuilderException { try { this.loadSchema(inputURI); buildTypeTree(schema); //refCounter = 0; counter = new HashMap(); Document xForm = createFormTemplate(_rootTagName, _rootTagName + " Form", getProperty(CSS_STYLE_PROP, DEFAULT_CSS_STYLE_PROP)); //this.buildInheritenceTree(schema); Element envelopeElement = xForm.getDocumentElement(); //Element formSection = (Element) envelopeElement.getElementsByTagNameNS(CHIBA_NS, "form").item(0); //Element formSection =(Element) envelopeElement.getElementsByTagName("body").item(0); //find form element: last element created NodeList children = xForm.getDocumentElement().getChildNodes(); int nb = children.getLength(); Element formSection = (Element) children.item(nb - 1); Element modelSection = (Element) envelopeElement.getElementsByTagNameNS(XFORMS_NS, "model").item(0); //add XMLSchema if we use schema types if (_useSchemaTypes && modelSection != null) { modelSection.setAttributeNS(XFORMS_NS, this.getXFormsNSPrefix() + "schema", inputURI); } //change stylesheet String stylesheet = this.getStylesheet(); if ((stylesheet != null) && !stylesheet.equals("")) { envelopeElement.setAttributeNS(CHIBA_NS, this.getChibaNSPrefix() + "stylesheet", stylesheet); } // TODO: Commented out because comments aren't output properly by the Transformer. //String comment = "This XForm was automatically generated by " + this.getClass().getName() + " on " + (new Date()) + System.getProperty("line.separator") + " from the '" + rootElementName + "' element from the '" + schema.getSchemaTargetNS() + "' XML Schema."; //xForm.insertBefore(xForm.createComment(comment),envelopeElement); //xxx XSDNode node = findXSDNodeByName(rootElementTagName,schemaNode.getElementSet()); //check if target namespace //no way to do this with XS API ? load DOM document ? //TODO: find a better way to find the targetNamespace try { Document domDoc = DOMUtil.parseXmlFile(inputURI, true, false); if (domDoc != null) { Element root = domDoc.getDocumentElement(); targetNamespace = root.getAttribute("targetNamespace"); if (targetNamespace != null && targetNamespace.equals("")) targetNamespace = null; } } catch (Exception ex) { LOGGER.error("Schema not loaded as DOM document: " + ex.getMessage()); } //if target namespace & we use the schema types: add it to form ns declarations if (_useSchemaTypes && targetNamespace != null && !targetNamespace.equals("")) { envelopeElement.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:schema", targetNamespace); } //TODO: WARNING: in Xerces 2.6.1, parameters are switched !!! (name, namespace) //XSElementDeclaration rootElementDecl =schema.getElementDeclaration(targetNamespace, _rootTagName); XSElementDeclaration rootElementDecl = schema.getElementDeclaration(_rootTagName, targetNamespace); if (rootElementDecl == null) { //DEBUG rootElementDecl = schema.getElementDeclaration(_rootTagName, targetNamespace); if (rootElementDecl != null && LOGGER.isDebugEnabled()) LOGGER.debug("getElementDeclaration: inversed parameters OK !!!"); throw new FormBuilderException("Invalid root element tag name [" + _rootTagName + ", targetNamespace=" + targetNamespace + "]"); } Element instanceElement = (Element) modelSection .appendChild(xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "instance")); this.setXFormsId(instanceElement); Element rootElement; if (_instanceMode == AbstractSchemaFormBuilder.INSTANCE_MODE_NONE) { rootElement = (Element) instanceElement.appendChild( xForm.createElementNS(targetNamespace, getElementName(rootElementDecl, xForm))); String prefix = xmlSchemaInstancePrefix.substring(0, xmlSchemaInstancePrefix.length() - 1); rootElement.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:" + prefix, XMLSCHEMA_INSTANCE_NAMESPACE_URI); } else if (_instanceMode == AbstractSchemaFormBuilder.INSTANCE_MODE_INCLUDED) //get the instance element { boolean ok = true; try { /*DOMResult result = new DOMResult(); TransformerFactory trFactory = TransformerFactory.newInstance(); Transformer tr = trFactory.newTransformer(); tr.transform(_instanceSource, result); Document instanceDoc = (Document) result.getNode();*/ DocumentBuilderFactory docFact = DocumentBuilderFactory.newInstance(); docFact.setNamespaceAware(true); docFact.setValidating(false); DocumentBuilder parser = docFact.newDocumentBuilder(); Document instanceDoc = parser.parse(new InputSource(_instanceSource.getSystemId())); //possibility abandonned for the moment: //modify the instance to add the correct "xsi:type" attributes wherever needed //Document instanceDoc=this.setXMLSchemaAndPSVILoad(inputURI, _instanceSource, targetNamespace); if (instanceDoc != null) { Element instanceInOtherDoc = instanceDoc.getDocumentElement(); if (instanceInOtherDoc.getNodeName().equals(_rootTagName)) { rootElement = (Element) xForm.importNode(instanceInOtherDoc, true); instanceElement.appendChild(rootElement); //add XMLSchema instance NS String prefix = xmlSchemaInstancePrefix.substring(0, xmlSchemaInstancePrefix.length() - 1); if (!rootElement.hasAttributeNS(XMLNS_NAMESPACE_URI, prefix)) rootElement.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:" + prefix, XMLSCHEMA_INSTANCE_NAMESPACE_URI); //possibility abandonned for the moment: //modify the instance to add the correct "xsi:type" attributes wherever needed //this.addXSITypeAttributes(rootElement); } else { ok = false; } } else { ok = false; } } catch (Exception ex) { ex.printStackTrace(); //if there is an exception we put the empty root element ok = false; } //if there was a problem if (!ok) { rootElement = (Element) instanceElement.appendChild(xForm.createElement(_rootTagName)); } } else if (_instanceMode == AbstractSchemaFormBuilder.INSTANCE_MODE_HREF) //add the xlink:href attribute { instanceElement.setAttributeNS(SchemaFormBuilder.XLINK_NS, this.getXLinkNSPrefix() + "href", _instanceHref); } Element formContentWrapper = _wrapper.createGroupContentWrapper(formSection); addElement(xForm, modelSection, formContentWrapper, rootElementDecl, rootElementDecl.getTypeDefinition(), "/" + getElementName(rootElementDecl, xForm)); Element submitInfoElement = (Element) modelSection .appendChild(xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "submission")); //submitInfoElement.setAttributeNS(XFORMS_NS,getXFormsNSPrefix()+"id","save"); String submissionId = this.setXFormsId(submitInfoElement); //action if (_action == null) { submitInfoElement.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "action", ""); } else { submitInfoElement.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "action", _action); } //method if ((_submitMethod != null) && !_submitMethod.equals("")) { submitInfoElement.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "method", _submitMethod); } else { //default is "post" submitInfoElement.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "method", AbstractSchemaFormBuilder.SUBMIT_METHOD_POST); } //Element submitButton = (Element) formSection.appendChild(xForm.createElementNS(XFORMS_NS,getXFormsNSPrefix()+"submit")); Element submitButton = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "submit"); Element submitControlWrapper = _wrapper.createControlsWrapper(submitButton); formContentWrapper.appendChild(submitControlWrapper); submitButton.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "submission", submissionId); this.setXFormsId(submitButton); Element submitButtonCaption = (Element) submitButton .appendChild(xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "label")); submitButtonCaption.appendChild(xForm.createTextNode("Submit")); this.setXFormsId(submitButtonCaption); return xForm; } catch (ParserConfigurationException x) { throw new FormBuilderException(x); } catch (java.lang.ClassNotFoundException x) { throw new FormBuilderException(x); } catch (java.lang.InstantiationException x) { throw new FormBuilderException(x); } catch (java.lang.IllegalAccessException x) { throw new FormBuilderException(x); } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
protected String setXFormsId(Element el) { //remove the eventuel "id" attribute if (el.hasAttributeNS(SchemaFormBuilder.XFORMS_NS, "id")) { el.removeAttributeNS(SchemaFormBuilder.XFORMS_NS, "id"); }/* ww w.jav a 2s . c o m*/ //long count=this.incIdCounter(); long count = 0; String name = el.getLocalName(); Long l = (Long) counter.get(name); if (l != null) { count = l.longValue(); } String id = name + "_" + count; //increment the counter counter.put(name, new Long(count + 1)); el.setAttributeNS(SchemaFormBuilder.XFORMS_NS, this.getXFormsNSPrefix() + "id", id); return id; }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
protected void addChoicesForSelectSwitchControl(Document xForm, Element choicesElement, Vector choiceValues, HashMap case_types) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("addChoicesForSelectSwitchControl, values="); Iterator it = choiceValues.iterator(); while (it.hasNext()) { //String name=(String) it.next(); XSTypeDefinition type = (XSTypeDefinition) it.next(); String name = type.getName(); LOGGER.debug(" - " + name); }//from w ww . j a v a 2s. c om } // sort the enums values and then add them as choices // // TODO: Should really put the default value (if any) at the top of the list. // /*List sortedList = choiceValues.subList(0, choiceValues.size()); Collections.sort(sortedList); Iterator iterator = sortedList.iterator();*/ // -> no, already sorted Iterator iterator = choiceValues.iterator(); while (iterator.hasNext()) { XSTypeDefinition type = (XSTypeDefinition) iterator.next(); String textValue = type.getName(); //String textValue = (String) iterator.next(); if (LOGGER.isDebugEnabled()) LOGGER.debug("addChoicesForSelectSwitchControl, processing " + textValue); Element item = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "item"); this.setXFormsId(item); choicesElement.appendChild(item); Element captionElement = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "label"); this.setXFormsId(captionElement); item.appendChild(captionElement); captionElement.appendChild(xForm.createTextNode(createCaption(textValue))); Element value = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "value"); this.setXFormsId(value); item.appendChild(value); value.appendChild(xForm.createTextNode(textValue)); /// action in the case Element action = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "action"); this.setXFormsId(action); item.appendChild(action); action.setAttributeNS(XMLEVENTS_NS, xmleventsNSPrefix + "event", "xforms-select"); Element toggle = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "toggle"); this.setXFormsId(toggle); //build the case element Element caseElement = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "case"); String case_id = this.setXFormsId(caseElement); case_types.put(textValue, caseElement); toggle.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "case", case_id); //toggle.setAttributeNS(XFORMS_NS,getXFormsNSPrefix() + "case",bindIdPrefix + "_" + textValue +"_case"); action.appendChild(toggle); } }