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

The following are Jave code examples for showing how to use addAttribute() 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: pndao   File: DaoGenHelper.java   View Source Code Vote up 6 votes
private Consumer<String> addRemove(DaoGen daoGen, String key, MapperMethod method, Element root) {
    return (prefix) -> {
        Element sql = root.addElement("delete");
        sql.addComment(COMMENT);
        sql.addAttribute("id", key);
        String left = key.replaceFirst(prefix, "");
        List<String> params = split(left, daoGen.separator());
        if (params.isEmpty()) throw new Error("Remove method needs at least  one param");
        StringBuilder select = new StringBuilder(50);
        select.append("delete from ")
                .append(method.getDaoEnv().getTableName());
        int len = params.size();
        if (!params.isEmpty()) select.append(" where ");
        int cur = 0;
        appendParams(params, select, len, cur);
        sql.addText(select.toString());
    };
}
 
Example 2
Project: iBase4J-Common   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * 将List数据类型转换为符合XML格式规范的字符串(基于节点属性值的方式)
 * 
 * @param pList 传入的List数据(List对象可以是Dto、VO、Domain的属性集)
 * @param pRootNodeName 根节点名称
 * @param pFirstNodeName 行节点名称
 * @return string 返回XML格式字符串
 */
public static final String parseList2Xml(List pList, String pRootNodeName, String pFirstNodeName) {
    Document document = DocumentHelper.createDocument();
    Element elRoot = document.addElement(pRootNodeName);
    for (int i = 0; i < pList.size(); i++) {
        Map map = (Map)pList.get(i);
        Element elRow = elRoot.addElement(pFirstNodeName);
        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry)it.next();
            elRow.addAttribute((String)entry.getKey(), String.valueOf(entry.getValue()));
        }
    }
    String outXml = document.asXML().substring(39);
    return outXml;
}
 
Example 3
Project: iBase4J   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * 将List数据类型转换为符合XML格式规范的字符串(基于节点属性值的方式)
 * 
 * @param pList 传入的List数据(List对象可以是Dto、VO、Domain的属性集)
 * @param pRootNodeName 根节点名称
 * @param pFirstNodeName 行节点名称
 * @return string 返回XML格式字符串
 */
public static final String parseList2Xml(List pList, String pRootNodeName, String pFirstNodeName) {
	Document document = DocumentHelper.createDocument();
	Element elRoot = document.addElement(pRootNodeName);
	for (int i = 0; i < pList.size(); i++) {
		Map map = (Map) pList.get(i);
		Element elRow = elRoot.addElement(pFirstNodeName);
		Iterator it = map.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			elRow.addAttribute((String) entry.getKey(), String.valueOf(entry.getValue()));
		}
	}
	String outXml = document.asXML().substring(39);
	return outXml;
}
 
Example 4
Project: unitimes   File: AcademicSessionSetupExport.java   View Source Code Vote up 6 votes
protected void exportTimePatterns(Element root, Session session) {
	Element patternsEl = root.addElement("timePatterns");
	for (TimePattern tp: new TreeSet<TimePattern>((List<TimePattern>)getHibSession().createQuery(
			"from TimePattern where session = :sessionId").setLong("sessionId", session.getUniqueId()).list())) {
		Element patternEl = patternsEl.addElement("timePattern");
		patternEl.addAttribute("name", tp.getName());
		patternEl.addAttribute("nbrMeetings", tp.getNrMeetings().toString());
		patternEl.addAttribute("minsPerMeeting", tp.getMinPerMtg().toString());
		patternEl.addAttribute("type", TimePattern.sTypes[tp.getType()]);
		patternEl.addAttribute("visible", tp.getVisible() != null && tp.getVisible().booleanValue() ? "true" : "false");
		patternEl.addAttribute("nbrSlotsPerMeeting", tp.getSlotsPerMtg().toString());
		patternEl.addAttribute("breakTime", tp.getBreakTime() == null ? "0" : tp.getBreakTime().toString());
		for (Department d: tp.getDepartments())
			patternEl.addElement("department").addAttribute("code", d.getDeptCode());
		for (TimePatternDays days: new TreeSet<TimePatternDays>(tp.getDays())) {
			patternEl.addElement("days").addAttribute("code", dayCode2days(days.getDayCode()));
		}
		for (TimePatternTime time: new TreeSet<TimePatternTime>(tp.getTimes())) {
			patternEl.addElement("time").addAttribute("start", startSlot2startTime(time.getStartSlot()));
		}
	}
}
 
