Java Code Examples for org.jdom2.Element#getChildText()

The following examples show how to use org.jdom2.Element#getChildText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobTimer.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 {
        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;
}
 
Example 2
Source File: WhiteTextCollectionReader.java    From bluima with Apache License 2.0 6 votes vote down vote up
public void getNext(JCas jcas) throws IOException, CollectionException {

        Element articleE = articleIt.next();
        String pmid = articleE.getChildText("PMID");
        LOG.trace("processing pmId {}", pmid);
        currentNrDocs++;

        StringBuilder sb = new StringBuilder();

        int i = addAnnotations(jcas, articleE.getChild("ArticleTitle")
                .getContent(), sb, 0);

        sb.append(" ");// add "space"
        i++;

        addAnnotations(jcas, articleE.getChild("AbstractText").getContent(),
                sb, i);

        jcas.setDocumentText(sb.toString());

        Header h = new Header(jcas);
        h.setDocId(pmid);
        h.addToIndexes();
    }
 
Example 3
Source File: FnmocTables.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Nullable
private Map<Integer, String> readGenProcess(String path) {
  try (InputStream is = GribResourceReader.getInputStream(path)) {
    SAXBuilder builder = new SAXBuilder();
    org.jdom2.Document doc = builder.build(is);
    Element root = doc.getRootElement();

    Map<Integer, String> result = new HashMap<>(200);
    Element fnmocTable = root.getChild("fnmocTable");
    List<Element> params = fnmocTable.getChildren("entry");
    for (Element elem1 : params) {
      int code = Integer.parseInt(elem1.getChildText("grib1Id"));
      String desc = elem1.getChildText("fullName");
      result.put(code, desc);
    }

    return Collections.unmodifiableMap(result); // all at once - thread safe

  } catch (IOException | JDOMException e) {
    logger.error("Cant read FNMOC Table 1 = " + path, e);
    return null;
  }
}
 
Example 4
Source File: MCROAISetManager.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
private MCRSet createSet(String setId, Element setElement) {
    String setSpec = setElement.getChildText("setSpec", NS_OAI);
    String setName = setElement.getChildText("setName", NS_OAI);
    MCRSet set = new MCRSet(setId, getSetSpec(setSpec), setName);
    set.getDescription()
        .addAll(setElement.getChildren("setDescription", NS_OAI)
            .stream() //all setDescription
            .flatMap(e -> e.getChildren().stream().limit(1)) //first childElement of setDescription
            .peek(Element::detach)
            .map(d -> (Description) new Description() {
                @Override
                public Element toXML() {
                    return d;
                }

                @Override
                public void fromXML(Element descriptionElement) {
                    throw new UnsupportedOperationException();
                }
            })
            .collect(Collectors.toList()));
    return set;
}
 
Example 5
Source File: OfferInteraction.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void parseConstraints(Element e, Namespace nsYawl)
                                                    throws ResourceParseException {
    // get the Constraints
    Element eConstraints = e.getChild("constraints", nsYawl);
    if (eConstraints != null) {
        List<Element> constraints = eConstraints.getChildren("constraint", nsYawl);
        if (constraints == null)
            throw new ResourceParseException(
                    "No constraint elements found in constraints element");

        for (Element eConstraint : constraints) {
            String constraintClassName = eConstraint.getChildText("name", nsYawl);
            if (constraintClassName != null) {
                AbstractConstraint constraint =
                        PluginFactory.newConstraintInstance(constraintClassName);
                if (constraint != null) {
                    constraint.setParams(parseParams(eConstraint, nsYawl));
                    _constraints.add(constraint);
                }
                else throw new ResourceParseException("Unknown constraint name: " +
                                                               constraintClassName);
            }
            else throw new ResourceParseException("Missing constraint element: name");
        }
    }
}
 
Example 6
Source File: MCRUserServlet.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
private void updateBasicUserInfo(Element u, MCRUser user) {
    String name = u.getChildText("realName");
    if ((name != null) && (name.trim().length() == 0)) {
        name = null;
    }
    user.setRealName(name);

    String eMail = u.getChildText("eMail");
    if ((eMail != null) && (eMail.trim().length() == 0)) {
        eMail = null;
    }
    user.setEMail(eMail);

    Element attributes = u.getChild("attributes");
    if (attributes != null) {
        List<Element> attributeList = attributes.getChildren("attribute");
        Set<MCRUserAttribute> newAttrs = attributeList.stream()
            .map(a -> new MCRUserAttribute(a.getAttributeValue("name"), a.getAttributeValue("value")))
            .collect(Collectors.toSet());
        user.getAttributes().retainAll(newAttrs);
        newAttrs.removeAll(user.getAttributes());
        user.getAttributes().addAll(newAttrs);
    }
}
 
