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

The following are Jave code examples for showing how to use elements() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: urule   File: RhsParser.java   View Source Code Vote up 6 votes
public List<Action> parseActions(Element element){
	List<Action> actions=new ArrayList<Action>();
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		String name=ele.getName();
		for(ActionParser actionParser:actionParsers){
			if(actionParser.support(name)){
				actions.add(actionParser.parse(ele));
				break;
			}
		}
	}
	return actions;
}
 
Example 2
Project: EasyML   File: OozieGraphXMLParser.java   View Source Code Vote up 6 votes
/** parse a dataset node from xml */
private static OozieDatasetNode parseDatasetNode(Element xml_node) {
	List<Element> childNodes = xml_node.elements();
	OozieDatasetNode node = new OozieDatasetNode();

	for( Element child : childNodes){
		String value = child.getText();
		String name = child.getName();

		if ("id".equals(name))
			node.setId(value);
		else if ("moduleId".equals(name))
			node.setModuleId(value);
		else if ("x".equals(name))
			node.setX((int) Float.parseFloat(value));
		else if ("y".equals(name))
			node.setY((int) Float.parseFloat(value));
		else if ("file".equals(name))
			node.setFile(value);
	}

	return node;
}
 
Example 3
Project: ureport   File: CheckboxParser.java   View Source Code Vote up 6 votes
@Override
public CheckboxInputComponent parse(Element element) {
	CheckboxInputComponent checkbox=new CheckboxInputComponent();
	checkbox.setBindParameter(element.attributeValue("bind-parameter"));
	checkbox.setOptionsInline(Boolean.valueOf(element.attributeValue("options-inline")));
	checkbox.setLabel(element.attributeValue("label"));
	checkbox.setType(element.attributeValue("type"));
	checkbox.setLabelPosition(LabelPosition.valueOf(element.attributeValue("label-position")));
	List<Option> options=new ArrayList<Option>();
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		if(!ele.getName().equals("option")){
			continue;
		}
		Option option=new Option();
		options.add(option);
		option.setLabel(ele.attributeValue("label"));
		option.setValue(ele.attributeValue("value"));
	}
	checkbox.setOptions(options);
	return checkbox;
}
 
Example 4
Project: iBase4J-Common   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * Element to map
 * @param e
 * @param map
 */
public static void element2Map(Element e, Map<String, Object> map) {
    List<Object> list = e.elements();
    if (e.attributeCount() > 0) {
        for (Object attri : e.attributes()) {
            Attribute at = (Attribute)attri;
            map.put(at.getName(), at.getValue());
        }
    }
    if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
        return;
    } else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
        map.put("text", e.getText());
    }
    for (Object aList : list) {
        Element iter = (Element)aList;
        Map<String, Object> cMap = new HashMap<String, Object>();
        element2Map(iter, cMap);
        map.put(iter.getName(), cMap);
    }
}
 
Example 5
Project: ureport   File: DatasourceParser.java   View Source Code Vote up 6 votes
private List<Parameter> parseParameters(Element element){
	List<Parameter> parameters=new ArrayList<Parameter>();
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		if(!ele.getName().equals("parameter")){
			continue;
		}
		Parameter param=new Parameter();
		param.setName(ele.attributeValue("name"));
		param.setDefaultValue(ele.attributeValue("default-value"));
		param.setType(DataType.valueOf(ele.attributeValue("type")));
		parameters.add(param);
	}
	return parameters;
}
 
Example 6
Project: zookeeper-test-demo   File: ConfigUtil.java   View Source Code Vote up 6 votes
/**
 * 从指定的xml文件返回在zookeeper中的key集合
 * 
 * @param fromDoc
 *            源xml文件
 * @param znodePath
 *            znode路径前缀
 * @return
 */
