List of usage examples for org.jdom2 Element getParentElement
final public Element getParentElement()
From source file:org.yawlfoundation.yawl.scheduling.FormGenerator.java
License:Open Source License
private StringBuffer getInputHTML(Element field, Element dependingField, String key) { StringBuffer tag1 = new StringBuffer(), tag2 = new StringBuffer(), tag3 = new StringBuffer(); String n = field.getName();/*from w w w. ja va 2 s.c om*/ String value = field.getText(); String title = "", onclick = "", onchange = "", onpropertychange = "", cssClass = "", style = ""; String dependingFieldKey = null, dependingFieldValue = null; String fromFieldKey = null, durationFieldKey = null; String keyPart = key.substring(0, key.lastIndexOf("_")); boolean readonly = false; boolean disabled = XMLUtils.isReadonlyFromSchema(n); // is field no more editable (if SOU or EOU) Element activity = field.getParentElement(); while (activity != null && !activity.getName().equals(XML_ACTIVITY)) { activity = activity.getParentElement(); } boolean eou = isRequestTypeEOU(activity); boolean sou = eou || isRequestTypeSOU(activity); ArrayList<String> enumerations = new ArrayList<String>(); try { ArrayList<Element> restrictions = new ArrayList<Element>(); cssClass = validateElement(field, restrictions); for (Element restriction : restrictions) { if (restriction.getName().equals("enumeration")) { enumerations.add(restriction.getAttributeValue("value")); } } if (cssClass == null) cssClass = ""; } catch (Exception e) { _log.error("cannot get css class for element: " + n, e); } if (dependingField != null) { durationFieldKey = keyPart + "_" + XML_DURATION; fromFieldKey = keyPart + "_" + XML_FROM; dependingFieldValue = dependingField.getText(); dependingFieldKey = keyPart + "_" + dependingField.getName(); } // set field layout if (!enumerations.isEmpty() || XMLUtils.isEnumerationFromSchema(n)) { tag1.append("<select size=\"1\""); if (XMLUtils.isEnumerationFromSchema(n)) { if (n.equals(XML_OTHERACTIVITYNAME)) { for (Element activityElem : activities) { String name = activityElem.getChildText(XML_ACTIVITYNAME); tag2.append("<option value=\"" + name + "\""); tag2.append(name.equals(value) ? " selected=\"selected\"" : ""); tag2.append(">" + config.getLocalizedString(name) + "</option>"); } } else if (n.equals(XML_ACTIVITYTYPE)) { try { tag2.append("<option value=\"\""); tag2.append("".equals(value) ? " selected=\"selected\"" : ""); tag2.append(">" + config.getLocalizedString("<msgNewEntry>") + "</option>"); List<String> activityTypes = ss.getActivityTypes(activity.getChildText(XML_ACTIVITYNAME), value); for (String activityType : activityTypes) { tag2.append("<option value=\"" + activityType + "\""); tag2.append(activityType.equals(value) ? " selected=\"selected\"" : ""); tag2.append(">" + config.getLocalizedString(activityType) + "</option>"); } } catch (Exception e) { XMLUtils.addWarningValue(field, "msgActivityTypesWarning"); } // activate if: // 1. 'new entry' was selected or // 2. 'new entry' was clicked and no more options than 'new entry' exists in selectbox onchange += " comboBox(this,0);"; // onpropertychange += " comboBox(this,0);"; onclick += " comboBox(this,1);"; } else { tag2.append("<script type=\"text/javascript\">"); tag2.append("writeDropDownBox('" + n + "','" + dependingFieldValue + "','" + value + "','" + key + "');"); tag2.append("</script>"); } } else { for (String s : enumerations) { tag2.append("<option value=\"" + s + "\""); tag2.append(s.equals(value) ? " selected=\"selected\"" : ""); tag2.append(">" + config.getLocalizedString(s) + "</option>"); } } tag3.append("</select>"); } else if (cssClass.equals(CSS_DATEINPUT)) { try { Date date = Utils.string2Date(value, Utils.DATETIME_PATTERN_XML); value = Utils.date2String(date, isShortForm ? Utils.DATE_PATTERN : Utils.DATETIME_PATTERN); } catch (ParseException e) { //_log.error("cannot parse " + value); } tag1.append("<input type=\"text\" value=\"" + value + "\""); String showCalendar = " displayCalendar(document.getElementById('" + key + "'),'"; if (isShortForm) { showCalendar += Utils.getJsCalendarFormat(Utils.DATE_PATTERN) + "',this);return false;"; } else { showCalendar += Utils.getJsCalendarFormat(Utils.DATETIME_PATTERN) + "',this,true);return false;"; } readonly = true; onclick += (disabled ? "" : showCalendar); tag3.append("</input>"); } else if (cssClass.equals(CSS_DURATIONINPUT)) { // TODO@tbe: not only minutes, use jquery.slider tag1.append("<input type=\"text\" value=\"" + Utils.stringXMLDuration2stringMinutes(value) + "\""); tag3.append("</input>"); } else { tag1.append("<input type=\"text\" value=\"" + value + "\""); tag3.append("</input>"); } // some javascript functions for convenience if (n.equals(XML_FROM)) { if (!isShortForm) { onchange += " addMinutes2DateField('" + dependingFieldKey + "','" + key + "','" + durationFieldKey + "',1,false,'" + Utils.getJsCalendarFormat(Utils.DATETIME_PATTERN) + "');"; onchange += " submitRescheduling('" + dependingFieldKey + "');"; } else { onchange += " setRescheduling('" + key + "');"; } disabled = disabled || sou; } else if (n.equals(XML_TO)) { if (!isShortForm) { onchange += " addMinutes2DateField('" + dependingFieldKey + "','" + key + "','" + durationFieldKey + "',-1,false,'" + Utils.getJsCalendarFormat(Utils.DATETIME_PATTERN) + "');"; onchange += " submitRescheduling('" + dependingFieldKey + "');"; } disabled = disabled || eou; } else if (n.equals(XML_ID) || n.equals(XML_ROLE) || n.equals(XML_CAPABILITY) || n.equals(XML_CATEGORY) || n.equals(XML_SUBCATEGORY)) { String statusFieldKey = keyPart.substring(0, keyPart.lastIndexOf("_") + 1) + XML_STATUS; onchange += " document.getElementById('" + statusFieldKey + "').selectedIndex=0;"; // set to "unknown" if (n.equals(XML_CATEGORY)) { onchange += " actualizeDropDownBox('" + XML_CATEGORY + "','" + XML_SUBCATEGORY + "',this.id);"; } disabled = disabled || sou || eou; } else if (n.equals(XML_STATUS) || n.equals(XML_STATUSTOBE)) { disabled = disabled || sou || eou; } else if (n.equals(XML_DURATION)) { if (!isShortForm) { onchange += " addMinutes2DateField('" + dependingFieldKey + "','" + fromFieldKey + "','" + durationFieldKey + "',1,true,'" + Utils.getJsCalendarFormat(Utils.DATETIME_PATTERN) + "');"; onchange += " submitRescheduling('" + dependingFieldKey + "');"; } disabled = disabled || sou || eou; } else if (n.equals(XML_WORKLOAD)) { disabled = disabled || sou || eou; } else if (n.equals(XML_OTHERACTIVITYNAME) || n.equals(XML_MIN) || n.equals(XML_MAX) || n.equals(XML_THISUTILISATIONTYPE) || n.equals(XML_OTHERUTILISATIONTYPE)) { onchange += " setRescheduling('" + key + "');"; } // show error and warning messages String error = config.getLocalizedJSONString(XMLUtils.getErrorValue(field)); String warning = config.getLocalizedJSONString(XMLUtils.getWarningValue(field)); if (error != null) { title = error; cssClass += " " + CSS_ERRORINPUT; } else { if (warning != null) { title = warning; cssClass += " " + CSS_WARNINGINPUT; } } if (XMLUtils.isRequiredFromSchema(n) || isShortForm) { cssClass += " " + CSS_REQUIRED; } tag1.append(disabled ? " disabled=\"disabled\"" : ""); tag1.append(readonly ? " readonly=\"readonly\"" : ""); tag1.append(" id=\"" + key + "\" name=\"" + key + "\""); tag1.append(title.isEmpty() ? "" : " title=\"" + title + "\""); tag1.append(cssClass.isEmpty() ? "" : " class=\"" + cssClass + "\""); tag1.append(style.isEmpty() ? "" : " style=\"" + style + "\""); tag1.append(" onchange=\"enableButton('Save', true);" + onchange + "\""); tag1.append(" onpropertychange=\"enableButton('Save', true);" + onpropertychange + "\""); tag1.append(onclick.isEmpty() ? "" : " onclick=\"" + onclick + "\""); tag1.append(">"); return tag1.append(tag2).append(tag3); }
From source file:org.yawlfoundation.yawl.scheduling.lanes.LaneImporter.java
License:Open Source License
private void update(Element resource, String resType, String resourceId, String categoryOrRoleId) { if (resourceId.equals(resource.getChildText(XML_ID))) { return; // no resource update necessary }//from ww w. j a v a 2 s . co m if (resourceId.equals("virtual")) { resource.getChild(XML_ID).setText(""); resource.getChild(resType).setText(categoryOrRoleId); } else { resource.getChild(XML_ID).setText(resourceId); } // remove reservationId to force cancellation and new creation of reservation // in RS, because resource changes cannot be updated in RS Element reservation = resource.getParentElement(); if (reservation.getChild(XML_RESERVATIONID) != null) { reservation.getChild(XML_RESERVATIONID).setText(""); } else { resource.addContent(new Element(XML_RESERVATIONID)); } }
From source file:org.yawlfoundation.yawl.scheduling.lanes.LaneProducer.java
License:Open Source License
public List<List<Map<String, Object>>> getLanes(String... dates) throws Exception { Date from, to;/*from www.j a v a 2 s .com*/ int count = 0; // show intraoperative activities only String possibleActivitiesSorted = PropertyReader.getInstance() .getSchedulingProperty("possibleActivitiesSorted"); String[] possibleActivities = Utils.parseCSV(possibleActivitiesSorted).toArray(new String[0]); // return dates in same order as given List<List<Map<String, Object>>> allLanes4AllDates = new ArrayList<List<Map<String, Object>>>(); for (String date : dates) { List<Map<String, Object>> allLanes4Date = (List<Map<String, Object>>) Utils.deepCopy(lanes); //logger.debug("date="+date+", allLanes4Date "+Utils.toString(allLanes4Date)); // lane goes from 00:00:00.001 bis 23:59:59.999 long tmp = Utils.string2Date(date, Utils.DATE_PATTERN_XML).getTime(); from = new Date(tmp - 1); to = new Date(tmp + 24 * 60 * 60 * 1000); List<Case> cases = dataMapper.getRupsByInterval(from, to, null, false); logger.debug("found " + cases.size() + " cases for date " + date); for (Case cas : cases) { try { String xpath = XMLUtils.getXPATH_Activities(possibleActivities); List<Element> activities = XMLUtils.getXMLObjects(cas.getRUP(), xpath); if (activities.isEmpty()) { continue; } // get original FROM and TO date Date originalEarlFrom = XMLUtils.getDateValue(activities.get(0).getChild(XML_FROM), false); Date originalLatestTo = XMLUtils .getDateValue(activities.get(activities.size() - 1).getChild(XML_TO), false); // set times for showable in OP plan, if no duration given, set 5 min as default Element earlFrom = XMLUtils.getEarliestBeginElement(cas.getRUP(), possibleActivities); Element latestTo = XMLUtils.getLatestEndElement(cas.getRUP(), possibleActivities); scheduler.setTimes(cas.getRUP(), earlFrom == null ? latestTo.getParentElement() : earlFrom.getParentElement(), false, false, Utils.stringXML2Duration("PT5M")); earlFrom = XMLUtils.getEarliestBeginElement(cas.getRUP(), possibleActivities); latestTo = XMLUtils.getLatestEndElement(cas.getRUP(), possibleActivities); Map<String, Object> processUnit = new HashMap<String, Object>(); put(processUnit, "caseId", cas.getCaseId()); put(processUnit, "title", cas.getCaseName()); put(processUnit, "start", Utils.date2String(XMLUtils.getDateValue(earlFrom, false), "yyyy-MM-dd HH:mm:ss")); put(processUnit, "end", Utils.date2String(XMLUtils.getDateValue(latestTo, false), "yyyy-MM-dd HH:mm:ss")); put(processUnit, "hasConflicts", false); // TODO@tbe: has rup conflicts ? put(processUnit, "hasErrors", XMLUtils.hasErrors(cas.getRUP().getRootElement())); put(processUnit, "hasWarnings", XMLUtils.hasWarnings(cas.getRUP().getRootElement())); //put(processUnit, "canBeEdited", true); // TODO@tbe: false wenn schon gestartet oder kein YAWL-Case mehr vorhanden, noch im OP-Plan erweitern Map<String, Object> data = new HashMap<String, Object>(); //put(data, "description", cas.getId() + ": " + cas.getPatientFullName() + (cas.getPatientSex()==null ? "" : " (" + cas.getPatientSex() + ")")); put(data, "description", "" + ": " + cas.getCaseDescription()); put(data, "note0", "xxx"); if (debug) put(data, "note1", originalEarlFrom == null ? "???" : Utils.date2String(originalEarlFrom, "HH:mm dd.MM.yyyy") + " - "); if (debug) put(data, "note2", originalLatestTo == null ? "???" : Utils.date2String(originalLatestTo, "HH:mm dd.MM.yyyy")); put(data, "note3", cas.getCaseId()); // YAWL-CaseId put(data, "note4", ""); // reserved for title put(data, "note5", ""); // reserved for activityNames put(data, "note6", ""); // reserved for activityNames put(data, "note7", ""); // reserved for activityNames put(data, "note8", ""); // reserved for activityNames put(data, "note9", ""); // reserved for activityNames put(processUnit, "data", data); List<Map<String, Object>> stages = new ArrayList<Map<String, Object>>(); Long firstActFrom = null; int note = 0; for (Element activity : activities) { String activityName = activity.getChildText(XML_ACTIVITYNAME); Date actFrom = XMLUtils.getDateValue(activity.getChild(XML_FROM), true); if (firstActFrom == null) { firstActFrom = actFrom.getTime(); } if (debug) { put(data, "note" + (note + 5), activityName); note++; } Map<String, Object> stage = new HashMap<String, Object>(); put(stage, "id", "stage-" + activityName); put(stage, "title", config.getLocalizedString(activityName)); put(stage, "start", Utils.date2String(actFrom, Utils.DATETIME_PATTERN)); put(stage, "offset", (actFrom.getTime() - firstActFrom) / 1000 / 60); put(stage, "running", UTILISATION_TYPE_BEGIN.equals(activity.getChildText(XML_REQUESTTYPE))); stages.add(stage); } put(processUnit, "stages", stages); // find matching lanes xpath = XMLUtils.getXPATH_ActivitiesElement(possibleActivities, XML_RESERVATION, null); List<Element> reservations = XMLUtils.getXMLObjects(cas.getRUP(), xpath); List<Map<String, Object>> lanes4Date = getMatchingLanes(reservations, allLanes4Date); logger.debug(lanes4Date.size() + " lanes found for caseId: " + cas.getCaseId()); for (Map<String, Object> lane4Date : lanes4Date) { List<Map<String, Object>> processUnits = (List) lane4Date.get("processUnits"); if (processUnits == null) { processUnits = new ArrayList<Map<String, Object>>(); } if (debug) put(data, "note4", lane4Date.get("title")); Map<String, Object> processUnitCopy = (Map<String, Object>) Utils.deepCopy(processUnit); put(processUnitCopy, "id", "id" + processUnitCopy.get("caseId") + "-" + count++); processUnits.add(processUnitCopy); put(lane4Date, "processUnits", processUnits); } } catch (Throwable e) { logger.error("cannot show case: " + cas.getCaseId(), e); } } allLanes4AllDates.add(allLanes4Date); } return allLanes4AllDates; }
From source file:org.yawlfoundation.yawl.scheduling.resource.ResourceServiceInterface.java
License:Open Source License
public Map<String, List<Element>> removeReservations(Document rup, String statusToBe) throws JDOMException { Map<String, List<Element>> res = new HashMap<String, List<Element>>(); String where = statusToBe == null ? "" : "[" + XML_STATUSTOBE + "='" + statusToBe + "']"; String xpath = XMLUtils.getXPATH_ActivityElement(null, XML_RESERVATION + where, null); List<Element> reservations = XMLUtils.getXMLObjects(rup, xpath); for (Element reservation : reservations) { Element activity = reservation.getParentElement(); activity.removeContent(reservation); List<Element> l = res.get(activity.getChildText(XML_ACTIVITYNAME)); if (l == null) l = new ArrayList<Element>(); Element reservationId = reservation.getChild(XML_RESERVATIONID); if (reservationId == null) { reservation.addContent(new Element(XML_RESERVATIONID)); } else {//w w w . j a v a 2 s . c o m reservationId.setText(""); } l.add(reservation); res.put(activity.getChildText(XML_ACTIVITYNAME), l); } return res; }
From source file:org.yawlfoundation.yawl.scheduling.Scheduler.java
License:Open Source License
/** * set TO time of an activity depending on FROM and DURATION set FROM time of * previous and following activities and recurses to set their TO times also * //from ww w .java 2s . c o m * TODO@tbe: erstmal ohne Beachtung von Max und ohne Ausnutzung des * Gummibandes zwischen Min und Max, d.h. es wird Min als fester Wert * angenommen, ausserdem wird nur von einer Relation pro Aktivitt * ausgegangen * * @param activity */ private void setTimes(Document rup, Element activity, boolean withValidation, List<String> activityNamesProcessed, Duration defaultDuration) { String activityName = activity.getChildText(XML_ACTIVITYNAME); Element durationElem = activity.getChild(XML_DURATION); Duration duration = XMLUtils.getDurationValue(durationElem, withValidation); Element from = activity.getChild(XML_FROM); Date fromDate = XMLUtils.getDateValue(from, withValidation); Element to = activity.getChild(XML_TO); Date toDate = XMLUtils.getDateValue(to, withValidation); // can be null String requestType = activity.getChildText(XML_REQUESTTYPE); if (requestType.equals("EOU")) { // calculate duration toDate = XMLUtils.getDateValue(to, withValidation); XMLUtils.setDurationValue(durationElem, toDate.getTime() - fromDate.getTime()); } else if (fromDate == null) { if (toDate != null) { fromDate = new Date(toDate.getTime()); if (duration != null) { duration.negate().addTo(fromDate); XMLUtils.setDateValue(from, fromDate); } } else if (defaultDuration != null) { defaultDuration.negate().addTo(fromDate); XMLUtils.setDateValue(from, fromDate); } } else { toDate = new Date(fromDate.getTime()); if (duration != null) { duration.addTo(toDate); // TODO@tbe: if very very long duration, to is // one hour to high XMLUtils.setDateValue(to, toDate); } else if (defaultDuration != null) { defaultDuration.addTo(toDate); XMLUtils.setDateValue(to, toDate); } } activityNamesProcessed.add(activityName); logger.debug(activityName + ", set from: " + from.getText() + ", to: " + to.getText() + ", duration: " + durationElem.getText()); // set times of following activities String xpath = XMLUtils.getXPATH_ActivityElement(activityName, XML_UTILISATIONREL, null); List relations = XMLUtils.getXMLObjects(rup, xpath); for (Object o : relations) { Element relation = (Element) o; String otherActivityName = relation.getChildText(XML_OTHERACTIVITYNAME); if (activityNamesProcessed.contains(otherActivityName)) { continue; // activity has been processed already } Duration min = XMLUtils.getDurationValue(relation.getChild(XML_MIN), withValidation); List otherActivities = XMLUtils.getXMLObjects(rup, XMLUtils.getXPATH_Activities(otherActivityName)); for (Object obj : otherActivities) { Element otherActivity = (Element) obj; Date thisDate; if (relation.getChildText(XML_THISUTILISATIONTYPE).equals(UTILISATION_TYPE_BEGIN)) { thisDate = fromDate; } else if (duration != null) { thisDate = toDate; } else { continue; } min.addTo(thisDate); // add time gap between activities if (relation.getChildText(XML_OTHERUTILISATIONTYPE).equals(UTILISATION_TYPE_END)) { Duration otherDuration = XMLUtils.getDurationValue(otherActivity.getChild(XML_DURATION), withValidation); (otherDuration == null ? defaultDuration : otherDuration).negate().addTo(thisDate); } XMLUtils.setDateValue(otherActivity.getChild(XML_FROM), thisDate); setTimes(rup, otherActivity, withValidation, activityNamesProcessed, defaultDuration); } } // set time of previous activities if this activity is not started if (!requestType.equals("POU")) { return; } xpath = XMLUtils.getXPATH_ActivityElement(null, XML_UTILISATIONREL, null); xpath += "[" + XML_OTHERACTIVITYNAME + "/text()='" + activityName + "']"; relations = XMLUtils.getXMLObjects(rup, xpath); for (Object o : relations) { Element relation = (Element) o; Element otherActivity = relation.getParentElement(); if (activityNamesProcessed.contains(otherActivity.getChildText(XML_ACTIVITYNAME))) { continue; // activity has been processed already } Duration min = XMLUtils.getDurationValue(relation.getChild(XML_MIN), withValidation); Date otherDate; if (relation.getChildText(XML_OTHERUTILISATIONTYPE).equals(UTILISATION_TYPE_BEGIN)) { fromDate = XMLUtils.getDateValue(from, withValidation); otherDate = fromDate; } else if (duration != null) { toDate = XMLUtils.getDateValue(to, withValidation); otherDate = toDate; } else { continue; } min.negate().addTo(otherDate); if (relation.getChildText(XML_THISUTILISATIONTYPE).equals(UTILISATION_TYPE_END)) { Duration otherDuration = XMLUtils.getDurationValue(otherActivity.getChild(XML_DURATION), withValidation); (otherDuration == null ? defaultDuration : otherDuration).negate().addTo(otherDate); } XMLUtils.setDateValue(otherActivity.getChild(XML_FROM), otherDate); setTimes(rup, otherActivity, withValidation, activityNamesProcessed, defaultDuration); } }
From source file:org.yawlfoundation.yawl.scheduling.SchedulingService.java
License:Open Source License
/** * cleans activityTypes for these activities, which a new activityType not * stored in DB yet forces a reload of activityTypes of related activityNames * * @param rup//ww w . j av a2s . co m */ private void removeActivityTypes(Document rup) { String xpath = XMLUtils.getXPATH_ActivityElement(null, XML_ACTIVITYTYPE, null); List<Element> activityTypeElems = XMLUtils.getXMLObjects(rup, xpath); for (Element activityTypeElem : activityTypeElems) { _log.debug("activityTypeElem.getText(): " + activityTypeElem.getText()); if (activityTypeElem.getText().trim().isEmpty()) { continue; } String activityName = activityTypeElem.getParentElement().getChildText(XML_ACTIVITYNAME); List<String> activityTypes = _allActivityTypes.get(activityName); if (activityTypes != null && !activityTypes.contains(activityTypeElem.getText())) { _allActivityTypes.put(activityName, null); _log.debug("remove activityTypes for " + activityName); } } }
From source file:org.yawlfoundation.yawl.scheduling.timer.JobCreateTestRUPs4Today.java
License:Open Source License
/** * sets TO time of running activities to actual time */// ww w . ja v a 2s .c o m public void run() { try { List<Case> cases = dataMapper.getAllRups(); for (Case cas : cases) { Document rup = cas.getRUP(); String possibleActivitiesSorted = PropertyReader.getInstance() .getSchedulingProperty("possibleActivitiesSorted"); String[] possibleActivities = Utils.parseCSV(possibleActivitiesSorted).toArray(new String[0]); Element earlFrom = XMLUtils.getEarliestBeginElement(rup, possibleActivities); if (earlFrom == null) continue; Date earlFromDate = XMLUtils.getDateValue(earlFrom, false); if (earlFromDate == null) continue; Calendar today = Calendar.getInstance(); today.setTime(new Date()); Calendar cal = Calendar.getInstance(); cal.setTime(earlFromDate); cal.set(Calendar.YEAR, today.get(Calendar.YEAR)); cal.set(Calendar.MONTH, today.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, today.get(Calendar.DAY_OF_MONTH)); XMLUtils.setDateValue(earlFrom, cal.getTime()); scheduler.setTimes(rup, earlFrom.getParentElement(), false, false, null); service.optimizeAndSaveRup(rup, context, null, false); } } catch (Exception e) { logger.error("cannot execute job " + context, e); } }
From source file:org.yawlfoundation.yawl.scheduling.timer.JobTimer.java
License:Open Source License
private static Calendar calcMsgTransferStartTime(Element msgTransfer) { Calendar cal = Calendar.getInstance(); String msgUtilisationType = msgTransfer.getChildText(XML_MSGUTILISATIONTYPE); Element activity = msgTransfer.getParentElement(); if (UTILISATION_TYPE_BEGIN.equals(msgUtilisationType)) { cal.setTime(XMLUtils.getDateValue(activity.getChild(XML_FROM), true)); } else {//www . ja v a 2 s . c o m cal.setTime(XMLUtils.getDateValue(activity.getChild(XML_TO), true)); } int min = XMLUtils.getDurationValueInMinutes(msgTransfer.getChild(XML_MSGDURATION), true); if (MSGREL_BEFORE.equals(msgTransfer.getChildText(XML_MSGREL))) { min = 0 - min; } cal.add(Calendar.MINUTE, min); return cal; }
From source file:password.pwm.config.value.EmailValue.java
License:Open Source License
public static StoredValueFactory factory() { return new StoredValueFactory() { public EmailValue fromJson(final String input) { if (input == null) { return new EmailValue(Collections.<String, EmailItemBean>emptyMap()); } else { Map<String, EmailItemBean> srcList = JsonUtil.deserialize(input, new TypeToken<Map<String, EmailItemBean>>() { });//from ww w . j av a 2 s .c om srcList = srcList == null ? Collections.<String, EmailItemBean>emptyMap() : srcList; srcList.remove(null); return new EmailValue(Collections.unmodifiableMap(srcList)); } } public EmailValue fromXmlElement(Element settingElement, final String input) throws PwmOperationalException { final Map<String, EmailItemBean> values = new TreeMap<>(); { final List valueElements = settingElement.getChildren("value"); for (final Object loopValue : valueElements) { final Element loopValueElement = (Element) loopValue; final String value = loopValueElement.getText(); if (value != null && value.length() > 0) { String localeValue = loopValueElement.getAttribute("locale") == null ? "" : loopValueElement.getAttribute("locale").getValue(); values.put(localeValue, JsonUtil.deserialize(value, EmailItemBean.class)); } } } // read old format values. can be removed someday.... this code iterates through the entire settings xml document to find old format versions { final Map<String, String> fromMap = new HashMap<>(); final Map<String, String> subjectMap = new HashMap<>(); final Map<String, String> bodyPlainMap = new HashMap<>(); final Map<String, String> bodyHtmlMap = new HashMap<>(); for (final Object loopSettingObj : settingElement.getParentElement().getChildren()) { Element loopSetting = (Element) loopSettingObj; if (loopSetting.getAttribute("key") != null) { if (loopSetting.getAttribute("key").getValue() .equals(settingElement.getAttribute("key").getValue() + ".from")) { final List valueElements = loopSetting.getChildren("value"); for (final Object loopValue : valueElements) { final Element loopValueElement = (Element) loopValue; final String value = loopValueElement.getText(); if (value != null && value.length() > 0) { String localeValue = settingElement.getAttribute("locale") == null ? "" : settingElement.getAttribute("locale").getValue(); fromMap.put(localeValue, value); } } } if (loopSetting.getAttribute("key").getValue() .equals(settingElement.getAttribute("key").getValue() + ".subject")) { final List valueElements = loopSetting.getChildren("value"); for (final Object loopValue : valueElements) { final Element loopValueElement = (Element) loopValue; final String value = loopValueElement.getText(); if (value != null && value.length() > 0) { String localeValue = settingElement.getAttribute("locale") == null ? "" : settingElement.getAttribute("locale").getValue(); subjectMap.put(localeValue, value); } } } if (loopSetting.getAttribute("key").getValue() .equals(settingElement.getAttribute("key").getValue() + ".plainBody")) { final List valueElements = loopSetting.getChildren("value"); for (final Object loopValue : valueElements) { final Element loopValueElement = (Element) loopValue; final String value = loopValueElement.getText(); if (value != null && value.length() > 0) { String localeValue = settingElement.getAttribute("locale") == null ? "" : settingElement.getAttribute("locale").getValue(); bodyPlainMap.put(localeValue, value); } } } if (loopSetting.getAttribute("key").getValue() .equals(settingElement.getAttribute("key").getValue() + ".htmlBody")) { final List valueElements = loopSetting.getChildren("value"); for (final Object loopValue : valueElements) { final Element loopValueElement = (Element) loopValue; final String value = loopValueElement.getText(); if (value != null && value.length() > 0) { String localeValue = settingElement.getAttribute("locale") == null ? "" : settingElement.getAttribute("locale").getValue(); bodyHtmlMap.put(localeValue, value); } } } } } final Set<String> seenLocales = new HashSet<>(); seenLocales.addAll(fromMap.keySet()); seenLocales.addAll(subjectMap.keySet()); seenLocales.addAll(bodyPlainMap.keySet()); seenLocales.addAll(bodyHtmlMap.keySet()); //final String defaultJson = PwmSetting.forKey(settingElement.getAttribute("key").getValue()).getDefaultValue(PwmSetting.Template.NOVL); //final Map<String,EmailItemBean> defaultList = gson.fromJson(defaultJson, new TypeToken<Map<String,EmailItemBean>>() {}.getType()); //final EmailItemBean defaultBean = defaultList.read(""); /* for (final String localeStr : seenLocales) { values.put(localeStr,new EmailItemBean( null, fromMap.containsKey(localeStr) ? fromMap.read(localeStr) : defaultBean.getFrom(), subjectMap.containsKey(localeStr) ? subjectMap.read(localeStr) : defaultBean.getSubject(), bodyPlainMap.containsKey(localeStr)? bodyPlainMap.read(localeStr) : defaultBean.getBodyPlain(), bodyHtmlMap.containsKey(localeStr) ? bodyHtmlMap.read(localeStr) : defaultBean.getBodyHtml() )); } */ } return new EmailValue(values); } }; }
From source file:ru.iteco.xmldoc.Config.java
License:Open Source License
/** * ? element.//w w w . j a v a 2 s . co m * ? ? , null. * * @param element * @return */ protected static String getPreviousComment(Element element) { //? ? Element parent = element.getParentElement(); //? ? int index = parent.indexOf(element); // "" ?, ?- for (int i = index - 1; i > 0; i--) { //? Content prev = parent.getContent(i); //? ? ? - ?, , ? /?? if (prev.getCType().equals(Content.CType.Text)) continue; //? ? - , ?, else if (prev.getCType().equals(Content.CType.Comment)) return prev.getValue(); // ?, ? , ? ? ?. . else return ""; } // ? . return ""; }