Example 7
Source File: YDecompositionParser.java    From yawl with GNU Lesser General Public License v3.0 6 votes vote down vote up
private YNet parseNet(YNet net, Element netElem) {
    if (!isBeta2Version()) {
        String isRootNet = netElem.getAttributeValue("isRootNet");
        if ("true".equals(isRootNet)) {
            _specificationParser.getSpecification().setRootNet(net);

            // set external data gateway (since 2.1)
            String gateway = netElem.getChildText("externalDataGateway", _yawlNS);
            if (gateway != null) net.setExternalDataGateway(gateway);
        }
    }
    for (Element localVariableElem : netElem.getChildren("localVariable", _yawlNS)) {
        YVariable localVar = new YVariable(_decomposition);
        parseLocalVariable(localVariableElem, localVar, _yawlNS, isBeta2Version());
        net.setLocalVariable(localVar);
    }
    parseProcessControlElements(net, netElem.getChild("processControlElements", _yawlNS));
    return net;
}
 
Example 8
Source File: FeatureDatasetCapabilitiesWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static LatLonRect getSpatialExtent(Document doc) {
  Element root = doc.getRootElement();
  Element latlonBox = root.getChild("LatLonBox");
  if (latlonBox == null)
    return null;

  String westS = latlonBox.getChildText("west");
  String eastS = latlonBox.getChildText("east");
  String northS = latlonBox.getChildText("north");
  String southS = latlonBox.getChildText("south");
  if ((westS == null) || (eastS == null) || (northS == null) || (southS == null))
    return null;

  try {
    double west = Double.parseDouble(westS);
    double east = Double.parseDouble(eastS);
    double south = Double.parseDouble(southS);
    double north = Double.parseDouble(northS);
    return new LatLonRect(LatLonPoint.create(south, east), LatLonPoint.create(north, west));

  } catch (Exception e) {
    return null;
  }
}
 
Example 9
Source File: SvnLogXmlParser.java    From gocd with Apache License 2.0 6 votes vote down vote up
private Modification parseLogEntry(Element logEntry, String path) throws ParseException {
    Element logEntryPaths = logEntry.getChild("paths");
    if (logEntryPaths == null) {
        /* Path-based access control forbids us from learning
         * details of this log entry, so skip it. */
        return null;
    }

    Date modifiedTime = convertDate(logEntry.getChildText("date"));
    String author = logEntry.getChildText("author");
    String comment = logEntry.getChildText("msg");
    String revision = logEntry.getAttributeValue("revision");

    Modification modification = new Modification(author, comment, null, modifiedTime, revision);

    List paths = logEntryPaths.getChildren("path");
    for (Iterator iterator = paths.iterator(); iterator.hasNext();) {
        Element node = (Element) iterator.next();
        if (underPath(path, node.getText())) {
            ModifiedAction action = convertAction(node.getAttributeValue("action"));
            modification.createModifiedFile(node.getText(), null, action);
        }
    }

    return modification;
}
 
Example 10
Source File: DynFormFieldAssembler.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private DynFormField addField(String name, String type, Element data,
                              String minOccurs, String maxOccurs, int level,
                              Map<String, String> appInfo) {
    String value = (data != null) ? data.getChildText(name) : "";
    DynFormField input = new DynFormField(name, type, value);
    populateField(input, name, minOccurs, maxOccurs, level, appInfo) ;
    return input;
}
 
Example 11
Source File: CmSynchronizer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected void addCanonicalCourse(Element element) {
	String eid = element.getChildText("eid");
	if(log.isDebugEnabled()) log.debug("Adding CanonicalCourse + " + eid);
	String title = element.getChildText("title");
	String description = element.getChildText("description");
	cmAdmin.createCanonicalCourse(eid, title, description);
}
 
Example 12
Source File: MCRMODSPagesHelper.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
void completeEndPage(Element extent) {
    String start = extent.getChildText("start", MCRConstants.MODS_NAMESPACE);
    String end = extent.getChildText("end", MCRConstants.MODS_NAMESPACE);
    if (isNumber(start) && isNumber(end) && start.length() > end.length()) {
        end = start.substring(0, start.length() - end.length()) + end;
        extent.getChild("end", MCRConstants.MODS_NAMESPACE).setText(end);
    }
}
 