public static Set<String> getKeysInXML(Document fromDoc, String znodePath) {
	Set<String> xmlKeys = new HashSet<>();

	Element rootEle = fromDoc.getRootElement();
	List<Element> paramsList = rootEle.elements("params");
	for (Element paramEle : paramsList) {
		String paramName = paramEle.attributeValue("name");
		List<Element> paramList = paramEle.elements("param");
		for (Element param : paramList) {
			String paramKey = param.attributeValue("name");
			xmlKeys.add(znodePath + "/" + paramName + "/" + paramKey);
		}
	}
	return xmlKeys;
}
 
Example 7
Project: lams   File: XMLContext.java   View Source Code Vote up 6 votes
private List<String> addEntityListenerClasses(Element element, String packageName, List<String> addedClasses) {
	List<String> localAddedClasses = new ArrayList<String>();
	Element listeners = element.element( "entity-listeners" );
	if ( listeners != null ) {
		@SuppressWarnings( "unchecked" )
		List<Element> elements = listeners.elements( "entity-listener" );
		for (Element listener : elements) {
			String listenerClassName = buildSafeClassName( listener.attributeValue( "class" ), packageName );
			if ( classOverriding.containsKey( listenerClassName ) ) {
				//maybe switch it to warn?
				if ( "entity-listener".equals( classOverriding.get( listenerClassName ).getName() ) ) {
					LOG.duplicateListener( listenerClassName );
					continue;
				}
				throw new IllegalStateException("Duplicate XML entry for " + listenerClassName);
			}
			localAddedClasses.add( listenerClassName );
			classOverriding.put( listenerClassName, listener );
		}
	}
	LOG.debugf( "Adding XML overriding information for listeners: %s", localAddedClasses );
	addedClasses.addAll( localAddedClasses );
	return localAddedClasses;
}
 
Example 8
Project: gen_code   File: ConfigParser.java   View Source Code Vote up 6 votes
/**
 * 解析list类型全局变量
 * @param node vars节点
 * @return 返回所有list类型变量
 */
public static Map<String,Object> parserVarList(Element node){
    Map<String,Object> vars = new HashMap<String, Object>();
    if(node!=null){
        List<Element> childs = node.elements("list");
        if(childs!=null&&childs.size()>0){
            for(Element list : childs){
                List<Element> itemsE = list.elements();
                List<String> itemsContainer = new ArrayList<String>();
                for(Element item : itemsE){
                    itemsContainer.add(item.getText());
                }
                vars.put(list.attributeValue("name"),itemsContainer);
            }
        }
    }
    return vars;
}
 
Example 9
Project: urule   File: FlowNodeParser.java   View Source Code Vote up 5 votes
protected List<Connection> parseConnections(Element element){
	List<Connection> connections=new ArrayList<Connection>();
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		if(!ele.getName().equals("connection")){
			continue;
		}
		connections.add(buildConnection(ele));
	}
	return connections;
}
 
Example 10
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 5 votes
private static void bindNamedAttributeNodes(Element subElement, AnnotationDescriptor ann) {
	List<Element> namedAttributeNodes = subElement.elements("named-attribute-node");
	List<NamedAttributeNode> annNamedAttributeNodes = new ArrayList<NamedAttributeNode>(  );
	for(Element namedAttributeNode : namedAttributeNodes){
		AnnotationDescriptor annNamedAttributeNode = new AnnotationDescriptor( NamedAttributeNode.class );
		copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "value", true );
		copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "subgraph", false );
		copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "key-subgraph", false );
		annNamedAttributeNodes.add( (NamedAttributeNode) AnnotationFactory.create( annNamedAttributeNode ) );
	}
	ann.setValue( "attributeNodes", annNamedAttributeNodes.toArray( new NamedAttributeNode[annNamedAttributeNodes.size()] ) );
}
 
