List of usage examples for org.w3c.dom Element getUserData
public Object getUserData(String key);
From source file:de.betterform.xml.xforms.action.LoadAction.java
private void destroyembeddedModels(Element targetElem) throws XFormsException { NodeList childNodes = targetElem.getChildNodes(); for (int index = 0; index < childNodes.getLength(); index++) { Node node = childNodes.item(index); if (node.getNodeType() == Node.ELEMENT_NODE) { Element elementImpl = (Element) node; String name = elementImpl.getLocalName(); String uri = elementImpl.getNamespaceURI(); if (NamespaceConstants.XFORMS_NS.equals(uri) && name.equals(XFormsConstants.MODEL)) { Model model = (Model) elementImpl.getUserData(""); if (LOGGER.isDebugEnabled()) { LOGGER.debug("dispatch 'model-destruct' event to embedded model: " + model.getId()); ;//ww w .ja va2s . c o m } String modelId = model.getId(); // do not dispatch model-destruct to avoid problems in lifecycle // TODO: review: this.container.dispatch(model.getTarget(), XFormsEventNames.MODEL_DESTRUCT, null); model.dispose(); this.container.removeModel(model); model = null; if (Config.getInstance().getProperty("betterform.debug-allowed").equals("true")) { Map contextInfo = new HashMap(1); contextInfo.put("modelId", modelId); this.container.dispatch(this.target, BetterFormEventNames.MODEL_REMOVED, contextInfo); } } else { destroyembeddedModels(elementImpl); } } } }
From source file:de.betterform.xml.xforms.model.submission.Submission.java
private void destroyembeddedModels(Element targetElem) throws XFormsException { NodeList childNodes = targetElem.getChildNodes(); for (int index = 0; index < childNodes.getLength(); index++) { Node node = childNodes.item(index); if (node.getNodeType() == Node.ELEMENT_NODE) { Element elementImpl = (Element) node; String name = elementImpl.getLocalName(); String uri = elementImpl.getNamespaceURI(); if (NamespaceConstants.XFORMS_NS.equals(uri) && name.equals(XFormsConstants.MODEL)) { Model model = (Model) elementImpl.getUserData(""); if (LOGGER.isDebugEnabled()) { LOGGER.debug("dispatch 'model-destruct' event to embedded model: " + model.getId()); }// w ww . jav a 2 s .co m String modelId = model.getId(); // do not dispatch model-destruct to avoid problems in lifecycle // TODO: review: this.container.dispatch(model.getTarget(), XFormsEventNames.MODEL_DESTRUCT, null); model.dispose(); this.container.removeModel(model); model = null; if (Config.getInstance().getProperty("betterform.debug-allowed").equals("true")) { Map contextInfo = new HashMap(1); contextInfo.put("modelId", modelId); this.container.dispatch(this.target, BetterFormEventNames.MODEL_REMOVED, contextInfo); } } else { destroyembeddedModels(elementImpl); } } } }
From source file:com.twinsoft.convertigo.beans.core.Sequence.java
public synchronized void flushStepDocument(String executeTimeID, Document doc) { Element stepElement = findStepElement(executeTimeID); if (stepElement == null) { stepElement = context.outputDocument.getDocumentElement(); }// www .ja v a 2 s . c om stepElement.appendChild(context.outputDocument.importNode(doc.getDocumentElement(), true)); if ("false".equals(stepElement.getUserData(Step.NODE_USERDATA_OUTPUT))) { stepElement.setUserData(Step.NODE_USERDATA_OUTPUT, "none", null); } }
From source file:de.betterform.connector.serializer.FormDataSerializer.java
protected void serializeElement(PrintWriter writer, Element element, String boundary, String charset) throws Exception { /* The specs http://www.w3.org/TR/2003/REC-xforms-20031014/slice11.html#serialize-form-data *//ww w. j a va 2s . c o m * Each element node is visited in document order. * * Each element that has exactly one text node child is selected * for inclusion. * * Element nodes selected for inclusion are as encoded as * Content-Disposition: form-data MIME parts as defined in * [RFC 2387], with the name parameter being the element local name. * * Element nodes of any datatype populated by upload are serialized * as the specified content and additionally have a * Content-Disposition filename parameter, if available. * * The Content-Type must be text/plain except for xsd:base64Binary, * xsd:hexBinary, and derived types, in which case the header * represents the media type of the attachment if known, otherwise * application/octet-stream. If a character set is applicable, the * Content-Type may have a charset parameter. * */ String nodeValue = null; boolean isCDATASection = false; boolean includeTextNode = true; NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); switch (n.getNodeType()) { /* CDATA sections are not mentioned ... ignore for now case Node.CDATA_SECTION_NODE: isCDATASection = true; */ case Node.TEXT_NODE: if (includeTextNode) { if (nodeValue != null) { /* only one text node allowed by specs */ includeTextNode = false; } else { nodeValue = n.getNodeValue(); } } break; /* Real ambiguity in specs, what if there's one text node and * n elements ? Let's assume if there is an element, ignore the * text nodes */ case Node.ELEMENT_NODE: includeTextNode = false; serializeElement(writer, (Element) n, boundary, charset); break; default: // ignore comments and other nodes... } } if (nodeValue != null && includeTextNode) { Object object = element.getUserData(""); if (object != null && !(object instanceof ModelItem)) { throw new XFormsException("Unknown instance data format."); } ModelItem item = (ModelItem) object; writer.print("\r\n--" + boundary); String name = element.getLocalName(); if (name == null) { name = element.getNodeName(); } // mediatype tells about file upload if (item != null && item.getMediatype() != null) { writer.print("\r\nContent-Disposition: form-data; name=\"" + name + "\";"); if (item.getFilename() != null) { File file = new File(item.getFilename()); writer.print(" filename=\"" + file.getName() + "\";"); } writer.print("\r\nContent-Type: " + item.getMediatype()); } else { writer.print("\r\nContent-Disposition: form-data; name=\"" + name + "\";"); writer.print("\r\nContent-Type: text/plain; charset=\"" + charset + "\";"); } String encoding = "8bit"; if (item != null && "base64Binary".equalsIgnoreCase(item.getDeclarationView().getDatatype())) { encoding = "base64"; } else if (item != null && "hexBinary".equalsIgnoreCase(item.getDeclarationView().getDatatype())) { // recode to base64 because of MIME nodeValue = new String(Base64.encodeBase64(Hex.decodeHex(nodeValue.toCharArray()), true)); encoding = "base64"; } writer.print("\r\nContent-Transfer-Encoding: " + encoding); writer.print("\r\n\r\n" + nodeValue); } writer.flush(); }
From source file:pl.psnc.ep.rt.web.servlets.CollXMLServlet.java
private static void addAuthors(Element metadata, Element content, MetadataServer ms) throws RemoteException, DLibraException { AttributeId authorAttrId = Util.getAttributeId("Autor", ms); AttributeValueSet avs = (AttributeValueSet) metadata.getUserData(KEY_AVS); List<AbstractAttributeValue> authorValues = getValues(avs, authorAttrId); if (authorValues != null && !authorValues.isEmpty()) { String authorsValue = authorValues.get(0).getValue(); NodeList authorsNodes = manualAuthorsHelper.parseAuthorsValue(authorsValue); if (authorsNodes != null) { for (int i = 0; i < authorsNodes.getLength(); i++) { Node imported = metadata.getOwnerDocument().importNode(authorsNodes.item(i), true); metadata.appendChild(imported); }/*from ww w . j a va2s .c o m*/ return; } } LinkedHashSet<String> authors = new LinkedHashSet<String>(); NodeList modules = content.getElementsByTagNameNS(Namespace.COL.URI, "module"); for (int i = 0; i < modules.getLength(); i++) { avs = (AttributeValueSet) modules.item(i).getUserData(KEY_AVS); List<AbstractAttributeValue> values = getValues(avs, authorAttrId); for (AbstractAttributeValue av : values) authors.add(av.getValue()); } Document doc = metadata.getOwnerDocument(); Element actors = element(doc, Namespace.MD, "actors", null); metadata.appendChild(actors); Element roles = element(doc, Namespace.MD, "roles", null); metadata.appendChild(roles); Pattern authorPattern = Pattern.compile("^([^<]+)<([^>]*)>$"); int id = 1; for (String author : authors) { String fullName = author; String email = ""; Matcher matcher = authorPattern.matcher(author); if (matcher.matches()) { fullName = matcher.group(1).trim(); email = matcher.group(2).trim(); } Element person = element(doc, Namespace.MD, "person", null); person.setAttribute("userid", "" + id); person.appendChild(element(doc, Namespace.MD, "fullname", fullName)); person.appendChild(element(doc, Namespace.MD, "firstname", fullName.lastIndexOf(' ') > -1 ? fullName.substring(0, fullName.lastIndexOf(' ')) : fullName)); person.appendChild(element(doc, Namespace.MD, "surname", fullName.lastIndexOf(' ') > -1 ? fullName.substring(fullName.lastIndexOf(' ') + 1, fullName.length()) : "")); person.appendChild(element(doc, Namespace.MD, "email", email)); actors.appendChild(person); Element role = element(doc, Namespace.MD, "role", "" + id); role.setAttribute("type", "author"); roles.appendChild(role); id++; } }