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

The following are Jave code examples for showing how to use element() 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: minlia-iot   File: XmlApiDeserializer.java   View Source Code Vote up 6 votes
/**
 * 处理@{@link XmlElement}注解
 */
@SuppressWarnings("unchecked")
protected void dealXmlElementAnnotation(Element rootElement, Field field, Object entity) {
  XmlElement xmlElementAnnotation = field.getAnnotation(XmlElement.class);
  Element element = rootElement.element(xmlElementAnnotation.name());
  if (Objects.nonNull(element)) {
    Optional<Object> valueOptional = super
        .elementValue(rootElement, field.getType(), xmlElementAnnotation.name());
    valueOptional.ifPresent(value -> {
      try {
        field.set(entity, value);
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      }
    });
  }
}
 
Example 2
Project: headb   File: HXmlUtils.java   View Source Code Vote up 6 votes
/**
 * 获得heaView的SQL
 * @return heaView里的SQL
 */
public String getView() {
	Map<String,Object> valueCacheMap=this.xmlCache.getValueMap();
	String path="view";
	if(null!=valueCacheMap.get(path)){

		return (String) valueCacheMap.get(path);
	}
	Element rootElement = document.getRootElement();
	Element hqlsElement = rootElement.element(VIEW );
	if (null == hqlsElement) {
		return null;
	}
	 valueCacheMap.put(path, hqlsElement.getTextTrim());
     return hqlsElement.getTextTrim();
}
 
Example 3
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 6 votes
private List<AttributeOverride> buildAttributeOverrides(List<Element> subelements, String nodeName) {
	List<AttributeOverride> overrides = new ArrayList<AttributeOverride>();
	if ( subelements != null && subelements.size() > 0 ) {
		for ( Element current : subelements ) {
			if ( !current.getName().equals( nodeName ) ) {
				continue;
			}
			AnnotationDescriptor override = new AnnotationDescriptor( AttributeOverride.class );
			copyStringAttribute( override, current, "name", true );
			Element column = current.element( "column" );
			override.setValue( "column", getColumn( column, true, current ) );
			overrides.add( (AttributeOverride) AnnotationFactory.create( override ) );
		}
	}
	return overrides;
}
 
Example 4
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 6 votes
private void getTemporal(List<Annotation> annotationList, Element element) {
	Element subElement = element != null ? element.element( "temporal" ) : null;
	if ( subElement != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Temporal.class );
		String temporal = subElement.getTextTrim();
		if ( "DATE".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.DATE );
		}
		else if ( "TIME".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.TIME );
		}
		else if ( "TIMESTAMP".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.TIMESTAMP );
		}
		else if ( StringHelper.isNotEmpty( temporal ) ) {
			throw new AnnotationException( "Unknown TemporalType: " + temporal + ". " + SCHEMA_VALIDATION );
		}
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example 5
Project: gen_code   File: ConfigParser.java   View Source Code Vote up 6 votes
/**
 * 解析变量配置
 * @param node  settings节点
 * @return 返回解析完的所有变量
 */
public static Map<String,Object> parserVars(Element node){
    Map<String,Object> vars = new HashMap<String, Object>();
    if(node!=null){
        Element varE = node.element("vars");
        if(varE!=null){
            //加在普通变量
            List<Element> childs = varE.elements("var");
            if(childs!=null&&childs.size()>0){
                for(Element c:childs){
                    vars.put(c.attributeValue("name"),c.attributeValue("value"));
                }
            }
            //加载map变量
            vars.putAll(parserVarMap(varE));
            //加载list变量
            vars.putAll(parserVarList(varE));
        }
    }
    return vars;
}
 
Example 6
Project: unitimes   File: DoubleVarcharSizes.java   View Source Code Vote up 5 votes
public void generate() throws IOException, DocumentException {
	Document document = read(iConfig);
	Element root = document.getRootElement();
	Element sessionFactoryElement = root.element("session-factory");
	for (Iterator<Element> i = sessionFactoryElement.elementIterator("mapping"); i.hasNext(); ) {
		Element m = i.next();
		String resource = m.attributeValue("resource");
		if (resource == null) continue;
		generate(read(resource).getRootElement(), null);
	}
}
 
Example 7
Project: unitimes   File: PointInTimeDataImport.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private void initializeCreditUnitTypeData(Element rootElement) throws Exception {
	for (CourseCreditUnitType creditUnitType : CourseCreditUnitType.getCourseCreditUnitTypeList()) {
		creditUnitTypesByRef.put(creditUnitType.getReference(), creditUnitType);
	}
			
	Element creditUnitTypesElement = rootElement.element(PointInTimeDataExport.sCreditUnitTypesElementName);
	for(Element creditUnitTypeElement : (List<Element>) creditUnitTypesElement.elements()){
		elementCreditUnitType(creditUnitTypeElement);
	}

}
 
