List of usage examples for org.dom4j Element remove
boolean remove(Text text);
Text
if the node is an immediate child of this element. From source file:org.b5chat.crossfire.xmpp.disco.IQDiscoItemsHandler.java
License:Open Source License
@Override public IQ handleIQ(IQ packet) { // Create a copy of the sent pack that will be used as the reply // we only need to add the requested items to the reply if any otherwise add // a not found error IQ reply = IQ.createResultIQ(packet); // TODO Implement publishing client items if (IQ.Type.set == packet.getType()) { reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.feature_not_implemented); return reply; }/*from w w w . ja v a 2s .c om*/ // Look for a IDiscoItemsProvider associated with the requested entity. // We consider the host of the recipient JID of the packet as the entity. It's the // IDiscoItemsProvider responsibility to provide the items associated with the JID's name // together with any possible requested node. IDiscoItemsProvider itemsProvider = getProvider( packet.getTo() == null ? XmppServer.getInstance().getServerInfo().getXMPPDomain() : packet.getTo().getDomain()); if (itemsProvider != null) { // Get the JID's name String name = packet.getTo() == null ? null : packet.getTo().getNode(); if (name == null || name.trim().length() == 0) { name = null; } // Get the requested node Element iq = packet.getChildElement(); String node = iq.attributeValue("node"); // Check if we have items associated with the requested name and node Iterator<DiscoItem> itemsItr = itemsProvider.getItems(name, node, packet.getFrom()); if (itemsItr != null) { reply.setChildElement(iq.createCopy()); Element queryElement = reply.getChildElement(); // See if the requesting entity would like to apply 'result set // management' final Element rsmElement = packet.getChildElement() .element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)); // apply RSM only if the element exists, and the (total) results // set is not empty. final boolean applyRSM = rsmElement != null && itemsItr.hasNext(); if (applyRSM) { if (!ResultSet.isValidRSMRequest(rsmElement)) { reply.setError(PacketError.Condition.bad_request); return reply; } // Calculate which results to include. final List<DiscoItem> rsmResults; final List<DiscoItem> allItems = new ArrayList<DiscoItem>(); while (itemsItr.hasNext()) { allItems.add(itemsItr.next()); } final ResultSet<DiscoItem> rs = new ResultSetImpl<DiscoItem>(allItems); try { rsmResults = rs.applyRSMDirectives(rsmElement); } catch (NullPointerException e) { final IQ itemNotFound = IQ.createResultIQ(packet); itemNotFound.setError(PacketError.Condition.item_not_found); return itemNotFound; } // add the applicable results to the IQ-result for (DiscoItem item : rsmResults) { final Element resultElement = item.getElement(); resultElement.setQName(new QName(resultElement.getName(), queryElement.getNamespace())); queryElement.add(resultElement.createCopy()); } // overwrite the 'set' element. queryElement.remove( queryElement.element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT))); queryElement.add(rs.generateSetElementFromResults(rsmResults)); } else { // don't apply RSM: // Add to the reply all the items provided by the IDiscoItemsProvider Element item; while (itemsItr.hasNext()) { item = itemsItr.next().getElement(); item.setQName(new QName(item.getName(), queryElement.getNamespace())); queryElement.add(item.createCopy()); } } } else { // If the IDiscoItemsProvider has no items for the requested name and node // then answer a not found error reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.item_not_found); } } else { // If we didn't find a IDiscoItemsProvider then answer a not found error reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.item_not_found); } return reply; }
From source file:org.codehaus.cargo.container.weblogic.WebLogic9x10x103x12xConfigXmlInstalledLocalDeployer.java
License:Apache License
/** * Remove the corresponding app-deployment element from the domain of the WebLogic server. * /*w ww. jav a 2 s .c o m*/ * @param deployable - application component to remove * @param domain - Domain element of the WebLogic server */ protected void removeDeployableFromDomain(Deployable deployable, Element domain) { // use contains in case there is whitespace List<Element> results = selectAppDeployments(deployable, domain); for (Element element : results) { domain.remove(element); } }
From source file:org.codehaus.cargo.container.weblogic.WebLogic9xConfigXmlInstalledLocalDeployer.java
License:Apache License
/** * Remove the corresponding app-deployment element from the domain of the WebLogic server. * /*from ww w . j a va 2 s. c o m*/ * @param deployable - application component to remove * @param domain - Domain element of the WebLogic server */ protected void removeDeployableFromDomain(Deployable deployable, Element domain) { // use contains in case there is whitespace List results = selectAppDeployments(deployable, domain); for (Iterator iter = results.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); domain.remove(element); } }
From source file:org.codehaus.cargo.util.Dom4JXmlFileBuilder.java
License:Apache License
/** * {@inheritDoc}/*from ww w . jav a2 s . c o m*/ */ public void insertElementsUnderXPath(String elementsToParse, String xpath) { Element parent = xmlUtil.selectElementMatchingXPath(xpath, document.getRootElement()); StringBuilder nested = new StringBuilder(); nested.append("<parent>"); nested.append(elementsToParse); nested.append("</parent>"); Element nestedElements = xmlUtil.parseIntoElement(nested.toString()); List<Element> elements = nestedElements.elements(); for (Element element : elements) { setNamespaceOfElementToTheSameAsParent(element, parent); nestedElements.remove(element); parent.add(element); } }
From source file:org.collectionspace.chain.util.xtmpl.XTmplTmpl.java
License:Educational Community License
@SuppressWarnings("unchecked") private void removeNamespaces(Element e) { for (Namespace ns : (List<Namespace>) e.declaredNamespaces()) { if (!XTMPL_URI.equals(ns.getURI())) continue; e.remove(ns); }/*w w w . ja v a 2 s .c om*/ for (Element k : (List<Element>) e.elements()) { removeNamespaces(k); } }
From source file:org.collectionspace.chain.util.xtmpl.XTmplTmpl.java
License:Educational Community License
@SuppressWarnings("unchecked") private void compileTemplate(Document template) throws InvalidXTmplException { try {//from w ww. j a va 2 s .c om Map<String, String> map = new HashMap<String, String>(); map.put("xtmpl", XTMPL_URI); Dom4jXPath xpath = new Dom4jXPath("//.[@xtmpl:point]"); xpath.setNamespaceContext(new SimpleNamespaceContext(map)); List<Node> paths = xpath.selectNodes(template); QName attr_qname = new QName("point", new Namespace("xtmpl", XTMPL_URI)); for (Node n : paths) { if (!(n instanceof Element)) continue; Element e = (Element) n; Attribute attr = e.attribute(attr_qname); String key = attr.getText(); String path = e.getPath(); e.remove(attr); attach.put(key, path); } removeNamespaces(template.getDocument().getRootElement()); document = template; } catch (JaxenException e) { throw new InvalidXTmplException("Cannot parse template file", e); } }
From source file:org.cpsolver.coursett.TimetableXMLSaver.java
License:Open Source License
protected void doSave(Element root) { root.addAttribute("version", "2.5"); root.addAttribute("initiative", getModel().getProperties().getProperty("Data.Initiative")); root.addAttribute("term", getModel().getProperties().getProperty("Data.Term")); root.addAttribute("year", String.valueOf(getModel().getYear())); root.addAttribute("created", String.valueOf(new Date())); root.addAttribute("nrDays", String.valueOf(Constants.DAY_CODES.length)); root.addAttribute("slotsPerDay", String.valueOf(Constants.SLOTS_PER_DAY)); if (!iConvertIds && getModel().getProperties().getProperty("General.SessionId") != null) root.addAttribute("session", getModel().getProperties().getProperty("General.SessionId")); if (iShowNames && !iConvertIds && getModel().getProperties().getProperty("General.SolverGroupId") != null) root.addAttribute("solverGroup", getId("solverGroup", getModel().getProperties().getProperty("General.SolverGroupId"))); HashMap<String, Element> roomElements = new HashMap<String, Element>(); Element roomsEl = root.addElement("rooms"); for (RoomConstraint roomConstraint : getModel().getRoomConstraints()) { Element roomEl = roomsEl.addElement("room").addAttribute("id", getId("room", roomConstraint.getResourceId())); roomEl.addAttribute("constraint", "true"); if (roomConstraint instanceof DiscouragedRoomConstraint) roomEl.addAttribute("discouraged", "true"); if (iShowNames) { roomEl.addAttribute("name", roomConstraint.getRoomName()); }/*from w w w .j ava 2s . c o m*/ if (!iConvertIds && roomConstraint.getBuildingId() != null) roomEl.addAttribute("building", getId("bldg", roomConstraint.getBuildingId())); roomElements.put(getId("room", roomConstraint.getResourceId()), roomEl); roomEl.addAttribute("capacity", String.valueOf(roomConstraint.getCapacity())); if (roomConstraint.getPosX() != null && roomConstraint.getPosY() != null) roomEl.addAttribute("location", roomConstraint.getPosX() + "," + roomConstraint.getPosY()); if (roomConstraint.getIgnoreTooFar()) roomEl.addAttribute("ignoreTooFar", "true"); if (!roomConstraint.getConstraint()) roomEl.addAttribute("fake", "true"); if (roomConstraint.getSharingModel() != null) { RoomSharingModel sharingModel = roomConstraint.getSharingModel(); Element sharingEl = roomEl.addElement("sharing"); sharingEl.addElement("pattern").addAttribute("unit", String.valueOf(sharingModel.getStep())) .setText(sharingModel.getPreferences()); sharingEl.addElement("freeForAll").addAttribute("value", String.valueOf(sharingModel.getFreeForAllPrefChar())); sharingEl.addElement("notAvailable").addAttribute("value", String.valueOf(sharingModel.getNotAvailablePrefChar())); for (Long id : sharingModel.getDepartmentIds()) { sharingEl.addElement("department") .addAttribute("value", String.valueOf(sharingModel.getCharacter(id))) .addAttribute("id", getId("dept", id)); } } if (roomConstraint.getType() != null && iShowNames) roomEl.addAttribute("type", roomConstraint.getType().toString()); Map<Long, Integer> travelTimes = getModel().getDistanceMetric().getTravelTimes() .get(roomConstraint.getResourceId()); if (travelTimes != null) for (Map.Entry<Long, Integer> time : travelTimes.entrySet()) roomEl.addElement("travel-time").addAttribute("id", getId("room", time.getKey())) .addAttribute("minutes", time.getValue().toString()); } Element instructorsEl = root.addElement("instructors"); Element departmentsEl = root.addElement("departments"); HashMap<Long, String> depts = new HashMap<Long, String>(); Element configsEl = (iShowNames ? root.addElement("configurations") : null); HashSet<Configuration> configs = new HashSet<Configuration>(); Element classesEl = root.addElement("classes"); HashMap<Long, Element> classElements = new HashMap<Long, Element>(); List<Lecture> vars = new ArrayList<Lecture>(getModel().variables()); if (getModel().hasConstantVariables()) vars.addAll(getModel().constantVariables()); for (Lecture lecture : vars) { Placement placement = getAssignment().getValue(lecture); if (lecture.isCommitted() && placement == null) placement = lecture.getInitialAssignment(); Placement initialPlacement = lecture.getInitialAssignment(); // if (initialPlacement==null) initialPlacement = // (Placement)lecture.getAssignment(); Placement bestPlacement = lecture.getBestAssignment(); Element classEl = classesEl.addElement("class").addAttribute("id", getId("class", lecture.getClassId())); classElements.put(lecture.getClassId(), classEl); if (iShowNames && lecture.getNote() != null) classEl.addAttribute("note", lecture.getNote()); if (iShowNames && !lecture.isCommitted()) classEl.addAttribute("ord", String.valueOf(lecture.getOrd())); if (lecture.getWeight() != 1.0) classEl.addAttribute("weight", String.valueOf(lecture.getWeight())); if (iShowNames && lecture.getSolverGroupId() != null) classEl.addAttribute("solverGroup", getId("solverGroup", lecture.getSolverGroupId())); if (lecture.getParent() == null && lecture.getConfiguration() != null) { if (!iShowNames) classEl.addAttribute("offering", getId("offering", lecture.getConfiguration().getOfferingId().toString())); classEl.addAttribute("config", getId("config", lecture.getConfiguration().getConfigId().toString())); if (iShowNames && configs.add(lecture.getConfiguration())) { configsEl.addElement("config") .addAttribute("id", getId("config", lecture.getConfiguration().getConfigId().toString())) .addAttribute("limit", String.valueOf(lecture.getConfiguration().getLimit())) .addAttribute("offering", getId("offering", lecture.getConfiguration().getOfferingId().toString())); } } classEl.addAttribute("committed", (lecture.isCommitted() ? "true" : "false")); if (lecture.getParent() != null) classEl.addAttribute("parent", getId("class", lecture.getParent().getClassId())); if (lecture.getSchedulingSubpartId() != null) classEl.addAttribute("subpart", getId("subpart", lecture.getSchedulingSubpartId())); if (iShowNames && lecture.isCommitted() && placement != null && placement.getAssignmentId() != null) { classEl.addAttribute("assignment", getId("assignment", placement.getAssignmentId())); } if (!lecture.isCommitted()) { if (lecture.minClassLimit() == lecture.maxClassLimit()) { classEl.addAttribute("classLimit", String.valueOf(lecture.maxClassLimit())); } else { classEl.addAttribute("minClassLimit", String.valueOf(lecture.minClassLimit())); classEl.addAttribute("maxClassLimit", String.valueOf(lecture.maxClassLimit())); } if (lecture.roomToLimitRatio() != 1.0f) classEl.addAttribute("roomToLimitRatio", sStudentWeightFormat.format(lecture.roomToLimitRatio())); } if (lecture.getNrRooms() != 1) classEl.addAttribute("nrRooms", String.valueOf(lecture.getNrRooms())); if (lecture.getNrRooms() > 1 && lecture.getMaxRoomCombinations() > 0) classEl.addAttribute("maxRoomCombinations", String.valueOf(lecture.getMaxRoomCombinations())); if (iShowNames) classEl.addAttribute("name", lecture.getName()); if (lecture.getDeptSpreadConstraint() != null) { classEl.addAttribute("department", getId("dept", lecture.getDeptSpreadConstraint().getDepartmentId())); depts.put(lecture.getDeptSpreadConstraint().getDepartmentId(), lecture.getDeptSpreadConstraint().getName()); } if (lecture.getScheduler() != null) classEl.addAttribute("scheduler", getId("dept", lecture.getScheduler())); for (InstructorConstraint ic : lecture.getInstructorConstraints()) { Element instrEl = classEl.addElement("instructor").addAttribute("id", getId("inst", ic.getResourceId())); if ((lecture.isCommitted() || iSaveCurrent) && placement != null) instrEl.addAttribute("solution", "true"); if (iSaveInitial && initialPlacement != null) instrEl.addAttribute("initial", "true"); if (iSaveBest && bestPlacement != null && !bestPlacement.equals(placement)) instrEl.addAttribute("best", "true"); } for (RoomLocation rl : lecture.roomLocations()) { Element roomLocationEl = classEl.addElement("room"); roomLocationEl.addAttribute("id", getId("room", rl.getId())); roomLocationEl.addAttribute("pref", String.valueOf(rl.getPreference())); if ((lecture.isCommitted() || iSaveCurrent) && placement != null && placement.hasRoomLocation(rl.getId())) roomLocationEl.addAttribute("solution", "true"); if (iSaveInitial && initialPlacement != null && initialPlacement.hasRoomLocation(rl.getId())) roomLocationEl.addAttribute("initial", "true"); if (iSaveBest && bestPlacement != null && !bestPlacement.equals(placement) && bestPlacement.hasRoomLocation(rl.getId())) roomLocationEl.addAttribute("best", "true"); if (!roomElements.containsKey(getId("room", rl.getId()))) { // room location without room constraint Element roomEl = roomsEl.addElement("room").addAttribute("id", getId("room", rl.getId())); roomEl.addAttribute("constraint", "false"); if (!iConvertIds && rl.getBuildingId() != null) roomEl.addAttribute("building", getId("bldg", rl.getBuildingId())); if (iShowNames) { roomEl.addAttribute("name", rl.getName()); } roomElements.put(getId("room", rl.getId()), roomEl); roomEl.addAttribute("capacity", String.valueOf(rl.getRoomSize())); if (rl.getPosX() != null && rl.getPosY() != null) roomEl.addAttribute("location", rl.getPosX() + "," + rl.getPosY()); if (rl.getIgnoreTooFar()) roomEl.addAttribute("ignoreTooFar", "true"); } } boolean first = true; Set<Long> dp = new HashSet<Long>(); for (TimeLocation tl : lecture.timeLocations()) { Element timeLocationEl = classEl.addElement("time"); timeLocationEl.addAttribute("days", sDF[7].format(Long.parseLong(Integer.toBinaryString(tl.getDayCode())))); timeLocationEl.addAttribute("start", String.valueOf(tl.getStartSlot())); timeLocationEl.addAttribute("length", String.valueOf(tl.getLength())); timeLocationEl.addAttribute("breakTime", String.valueOf(tl.getBreakTime())); if (iShowNames) { timeLocationEl.addAttribute("pref", String.valueOf(tl.getPreference())); timeLocationEl.addAttribute("npref", String.valueOf(tl.getNormalizedPreference())); } else { timeLocationEl.addAttribute("pref", String.valueOf(tl.getNormalizedPreference())); } if (!iConvertIds && tl.getTimePatternId() != null) timeLocationEl.addAttribute("pattern", getId("pat", tl.getTimePatternId())); if (tl.getDatePatternId() != null && dp.add(tl.getDatePatternId())) { Element dateEl = classEl.addElement("date"); dateEl.addAttribute("id", getId("dpat", String.valueOf(tl.getDatePatternId()))); if (iShowNames) dateEl.addAttribute("name", tl.getDatePatternName()); dateEl.addAttribute("pattern", bitset2string(tl.getWeekCode())); } if (tl.getDatePatternPreference() != 0) timeLocationEl.addAttribute("datePref", String.valueOf(tl.getDatePatternPreference())); if (tl.getTimePatternId() == null && first) { if (iShowNames) classEl.addAttribute("datePatternName", tl.getDatePatternName()); classEl.addAttribute("dates", bitset2string(tl.getWeekCode())); first = false; } if (tl.getDatePatternId() != null) { timeLocationEl.addAttribute("date", getId("dpat", String.valueOf(tl.getDatePatternId()))); } if ((lecture.isCommitted() || iSaveCurrent) && placement != null && placement.getTimeLocation().equals(tl)) timeLocationEl.addAttribute("solution", "true"); if (iSaveInitial && initialPlacement != null && initialPlacement.getTimeLocation().equals(tl)) timeLocationEl.addAttribute("initial", "true"); if (iSaveBest && bestPlacement != null && !bestPlacement.equals(placement) && bestPlacement.getTimeLocation().equals(tl)) timeLocationEl.addAttribute("best", "true"); } } for (InstructorConstraint ic : getModel().getInstructorConstraints()) { if (iShowNames || ic.isIgnoreDistances()) { Element instrEl = instructorsEl.addElement("instructor").addAttribute("id", getId("inst", ic.getResourceId())); if (iShowNames) { if (ic.getPuid() != null && ic.getPuid().length() > 0) instrEl.addAttribute("puid", ic.getPuid()); instrEl.addAttribute("name", ic.getName()); if (ic.getType() != null && iShowNames) instrEl.addAttribute("type", ic.getType().toString()); } if (ic.isIgnoreDistances()) { instrEl.addAttribute("ignDist", "true"); } } if (ic.getUnavailabilities() != null) { for (Placement placement : ic.getUnavailabilities()) { Lecture lecture = placement.variable(); Element classEl = classElements.get(lecture.getClassId()); classEl.addElement("instructor").addAttribute("id", getId("inst", ic.getResourceId())) .addAttribute("solution", "true"); } } } if (instructorsEl.elements().isEmpty()) root.remove(instructorsEl); Element grConstraintsEl = root.addElement("groupConstraints"); for (GroupConstraint gc : getModel().getGroupConstraints()) { Element grEl = grConstraintsEl.addElement("constraint").addAttribute("id", getId("gr", String.valueOf(gc.getId()))); grEl.addAttribute("type", gc.getType().reference()); grEl.addAttribute("pref", gc.getPrologPreference()); for (Lecture l : gc.variables()) { grEl.addElement("class").addAttribute("id", getId("class", l.getClassId())); } } for (SpreadConstraint spread : getModel().getSpreadConstraints()) { Element grEl = grConstraintsEl.addElement("constraint").addAttribute("id", getId("gr", String.valueOf(spread.getId()))); grEl.addAttribute("type", "SPREAD"); grEl.addAttribute("pref", Constants.sPreferenceRequired); if (iShowNames) grEl.addAttribute("name", spread.getName()); for (Lecture l : spread.variables()) { grEl.addElement("class").addAttribute("id", getId("class", l.getClassId())); } } for (Constraint<Lecture, Placement> c : getModel().constraints()) { if (c instanceof MinimizeNumberOfUsedRoomsConstraint) { Element grEl = grConstraintsEl.addElement("constraint").addAttribute("id", getId("gr", String.valueOf(c.getId()))); grEl.addAttribute("type", "MIN_ROOM_USE"); grEl.addAttribute("pref", Constants.sPreferenceRequired); for (Lecture l : c.variables()) { grEl.addElement("class").addAttribute("id", getId("class", l.getClassId())); } } if (c instanceof MinimizeNumberOfUsedGroupsOfTime) { Element grEl = grConstraintsEl.addElement("constraint").addAttribute("id", getId("gr", String.valueOf(c.getId()))); grEl.addAttribute("type", ((MinimizeNumberOfUsedGroupsOfTime) c).getConstraintName()); grEl.addAttribute("pref", Constants.sPreferenceRequired); for (Lecture l : c.variables()) { grEl.addElement("class").addAttribute("id", getId("class", l.getClassId())); } } if (c instanceof IgnoreStudentConflictsConstraint) { Element grEl = grConstraintsEl.addElement("constraint").addAttribute("id", getId("gr", String.valueOf(c.getId()))); grEl.addAttribute("type", IgnoreStudentConflictsConstraint.REFERENCE); grEl.addAttribute("pref", Constants.sPreferenceRequired); for (Lecture l : c.variables()) { grEl.addElement("class").addAttribute("id", getId("class", l.getClassId())); } } } for (ClassLimitConstraint clc : getModel().getClassLimitConstraints()) { Element grEl = grConstraintsEl.addElement("constraint").addAttribute("id", getId("gr", String.valueOf(clc.getId()))); grEl.addAttribute("type", "CLASS_LIMIT"); grEl.addAttribute("pref", Constants.sPreferenceRequired); if (clc.getParentLecture() != null) { grEl.addElement("parentClass").addAttribute("id", getId("class", clc.getParentLecture().getClassId())); } else grEl.addAttribute("courseLimit", String.valueOf(clc.classLimit() - clc.getClassLimitDelta())); if (clc.getClassLimitDelta() != 0) grEl.addAttribute("delta", String.valueOf(clc.getClassLimitDelta())); if (iShowNames) grEl.addAttribute("name", clc.getName()); for (Lecture l : clc.variables()) { grEl.addElement("class").addAttribute("id", getId("class", l.getClassId())); } } for (FlexibleConstraint gc : getModel().getFlexibleConstraints()) { Element flEl = grConstraintsEl.addElement("constraint").addAttribute("id", getId("gr", String.valueOf(gc.getId()))); flEl.addAttribute("reference", gc.getReference()); flEl.addAttribute("owner", gc.getOwner()); flEl.addAttribute("pref", gc.getPrologPreference()); flEl.addAttribute("type", gc.getType().toString()); for (Lecture l : gc.variables()) { flEl.addElement("class").addAttribute("id", getId("class", l.getClassId())); } } HashMap<Student, List<String>> students = new HashMap<Student, List<String>>(); for (Lecture lecture : vars) { for (Student student : lecture.students()) { List<String> enrls = students.get(student); if (enrls == null) { enrls = new ArrayList<String>(); students.put(student, enrls); } enrls.add(getId("class", lecture.getClassId())); } } Element studentsEl = root.addElement("students"); Element groupsEl = root.addElement("groups"); Map<StudentGroup, Element> groups = new HashMap<StudentGroup, Element>(); for (Student student : new TreeSet<Student>(students.keySet())) { Element stEl = studentsEl.addElement("student").addAttribute("id", getId("student", student.getId())); if (iShowNames) { if (student.getAcademicArea() != null) stEl.addAttribute("area", student.getAcademicArea()); if (student.getAcademicClassification() != null) stEl.addAttribute("classification", student.getAcademicClassification()); if (student.getMajor() != null) stEl.addAttribute("major", student.getMajor()); if (student.getCurriculum() != null) stEl.addAttribute("curriculum", student.getCurriculum()); } for (Map.Entry<Long, Double> entry : student.getOfferingsMap().entrySet()) { Long offeringId = entry.getKey(); Double weight = entry.getValue(); Element offEl = stEl.addElement("offering").addAttribute("id", getId("offering", offeringId.toString())); if (weight.doubleValue() != 1.0) offEl.addAttribute("weight", sStudentWeightFormat.format(weight)); Double priority = student.getPriority(offeringId); if (priority != null) offEl.addAttribute("priority", priority.toString()); } if (iExportStudentSectioning || getModel().nrUnassignedVariables(getAssignment()) == 0 || student.getOfferingsMap().isEmpty()) { List<String> lectures = students.get(student); Collections.sort(lectures); for (String classId : lectures) { stEl.addElement("class").addAttribute("id", classId); } } Map<Long, Set<Lecture>> canNotEnroll = student.canNotEnrollSections(); if (canNotEnroll != null) { for (Set<Lecture> canNotEnrollLects : canNotEnroll.values()) { for (Iterator<Lecture> i3 = canNotEnrollLects.iterator(); i3.hasNext();) { stEl.addElement("prohibited-class").addAttribute("id", getId("class", (i3.next()).getClassId())); } } } if (student.getCommitedPlacements() != null) { for (Placement placement : student.getCommitedPlacements()) { stEl.addElement("class").addAttribute("id", getId("class", placement.variable().getClassId())); } } if (student.getInstructor() != null) stEl.addAttribute("instructor", getId("inst", student.getInstructor().getResourceId())); for (StudentGroup group : student.getGroups()) { Element groupEl = groups.get(group); if (groupEl == null) { groupEl = groupsEl.addElement("group"); groupEl.addAttribute("id", getId("group", group.getId())); if (group.getWeight() != 1.0) groupEl.addAttribute("weight", String.valueOf(group.getWeight())); if (iShowNames && group.getName() != null) groupEl.addAttribute("name", group.getName()); groups.put(group, groupEl); } groupEl.addElement("student").addAttribute("id", getId("student", student.getId())); } } if (getModel().getProperties().getPropertyInt("MPP.GenTimePert", 0) > 0) { Element perturbationsEl = root.addElement("perturbations"); int nrChanges = getModel().getProperties().getPropertyInt("MPP.GenTimePert", 0); List<Lecture> lectures = new ArrayList<Lecture>(); while (lectures.size() < nrChanges) { Lecture lecture = ToolBox.random(getAssignment().assignedVariables()); if (lecture.isCommitted() || lecture.timeLocations().size() <= 1 || lectures.contains(lecture)) continue; Placement placement = getAssignment().getValue(lecture); TimeLocation tl = placement.getTimeLocation(); perturbationsEl.addElement("class").addAttribute("id", getId("class", lecture.getClassId())) .addAttribute("days", sDF[7].format(Long.parseLong(Integer.toBinaryString(tl.getDayCode())))) .addAttribute("start", String.valueOf(tl.getStartSlot())) .addAttribute("length", String.valueOf(tl.getLength())); lectures.add(lecture); } } for (Map.Entry<Long, String> entry : depts.entrySet()) { Long id = entry.getKey(); String name = entry.getValue(); if (iShowNames) { departmentsEl.addElement("department").addAttribute("id", getId("dept", id.toString())) .addAttribute("name", name); } } if (departmentsEl.elements().isEmpty()) root.remove(departmentsEl); }
From source file:org.craftercms.search.service.impl.TokenizedElementParser.java
License:Open Source License
@Override public boolean parse(Element element, String fieldName, String parentFieldName, SolrInputDocument solrDoc, ElementParserService parserService) { Attribute tokenizedAttribute = element.attribute(tokenizedAttributeName); if (tokenizedAttribute != null && BooleanUtils.toBoolean(tokenizedAttribute.getValue())) { logger.debug("Parsing element '{}' marked to tokenize", fieldName); // Remove the attribute so that at the end the element can be parsed as a normal attribute. element.remove(tokenizedAttribute); String elementName = element.getName(); for (Map.Entry<String, String> mapping : fieldSuffixMappings.entrySet()) { if (elementName.endsWith(mapping.getKey())) { String newElementName = StringUtils.substringBefore(elementName, mapping.getKey()) + mapping.getValue(); Element tokenizedElement = element.createCopy(newElementName); if (logger.isDebugEnabled()) { logger.debug("Created new element for tokenized search: " + tokenizedElement.getName()); }/*from www . j av a 2 s . c o m*/ parserService.parse(tokenizedElement, parentFieldName, solrDoc); break; } } parserService.parse(element, parentFieldName, solrDoc); return true; } else { return false; } }
From source file:org.eclipse.jubula.client.core.businessprocess.AbstractXMLReportGenerator.java
License:Open Source License
/** * Adds Parameter elements to the given element based on the given * Test Result Node.//from w w w . j av a 2s.c o m * * @param resultNode The source for Parameter data. * @param insertInto The target for the Parameter data. */ protected void addParamNodeElements(TestResultNode resultNode, Element insertInto) { for (TestResultParameter parameter : resultNode.getParameters()) { String name = parameter.getName(); String type = parameter.getType(); String value = parameter.getValue(); Element paramEl = insertInto.addElement("parameter"); //$NON-NLS-1$ if (name != null) { Element paramNameEl = paramEl.addElement("parameter-name"); //$NON-NLS-1$ paramNameEl.addText(name); } if (type != null) { Element paramTypeEl = paramEl.addElement("parameter-type"); //$NON-NLS-1$ paramTypeEl.addText(type); } if (value != null) { Element paramValueEl = paramEl.addElement("parameter-value"); //$NON-NLS-1$ paramValueEl.addText(value); } if (!paramEl.hasContent()) { insertInto.remove(paramEl); } } }
From source file:org.ecocean.servlet.ServletUtilities.java
License:Open Source License
public static synchronized void addRSSEntry(String title, String link, String description, File rssFile) { //File rssFile=new File("nofile.xml"); try {//www. ja va 2 s . c om System.out.println("Looking for RSS file: " + rssFile.getCanonicalPath()); if (rssFile.exists()) { SAXReader reader = new SAXReader(); Document document = reader.read(rssFile); Element root = document.getRootElement(); Element channel = root.element("channel"); List items = channel.elements("item"); int numItems = items.size(); items = null; if (numItems > 9) { Element removeThisItem = channel.element("item"); channel.remove(removeThisItem); } Element newItem = channel.addElement("item"); Element newTitle = newItem.addElement("title"); Element newLink = newItem.addElement("link"); Element newDescription = newItem.addElement("description"); newTitle.setText(title); newDescription.setText(description); newLink.setText(link); Element pubDate = channel.element("pubDate"); pubDate.setText((new java.util.Date()).toString()); //now save changes FileWriter mywriter = new FileWriter(rssFile); OutputFormat format = OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); XMLWriter writer = new XMLWriter(mywriter, format); writer.write(document); writer.close(); } } catch (IOException ioe) { System.out.println("ERROR: Could not find the RSS file."); ioe.printStackTrace(); } catch (DocumentException de) { System.out.println("ERROR: Could not read the RSS file."); de.printStackTrace(); } catch (Exception e) { System.out.println("Unknown exception trying to add an entry to the RSS file."); e.printStackTrace(); } }