Example 5
Project: directory-ldap-api   File: AbstractResultResponseRequestDsml.java   View Source Code Vote up 6 votes
/**
 * Creates the Request Element and adds RequestID and Controls.
 *
 * @param root the root element
 * @return the Request Element of the given name containing
 */
@Override
public Element toDsml( Element root )
{
    Element element = root.addElement( getRequestName() );

    // Request ID
    int requestID = getDecorated().getMessageId();
    if ( requestID > 0 )
    {
        element.addAttribute( "requestID", Integer.toString( requestID ) );
    }

    // Controls
    ParserUtils.addControls( getCodecService(), element, getDecorated().getControls().values() );

    return element;
}
 
Example 6
Project: bdf2   File: ModelBuilder.java   View Source Code Vote up 6 votes
private Element createReferencePropertyDef(Entity entity,RuleSet ruleSet,boolean isSelf){
	String nodeName=Reference.class.getSimpleName();
	Rule rule=ruleSet.getRule(nodeName);
	Element referenceDefElement=new BaseElement(rule.getNodeName());
	referenceDefElement.addAttribute("name", entity.getName());
	//创建dataType与dataProvider属性
	Element dataTypeElement=createPropertyElement("dataType",null);
	if(isSelf){
		dataTypeElement.setText("[SELF]");			
	}else{
		dataTypeElement.setText("["+ entity.getName()+"]");						
	}
	referenceDefElement.add(dataTypeElement);
	String entityName=entity.getName();
	Element dataProviderElement=createPropertyElement("dataProvider","dataProvider"+entityName.substring(0,1).toUpperCase()+entityName.substring(1,entityName.length()));
	if(entity.getPageSize()>0){
		Element pageSizeElement=createPropertyElement("pageSize",String.valueOf(entity.getPageSize()));
		referenceDefElement.add(pageSizeElement);
	}
	referenceDefElement.add(dataProviderElement);
	referenceDefElement.add(createReferenceParameterElement(entity));
	return referenceDefElement;
}
 
Example 7
Project: EasyML   File: ForkNodeDef.java   View Source Code Vote up 5 votes
@Override
public void append2XML(Element root) {
	Element fork = root.addElement("fork");
	fork.addAttribute("name", getName());

	for (NodeDef node : outNodes) {
		Element path = fork.addElement("path");
		path.addAttribute("start", node.getName());
	}

}
 