Example 8
Project: unitimes   File: PointInTimeDataImport.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private void initializeClassDurationTypeData(Element rootElement) throws Exception {
	for (ClassDurationType classDurationType : ClassDurationType.findAll()) {
		classDurationTypes.put(classDurationType.getReference(), classDurationType);
	}
			
	Element classDurationTypesElement = rootElement.element(PointInTimeDataExport.sClassDurationTypesElementName);
	for(Element classDurationTypeElement : (List<Element>) classDurationTypesElement.elements()){
		elementClassDurationType(classDurationTypeElement);
	}
	
}
 
Example 9
Project: lams   File: HbmBinder.java   View Source Code Vote up 5 votes
private static void bindSimpleValueType(Element node, SimpleValue simpleValue, Mappings mappings)
		throws MappingException {
	String typeName = null;

	Properties parameters = new Properties();

	Attribute typeNode = node.attribute( "type" );
       if ( typeNode == null ) {
           typeNode = node.attribute( "id-type" ); // for an any
       }
       else {
           typeName = typeNode.getValue();
       }

	Element typeChild = node.element( "type" );
	if ( typeName == null && typeChild != null ) {
		typeName = typeChild.attribute( "name" ).getValue();
		Iterator typeParameters = typeChild.elementIterator( "param" );

		while ( typeParameters.hasNext() ) {
			Element paramElement = (Element) typeParameters.next();
			parameters.setProperty(
					paramElement.attributeValue( "name" ),
					paramElement.getTextTrim()
				);
		}
	}

	resolveAndBindTypeDef(simpleValue, mappings, typeName, parameters);
}
 
Example 10
Project: unitimes   File: TimetableSolver.java   View Source Code Vote up 5 votes
public static RecordedAssignment fromXml(Element element) {
	Hint before = null, after = null;
	if (element.element("before")!=null) {
		before = Hint.fromXml(element.element("before"));
	}
	if (element.element("after")!=null) {
		after = Hint.fromXml(element.element("after"));
	}
	return new RecordedAssignment(before, after);
}
 
Example 11
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 12
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 5 votes
private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
	Element element = tree != null ? tree.element( "inheritance" ) : null;
	if ( element != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Inheritance.class );
		Attribute attr = element.attribute( "strategy" );
		InheritanceType strategy = InheritanceType.SINGLE_TABLE;
		if ( attr != null ) {
			String value = attr.getValue();
			if ( "SINGLE_TABLE".equals( value ) ) {
				strategy = InheritanceType.SINGLE_TABLE;
			}
			else if ( "JOINED".equals( value ) ) {
				strategy = InheritanceType.JOINED;
			}
			else if ( "TABLE_PER_CLASS".equals( value ) ) {
				strategy = InheritanceType.TABLE_PER_CLASS;
			}
			else {
				throw new AnnotationException(
						"Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
				);
			}
		}
		ad.setValue( "strategy", strategy );
		return AnnotationFactory.create( ad );
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( Inheritance.class );
	}
	else {
		return null;
	}
}
 
Example 13
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 5 votes
private IdClass getIdClass(Element tree, XMLContext.Default defaults) {
	Element element = tree == null ? null : tree.element( "id-class" );
	if ( element != null ) {
		Attribute attr = element.attribute( "class" );
		if ( attr != null ) {
			AnnotationDescriptor ad = new AnnotationDescriptor( IdClass.class );
			Class clazz;
			try {
				clazz = ReflectHelper.classForName(
						XMLContext.buildSafeClassName( attr.getValue(), defaults ),
						this.getClass()
				);
			}
			catch ( ClassNotFoundException e ) {
				throw new AnnotationException( "Unable to find id-class: " + attr.getValue(), e );
			}
			ad.setValue( "value", clazz );
			return AnnotationFactory.create( ad );
		}
		else {
			throw new AnnotationException( "id-class without class. " + SCHEMA_VALIDATION );
		}
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( IdClass.class );
	}
	else {
		return null;
	}
}
 
Example 14
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 5 votes
private Annotation getTableGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
	for ( Element element : elementsForProperty ) {
		Element subelement = element != null ? element.element( annotationToXml.get( TableGenerator.class ) ) : null;
		if ( subelement != null ) {
			return buildTableGeneratorAnnotation( subelement, defaults );
		}
	}
	if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( TableGenerator.class );
	}
	else {
		return null;
	}
}
 