Example 11
Project: urule   File: SpringBeanParser.java   View Source Code Vote up 5 votes
public SpringBean parse(Element element) {
	SpringBean bean=new SpringBean();
	bean.setId(element.attributeValue("id"));
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		if(ele.getName().equals("method")){
			Method method=parseMethod(ele);
			bean.addMethod(method);
		}
	}
	return bean;
}
 
Example 12
Project: unitimes   File: PointInTimeDataImport.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private void initializeTimePatternData(Element rootElement) throws Exception {
       loadExistingTimePatterns(session.getUniqueId());

       Element timePatternsElement = rootElement.element(PointInTimeDataExport.sTimePatternsElementName);
       for(Element timePatternElement : (List<Element>) timePatternsElement.elements()){
       	elementTimePattern(timePatternElement);
       }
	
}
 
Example 13
Project: ureport   File: SlashValueParser.java   View Source Code Vote up 5 votes
@Override
public Value parse(Element element) {
	SlashValue value=new SlashValue();
	List<Slash> slashes=new ArrayList<Slash>();
	value.setSlashes(slashes);
	for(Object obj:element.elements()){
		if(obj==null || !(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		if(ele.getName().equals("slash")){
			Slash slash=new Slash();
			slashes.add(slash);
			slash.setDegree(Integer.valueOf(ele.attributeValue("degree")));
			slash.setX(Integer.valueOf(ele.attributeValue("x")));
			slash.setY(Integer.valueOf(ele.attributeValue("y")));
			slash.setText(ele.attributeValue("text"));				
		}else if(ele.getName().equals("base64-data")){
			String prefix="data:image/png;base64,";
			String base64Data=ele.getText();
			if(base64Data.startsWith(prefix)){
				base64Data=base64Data.substring(prefix.length(),base64Data.length());
			}
			value.setBase64Data(base64Data);
		}
	}
	return value;
}
 
Example 14
Project: ExcelUtils   File: ParseXMLUtilTest.java   View Source Code Vote up 5 votes
@Before
    public void setUp() throws Exception {
        InputStream is = new FileInputStream(new File(xmlFile));
        if (is == null) {
            throw new FileNotFoundException("Excel的描述文件 : " + xmlFile + " 未找到.");
        }
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(is);
        // 根节点
        Element root = document.getRootElement();
        // 一次导入
        onceList = root.elements("onceImport");
        // 重复导入
        List repeatList = root.elements("repeatImport");

        // 校验器的定义
        List validators = root.elements("validators");
        // 单元格校验
        List cellValidators = root.elements("cell-validators");

        excelStruct = new ExcelStruct();

        // 读取校验器配置
//        parseValidatorConfig(excelStruct, validators, cellValidators);

//        simpleParseOnceImport(excelStruct, onceList);

        is.close();

    }
 
Example 15
Project: joai-project   File: DocMap.java   View Source Code Vote up 5 votes
/**
 *  Put sequence elements in the order specified by the sequence compositor.
 *
 * @param  parent  NOT YET DOCUMENTED
 */
public void orderSequenceElements(Element parent) {
	String xpath = parent.getPath();
	List order = schemaHelper.getChildrenOrder(xpath);

	// just as a safeguard, don't reorder if there is only one child
	// for the schemaNode, since parent is probably a repeating element
	// and reordering would wipe out all but one child
	if (order.size() < 2)
		return;

	// map element name to a list of elements to accomodate repeating elements
	Map elementMap = new HashMap();
	List elements = parent.elements();
	for (int i = elements.size() - 1; i > -1; i--) {
		Element e = (Element) elements.get(i);
		String tagName = e.getName();
		List items = (List) elementMap.get(tagName);
		if (items == null)
			items = new ArrayList();
		items.add(0, e.detach()); // add to beginning to maintain doc ordering
		elementMap.put(tagName, items);
	}

	for (Iterator i = order.iterator(); i.hasNext(); ) {
		String name = (String) i.next();
		elements = (List) elementMap.get(name);
		if (elements != null) {
			for (Iterator ii = elements.iterator(); ii.hasNext(); ) {
				parent.add((Element) ii.next());
			}
		}
	}
}
 
Example 16
Project: urule   File: VariableEditorServletHandler.java   View Source Code Vote up 4 votes
public void importXml(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	DiskFileItemFactory factory = new DiskFileItemFactory();
	ServletContext servletContext = req.getSession().getServletContext();
	File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
	factory.setRepository(repository);
	ServletFileUpload upload = new ServletFileUpload(factory);
	InputStream inputStream=null;
	try {
		List<FileItem> items = upload.parseRequest(req);
		if(items.size()!=1){
			throw new ServletException("Upload xml file is invalid.");
		}
		FileItem item=items.get(0);
		inputStream=item.getInputStream();
		String xmlContent=IOUtils.toString(inputStream, "utf-8");
		List<Variable> variables=new ArrayList<Variable>();
		Document doc=DocumentHelper.parseText(xmlContent);
		Element root=doc.getRootElement();
		String clazz=root.attributeValue("clazz");
		for(Object obj:root.elements()){
			if(obj==null || !(obj instanceof Element)){
				continue;
			}
			Element ele=(Element)obj;
			Variable var=new Variable();
			var.setAct(Act.InOut);
			var.setDefaultValue(ele.attributeValue("defaultValue"));
			var.setLabel(ele.attributeValue("label"));
			var.setName(ele.attributeValue("name"));
			var.setType(Datatype.valueOf(ele.attributeValue("type")));
			variables.add(var);
		}
		Map<String,Object> result=new HashMap<String,Object>();
		result.put("clazz", clazz);
		result.put("variables", variables);
		writeObjectToJson(resp, result);
	} catch (Exception e) {
		throw new ServletException(e);
	} finally {
		IOUtils.closeQuietly(inputStream);
	}
}
 
Example 17
Project: push-server   File: XMLBeanFactory.java   View Source Code Vote up 4 votes
/**
 * 获取property内嵌的bean.
 * @param name id或者bean的name
 * @param root 根节点.
 * @return 返回封装完整的bean.
 * @throws Exception Exception.
 */
public Object getBean(String name, Element root) throws Exception {

    Object object = null;
    List<Element> beans = root.elements();
    if (beans.size() > 0) {
        for (Element bean : beans) {
            if (bean.attributeValue("name").equals(name)) {
                // 如果bean name相同则开始创建对象
                String clazz = bean.attributeValue("class");
                // 通过反射来创建对象
                Class beanClass = Class.forName(clazz);
                object = beanClass.newInstance();

                List<Element> propertys = bean.elements();

                if (propertys.size() > 0) {
                    for (Element property : propertys) {
                        String key = property.attributeValue("name");
                        Field field = beanClass.getDeclaredField(key);
                        field.setAccessible(true);

                        List<Element> childBean = property.elements();

                        // 如果property下内嵌bean
                        if (childBean.size() > 0) {
                            field.set(object, getBean(key, property));
                        }

                        if (property.attribute("ref") != null) {
                            /**
                             * 此属性的值是一个对象.这里由于直接调用getBean方法赋值给对象,返回的对象一定是Bean参数的对象, 因此强制转换不会出问题
                             */
                            String refid = property.attributeValue("ref");
                            field.set(object, getBean(refid));
                        } else {
                            /**
                             * 此属性值是一个字符串.这里单独处理int,float类型变量.如果不处理,会将String类型直接赋值给int类型,
                             * 发生ClassCastException
                             */
                            String value = property.attributeValue("value");
                            /**
                             *  需要对类型进行判断,处理String类型.
                             */
                            field.set(object, value);
                        }
                    }
                }

            }
        }
    }

    return object;
}
 
Example 18
Project: ureport   File: CellParser.java   View Source Code Vote up 4 votes
@Override
public CellDefinition parse(Element element) {
	CellDefinition cell=new CellDefinition();
	cell.setName(element.attributeValue("name"));
	cell.setColumnNumber(Integer.valueOf(element.attributeValue("col")));
	cell.setRowNumber(Integer.valueOf(element.attributeValue("row")));
	cell.setLeftParentCellName(element.attributeValue("left-cell"));
	cell.setTopParentCellName(element.attributeValue("top-cell"));
	String rowSpan=element.attributeValue("row-span");
	if(StringUtils.isNotBlank(rowSpan)){
		cell.setRowSpan(Integer.valueOf(rowSpan));
	}
	String colSpan=element.attributeValue("col-span");
	if(StringUtils.isNotBlank(colSpan)){
		cell.setColSpan(Integer.valueOf(colSpan));
	}
	String expand=element.attributeValue("expand");
	if(StringUtils.isNotBlank(expand)){
		cell.setExpand(Expand.valueOf(expand));			
	}
	String fillBlankRows=element.attributeValue("fill-blank-rows");
	if(StringUtils.isNotBlank(fillBlankRows)){
		cell.setFillBlankRows(Boolean.valueOf(fillBlankRows));
		String multiple=element.attributeValue("multiple");
		if(StringUtils.isNotBlank(multiple)){
			cell.setMultiple(Integer.valueOf(multiple));
		}
	}
	cell.setLinkTargetWindow(element.attributeValue("link-target-window"));
	String linkUrl=element.attributeValue("link-url");
	cell.setLinkUrl(linkUrl);
	if(StringUtils.isNotBlank(linkUrl)){
		if(linkUrl.startsWith(ExpressionUtils.EXPR_PREFIX) && linkUrl.endsWith(ExpressionUtils.EXPR_SUFFIX)){
			String expr=linkUrl.substring(2,linkUrl.length()-1);
			Expression urlExpression=ExpressionUtils.parseExpression(expr);
			cell.setLinkUrlExpression(urlExpression);
		}
	}
	List<LinkParameter> linkParameters=null;
	List<ConditionPropertyItem> conditionPropertyItems=null;
	for(Object obj:element.elements()){
		if(!(obj instanceof Element)){
			continue;
		}
		Element ele=(Element)obj;
		Object parseData=parseValue(ele);
		if(parseData instanceof Value){
			Value value=(Value)parseData;
			cell.setValue(value);
		}else if(parseData instanceof CellStyle){
			CellStyle cellStyle=(CellStyle)parseData;
			cell.setCellStyle(cellStyle);
		}else if(parseData instanceof LinkParameter){
			if(linkParameters==null){
				linkParameters=new ArrayList<LinkParameter>();
			}
			linkParameters.add((LinkParameter)parseData);
		}else if(parseData instanceof ConditionPropertyItem){
			if(conditionPropertyItems==null){
				conditionPropertyItems=new ArrayList<ConditionPropertyItem>();
			}
			conditionPropertyItems.add((ConditionPropertyItem)parseData);
		}
	}
	if(linkParameters!=null){
		cell.setLinkParameters(linkParameters);
	}
	cell.setConditionPropertyItems(conditionPropertyItems);
	if(cell.getValue()==null){
		throw new ReportException("Cell ["+cell.getName()+"] value not define.");
	}
	return cell;
}
 
Example 19
Project: etagate   File: GateSetting.java   View Source Code Vote up 2 votes
@SuppressWarnings("unchecked")
private void parseApp(Element root){
	
	this.app_tags = root.elements(APP_TAG);
	
}
 
Example 20
Project: joai-project   File: ChoiceGuard.java   View Source Code Vote up 2 votes
/**
 *  Constructor for the ChoiceGuard object
 *
 * @param  compositor       NOT YET DOCUMENTED
 * @param  instanceElement  NOT YET DOCUMENTED
 */
public ChoiceGuard(Compositor compositor, Element instanceElement) {
	this (compositor, instanceElement.elements());
}