Example 8
Project: EasyML   File: EndNodeDef.java   View Source Code Vote up 5 votes
@Override
public void append2XML(Element root) {
	Element kill = root.addElement("kill");
	Element msg = kill.addElement("message");
	msg.addText("Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
	kill.addAttribute("name", "fail");

	Element end = root.addElement("end");
	end.addAttribute("name", getName());
}
 
Example 9
Project: parabuild-ci   File: Dom4JXMLOutput.java   View Source Code Vote up 5 votes
public void openTag(String tagName, XMLAttributeList attributeList) {
	Branch top = stack.getLast();
	Element element = top.addElement(tagName);
	stack.addLast(element);

	for (Iterator<XMLAttributeList.NameValuePair> i= attributeList.iterator();
		i.hasNext(); ) {
		XMLAttributeList.NameValuePair pair = i.next();
		element.addAttribute(pair.getName(), pair.getValue());
	}
}
 
Example 10
Project: unitimes   File: CourseOfferingExport.java   View Source Code Vote up 5 votes
protected void exportTimeLocation(Element classElement, Assignment assignment, Session session) {
    TimeLocation time = assignment.getTimeLocation();
    if (time!=null) {
        Element timeElement = classElement.addElement("time");
        timeElement.addAttribute("days", dayCode2days(time.getDayCode()));
        timeElement.addAttribute("startTime", startSlot2startTime(time.getStartSlot()));
        timeElement.addAttribute("endTime", timeLocation2endTime(time));
        DatePattern dp = assignment.getDatePattern();
        if (dp != null && (!dp.isDefault() || ApplicationProperty.DataExchangeIncludeDefaultDatePattern.isTrue()))
        	timeElement.addAttribute("datePattern", dp.getName());
        if (assignment.getTimePattern() != null)
        	timeElement.addAttribute("timePattern", assignment.getTimePattern().getName());
    }
}
 
Example 11
Project: unitimes   File: CourseOfferingExport.java   View Source Code Vote up 5 votes
protected void exportEvent(Element classElement, Event event, Session session) {
  	if (event == null) return;
  	List<Meeting> meetings = new ArrayList<Meeting>(event.getMeetings());
  	Collections.sort(meetings, new Comparator<Meeting>() {
	@Override
	public int compare(Meeting m1, Meeting m2) {
		if (m1.equals(m2)) return 0;
		int cmp = m1.getMeetingDate().compareTo(m2.getMeetingDate());
		if (cmp != 0) return cmp;
		cmp = m1.getStartPeriod().compareTo(m2.getStartPeriod());
		if (cmp != 0) return cmp;
		Location l1 = (m1.getLocationPermanentId() == null ? null : iMeetingLocations.get(m1.getLocationPermanentId()));
		Location l2 = (m2.getLocationPermanentId() == null ? null : iMeetingLocations.get(m2.getLocationPermanentId()));
		cmp = (l1 == null ? "" : l1.getLabel()).compareTo(l2 == null ? "" : l2.getLabel());
		if (cmp != 0) return cmp;
		return m1.getUniqueId().compareTo(m2.getUniqueId());
	}
});
      for (Meeting meeting: meetings) {
          if (meeting.getStatus() != Meeting.Status.APPROVED) continue;
          Element meetingElement = classElement.addElement("meeting");
          meetingElement.addAttribute("startDate", sDateFormat.format(meeting.getMeetingDate()));
          meetingElement.addAttribute("endDate", sDateFormat.format(meeting.getMeetingDate()));
          meetingElement.addAttribute("startTime", sTimeFormat.format(meeting.getStartTime()));
          meetingElement.addAttribute("endTime", sTimeFormat.format(meeting.getStopTime()));
          Calendar c = Calendar.getInstance(Locale.US); c.setTime(meeting.getMeetingDate());
          switch (c.get(Calendar.DAY_OF_WEEK)) {
              case Calendar.MONDAY : meetingElement.addAttribute("days","M"); break;
              case Calendar.TUESDAY : meetingElement.addAttribute("days","T"); break;
              case Calendar.WEDNESDAY : meetingElement.addAttribute("days","W"); break;
              case Calendar.THURSDAY : meetingElement.addAttribute("days","R"); break;
              case Calendar.FRIDAY : meetingElement.addAttribute("days","F"); break;
              case Calendar.SATURDAY : meetingElement.addAttribute("days","S"); break;
              case Calendar.SUNDAY : meetingElement.addAttribute("days","U"); break;
          }
          Location location = (meeting.getLocationPermanentId() == null ? null : iMeetingLocations.get(meeting.getLocationPermanentId()));
          if (location==null) {
          } else if (location instanceof Room) {
              meetingElement.addAttribute("building", ((Room)location).getBuildingAbbv());
              meetingElement.addAttribute("room", ((Room)location).getRoomNumber());
          } else {
              meetingElement.addAttribute("location", location.getLabel());
          }
      }
  }
 
Example 12
Project: unitimes   File: GroupConstraintInfo.java   View Source Code Vote up 5 votes
public void save(Element root) {
	root.addAttribute("version", String.valueOf(sVersion));
	if (iName!=null)
		root.addElement("name").setText(iName);
	root.addElement("pref").setText(iPreference);
       if (iType!=null)
           root.addElement("type").setText(iType);
	root.addElement("isSatisfied").setText(String.valueOf(iIsSatisfied));
}
 
Example 13
Project: joai-project   File: MdeStdsNode.java   View Source Code Vote up 4 votes
/**  Renders a managed standards field, unless this collection does not allow the suggestion
service, in which case the field is rendered as a repeating simple type */
protected void render_edit_mode() {
	Element parentExists = rhelper.parentNodeExistsTest(xpath);
	parent.add(parentExists);
	insertDisplaySetup(parentExists);

	// LABEL - use a complex label so we can make it
	// collapsible. Otherwise, use simpleTypeLabel
	Label label = renderer.getMultiBoxLabel(xpath);

	// add a controller to delete this element
	Element deleteController = renderer.getDeleteController(xpath, "field");
	((SimpleTypeLabel) label).control = deleteController;

	// create box
	Element box = df.createElement("div")
		.addAttribute("id", "${id}_box");
	embedDebugInfo(box, "simpleType");

	// attach box
	parentExists.add(box);

	// create fieldElement (containing input element)
	Element fieldElement = df.createElement("div");
	fieldElement.addAttribute("id", "${id}");

	Element inputElement = null;
	try {
		prtln("rendering as managedStandards_MultiBox (" + normalizedXPath + ")");
		
		Element helperChoice = df.createElement("c__choose");
		Element helperPresent = df.createElement ("c__when")
			.addAttribute("test", "${not empty "+this.formBeanName+".suggestionServiceHelper}");
		Element otherwise = df.createElement ("c__otherwise");

		helperChoice.add (helperPresent);
		helperChoice.add (otherwise);
		
		prtln("rendering as managedStandards_MultiBox (" + normalizedXPath + ")");
		Element standardsTag = df.createElement("std__" + standardsManager.getRendererTag())
			.addAttribute("elementPath", "enumerationValuesOf(" + XPathUtils.getSiblingXPath(xpath) + ")")
			.addAttribute("pathArg", XPathUtils.getSiblingXPath(xpath));
		helperPresent.add (standardsTag);

		// render this xpath as a repeatingSimpleType, attached to the "otherwise" clause
		RendererImpl newRenderer = (RendererImpl)newRenderer(xpath, otherwise);
		MdeRepeatingSimpleType s = new MdeRepeatingSimpleType(newRenderer);
		s.render();
		
		fieldElement.add(helperChoice);
	} catch (Throwable t) {
		prtln("WARNING: getMultiBoxInput() standards error: " + t.getMessage());
		t.printStackTrace();
	}

	box.add(getRenderedField(label, fieldElement));
}
 
Example 14
Project: joai-project   File: MdeComplexType.java   View Source Code Vote up 4 votes
/**  Render editing field for this complex element */
	private void render_edit_mode() {
		prtln ("reder_edit_mode with: " + xpath);
		if (getLevel() != 0) {
			insertDisplaySetup(parent);
		}
		else {
			Element elementPath = df.createElement("c__set")
				.addAttribute("var", "elementPath")
				.addAttribute("value", xpath);
			parent.add(elementPath);

			Element setId = df.createElement("c__set")
				.addAttribute("var", "id")
				.addAttribute("value", "${sf__pathToId(elementPath)}");
			parent.add(setId);
		}
		
		Label label = renderer.getComplexTypeLabel(xpath);
		Element controlElement = null;

		Element containerBox = getComplexTypeBox();
		containerBox.addAttribute("id", "${id}_box");
		parent.add(containerBox);
		
		// test for the existence of a parent, unless we are at the 0th level of the page
		Element parentExists = null;
		if (getLevel() == 0) {
			parentExists = df.createElement("div");
			attachElementId (parentExists);
		}
		else {
			parentExists = rhelper.parentNodeExistsTest(xpath);
		}
		containerBox.add(parentExists);


		controlElement = df.createElement("div");
		attachControl(controlElement);

/* 		prtln ("---------- Control Element --------------");
		prtln (Dom4jUtils.prettyPrint(controlElement)); */
		
		parent = parentExists;
		
		Element inputHelper = this.renderer.getInputHelperElement(this.xpath);
		parent.add(getRenderedNoInputField(label, controlElement, inputHelper));
		
		// make collapsible subElementBox
		Element subElementsBox = parent.addElement("div");
		// this.attachElementDebugInfo(subElementsBox, "MdeComplexType - subElementsBox - ${id}");

		// add id to subElement Box so it can be collapsed
		subElementsBox.addAttribute("id", "${id}");
		if (getLevel() > 0 && isEditMode()) {
			subElementsBox.addAttribute("style", "display:${" + formBeanName + ".collapseBean.displayState};");
		}
		
		// new attach point becomes subElementsBox
		parent = subElementsBox;
		
		renderSubElements();

	}
 
Example 15
Project: unitimes   File: ConflictStatisticsInfo.java   View Source Code Vote up 4 votes
public void save(Element root) {
	root.addAttribute("version", String.valueOf(sVersion));
	for (Iterator i1=iVariables.values().iterator();i1.hasNext();) {
		((CBSVariable)i1.next()).save(root.addElement("var"));
	}
}
 
Example 16
Project: unitimes   File: BtbInstructorConstraintInfo.java   View Source Code Vote up 4 votes
public void save(Element root) {
	root.addAttribute("version", String.valueOf(sVersion));
	root.addElement("pref").setText(String.valueOf(iPreference));
	root.addElement("instructor").setText(String.valueOf(iInstructorId));
}
 
Example 17
Project: unitimes   File: StudentEnrollmentExport.java   View Source Code Vote up 4 votes
@Override
public void saveXml(Document document, Session session, Properties parameters) throws Exception {
	try {
		beginTransaction();
		
		Element root = document.addElement("studentEnrollments");
        root.addAttribute("campus", session.getAcademicInitiative());
        root.addAttribute("year", session.getAcademicYear());
        root.addAttribute("term", session.getAcademicTerm());
        document.addDocType("studentEnrollments", "-//UniTime//UniTime Student Enrollments DTD/EN", "http://www.unitime.org/interface/StudentEnrollment.dtd");
        
        for (Student student: (List<Student>)getHibSession().createQuery(
        		"select s from Student s where s.session.uniqueId = :sessionId")
        		.setLong("sessionId", session.getUniqueId()).list()) {
        	if (student.getClassEnrollments().isEmpty()) continue;
        	Element studentEl = root.addElement("student");
        	studentEl.addAttribute("externalId",
        			student.getExternalUniqueId() == null || student.getExternalUniqueId().isEmpty() ? student.getUniqueId().toString() : student.getExternalUniqueId());
        	for (StudentClassEnrollment enrollment: student.getClassEnrollments()) {
        		Element classEl = studentEl.addElement("class");
        		Class_ clazz = enrollment.getClazz();
        		CourseOffering course = enrollment.getCourseOffering();
        		String extId = (course == null ? clazz.getExternalUniqueId() : clazz.getExternalId(course));
        		if (extId != null && !extId.isEmpty())
        			classEl.addAttribute("externalId", extId);
        		classEl.addAttribute("id", clazz.getUniqueId().toString());
        		if (course != null) {
        			if (course.getExternalUniqueId() != null && !course.getExternalUniqueId().isEmpty())
        				classEl.addAttribute("courseId", course.getExternalUniqueId());
        			classEl.addAttribute("subject", course.getSubjectAreaAbbv());
        			classEl.addAttribute("courseNbr", course.getCourseNbr());
        		}
        		classEl.addAttribute("type", clazz.getSchedulingSubpart().getItypeDesc().trim());
        		classEl.addAttribute("suffix", getClassSuffix(clazz));
        	}
        }
        
           commitTransaction();
       } catch (Exception e) {
           fatal("Exception: "+e.getMessage(),e);
           rollbackTransaction();
	}
}
 
Example 18
Project: unitimes   File: ExportPreferences.java   View Source Code Vote up 4 votes
public void exportRoomFeaturePref(Element parent, RoomFeaturePref roomFeaturePref) {
	Element el = parent.addElement("roomFeaturePref");
	el.addAttribute("uniqueId", roomFeaturePref.getUniqueId().toString());
	el.addAttribute("level", roomFeaturePref.getPrefLevel().getPrefProlog());
	el.addAttribute("feature", roomFeaturePref.getRoomFeature().getLabel());
}
 
Example 19
Project: unitimes   File: ExportPreferences.java   View Source Code Vote up 4 votes
public void exportBuildingPref(Element parent, BuildingPref bldgPref) {
	Element el = parent.addElement("buildingPref");
	el.addAttribute("uniqueId", bldgPref.getUniqueId().toString());
	el.addAttribute("level", bldgPref.getPrefLevel().getPrefProlog());
	el.addAttribute("building", bldgPref.getBuilding().getAbbreviation());
}
 
Example 20
Project: unitimes   File: ExportPreferences.java   View Source Code Vote up 4 votes
public void exportRoomGroupPref(Element parent, RoomGroupPref roomGroupPref) {
	Element el = parent.addElement("roomGroupPref");
	el.addAttribute("uniqueId", roomGroupPref.getUniqueId().toString());
	el.addAttribute("level", roomGroupPref.getPrefLevel().getPrefProlog());
	el.addAttribute("group", roomGroupPref.getRoomGroup().getName());
}