Example 15
Project: unitimes   File: TimetableSolver.java   View Source Code Vote up 5 votes
public static AssignmentRecord fromXml(Element element) {
	AssignmentRecord r = new AssignmentRecord();
	if (element.attributeValue("timeStamp")!=null)
		r.iTimeStamp = new Date(Long.parseLong(element.attributeValue("timeStamp")));
	if (element.element("before")!=null)
		r.iBefore = Suggestion.fromXml(element.element("before"));
	if (element.element("after")!=null)
		r.iAfter = Suggestion.fromXml(element.element("after"));
	for (Iterator i=element.elementIterator("assignment");i.hasNext();) {
		r.iAssignments.add(RecordedAssignment.fromXml((Element)i.next()));
	}
	return r;
}
 
Example 16
Project: lams   File: JPAOverriddenAnnotationReader.java   View Source Code Vote up 5 votes
private Annotation getSequenceGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
	for ( Element element : elementsForProperty ) {
		Element subelement = element != null ? element.element( annotationToXml.get( SequenceGenerator.class ) ) : null;
		if ( subelement != null ) {
			return buildSequenceGeneratorAnnotation( subelement );
		}
	}
	if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( SequenceGenerator.class );
	}
	else {
		return null;
	}
}
 
Example 17
Project: unitimes   File: Suggestion.java   View Source Code Vote up 5 votes
public static StudentConflictInfo fromXml(Element element) {
	StudentConflictInfo s = new StudentConflictInfo();
	if (element.element("first")!=null)
		s.iFirst = Hint.fromXml(element.element("first"));
	if (element.element("second")!=null)
		s.iSecond = Hint.fromXml(element.element("second"));
	if (element.element("jenrl")!=null) {
		s.iInfo = new JenrlInfo();
		s.iInfo.load(element.element("jenrl"));
	}
	return s;
}
 
Example 18
Project: alfresco-repository   File: QueryParameterDefImpl.java   View Source Code Vote up 4 votes
public static QueryParameterDefinition createParameterDefinition(Element element, DictionaryService dictionaryService,  NamespacePrefixResolver nspr)
{

    if (element.getQName().getName().equals(ELEMENT_QNAME.getName()))
    {
        QName qName = null;
        Element qNameElement = element.element(DEF_QNAME.getName());
        if (qNameElement != null)
        {
            qName = QName.createQName(qNameElement.getText(), nspr);
        }

        PropertyDefinition propDef = null;
        Element propDefElement = element.element(PROPERTY_QNAME.getName());
        if (propDefElement != null)
        {
            propDef = dictionaryService.getProperty(QName.createQName(propDefElement.getText(), nspr));
        }

        DataTypeDefinition typeDef = null;
        Element typeDefElement = element.element(PROPERTY_TYPE_QNAME.getName());
        if (typeDefElement != null)
        {
            typeDef = dictionaryService.getDataType(QName.createQName(typeDefElement.getText(), nspr));
        }

        boolean hasDefault = false;
        String defaultValue = null;
        Element defaultValueElement = element.element(DEFAULT_VALUE.getName());
        if(defaultValueElement != null)
        {
            hasDefault = true;
            defaultValue = defaultValueElement.getText();
        }
        
        if (propDef != null)
        {
            return new QueryParameterDefImpl(qName, propDef, hasDefault, defaultValue);
        }
        else
        {
            return new QueryParameterDefImpl(qName, typeDef, hasDefault, defaultValue);
        }
    }
    else
    {
        return null;
    }
}
 
