List of usage examples for org.dom4j Element elements
List<Element> elements();
From source file:com.magicpwd.v.app.MenuPtn.java
License:Open Source License
public boolean getSubMenu(String partId, javax.swing.JPopupMenu menu, java.awt.event.ActionListener action) { if (!Char.isValidate(partId) || document == null) { return false; }// www .ja v a2 s .c om Node node = document.getRootElement().selectSingleNode(Char.format("/magicpwd/submenu[@id='{0}']", partId)); if (node == null || !(node instanceof Element)) { return false; } Element element = (Element) node; java.util.List elementList = element.elements(); if (elementList != null) { Element tmp; for (Object obj : elementList) { if (!(obj instanceof Element)) { continue; } tmp = (Element) obj; if ("menu".equals(tmp.getName())) { menu.add(createMenu(tmp, null, action)); continue; } if ("item".equals(tmp.getName())) { menu.add(createItem(tmp, null, action)); continue; } if ("seperator".equals(tmp.getName())) { menu.addSeparator(); continue; } } } return true; }
From source file:com.magicpwd.v.app.MenuPtn.java
License:Open Source License
public boolean getSubMenu(String partId, javax.swing.JMenu menu, java.awt.event.ActionListener action) { if (!Char.isValidate(partId) || document == null) { return false; }// w w w . j av a 2s .co m Node node = document.getRootElement().selectSingleNode(Char.format("/magicpwd/submenu[@id='{0}']", partId)); if (node == null || !(node instanceof Element)) { return false; } Element element = (Element) node; java.util.List elementList = element.elements(); if (elementList != null) { Element tmp; for (Object obj : elementList) { if (!(obj instanceof Element)) { continue; } tmp = (Element) obj; if ("menu".equals(tmp.getName())) { menu.add(createMenu(tmp, null, action)); continue; } if ("item".equals(tmp.getName())) { menu.add(createItem(tmp, null, action)); continue; } if ("seperator".equals(tmp.getName())) { menu.addSeparator(); continue; } } } return true; }
From source file:com.magicpwd.v.app.MenuPtn.java
License:Open Source License
private javax.swing.JMenu createMenu(Element element, javax.swing.JComponent component, java.awt.event.ActionListener action) { javax.swing.JMenu menu = new javax.swing.JMenu(); String id = element.attributeValue("id"); if (Char.isValidate(id)) { buttons.put(id, menu);/* www . j ava2 s .co m*/ } processText(element, menu); processTips(element, menu); processIcon(element, menu); java.util.List list = element.elements(); if (list != null) { for (Object obj : list) { if (!(obj instanceof Element)) { continue; } element = (Element) obj; if ("menu".equals(element.getName())) { menu.add(createMenu(element, component, action)); continue; } if ("item".equals(element.getName())) { menu.add(createItem(element, component, action)); continue; } if ("seperator".equals(element.getName())) { menu.addSeparator(); continue; } } } return menu; }
From source file:com.mg.framework.support.ui.UIProducer.java
License:Open Source License
private static Element copyElement(Element element, RuntimeMacrosLoader runtimeMacrosLoader) { //if (INCLUDE_TAG_NAME.equals(element.getQualifiedName())) //return includeMacros(); Element result = DocumentHelper.createElement(element.getQualifiedName()); result.setAttributes(element.attributes()); List<Element> childElements = MiscUtils.convertUncheckedList(Element.class, element.elements()); for (Element childElement : childElements) { Element copy;/*from w w w .j a v a 2 s .c om*/ if (childElement.getQualifiedName().equals(INCLUDE_TAG_NAME)) { copy = includeMacros(result, childElement, runtimeMacrosLoader); /*Document macros = null; String runtimeMacros = childElement.attributeValue(RUNTIME_MACROS_NAME_ATTR); if (runtimeMacros == null) macros = loadMacros(childElement.attributeValue(MACROS_NAME_ATTR)); else macros = loadRuntimeMacros(runtimeMacros, runtimeMacrosLoader); String macrosType = macros.getRootElement().getQualifiedName(); if (macrosType.equals(EMPTY_MACROS)) copy = null; //handle special case for empty macros else if (macrosType.equals(WRAP_MACROS)) { //copy macros contents exclude root element List<Element> macrosChildElements = MiscUtils.convertUncheckedList(Element.class, macros.getRootElement().elements()); for (Element macrosChild : macrosChildElements) { Element macrosElement = copyElement(macrosChild, runtimeMacrosLoader); if (macrosElement != null) result.add(macrosElement); } copy = null; } else copy = copyElement(macros.getRootElement(), runtimeMacrosLoader); //copy root element */ } else { copy = copyElement(childElement, runtimeMacrosLoader); } if (copy != null) result.add(copy); } return result; }
From source file:com.mg.framework.support.ui.UIRender.java
License:Open Source License
private void initWidgets(Element rootElement, View view, Container contentPane, Map<String, Widget> componentMap) { this.componentMap = componentMap; this.view = view; this.controller = view.getController(); widgetFactory = WidgetFactoryFactory.getInstance().getDefaultWidgetFactory(); List<Element> elements = MiscUtils.convertUncheckedList(Element.class, rootElement.elements()); for (Element element : elements) handleElement(element, contentPane); }
From source file:com.mg.framework.support.ui.UIRender.java
License:Open Source License
private void handleElement(Element element, Container parent) { Widget widget = createWidget(element, parent); if (widget instanceof Container) { ((Container) widget).startContainer(); try {//w w w. j a v a 2 s . c om // , ? ? List<Element> nestedElements = MiscUtils.convertUncheckedList(Element.class, element.elements()); for (Element nestedElement : nestedElements) { handleElement(nestedElement, (Container) widget); } } finally { ((Container) widget).endContainer(); } } else { } }
From source file:com.mgmtp.perfload.core.client.web.io.XmlRequestFlowReader.java
License:Apache License
/** * Reads the XML resource transforming it into an objewct tree. * /* w w w . j a v a2 s . c o m*/ * @return the request flow instance */ public RequestFlow readFlow() throws ParserConfigurationException, SAXException, DocumentException { Element root = loadDocument().getRootElement(); @SuppressWarnings("unchecked") List<Element> requests = root.elements(); List<RequestTemplate> templates = newArrayListWithCapacity(requests.size()); for (Element requestElem : requests) { String type = requestElem.attributeValue("type"); String skip = defaultString(emptyToNull(requestElem.attributeValue("skip")), "false"); String uri = requestElem.attributeValue("uri"); String uriAlias = emptyToNull(requestElem.attributeValue("uriAlias")); String validateResponse = defaultString(emptyToNull(requestElem.attributeValue("validateResponse")), "true"); @SuppressWarnings("unchecked") List<Element> params = requestElem.elements("param"); SetMultimap<String, String> paramsMultiMap = HashMultimap.create(params.size(), 3); for (Element paramElem : params) { String key = paramElem.attributeValue("name"); String value = paramElem.getText(); paramsMultiMap.put(key, value); } @SuppressWarnings("unchecked") List<Element> headers = requestElem.elements("header"); SetMultimap<String, String> headersMultiMap = HashMultimap.create(headers.size(), 3); for (Element headerElem : headers) { String key = headerElem.attributeValue("name"); String value = headerElem.getText(); headersMultiMap.put(key, value); } Element bodyElement = requestElem.element("body"); Body body = null; if (bodyElement != null) { String bodyContent = emptyToNull(bodyElement.getText()); String resPath = bodyElement.attributeValue("resourcePath"); String resourceType = bodyElement.attributeValue("resourceType"); checkState(bodyContent != null ^ (resPath != null && resourceType != null), "Must specify either body content or resource path and type. [" + requestElem.asXML() + "]"); if (bodyContent != null) { body = Body.create(bodyContent); } else { body = Body.create(resPath, resourceType); } } @SuppressWarnings("unchecked") List<Element> headerExtractions = requestElem.elements("headerExtraction"); List<HeaderExtraction> extractHeadersList = newArrayListWithCapacity(headerExtractions.size()); for (Element extractHeaderElem : headerExtractions) { String name = extractHeaderElem.attributeValue("name"); String placeholderName = extractHeaderElem.attributeValue("placeholderName"); extractHeadersList.add(new HeaderExtraction(name, placeholderName)); } @SuppressWarnings("unchecked") List<Element> detailExtractions = requestElem.elements("detailExtraction"); List<DetailExtraction> extractDetailsList = newArrayListWithCapacity(detailExtractions.size()); for (Element extractDetailElem : detailExtractions) { String name = extractDetailElem.attributeValue("name"); String groupIndexString = extractDetailElem.attributeValue("groupIndex"); // int groupIndex = groupIndexString != null ? Integer.parseInt(groupIndexString) : 1; String defaultValue = extractDetailElem.attributeValue("defaultValue"); String indexedString = extractDetailElem.attributeValue("indexed"); // boolean indexed = indexedString != null ? Boolean.parseBoolean(indexedString) : false; String failIfNotFoundString = extractDetailElem.attributeValue("failIfNotFound"); // boolean failIfNotFound = failIfNotFoundString == null || Boolean.valueOf(failIfNotFoundString); String pattern = extractDetailElem.getText().trim(); DetailExtraction ed = new DetailExtraction(name, pattern, groupIndexString, defaultValue, indexedString, failIfNotFoundString); extractDetailsList.add(ed); } templates.add(new RequestTemplate(type, skip, uri, uriAlias, headersMultiMap, paramsMultiMap, body, extractHeadersList, extractDetailsList, validateResponse)); } return new RequestFlow(resourceName, templates); }
From source file:com.mgmtp.perfload.core.common.config.XmlConfigReader.java
License:Apache License
private PropertiesMap readProperties(final Element testplan) { PropertiesMap properties = new PropertiesMap(); Element element = testplan.element("properties"); if (element != null) { @SuppressWarnings("unchecked") List<Element> propsElems = element.elements(); for (Element propsElem : propsElems) { String name = propsElem.attributeValue("name"); String value = propsElem.getText(); properties.put(name, value); }/*ww w.j a v a 2s. c o m*/ } return properties; }
From source file:com.mgmtp.perfload.core.common.config.XmlConfigReader.java
License:Apache License
private List<String> readJvmArgs(final Element testplan) { List<String> result = newArrayListWithExpectedSize(2); Element element = testplan.element("jvmargs"); if (element != null) { @SuppressWarnings("unchecked") List<Element> propsElems = element.elements(); for (Element propsElem : propsElems) { result.add(propsElem.getTextTrim()); }// www .j av a 2s. co m } return ImmutableList.copyOf(result); }
From source file:com.nokia.ant.Database.java
License:Open Source License
private void processTarget(Element targetNode, Element outProjectNode) throws IOException, DocumentException { String targetName = targetNode.attributeValue("name"); log("Processing target: " + targetName, Project.MSG_DEBUG); // Add documentation // Get comment element before the target element to extract target doc String commentText = ""; List children = targetNode.selectNodes("preceding-sibling::node()"); if (children.size() > 0) { // Scan past the text nodes, which are most likely whitespace int index = children.size() - 1; Node child = (Node) children.get(index); while (index > 0 && child.getNodeType() == Node.TEXT_NODE) { index--;/*from ww w . j a v a 2 s .c o m*/ child = (Node) children.get(index); } // Check if there is a comment node if (child.getNodeType() == Node.COMMENT_NODE) { Comment targetComment = (Comment) child; commentText = targetComment.getStringValue().trim(); log(targetName + " comment: " + commentText, Project.MSG_DEBUG); } else { log("Target has no comment: " + targetName, Project.MSG_WARN); } Node previousNode = (Node) children.get(children.size() - 1); } if (!commentText.contains("Private:")) { Element outTargetNode = outProjectNode.addElement("target"); addTextElement(outTargetNode, "name", targetNode.attributeValue("name")); addTextElement(outTargetNode, "ifDependency", targetNode.attributeValue("if")); addTextElement(outTargetNode, "unlessDependency", targetNode.attributeValue("unless")); addTextElement(outTargetNode, "description", targetNode.attributeValue("description")); addTextElement(outTargetNode, "tasks", String.valueOf(targetNode.elements().size())); // Add location Project project = getProject(); Target antTarget = (Target) project.getTargets().get(targetName); if (antTarget == null) return; addTextElement(outTargetNode, "location", antTarget.getLocation().toString()); // Add dependencies Enumeration dependencies = antTarget.getDependencies(); while (dependencies.hasMoreElements()) { String dependency = (String) dependencies.nextElement(); Element dependencyElement = addTextElement(outTargetNode, "dependency", dependency); dependencyElement.addAttribute("type", "direct"); } callAntTargetVisitor(targetNode, outTargetNode, outProjectNode); // Process the comment text as MediaWiki syntax and convert to HTML insertDocumentation(outTargetNode, commentText); // Get names of all properties used in this target ArrayList properties = new ArrayList(); Visitor visitor = new AntPropertyVisitor(properties); targetNode.accept(visitor); for (Iterator iterator = properties.iterator(); iterator.hasNext();) { String property = (String) iterator.next(); addTextElement(outTargetNode, "propertyDependency", property); } // Add the raw XML content of the element String targetXml = targetNode.asXML(); // Replace the CDATA end notation to avoid nested CDATA sections targetXml = targetXml.replace("]]>", "] ]>"); addTextElement(outTargetNode, "source", targetXml, true); } }