List of usage examples for org.w3c.dom Node getUserData
public Object getUserData(String key);
From source file:org.dozer.eclipse.plugin.sourcepage.validation.Validator.java
@SuppressWarnings("restriction") private void checkClassNodes(NodeList nodeList, IFile file, ValidationInfo validationReport) throws JavaModelException, DOMException { int len = nodeList.getLength(); for (int i = 0; i < len; i++) { Node node = nodeList.item(i); Node textNode = node.getFirstChild(); if (textNode.getNodeType() == Node.TEXT_NODE) { String className = textNode.getNodeValue(); IType javaType = JdtUtils.getJavaType(file.getProject(), className); //class not found if (javaType == null) { Integer[] location = (Integer[]) node.getUserData("location"); validationReport.addError("Class " + className + " not found.", location[0], location[1], validationReport.getFileURI()); }/*from www .j a v a 2s. c om*/ } } }
From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java
@SuppressWarnings("unchecked") private void postProcessNodeReplacement(Element element) { Document ownerDocument = element.getOwnerDocument(); Node child = element.getFirstChild(); while (child != null) { Node nextChild = child.getNextSibling(); if (child instanceof Element) { if (child.getUserData("dorado.delete") != null) { List<Element> replaceContent = (List<Element>) child.getUserData("dorado.replace"); if (replaceContent != null) { for (Element el : replaceContent) { Element clonedElement = (Element) ownerDocument.importNode(el, true); element.insertBefore(clonedElement, child); }/*from ww w . ja v a 2s . c om*/ child.setUserData("dorado.replace", null, null); } element.removeChild(child); child.setUserData("dorado.delete", null, null); } } child = nextChild; } }
From source file:org.dozer.eclipse.plugin.sourcepage.validation.Validator.java
@SuppressWarnings("restriction") private void checkFieldNodes(NodeList nodeList, IFile file, ValidationInfo validationReport) throws JavaModelException, DOMException { int len = nodeList.getLength(); //check all field-nodes... for (int i = 0; i < len; i++) { Node node = nodeList.item(i); //field //..have custom-converter attributes Node attrNode = node.getAttributes().getNamedItem("custom-converter"); if (attrNode != null) { //...doesnt implement the CustomConverter Interface if (!checkClassImplementsCustomConverter(file.getProject(), attrNode.getNodeValue())) { //this class doesnt implement the interface and is worth an error Integer[] location = (Integer[]) node.getUserData("location"); validationReport.addError("Class does not implement interface CustomConverter", location[0], location[1], validationReport.getFileURI()); }// w w w . j a v a 2 s .c o m //...have custom-converter-id attributes } else { attrNode = node.getAttributes().getNamedItem("custom-converter-id"); if (attrNode != null) { String className = DozerPluginUtils.getClassNameForCCI(file, attrNode.getNodeValue()); if (className != null && !checkClassImplementsCustomConverter(file.getProject(), className)) { //this class doesnt implement the interface and is worth an error Integer[] location = (Integer[]) node.getUserData("location"); validationReport.addError("Bean does not implement interface CustomConverter", location[0], location[1], validationReport.getFileURI()); } } } NodeList abList = node.getChildNodes(); int abLen = abList.getLength(); for (int a = 0; a < abLen; a++) { Node abNode = abList.item(a); //a or b if ("a".equals(abNode.getNodeName()) || "b".equals(abNode.getNodeName())) { Node textNode = abNode.getFirstChild(); //...no value set between <a></a> or <b></b>? if (textNode == null) { Integer[] location = (Integer[]) node.getUserData("location"); String className = DozerPluginUtils.getMappingClassName(abNode); String nodeName = abNode.getNodeName(); validationReport.addError( "Unsetted property value in node " + nodeName + " for class " + className, location[0], location[1], validationReport.getFileURI()); } //...is fieldname correct? else if (textNode.getNodeType() == Node.TEXT_NODE) { String property = textNode.getNodeValue(); String className = DozerPluginUtils.getMappingClassName(abNode); attrNode = DozerPluginUtils.getMappingNode(abNode).getAttributes().getNamedItem("type"); boolean bIsBiDirectional = true; if (attrNode != null) { bIsBiDirectional = "bi-directional".equals(attrNode.getNodeValue()); } if (!"this".equals(property)) { Node isAccessibleNode = abNode.getAttributes().getNamedItem("is-accessible"); boolean isAccessible = isAccessibleNode != null && "true".equals(isAccessibleNode.getNodeValue()); if ((bIsBiDirectional || "a".equals(abNode.getNodeName())) && DozerPluginUtils.hasReadProperty(property, className, file.getProject(), isAccessible) == null) { Integer[] location = (Integer[]) abNode.getUserData("location"); validationReport.addError( "Property " + property + " for class " + className + " cannot be read from.", location[0], location[1], validationReport.getFileURI()); } else if ((bIsBiDirectional || "b".equals(abNode.getNodeName())) && DozerPluginUtils .hasWriteProperty(property, className, file.getProject()) == null) { Integer[] location = (Integer[]) abNode.getUserData("location"); validationReport.addError( "Property " + property + " for class " + className + " cannot be written to.", location[0], location[1], validationReport.getFileURI()); } } } } } } }
From source file:de.betterform.xml.xforms.model.Instance.java
private void listModelItems(List list, Node node, boolean deep) { ModelItem modelItem = (ModelItem) node.getUserData(""); if (modelItem == null) { modelItem = createModelItem(node); }/*from w w w .j av a2 s .co m*/ list.add(modelItem); if (deep) { NamedNodeMap attributes = node.getAttributes(); for (int index = 0; attributes != null && index < attributes.getLength(); index++) { listModelItems(list, attributes.item(index), deep); } if (node.getNodeType() != Node.ATTRIBUTE_NODE) { NodeList children = node.getChildNodes(); for (int index = 0; index < children.getLength(); index++) { listModelItems(list, children.item(index), deep); } } } }
From source file:de.betterform.xml.xforms.model.Instance.java
/** * this method lets you access the state of individual instance data nodes. * each node has an associated ModelItem object which holds the current * status of readonly, required, validity, relevant. it also annotates the * DOM node with type information./*from w ww .j av a 2 s .c o m*/ * <p/> * When an ModelItem does not exist already it will be created and attached * as useroject to its corresponding node in the instancedata. * * @param locationPath - an absolute location path pointing to some node in * this instance * @return the ModelItem for the specified node */ public ModelItem getModelItem(String locationPath) throws XFormsException { if (LOGGER.isDebugEnabled()) { LOGGER.debug(this + " get model item for locationPath '" + locationPath + "'"); } // ensure that node exists since getPointer is buggy if (!existsNode(locationPath)) { return null; } Node node = getNode(locationPath); ModelItem item = (ModelItem) node.getUserData(""); if (item == null) { // create item item = createModelItem(node); // if (LOGGER.isDebugEnabled()) { // LOGGER.debug(this + " get model item: created item for path '" + pointer + "'"); // } } return item; }
From source file:de.betterform.xml.xforms.model.Instance.java
/** * * @param node/*from w w w. j a v a2s .c o m*/ * @return */ public ModelItem getModelItem(Node node) { if (node == null) { return null; } ModelItem item = (ModelItem) node.getUserData(""); if (item == null) { // create item item = Instance.createModelItem(node); if (LOGGER.isDebugEnabled()) { LOGGER.debug( this + " get model item: created item for path " + BindingResolver.getCanonicalPath(node)); } } return item; }
From source file:com.twinsoft.convertigo.beans.core.Sequence.java
private static Node cloneNodeWithUserData(Node node, boolean recurse) { if (node != null) { Object node_output = node.getUserData(Step.NODE_USERDATA_OUTPUT); Node clonedNode = node.cloneNode(false); clonedNode.setUserData(Step.NODE_USERDATA_OUTPUT, node_output, null); if (node.getNodeType() == Node.ELEMENT_NODE) { // attributes NamedNodeMap attributeMap = clonedNode.getAttributes(); for (int i = 0; i < attributeMap.getLength(); i++) { Node clonedAttribute = attributeMap.item(i); String attr_name = clonedAttribute.getNodeName(); Object attr_output = ((Element) node).getAttributeNode(attr_name) .getUserData(Step.NODE_USERDATA_OUTPUT); clonedAttribute.setUserData(Step.NODE_USERDATA_OUTPUT, attr_output, null); }// ww w. j a va 2 s .c o m // recurse on element child nodes only if (recurse && node.hasChildNodes()) { NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node clonedChild = cloneNodeWithUserData(list.item(i), recurse); if (clonedChild != null) { clonedNode.appendChild(clonedChild); } } } } return clonedNode; } return null; }
From source file:org.apache.shindig.gadgets.templates.tags.FlashTagHandler.java
/** * Ensure that the swfobject JS is inlined *//*from ww w. j av a 2s.co m*/ void ensureSwfobject(Document doc, TemplateProcessor processor) { // TODO: This should probably be a function of the rewriter. Element head = (Element) DomUtil.getFirstNamedChildNode(doc.getDocumentElement(), "head"); NodeList childNodes = head.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getUserData(SWFOBJECT) != null) { return; } } Element swfobject = doc.createElement("script"); swfobject.setAttribute("type", "text/javascript"); List<FeatureResource> resources = featureRegistry.getFeatureResources( processor.getTemplateContext().getGadget().getContext(), ImmutableSet.of(SWFOBJECT), null); for (FeatureResource resource : resources) { // Emits all content for feature SWFOBJECT, which has no downstream dependencies. swfobject.setTextContent(resource.getContent()); } swfobject.setUserData(SWFOBJECT, SWFOBJECT, null); head.appendChild(swfobject); SanitizingGadgetRewriter.bypassSanitization(swfobject, false); }
From source file:org.nuxeo.theme.themes.ThemeParser.java
public static void parseLayout(final Element parent, Node node) throws ThemeIOException, ThemeException { TypeRegistry typeRegistry = Manager.getTypeRegistry(); ThemeManager themeManager = Manager.getThemeManager(); for (String formatName : typeRegistry.getTypeNames(TypeFamily.FORMAT)) { Format format = (Format) node.getUserData(formatName); if (format != null) { if (ElementFormatter.getElementsFor(format).isEmpty()) { ElementFormatter.setFormat(parent, format); } else { Format duplicatedFormat = themeManager.duplicateFormat(format); ElementFormatter.setFormat(parent, duplicatedFormat); }// w w w. ja va 2 s . co m } } Properties properties = (Properties) node.getUserData("properties"); if (properties != null) { FieldIO.updateFieldsFromProperties(parent, properties); } for (Node n : getChildElements(node)) { String nodeName = n.getNodeName(); NamedNodeMap attributes = n.getAttributes(); Element elem; if ("fragment".equals(nodeName)) { String fragmentType = attributes.getNamedItem("type").getNodeValue(); elem = FragmentFactory.create(fragmentType); if (elem == null) { log.error("Could not create fragment: " + fragmentType); continue; } Fragment fragment = (Fragment) elem; Node perspectives = attributes.getNamedItem("perspectives"); if (perspectives != null) { for (String perspectiveName : perspectives.getNodeValue().split(",")) { PerspectiveType perspective = (PerspectiveType) typeRegistry.lookup(TypeFamily.PERSPECTIVE, perspectiveName); if (perspective == null) { log.warn("Could not find perspective: " + perspectiveName); } else { fragment.setVisibleInPerspective(perspective); } } } } else { elem = ElementFactory.create(nodeName); } if (elem == null) { throw new ThemeIOException("Could not parse node: " + nodeName); } Node nameAttr = attributes.getNamedItem("name"); if (nameAttr != null) { String elementName = nameAttr.getNodeValue(); if (checkElementName(elementName)) { elem.setName(elementName); } else { log.warn( "Element names may only contain lower-case alpha-numeric characters, digits, underscores, spaces and dashes: " + elementName); } } Node classAttr = attributes.getNamedItem("class"); if (classAttr != null) { elem.setCssClassName(classAttr.getNodeValue()); } String description = getCommentAssociatedTo(n); if (description != null) { elem.setDescription(description); } try { parent.addChild(elem); } catch (NodeException e) { throw new ThemeIOException("Failed to parse layout.", e); } parseLayout(elem, n); } }
From source file:sf.net.experimaestro.utils.JSUtils.java
/** * Transforms a DOM node to a E4X scriptable object * * @param node/*from ww w . ja va 2 s . c o m*/ * @param cx * @param scope * @return */ public static Object domToE4X(Node node, Context cx, Scriptable scope) { if (node == null) { LOGGER.info("XML is null"); return Context.getUndefinedValue(); } if (node instanceof Document) node = ((Document) node).getDocumentElement(); if (node instanceof DocumentFragment) { final Document document = node.getOwnerDocument(); Element root = document.createElement("root"); document.appendChild(root); Scriptable xml = cx.newObject(scope, "XML", new Node[] { root }); final Scriptable list = (Scriptable) xml.get("*", xml); int count = 0; for (Node child : XMLUtils.children(node)) { list.put(count++, list, cx.newObject(scope, "XML", new Node[] { child })); } return list; } LOGGER.debug("XML is of type %s [%s]; %s", node.getClass(), XMLUtils.toStringObject(node), node.getUserData("org.mozilla.javascript.xmlimpl.XmlNode")); return cx.newObject(scope, "XML", new Node[] { node }); }