Example 19
Project: uflo   File: ProcessParser.java   View Source Code Vote up 4 votes
public Object parse(Element element,long processId,boolean parseChildren) {
	ProcessDefinition process=new ProcessDefinition();
	process.setId(processId);
	process.setEventHandlerBean(unescape(element.attributeValue("event-handler-bean")));
	process.setName(unescape(element.attributeValue("name")));
	process.setStartProcessUrl(unescape(element.attributeValue("start-process-url")));
	process.setKey(unescape(element.attributeValue("key")));
	process.setCategoryId(unescape(element.attributeValue("category-id")));
	String effectDateStr=unescape(element.attributeValue("effect-date"));
	if(StringUtils.isNotEmpty(effectDateStr)){
		SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			process.setEffectDate(sd.parse(effectDateStr));
		} catch (ParseException e) {
			log.error("Process definition "+process.getName()+" effect date is invalid:"+effectDateStr);
		}
	}
	if(StringUtils.isEmpty(process.getCategoryId())){
		process.setCategoryId(EnvironmentUtils.getEnvironment().getCategoryId());
	}
	Element descElement=element.element("description");
	if(descElement!=null){
		String desc=descElement.getTextTrim();
		desc=(desc.length()>120?desc.substring(0,120):desc);
		process.setDescription(unescape(desc));
	}
	if(parseChildren){
		List<Node> nodes=new ArrayList<Node>();
		List<Swimlane> swimlanes=new ArrayList<Swimlane>();
		for(Object obj:element.elements()){
			if(!(obj instanceof Element)){
				continue;
			}
			Element childElement=(Element)obj;
			for(Parser parser:parsers){
				if(!parser.support(childElement)){
					continue;
				}
				Object processElement=parser.parse(childElement,processId,parseChildren);
				if(processElement instanceof Node){
					Node node=(Node)processElement;
					node.setProcessId(processId);
					nodes.add(node);
				}
				if(processElement instanceof StartNode){
					process.setStartNode((StartNode)processElement);
				}
				if(processElement instanceof Swimlane){
					swimlanes.add((Swimlane)processElement);
				}
				break;
			}
		}
		process.setSwimlanes(swimlanes);
		process.setNodes(nodes);
	}
	if(parseChildren){
		process.setDiagram(buildProcessDiagram(process));			
	}
	return process;
}
 
Example 20
Project: unitimes   File: CourseCatalogImport.java   View Source Code Vote up 4 votes
public void loadXml(Element root) throws Exception {
       if (!root.getName().equalsIgnoreCase("courseCatalog")) {
       	throw new Exception("Given XML file is not a Course Catalog load file.");
       }
       try {
           beginTransaction();

           String campus = root.attributeValue("campus");
           String year   = root.attributeValue("year");
           String term   = root.attributeValue("term");

           Session session = Session.getSessionUsingInitiativeYearTerm(campus, year, term);
           if(session == null) {
               throw new Exception("No session found for the given campus, year, and term.");
           }

           for ( Iterator it = root.elementIterator(); it.hasNext(); ) {
               Element element = (Element) it.next();
               CourseCatalog catalog = new CourseCatalog();
               catalog.setCourseNumber(element.attributeValue("courseNumber"));
               catalog.setApprovalType(element.attributeValue("approvalType"));
               catalog.setExternalUniqueId(element.attributeValue("externalId"));
               catalog.setPermanentId(element.attributeValue("permanentId"));
               catalog.setPreviousCourseNumber(element.attributeValue("previousCourseNumber"));
               catalog.setPreviousSubject(element.attributeValue("previousSubject"));
               catalog.setSession(session);
               catalog.setSubject(element.attributeValue("subject"));
               catalog.setTitle(element.attributeValue("title"));

               Element credit = element.element("courseCredit");
               if (credit == null) {
                   error("Course credit not provided for "+catalog.getSubject()+" "+catalog.getCourseNumber()+".");
                   continue;
               }
               catalog.setCreditFormat(credit.attributeValue("creditFormat"));
               catalog.setCreditType(credit.attributeValue("creditType"));
               catalog.setCreditUnitType(credit.attributeValue("creditUnitType"));
               catalog.setFractionalCreditAllowed(Boolean.valueOf(credit.attributeValue("fractionalCreditAllowed")));
               String minCredit = credit.attributeValue("fixedCredit");
               if(minCredit != null) 
                   catalog.setFixedMinimumCredit(Float.parseFloat(minCredit));
               else {
                   minCredit = credit.attributeValue("minimumCredit");
                   if(minCredit != null) 
                       catalog.setFixedMinimumCredit(Float.parseFloat(minCredit));
                   else
                       catalog.setFixedMinimumCredit(new Float(MIN_CREDIT));
                   String maxCredit = credit.attributeValue("maximumCredit");
                   if(maxCredit != null)
                       catalog.setMaximumCredit(Float.parseFloat(maxCredit));
                   else
                       catalog.setMaximumCredit(new Float(MAX_CREDIT));
               }

               getHibSession().saveOrUpdate(catalog);  // to set the uniqueId
               loadCredits(element, catalog);
               getHibSession().saveOrUpdate(catalog);  // to save the subparts
               flushIfNeeded(false);
           }

           commitTransaction();
       } catch (Exception e) {
           fatal("Exception: " + e.getMessage(), e);
           rollbackTransaction();
           throw e;
       }
}