Example 13
Source File: CmSynchronizer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected void addAcademicSession(Element element) {
	String eid = element.getChildText("eid");
	if(log.isDebugEnabled()) log.debug("Adding AcademicSession + " + eid);
	String title = element.getChildText("title");
	String description = element.getChildText("description");
	Date startDate = getDate(element.getChildText("start-date"));
	Date endDate = getDate(element.getChildText("end-date"));
	cmAdmin.createAcademicSession(eid, title, description, startDate, endDate);
}
 
Example 14
Source File: MCRDerivate.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reads all files and urns from the derivate.
 * 
 * @return A {@link Map} which contains the files as key and the urns as value.
 * If no URN assigned the map will be empty.
 */
public Map<String, String> getUrnMap() {
    Map<String, String> fileUrnMap = new HashMap<>();

    XPathExpression<Element> filesetPath = XPathFactory.instance().compile("./mycorederivate/derivate/fileset",
        Filters.element());

    Element result = filesetPath.evaluateFirst(this.createXML());
    if (result == null) {
        return fileUrnMap;
    }
    String urn = result.getAttributeValue("urn");

    if (urn != null) {
        XPathExpression<Element> filePath = XPathFactory
            .instance()
            .compile("./mycorederivate/derivate/fileset[@urn='" + urn + "']/file", Filters.element());
        List<Element> files = filePath.evaluate(this.createXML());

        for (Element currentFileElement : files) {
            String currentUrn = currentFileElement.getChildText("urn");
            String currentFile = currentFileElement.getAttributeValue("name");
            fileUrnMap.put(currentFile, currentUrn);
        }
    }
    return fileUrnMap;
}
 
Example 15
Source File: YDecompositionParser.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void parseExternalInteraction(YDecomposition decomposition,
                                       Element decompElem) {
     String interactionStr = decompElem.getChildText("externalInteraction", _yawlNS);
     if (interactionStr != null)
         decomposition.setExternalInteraction(
                       interactionStr.equalsIgnoreCase("manual"));
}
 
Example 16
Source File: SchedulingService.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * completes a rup with historical data of rups with same ActivityType, but
 * only for new added activities and if data fields are empty yet
 *
 * @param rup
 * @param addedActivitiyNames
 * @return
 */
public void completeRupFromHistory(Document rup, Set<String> addedActivitiyNames) {
    String xpath = XMLUtils.getXPATH_Activities();
    List<Element> activities = XMLUtils.getElements(rup, xpath);
    List<List<Element>> nodes;
    boolean changed = false;

    for (Element activity : activities) {
        String activityName = activity.getChildText(XML_ACTIVITYNAME);
        if (!addedActivitiyNames.contains(activityName)) {
            continue;
        }

        String activityType = activity.getChildText(XML_ACTIVITYTYPE);

        Integer dur = XMLUtils.getDurationValueInMinutes(activity.getChild(XML_DURATION), false);
        if (dur == null || dur == 0) {
            nodes = getRupNodes(activityName, activityType, XML_DURATION, HistoricalMode.median);
            activity.getChild(XML_DURATION).setText(nodes.isEmpty() ? "" : nodes.get(0).get(0).getText());
            changed = true;
        }

        xpath = XMLUtils.getXPATH_ActivityElement(activityName, XML_RESERVATION, null);
        List<Element> reservations = XMLUtils.getElements(rup, xpath);
        if (reservations.isEmpty()) {
            nodes = getRupNodes(activityName, activityType, XML_RESERVATION, HistoricalMode.most);
            activity.addContent(nodes.isEmpty() ? new ArrayList<Element>() : nodes.get(0));
            changed = true;
        }
    }

    if (changed) {
        _log.info("update rup for case " + XMLUtils.getCaseId(rup) + " from history: "
                + Utils.document2String(rup, false));
    }
}
 
Example 17
Source File: CmSynchronizer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected CourseSet updateCourseSet(CourseSet courseSet, Element element) {
	if(log.isDebugEnabled()) log.debug("Updating CourseSet + " + courseSet.getEid());
	courseSet.setTitle(element.getChildText("title"));
	courseSet.setDescription(element.getChildText("description"));
	courseSet.setCategory(element.getChildText("category"));
	String parentEid = element.getChildText("parent-course-set");
	if(cmService.isCourseSetDefined(parentEid)) {
		CourseSet parent = cmService.getCourseSet(parentEid);
		courseSet.setParent(parent);
	}
	cmAdmin.updateCourseSet(courseSet);
	return courseSet;
}
 
