List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Parses the xml bean into a standard bean definition format and fills the information in the passed in definition * builder/*from w ww .ja v a 2s.c om*/ * * @param element - The xml bean being parsed. * @param parserContext - Provided information and functionality regarding current bean set. * @param bean - A definition builder used to build a new spring bean from the information it is filled with. */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) { // Retrieve custom schema information build from the annotations Map<String, Map<String, BeanTagAttributeInfo>> attributeProperties = CustomTagAnnotations .getAttributeProperties(); Map<String, BeanTagAttributeInfo> entries = attributeProperties.get(element.getLocalName()); // Log error if there are no attributes found for the bean tag if (entries == null) { LOG.error("Bean Tag not found " + element.getLocalName()); } if (element.getTagName().equals(INC_TAG)) { String parentId = element.getAttribute("compId"); bean.setParentName(parentId); return; } if (element.getTagName().equals("content")) { bean.setParentName("Uif-Content"); String markup = nodesToString(element.getChildNodes()); bean.addPropertyValue("markup", markup); return; } // Retrieve the information for the new bean tag and fill in the default parent if needed BeanTagInfo tagInfo = CustomTagAnnotations.getBeanTags().get(element.getLocalName()); String elementParent = element.getAttribute("parent"); if (StringUtils.isNotBlank(elementParent) && !StringUtils.equals(elementParent, tagInfo.getParent())) { bean.setParentName(elementParent); } else if (StringUtils.isNotBlank(tagInfo.getParent())) { bean.setParentName(tagInfo.getParent()); } // Create the map for the attributes found in the tag and process them in to the definition builder. NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { processSingleValue(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue(), entries, bean); } ArrayList<Element> children = (ArrayList<Element>) DomUtils.getChildElements(element); // Process the children found in the xml tag for (int i = 0; i < children.size(); i++) { String tag = children.get(i).getLocalName(); BeanTagAttributeInfo info = entries.get(tag); if (children.get(i).getTagName().equals("spring:property") || children.get(i).getTagName().equals("property")) { BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); delegate.parsePropertyElement(children.get(i), bean.getBeanDefinition()); continue; } // Sets the property name to be used when adding the property value String propertyName; BeanTagAttribute.AttributeType type = null; if (info == null) { propertyName = CustomTagAnnotations.findPropertyByType(element.getLocalName(), tag); if (StringUtils.isNotBlank(propertyName)) { bean.addPropertyValue(propertyName, parseBean(children.get(i), bean, parserContext)); continue; } else { // If the tag is not in the schema map let spring handle the value by forwarding the tag as the // propertyName propertyName = tag; type = findBeanType(children.get(i)); } } else { // If the tag is found in the schema map use the connected name stored in the attribute information propertyName = info.getPropertyName(); type = info.getType(); } // Process the information stored in the child bean ArrayList<Element> grandChildren = (ArrayList<Element>) DomUtils.getChildElements(children.get(i)); if (type == BeanTagAttribute.AttributeType.SINGLEVALUE) { String propertyValue = DomUtils.getTextValue(children.get(i)); bean.addPropertyValue(propertyName, propertyValue); } else if (type == BeanTagAttribute.AttributeType.ANY) { String propertyValue = nodesToString(children.get(i).getChildNodes()); bean.addPropertyValue(propertyName, propertyValue); } else if ((type == BeanTagAttribute.AttributeType.DIRECT) || (type == BeanTagAttribute.AttributeType.DIRECTORBYTYPE)) { boolean isPropertyTag = false; if ((children.get(i).getAttributes().getLength() == 0) && (grandChildren.size() == 1)) { String grandChildTag = grandChildren.get(0).getLocalName(); Class<?> valueClass = info.getValueType(); if (valueClass.isInterface()) { try { valueClass = Class.forName(valueClass.getName() + "Base"); } catch (ClassNotFoundException e) { throw new RuntimeException("Unable to find impl class for interface", e); } } Set<String> validTagNames = CustomTagAnnotations.getBeanTagsByClass(valueClass); if (validTagNames.contains(grandChildTag)) { isPropertyTag = true; } } if (isPropertyTag) { bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext)); } else { bean.addPropertyValue(propertyName, parseBean(children.get(i), bean, parserContext)); } } else if ((type == BeanTagAttribute.AttributeType.SINGLEBEAN) || (type == BeanTagAttribute.AttributeType.BYTYPE)) { bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.LISTBEAN) { bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.LISTVALUE) { bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.MAPVALUE) { bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.MAPBEAN) { bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.SETVALUE) { bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.SETBEAN) { bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext)); } } }
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Parses a list of elements into a list of beans/standard content. * * @param grandChildren - The list of beans/content in a bean property * @param child - The property tag for the parent. * @param parent - The parent bean that the tag is nested in. * @param parserContext - Provided information and functionality regarding current bean set. * @return A managedList of the nested content. *//*from w w w . ja v a 2s . co m*/ protected ManagedList parseList(ArrayList<Element> grandChildren, Element child, BeanDefinitionBuilder parent, ParserContext parserContext) { ArrayList<Object> listItems = new ArrayList<Object>(); for (int i = 0; i < grandChildren.size(); i++) { Element grandChild = grandChildren.get(i); if (grandChild.getTagName().compareTo("value") == 0) { listItems.add(grandChild.getTextContent()); } else { listItems.add(parseBean(grandChild, parent, parserContext)); } } String merge = child.getAttribute("merge"); ManagedList beans = new ManagedList(listItems.size()); beans.addAll(listItems); if (merge != null) { beans.setMergeEnabled(Boolean.valueOf(merge)); } return beans; }
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Parses a list of elements into a set of beans/standard content. * * @param grandChildren - The set of beans/content in a bean property * @param child - The property tag for the parent. * @param parent - The parent bean that the tag is nested in. * @param parserContext - Provided information and functionality regarding current bean set. * @return A managedSet of the nested content. *//* w w w . ja va 2s .co m*/ protected ManagedSet parseSet(ArrayList<Element> grandChildren, Element child, BeanDefinitionBuilder parent, ParserContext parserContext) { ManagedSet setItems = new ManagedSet(); for (int i = 0; i < grandChildren.size(); i++) { Element grandChild = grandChildren.get(i); if (child.getTagName().compareTo("value") == 0) { setItems.add(grandChild.getTextContent()); } else { setItems.add(parseBean(grandChild, parent, parserContext)); } } String merge = child.getAttribute("merge"); if (merge != null) { setItems.setMergeEnabled(Boolean.valueOf(merge)); } return setItems; }
From source file:org.kuali.test.handlers.htmltag.DefaultHtmlTagHandler.java
@Override public boolean isInput(Element node) { return Utils.isFormInputTag(node.getTagName()); }
From source file:org.kuali.test.handlers.htmltag.KualiTabContainerTagHandler.java
private String findTabName(Element node) { String retval = null;/*from w w w. ja v a 2s. co m*/ Element prev = Utils.getPreviousSiblingElement(node); if (prev != null) { String cname = prev.getAttribute(Constants.HTML_TAG_ATTRIBUTE_CLASS); if (Constants.TAB.equals(cname) && Constants.HTML_TAG_TYPE_TABLE.equals(prev.getTagName())) { Element child = Utils.getFirstChildNodeByNodeName(prev, Constants.HTML_TAG_TYPE_TBODY); if (child != null) { child = Utils.getFirstChildNodeByNodeName(child, Constants.HTML_TAG_TYPE_TR); if (child != null) { child = Utils.getFirstChildNodeByNodeName(child, Constants.HTML_TAG_TYPE_TD); if (child != null) { retval = Utils.cleanDisplayText(child); } } } } } return retval; }
From source file:org.kuali.test.handlers.htmltag.KualiTabTagHandler.java
private String findTabName(Element node) { String retval = null;/* www . j a v a2 s. com*/ Element prev = Utils.getPreviousSiblingElement(node); if (prev != null) { String cname = prev.getAttribute(Constants.HTML_TAG_ATTRIBUTE_CLASS); if (TAB_NAME_HTML_CLASSES.contains(cname)) { retval = Utils.cleanDisplayText(prev); } if (StringUtils.isBlank(retval)) { if (Constants.TAB.equals(cname) && Constants.HTML_TAG_TYPE_TABLE.equals(prev.getTagName())) { Element child = Utils.getFirstChildNodeByNodeName(prev, Constants.HTML_TAG_TYPE_TBODY); // special handling for tbody - sometimes there sometimes not if (child == null) { child = Utils.getFirstChildNodeByNodeName(prev, Constants.HTML_TAG_TYPE_TR); } else { child = Utils.getFirstChildNodeByNodeName(child, Constants.HTML_TAG_TYPE_TR); } if (child != null) { child = Utils.getFirstChildNodeByNodeName(child, Constants.HTML_TAG_TYPE_TD); if (child != null) { retval = Utils.cleanDisplayText(child); } } } } } return retval; }
From source file:org.kuali.test.handlers.htmltag.TdTagHandler.java
/** * * @param node//w ww .ja va2s . c om * @return */ @Override public String getSectionName(Element node) { String retval = null; if (getTagHandler().getSectionMatcher() != null) { retval = Utils.getMatchedNodeText(getTagHandler().getSectionMatcher().getTagMatcherArray(), node); } if (StringUtils.isBlank(retval)) { Element pnode = (Element) node.getParentNode(); if ((pnode != null) && Constants.HTML_TAG_TYPE_TR.equals(pnode.getTagName())) { int row = Utils.getChildNodeIndex(pnode); if (row > 0) { retval = "row[" + row + "]"; } } } if (LOG.isDebugEnabled()) { LOG.debug("section: " + retval); } return retval; }
From source file:org.kuali.test.utils.HtmlDomProcessor.java
private void processNode(DomInformation domInformation) { Element node = domInformation.getCurrentNode(); HtmlTagHandler th = Utils.getHtmlTagHandler(domInformation.getPlatform().getApplication().toString(), node); if (th != null) { if (th.isContainer(node)) { String groupContainerName = th.getGroupContainerName(node); String groupName = th.getGroupName(node); if (StringUtils.isNotBlank(groupContainerName)) { domInformation.getGroupContainerStack().push(groupContainerName); }//from ww w . j ava 2 s . c om if (StringUtils.isNotBlank(groupName)) { domInformation.getGroupStack().push(groupName); } for (Element child : Utils.getChildElements(node)) { domInformation.setCurrentNode(child); processNode(domInformation); } if (StringUtils.isNotBlank(groupName)) { domInformation.getGroupStack().pop(); } if (StringUtils.isNotBlank(groupContainerName)) { domInformation.getGroupContainerStack().pop(); } } else { CheckpointProperty cp = th.getCheckpointProperty(node); if ((cp != null) && !Utils.isNodeProcessed(domInformation.getProcessedNodes(), node)) { if (StringUtils.isBlank(cp.getPropertyGroupContainer()) && !domInformation.getGroupContainerStack().isEmpty()) { cp.setPropertyGroupContainer(domInformation.getGroupContainerStack().peek()); } if (StringUtils.isBlank(cp.getPropertyGroup()) || Constants.DEFAULT_HTML_PROPERTY_GROUP.equals(cp.getPropertyGroup())) { cp.setPropertyGroup(domInformation.getGroupStack().peek()); } cp.setPropertySection(Utils.buildCheckpointSectionName(th, node)); if (th.getTagHandler().getLabelMatcher() != null) { cp.setDisplayName(Utils.getMatchedNodeText( th.getTagHandler().getLabelMatcher().getTagMatcherArray(), node)); } else if (domInformation.getLabelMap().containsKey(cp.getPropertyName())) { cp.setDisplayName(Utils.trimString(domInformation.getLabelMap().get(cp.getPropertyName()))); } if (StringUtils.isNotBlank(cp.getPropertyValue())) { cp.setOperator(ComparisonOperator.EQUAL_TO); } if (StringUtils.isNotBlank(cp.getDisplayName()) && isValidSectionName(cp, th)) { cp.addNewTagInformation(); Parameter p = null; if (Constants.HTML_TAG_TYPE_TD.equals(node.getTagName()) || Constants.HTML_TAG_TYPE_TH.equals(node.getTagName())) { Element table = Utils.getParentNodeByTagName(node, Constants.HTML_TAG_TYPE_TABLE); if (table != null) { String tid = table.getAttribute(Constants.HTML_TAG_ATTRIBUTE_ID); String tname = table.getAttribute(Constants.HTML_TAG_ATTRIBUTE_NAME); if (StringUtils.isNotBlank(tid)) { p = cp.getTagInformation().addNewParameter(); p.setName(Constants.TABLE_ID); p.setValue(tid); } if (StringUtils.isNotBlank(tname)) { p = cp.getTagInformation().addNewParameter(); p.setName(Constants.TABLE_NAME); p.setValue(tname); } Element row = Utils.getParentNodeByTagName(node, Constants.HTML_TAG_TYPE_TR); if (row != null) { p = cp.getTagInformation().addNewParameter(); p.setName(Constants.ROW_NUMBER); p.setValue("" + Utils.getChildNodeIndex(row)); } p = cp.getTagInformation().addNewParameter(); p.setName(Constants.COLUMN_NUMBER); p.setValue("" + Utils.getChildNodeIndex(node)); } Node anchor = Utils.getFirstChildNodeByNodeName(node, Constants.HTML_TAG_TYPE_ANCHOR); if (anchor != null) { p = cp.getTagInformation().addNewParameter(); p.setName(Constants.ANCHOR_PARAMETERS); p.setValue(getAnchorParameters(anchor)); } } Element useNode = node; if (th.isInputWrapper(node)) { useNode = th.getInputElement(node); } p = cp.getTagInformation().addNewParameter(); p.setName(Constants.TAG_NAME); p.setValue(useNode.getTagName()); String s = useNode.getAttribute(Constants.HTML_TAG_ATTRIBUTE_ID); if (StringUtils.isNotBlank(s)) { p = cp.getTagInformation().addNewParameter(); p.setName(Constants.HTML_TAG_ATTRIBUTE_ID); p.setValue(s); } s = useNode.getAttribute(Constants.HTML_TAG_ATTRIBUTE_NAME); if (StringUtils.isNotBlank(s)) { p = cp.getTagInformation().addNewParameter(); p.setName(Constants.HTML_TAG_ATTRIBUTE_NAME); p.setValue(s); } s = useNode.getAttribute(Constants.HTML_TAG_ATTRIBUTE_TYPE); if (StringUtils.isNotBlank(s)) { p = cp.getTagInformation().addNewParameter(); p.setName(Constants.HTML_TAG_ATTRIBUTE_TYPE); p.setValue(s); } String iframeids = getIframeParentIds(node); if (StringUtils.isNotBlank(iframeids)) { p = cp.getTagInformation().addNewParameter(); p.setName(Constants.IFRAME_IDS); p.setValue(iframeids); } domInformation.getCheckpointProperties().add(cp); } } } } else if (Utils.isValidContainerNode(node)) { for (Element child : Utils.getChildElements(node)) { domInformation.setCurrentNode(child); processNode(domInformation); } } }
From source file:org.kuali.test.utils.JWebBrowserDocumentGenerator.java
private Element getIframeParent(Element element) { Element retval = null;//www . ja v a 2 s .co m Element pnode = (Element) element.getParentNode(); while (pnode != null) { if (Constants.HTML_TAG_TYPE_IFRAME.equalsIgnoreCase(pnode.getTagName())) { retval = pnode; break; } if (pnode.getParentNode() instanceof Element) { pnode = (Element) pnode.getParentNode(); } else { break; } } return retval; }
From source file:org.kuali.test.utils.JWebBrowserDocumentGenerator.java
private void populateIframes(JWebBrowser webBrowser, Document doc, Element element) { if (Constants.HTML_TAG_TYPE_IFRAME.equalsIgnoreCase(element.getTagName()) && !element.hasChildNodes()) { String id = element.getAttribute("id"); String name = element.getAttribute("name"); String iframeCall = getIframeContentCall(element, id, name); if (StringUtils.isNotBlank(iframeCall)) { Object o = webBrowser.executeJavascriptWithResult(iframeCall); if (o != null) { if (o.toString().contains("<html>")) { element.appendChild(Utils.cleanHtml(o.toString()).getDocumentElement()); } else { element.appendChild( Utils.cleanHtml("<html>" + o.toString() + "</html>").getDocumentElement()); }//from www . j a v a 2s. c o m } } } for (Element e : Utils.getChildElements(element)) { populateIframes(webBrowser, doc, e); } }