Java Code Examples for org.dom4j.Element#elements()

The following examples show how to use org.dom4j.Element#elements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractParser.java    From uflo with Apache License 2.0 6 votes vote down vote up
protected List<Assignee> parserAssignees(Element element){
	List<Assignee> assignees=new ArrayList<Assignee>();
	for(Object obj:element.elements()){
		if(!(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		if(!ele.getName().equals("assignee")){
			continue;
		}
		String id=unescape(ele.attributeValue("id"));
		String name=unescape(ele.attributeValue("name"));
		String providerId=unescape(ele.attributeValue("provider-id"));
		Assignee assignee=new Assignee();
		assignee.setId(id);
		assignee.setName(name);
		assignee.setProviderId(providerId);
		assignees.add(assignee);
	}
	return assignees;
}
 
Example 2
Source File: CriterionParser.java    From urule with Apache License 2.0 6 votes vote down vote up
protected List<Criterion> parseCriterion(Element element){
	List<Criterion> list=null;
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		String name=ele.getName();
		for(CriterionParser parser:criterionParsers){
			if(parser.support(name)){
				if(list==null)list=new ArrayList<Criterion>();
				Criterion criterion=parser.parse(ele);
				if(criterion!=null){
					list.add(criterion);						
				}
				break;
			}
		}
	}
	return list;
}
 
Example 3
Source File: AbstractParser.java    From uflo with Apache License 2.0 6 votes vote down vote up
protected List<SequenceFlowImpl> parseFlowElement(Element element,long processId,boolean parseChildren){
	List<SequenceFlowImpl> flows=new ArrayList<SequenceFlowImpl>();
	for(Object obj:element.elements()){
		if(!(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		for(Parser parser:parsers){
			if(!parser.support(ele)){
				continue;
			}
			Object processElement=parser.parse(ele,processId,parseChildren);
			if(processElement instanceof SequenceFlowImpl){
				SequenceFlowImpl flow=(SequenceFlowImpl)processElement;
				flows.add(flow);
			}
			break;
		}
	}
	return flows;
}
 
Example 4
Source File: OptionsTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void withoutItems() throws Exception {
	this.tag.setItemValue("isoCode");
	this.tag.setItemLabel("name");
	this.selectTag.setPath("testBean");

	this.selectTag.doStartTag();
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);
	this.tag.doEndTag();
	this.selectTag.doEndTag();

	String output = getOutput();
	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();

	List children = rootElement.elements();
	assertEquals("Incorrect number of children", 0, children.size());
}
 
Example 5
Source File: SelectTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void validateOutput(String output, boolean selected) throws DocumentException {
	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();
	assertEquals("select", rootElement.getName());
	assertEquals("country", rootElement.attribute("name").getValue());

	List children = rootElement.elements();
	assertEquals("Incorrect number of children", 4, children.size());

	Element e = (Element) rootElement.selectSingleNode("option[@value = 'UK']");
	Attribute selectedAttr = e.attribute("selected");
	if (selected) {
		assertTrue(selectedAttr != null && "selected".equals(selectedAttr.getValue()));
	}
	else {
		assertNull(selectedAttr);
	}
}
 
Example 6
Source File: QTI_and_test.java    From olat with Apache License 2.0 6 votes vote down vote up
@Override
public boolean eval(final Element boolElement, final float score) {
    final List elems = boolElement.elements();
    final int size = elems.size();
    boolean ev = true;
    for (int i = 0; i < size; i++) {
        final Element child = (Element) elems.get(i);
        final String name = child.getName();
        final ScoreBooleanEvaluable bev = QTIHelper.getSectionBooleanEvaluableInstance(name);
        final boolean res = bev.eval(child, score);
        ev = ev && res;
        if (!ev) {
            return false;
        }
    }
    return true;
}
 
Example 7
Source File: PopupButtonLoader.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadActions(ActionsHolder actionsHolder, Element element) {
    Element actionsEl = element.element("actions");
    if (actionsEl == null) {
        return;
    }

    for (Element actionEl : actionsEl.elements("action")) {
        Action action = loadDeclarativeAction(actionsHolder, actionEl);
        actionsHolder.addAction(action);

        ComponentContext componentContext = getComponentContext();

        componentContext.addPostInitTask(new ActionHolderAssignActionPostInitTask(actionsHolder,
                action.getId(), componentContext.getFrame()));
    }
}
 
Example 8
Source File: DefaultXmlReader.java    From yarg with Apache License 2.0 6 votes vote down vote up
protected Map<String, ReportTemplate> parseTemplates(Element rootElement) throws IOException {
    Element templatesElement = rootElement.element("templates");
    List<Element> templates = templatesElement.elements("template");
    Map<String, ReportTemplate> templateMap = new HashMap<String, ReportTemplate>();
    for (Element template : templates) {
        String code = template.attribute("code").getText();
        String documentName = template.attribute("documentName").getText();
        String documentPath = template.attribute("documentPath").getText();
        String outputType = template.attribute("outputType").getText();
        String outputNamePattern = template.attribute("outputNamePattern").getText();

        ReportTemplate reportTemplate = new ReportTemplateBuilder()
                .code(code)
                .documentName(documentName)
                .documentPath(documentPath)
                .documentContent(getDocumentContent(documentPath))
                .outputType(ReportOutputType.getOutputTypeById(outputType))
                .outputNamePattern(outputNamePattern).build();


        templateMap.put(reportTemplate.getCode(), reportTemplate);
    }

    return templateMap;
}
 
Example 9
Source File: ScreenViewsLoader.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Deploy views defined in <code>metadataContext</code> of a frame.
 *
 * @param rootElement root element of a frame XML
 */
public void deployViews(Element rootElement) {
    Element metadataContextEl = rootElement.element("metadataContext");
    if (metadataContextEl != null) {
        for (Element fileEl : metadataContextEl.elements("deployViews")) {
            String resource = fileEl.attributeValue("name");
            InputStream resourceInputStream = getInputStream(resource);
            try {
                viewRepository.deployViews(resourceInputStream);
            } finally {
                IOUtils.closeQuietly(resourceInputStream);
            }
        }

        for (Element viewEl : metadataContextEl.elements("view")) {
            viewRepository.deployView(metadataContextEl, viewEl);
        }
    }
}
 
Example 10
Source File: ChartValueParser.java    From ureport with Apache License 2.0 6 votes vote down vote up
private void parseAxes(Element element,BaseAxes axes){
	String rotation=element.attributeValue("rotation");
	if(StringUtils.isNotBlank(rotation)){
		axes.setRotation(Integer.valueOf(rotation));
	}
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		String name=ele.getName();
		if(name.equals("scale-label")){
			ScaleLabel label=new ScaleLabel();
			String display=ele.attributeValue("display");
			if(StringUtils.isNotBlank(display)){
				label.setDisplay(Boolean.valueOf(display));
			}
			String labelString=ele.attributeValue("label-string");
			label.setLabelString(labelString);
			axes.setScaleLabel(label);
			break;
		}
	}
}
 
Example 11
Source File: DesktopThemeLoaderImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void loadUIDefaults(Map<String, Object> uiDefaults, Element rootElement) {
    for (Element element : rootElement.elements()) {
        String propertyName = element.attributeValue("property");

        Object value = loadUIValue(element);
        if (value != null) {
            uiDefaults.put(propertyName, value);
        }
    }
}
 
Example 12
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 5 votes vote down vote up
@Override
public List<UserPermission> loadResourceSecurityConfigs(String companyId) throws Exception{
	List<UserPermission> configs=new ArrayList<UserPermission>();
	String filePath=RESOURCE_SECURITY_CONFIG_FILE+(companyId == null ? "" : companyId);
	Node rootNode=getRootNode();
	Node fileNode = rootNode.getNode(filePath);
	Property property = fileNode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	InputStream inputStream = fileBinary.getStream();
	String content = IOUtils.toString(inputStream, "utf-8");
	inputStream.close();
	Document document = DocumentHelper.parseText(content);
	Element rootElement = document.getRootElement();
	for (Object obj : rootElement.elements()) {
		if (!(obj instanceof Element)) {
			continue;
		}
		Element element = (Element) obj;
		if (!element.getName().equals("user-permission")) {
			continue;
		}
		UserPermission userResource=new UserPermission();
		userResource.setUsername(element.attributeValue("username"));
		userResource.setProjectConfigs(parseProjectConfigs(element));
		configs.add(userResource);
	}
	return configs;
}
 
Example 13
Source File: SelectTagTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void multipleExplicitlyTrue() throws Exception {
	this.tag.setPath("name");
	this.tag.setItems(Country.getCountries());
	this.tag.setItemValue("isoCode");
	this.tag.setMultiple("true");
	int result = this.tag.doStartTag();
	assertEquals(Tag.SKIP_BODY, result);

	String output = getOutput();
	output = "<doc>" + output + "</doc>";

	SAXReader reader = new SAXReader();
	Document document = reader.read(new StringReader(output));
	Element rootElement = document.getRootElement();
	assertEquals(2, rootElement.elements().size());

	Element selectElement = rootElement.element("select");
	assertEquals("select", selectElement.getName());
	assertEquals("name", selectElement.attribute("name").getValue());
	assertEquals("multiple", selectElement.attribute("multiple").getValue());

	List children = selectElement.elements();
	assertEquals("Incorrect number of children", 4, children.size());

	Element inputElement = rootElement.element("input");
	assertNotNull(inputElement);
}
 
Example 14
Source File: ScreenDataXmlLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
public void load(ScreenData screenData, Element element, @Nullable ScreenData hostScreenData) {
    Preconditions.checkNotNullArgument(screenData, "screenData is null");
    Preconditions.checkNotNullArgument(element, "element is null");

    DataContext hostDataContext = null;
    if (hostScreenData != null) {
        hostDataContext = hostScreenData.getDataContext();
    }
    if (hostDataContext != null) {
        screenData.setDataContext(hostDataContext);
    } else {
        boolean readOnly = Boolean.valueOf(element.attributeValue("readOnly"));
        DataContext dataContext = readOnly ? new NoopDataContext() : factory.createDataContext();
        screenData.setDataContext(dataContext);
    }

    for (Element el : element.elements()) {
        switch (el.getName()) {
            case "collection":
                loadCollectionContainer(screenData, el, hostScreenData);
                break;
            case "instance":
                loadInstanceContainer(screenData, el, hostScreenData);
                break;
            case "keyValueCollection":
                loadKeyValueCollectionContainer(screenData, el, hostScreenData);
                break;
            case "keyValueInstance":
                loadKeyValueInstanceContainer(screenData, el, hostScreenData);
                break;
            default:
                // no action
                break;
        }
    }
}
 
Example 15
Source File: Tools.java    From wechat-framework with GNU General Public License v2.0 5 votes vote down vote up
public static Map<String, String> xml2Map(String xml) {
    Map<String, String> map = new HashMap<String, String>();
    try {
        Document document = DocumentHelper.parseText(xml);
        Element list = document.getRootElement();
        List<Element> elements = list.elements();
        for (Element element : elements) {
            map.put(element.getName().trim(), element.getStringValue());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return map;
}
 
Example 16
Source File: FormLoader.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected List<ComponentPosition> loadComponents(Element element, @Nullable String columnWidth, @Nullable Float flex) {
    List<Element> elements = element.elements();
    if (elements.isEmpty()) {
        return Collections.emptyList();
    } else {
        List<ComponentPosition> components = new ArrayList<>(elements.size());
        for (Element componentElement : elements) {
            ComponentPosition component = loadComponent(componentElement, columnWidth, flex);
            components.add(component);
        }
        return components;
    }
}
 
Example 17
Source File: Simplicity.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void loadSettingsFile(StringArray s){
	if (s == null)
		return;
	settingsLoaded = true;
	InterfaceManager.hiddenPackages.removeAllElements(false);
	InterfaceManager.hiddenMenuItems.removeAllElements(false);
	InterfaceManager.hiddenTools.removeAllElements(false);
	String settingsXML = s.getValue(XML);
	Element root = XMLUtil.getRootXMLElementFromString("mesquite",settingsXML);
	if (root==null)
		return;
	Element element = root.element("simplicitySettings");
	if (element != null) {
		Element versionElement = element.element("version");
		if (versionElement == null)
			return ;
		else {
			int version = MesquiteInteger.fromString(element.elementText("version"));
			boolean acceptableVersion = version==1;
			if (acceptableVersion) {
				String name = (element.elementText("name"));
				InterfaceManager.themeName = name;
				Element packages = element.element("hiddenPackages");
				if (packages != null){
					List packageElements = packages.elements("package");
					for (Iterator iter = packageElements.iterator(); iter.hasNext();) {   // this is going through all of the notices
						Element hiddenPackage = (Element) iter.next();
						String pkg = hiddenPackage.element("name").getText();
						InterfaceManager.addPackageToHidden(pkg, false);						
					}
				}
				Element menuItems = element.element("hiddenMenuItems");
				if (menuItems != null){
					List menuElements = menuItems.elements("menuItem");
					for (Iterator iter = menuElements.iterator(); iter.hasNext();) {   // this is going through all of the notices
						Element hiddenM = (Element) iter.next();
						String label = XMLUtil.getTextFromElement(hiddenM, "label");
						String arguments = XMLUtil.getTextFromElement(hiddenM, "arguments");
						String command = XMLUtil.getTextFromElement(hiddenM, "command");
						String commandableClass = XMLUtil.getTextFromElement(hiddenM, "commandableClass");
						String dutyClass = XMLUtil.getTextFromElement(hiddenM, "dutyClass");
						InterfaceManager.hiddenMenuItems.addElement(new MenuVisibility(label, arguments, command, commandableClass, dutyClass), false);
					}
				}
				Element tools = element.element("hiddenTools");
				if (tools != null){
					List buttonElement = tools.elements("tool");
					for (Iterator iter = buttonElement.iterator(); iter.hasNext();) {   // this is going through all of the notices
						Element hiddenT = (Element) iter.next();
						String n = XMLUtil.getTextFromElement(hiddenT,"name");
						String d = XMLUtil.getTextFromElement(hiddenT,"description");
						InterfaceManager.hiddenTools.addElement(new MesquiteString(n, d), false);
					}
				}
				storePreferences();
			}
		}
	} 
	InterfaceManager.reset();

}
 
Example 18
Source File: ScormCPManifestTreeModel.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor of the content packaging tree model
 * 
 * @param scormFolderPath
 *            the imsmanifest.xml file
 * @param itemStatus
 *            a Map containing the status of each item like "completed, not attempted, ..."
 */
public ScormCPManifestTreeModel(final String scormFolderPath, final Map itemStatus) {
    ScormEBL scormEbl = CoreSpringFactory.getBean(ScormEBL.class);
    this.itemStatus = itemStatus;
    final Document doc = loadDocument(scormEbl.getManifestFile(scormFolderPath));
    // get all organization elements. need to set namespace
    rootElement = doc.getRootElement();
    final String nsuri = rootElement.getNamespace().getURI();
    nsuris.put("ns", nsuri);

    final XPath meta = rootElement.createXPath("//ns:organization");
    meta.setNamespaceURIs(nsuris);

    final XPath metares = rootElement.createXPath("//ns:resources");
    metares.setNamespaceURIs(nsuris);
    final Element elResources = (Element) metares.selectSingleNode(rootElement);
    if (elResources == null) {
        throw new AssertException("could not find element resources");
    }

    final List resourcesList = elResources.elements("resource");
    resources = new HashMap(resourcesList.size());
    for (final Iterator iter = resourcesList.iterator(); iter.hasNext();) {
        final Element elRes = (Element) iter.next();
        final String identVal = elRes.attributeValue("identifier");
        String hrefVal = elRes.attributeValue("href");
        if (hrefVal != null) { // href is optional element for resource element
            try {
                hrefVal = URLDecoder.decode(hrefVal, "UTF-8");
            } catch (final UnsupportedEncodingException e) {
                // each JVM must implement UTF-8
            }
        }
        resources.put(identVal, hrefVal);
    }
    /*
     * Get all organizations
     */
    List organizations = new LinkedList();
    organizations = meta.selectNodes(rootElement);
    if (organizations.isEmpty()) {
        throw new AssertException("could not find element organization");
    }
    final GenericTreeNode gtn = buildTreeNodes(organizations);
    setRootNode(gtn);
    rootElement = null; // help gc
    resources = null;
}
 
Example 19
Source File: Scenario.java    From mts with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Parse the scenario
 */
private void parse(XMLDocument scenarioDocument) throws Exception {
    //String relativePath = getFilename();

    //XMLDocument scenarioDocument = XMLDocumentCache.getXMLDocument(URIRegistry.MTS_TEST_HOME.resolve(relativePath), URIFactory.newURI("../conf/schemas/scenario.xsd"));

    Element root = scenarioDocument.getDocument().getRootElement();


    /**
     * Check the position of the finally tag
     */
    boolean isFinallyLast = false;
    int finallyInstances = 0;
    List<Element> elements = root.elements();
    for (Element element : elements) {
        isFinallyLast = false;
        if (element.getName().equals("finally")) {
            isFinallyLast = true;
            finallyInstances++;
        }
    }

    if (finallyInstances == 1 && !isFinallyLast) {
        throw new ParsingException("Finally must be the last operation of the scenario.");
    }
    else if (finallyInstances > 1) {
        throw new ParsingException("There must be at most one finally operation.");
    }

    /**
     * Create the finally operations sequence. If there is a finally then the sequence is created and then the finally tag is removed from the scenario. To allow the creation of the scenario
     * operations sequence.
     */
    if (finallyInstances == 1) {
        Element finallyRoot = root.element("finally");
        root.remove(finallyRoot);
        this._operationSequenceFinally = new OperationSequence(finallyRoot, this);
    }

    _operationSequenceScenario = new OperationSequence(root, this);
}
 
Example 20
Source File: ConditionTreeNodeParser.java    From urule with Apache License 2.0 4 votes vote down vote up
@Override
public ConditionTreeNode parse(Element element) {
	ConditionTreeNode node=new ConditionTreeNode();
	node.setNodeType(TreeNodeType.condition);
	node.setOp(Op.valueOf(element.attributeValue("op")));
	List<ConditionTreeNode> conditionTreeNodes=new ArrayList<ConditionTreeNode>();
	List<ActionTreeNode> actionTreeNodes=new ArrayList<ActionTreeNode>();
	List<VariableTreeNode> variableTreeNodes=new ArrayList<VariableTreeNode>();
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		String name=ele.getName();
		if(valueParser.support(name)){
			node.setValue(valueParser.parse(ele));
		}else if(support(name)){
			ConditionTreeNode cn=parse(ele);
			cn.setParentNode(node);
			conditionTreeNodes.add(cn);
		}else if(variableTreeNodeParser.support(name)){
			VariableTreeNode vn=variableTreeNodeParser.parse(ele);
			vn.setParentNode(node);
			variableTreeNodes.add(vn);
		}else if(actionTreeNodeParser.support(name)){
			ActionTreeNode an=actionTreeNodeParser.parse(ele);
			an.setParentNode(node);
			actionTreeNodes.add(an);
		}
	}
	if(conditionTreeNodes.size()>0){
		node.setConditionTreeNodes(conditionTreeNodes);
	}
	if(actionTreeNodes.size()>0){
		node.setActionTreeNodes(actionTreeNodes);
	}
	if(variableTreeNodes.size()>0){
		node.setVariableTreeNodes(variableTreeNodes);
	}
	return node;
}