Example 18
Source File: SchedulingService.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * call from JobRUPCheck, sets TO time of running activities to actual time
 * and calculate new DURATION value
 */
public void updateRunningRups(String savedBy) throws Exception {
    Date now = new Date();
    List<Document> rups = getActiveRups(now);

    // update rups startzeit und/oder endzeit
    for (Document rup : rups) {
        for (Element activity : (List<Element>) rup.getRootElement().getChildren(XML_ACTIVITY)) {
            String activityName = activity.getChildText(XML_ACTIVITYNAME);
            Element from = activity.getChild(XML_FROM);
            Date fromDate = XMLUtils.getDateValue(from, true);
            Element to = activity.getChild(XML_TO);
            Date toDate = XMLUtils.getDateValue(to, true);
            Element duration = activity.getChild(XML_DURATION);
            String requestType = activity.getChildText(XML_REQUESTTYPE);

            // _log.debug("caseId: "+caseId+", requestType: "+requestType+", from: "+from.getText()+", to: "+to.getText());
            if (requestType.equals(UTILISATION_TYPE_BEGIN) &&
                    toDate.before(now)) {
                XMLUtils.setDateValue(to, now);
                XMLUtils.setDurationValue(duration, toDate.getTime() - fromDate.getTime());

                _log.info("update caseId: " + XMLUtils.getCaseId(rup) + ", set " + activityName + ".TO: "
                        + Utils.date2String(now, Utils.DATETIME_PATTERN));

                _scheduler.setTimes(rup, activity, true, true, null);
            }
        }
        optimizeAndSaveRup(rup, savedBy, null, false);
    }
}
 
Example 19
Source File: CmSynchronizer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected CourseSet addCourseSet(Element element) {
	String eid = element.getChildText("eid");
	if(log.isDebugEnabled()) log.debug("Adding CourseSet + " + eid);
	String title = element.getChildText("title");
	String description = element.getChildText("description");
	String category = element.getChildText("category");
	String parentEid = null;
	String parentFromXml = element.getChildText("parent-course-set");
	if(parentFromXml != null && ! "".equals(parentFromXml)) {
		parentEid = parentFromXml;
	}
	return cmAdmin.createCourseSet(eid, title, description, category, parentEid);
}
 
Example 20
Source File: SMSSender.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
     * Checks the work item out of the engine, sends an sms message, and
     * starts the thread that checks for a reply.
     * @param enabledWorkItem
     */
    public void handleEnabledWorkItemEvent(WorkItemRecord enabledWorkItem) {
        try {
            if (!checkConnection(_sessionHandle)) {
                _sessionHandle = connect(engineLogonName, engineLogonPassword);
            }
            if (successful(_sessionHandle)) {
                List executingChildren = checkOutAllInstancesOfThisTask(enabledWorkItem, _sessionHandle);
                String resultsFromService = "";
                for (int i = 0; i < executingChildren.size(); i++) {
                    WorkItemRecord itemRecord = (WorkItemRecord) executingChildren.get(i);

                    Element caseDataBoundForEngine = prepareReplyRootElement(enabledWorkItem, _sessionHandle);

//                    first of all do a connection with the SMS Service
//                    String smsConnectionID = performSMSConnection(_smsUsername, _smsPassword);

                    //next get the parameters for message sending.
                    Element paramsData = itemRecord.getDataList();
                    String message = paramsData.getChildText(SMS_MESSAGE_PARAMNAME);
                    String toPhone = paramsData.getChildText(SMS_PHONENO_PARAMNAME);
//                    String msgCorrelationID = itemRecord.getID().substring(0, 12);

//                    resultsFromService += performSMSSend(message, toPhone, smsConnectionID, msgCorrelationID);

                    String jobID = performSMSSend(message, toPhone);

                    //an outstanding interaction is an object that records the
                    //details of a reply that needs to be polled for.
                    Interaction inter = new Interaction();
                    inter._smsJobID = jobID;
                    inter._archivable = false;
                    inter._timeOfSend = new Date();
                    inter._workItemRecord = itemRecord;
                    inter._caseDataBoundForEngine = caseDataBoundForEngine;
                    _outStandingInteractions.add(inter);
                }

                System.out.println("\n\nSMSSender " +
                        "\nResults of engine interactions : " + _report +
                        "\nResults of SMS invocations : " + resultsFromService);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        if (!_running) {
            //this thread polls for a reply while running
            Thread replyPoller = new Thread(this, "ReplyPoller");
            replyPoller.start();
        }
    }