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

The following examples show how to use org.jdom2.Element#getText() . These examples are extracted from open source projects. 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
/**
 * Gets a String-pair of steno data, i.e. a string array with 2 fields. first
 * field contains the short steno word, the second field holds the complete
 * version of the word
 * @param nr the position of the element we want to retrieve
 * @return a string array containing the steno and the complete word
 */
public String[] getElement(int nr) {
    // get all elements
    List<Element> all = steno.getRootElement().getChildren();
    // get the requested element
    Element el = all.get(nr);
    // new string array
    String[] retval = null;
    // if we found an element, return its content
    if (el!=null) {
        retval = new String[2];
        retval[0] = el.getAttributeValue("id");
        retval[1] = el.getText();
    }

    return retval;
}
 
Example 2
private Map<String, String> getAppInfo(Element eField) {
    Namespace ns = eField.getNamespace();
    Element annotation = eField.getChild("annotation", ns);
    if (annotation != null) {
        Map<String, String> infoMap = new HashMap<>();
        Element appInfo = annotation.getChild("appinfo", ns);
        if (appInfo != null) {
            for (Element child : appInfo.getChildren()) {
                String text = child.getText();
                if (!StringUtil.isNullOrEmpty(text)) {
                    infoMap.put(child.getName(), text);
                }
            }
        }
        eField.removeChild("annotation", ns);   // done processing the annotation
        return infoMap;
    }
    return Collections.emptyMap();
}
 
Example 3
Source Project: zap-extensions   File: SQLiTestResponse.java    License: Apache License 2.0 6 votes vote down vote up
/** @param el */
protected SQLiTestResponse(Element el) {
    this();

    Element value = el.getChild(TAG_RESPONSE_COMPARISON);
    if (value != null) {
        this.comparison = value.getText();
    }

    value = el.getChild(TAG_RESPONSE_GREP);
    if (value != null) {
        this.grep = value.getText();
    }

    value = el.getChild(TAG_RESPONSE_TIME);
    if (value != null) {
        this.time = value.getText();
    }

    value = el.getChild(TAG_RESPONSE_UNION);
    this.union = (value != null);
}
 
Example 4
public String getTargetValue(String wfcKey) throws JDOMException {

        Element rootNode;
        if (wfcKey.startsWith("version.camel.")) {
            rootNode = camelRoot;
        } else if (wfcKey.startsWith("version.wildfly.")) {
            rootNode = wfRoot;
        } else {
            return null;
        }

        String targetKey = mapping.get(wfcKey);
        if (targetKey == null) {
            problems.add("Cannot find mapping for: " + wfcKey);
            return null;
        }
        XPath xpath = XPath.newInstance("/ns:project/ns:properties/ns:" + targetKey);
        xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0"));
        Element propNode = (Element) xpath.selectSingleNode(rootNode);
        if (propNode == null) {
            problems.add("Cannot obtain target property: " + targetKey);
            return null;
        }
        return propNode.getText();
    }
 
Example 5
@Override
public void setFromDOM(Element element) throws MCRException {
    super.setFromDOM(element);
    String textData = element.getText();
    String[] splitData = textData.split(",");
    if (splitData.length % 2 != 0) {
        throw new MCRException(String.format(Locale.ROOT,
            "Unable to parse MCRMetaSpatial cause text data '%s' contains invalid content", textData));
    }
    try {
        Arrays.stream(splitData).map(BigDecimal::new).forEach(this.data::add);
    } catch (NumberFormatException nfe) {
        throw new MCRException(String.format(Locale.ROOT,
            "Unable to parse MCRMetaSpatial cause text data '%s' contains invalid content", textData), nfe);
    }
}
 
Example 6
/**
 * This method read the XML input stream part from a DOM part for the
 * metadata of the document.
 * 
 * @param element
 *            a relevant JDOM element for the metadata
 */
@Override
public void setFromDOM(Element element) {
    super.setFromDOM(element);

    String tempText = element.getText();

    if (tempText == null) {
        tempText = "";
    }

    text = tempText.trim();

    String tempForm = element.getAttributeValue("form");

    if (tempForm == null) {
        tempForm = "plain";
    }

    form = tempForm.trim();
}
 
Example 7
private void parseParticipants(Element e, Namespace nsYawl) {

        // from the specified initial set, add all participants
        for (Element eParticipant : e.getChildren("participant", nsYawl)) {
            String participant = eParticipant.getText();
            if (participant.indexOf(',') > -1)
                addParticipantsByID(participant);
            else
                addParticipant(participant);
        }
    }
 
Example 8
public PasswordCryptAnswer fromXml( final Element element, final boolean caseInsensitive, final String challengeText )
{
    final String answerValue = element.getText();
    final String formatStr = element.getAttributeValue( ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT );
    final FormatType formatType;
    try
    {
        formatType = FormatType.valueOf( formatStr );
    }
    catch ( IllegalArgumentException e )
    {
        throw new IllegalArgumentException( "unknown content format specified in xml format value: '" + formatStr + "'" );
    }
    return new PasswordCryptAnswer( answerValue, caseInsensitive, formatType );
}
 
Example 9
private JoinArray readJoinArray(NetcdfDataset ds, Element joinElement) {
  JoinArray.Type type = JoinArray.Type.valueOf(joinElement.getAttributeValue("type"));
  Element paramElem = joinElement.getChild("param");
  String paramS = paramElem.getText();
  int param = Integer.parseInt(paramS);

  Element varElem = joinElement.getChild("variable");
  String varName = varElem.getText();
  VariableDS v = (VariableDS) ds.findVariable(varName);
  return new JoinArray(v, type, param);
}
 
Example 10
public ItemStack parseBook(Element el) throws InvalidXMLException {
  ItemStack itemStack = parseItem(el, Material.WRITTEN_BOOK);
  BookMeta meta = (BookMeta) itemStack.getItemMeta();
  meta.setTitle(BukkitUtils.colorize(XMLUtils.getRequiredUniqueChild(el, "title").getText()));
  meta.setAuthor(BukkitUtils.colorize(XMLUtils.getRequiredUniqueChild(el, "author").getText()));

  Element elPages = el.getChild("pages");
  if (elPages != null) {
    for (Element elPage : elPages.getChildren("page")) {
      String text = elPage.getText();
      text = text.trim(); // Remove leading and trailing whitespace
      text =
          Pattern.compile("^[ \\t]+", Pattern.MULTILINE)
              .matcher(text)
              .replaceAll(""); // Remove indentation on each line
      text =
          Pattern.compile("^\\n", Pattern.MULTILINE)
              .matcher(text)
              .replaceAll(
                  " \n"); // Add a space to blank lines, otherwise they vanish for unknown reasons
      text = BukkitUtils.colorize(text); // Color codes
      meta.addPage(text);
    }
  }

  itemStack.setItemMeta(meta);
  return itemStack;
}
 
Example 11
/**
 * This method returns the name of the category at position {@code pos}
 *
 * @param pos the position of the requested category
 * @return the name of the requested category, or an empty string if no
 * category was found
 */
public String getCategory(int pos) {
    // retrieve category element
    Element cat = retrieveCategoryElement(pos);
    // if it does not exist, return empty string
    if (null == cat) {
        return "";
    }
    // else return category name
    return cat.getText();
}
 
Example 12
@SuppressWarnings("unchecked")
private static String getCurrentLangLabel(Element item, String language) {
    List<Element> labels = item.getChildren("label");
    for (Element label : labels) {
        if (label.getAttributeValue("lang", Namespace.XML_NAMESPACE).equals(language)) {
            return label.getText();
        }
    }
    if (labels.size() > 0) {
        //fallback to first label if currentLang label is not found
        return labels.get(0).getText();
    }
    return "";
}
 
Example 13
/**
 * This method reads the XML input stream part from a DOM part for the
 * metadata of the document.
 * 
 * @param element
 *            a relevant JDOM element for the metadata
 */
@Override
public void setFromDOM(Element element) {
    super.setFromDOM(element);
    texts.clear(); // clear

    for (Element textElement : element.getChildren("text")) {
        String text = textElement.getText();
        String lang = textElement.getAttributeValue("lang", Namespace.XML_NAMESPACE);
        if (lang != null) {
            setText(text, lang);
        } else {
            setText(text);
        }
    }
    setCalendar(element.getChildTextTrim("calendar"));
    setVonDate(element.getChildTextTrim("von"), calendar);
    setBisDate(element.getChildTextTrim("bis"), calendar);
    /** 
     * If dates higher than 1582 and calendar is Julian the calendar must switch to 
     * Gregorian cause the date transforming is implicit in the calendar methods. In
     * other cases before 1582 both calendar are equal.
     * */
    if (calendar.equals(MCRCalendar.TAG_JULIAN)) {
        calendar = MCRCalendar.TAG_GREGORIAN;
    }
}
 
Example 14
public void setFromDOM(Element element) throws MCRException {
    super.setFromDOM(element);
    List<Element> childrenList = element.getChildren(MCRMetaDerivateLink.ANNOTATION);
    if (childrenList == null) {
        return;
    }

    for (Element anAnnotation : childrenList) {
        String key = anAnnotation.getAttributeValue(MCRMetaDerivateLink.ATTRIBUTE, Namespace.XML_NAMESPACE);
        String annotationText = anAnnotation.getText();
        this.map.put(key, annotationText);
    }
}
 
Example 15
public ChaiHelpdeskAnswer fromXml( final Element element, final boolean caseInsensitive, final String challengeText )
{
    final String hashedAnswer = element.getText();
    final String answerValue = decryptValue( hashedAnswer, challengeText );
    return new ChaiHelpdeskAnswer( answerValue, challengeText );
}
 
Example 16
protected ThreddsMetadata.Vocab readControlledVocabulary(Element elem) {
  if (elem == null) {
    return null;
  }
  return new ThreddsMetadata.Vocab(elem.getText(), elem.getAttributeValue("vocabulary"));
}
 
Example 17
String getVal(Element parent, String name) {
  Element elem = parent.getChild(name, wmsNamespace);
  return (name == null) ? "" : elem.getText();
}
 
Example 18
/**
 *
 * @param wrong
 * @return the correct spelling of the word {@code wrong} or {@code null}, if no spellcorrection was found
 */
public String getCorrectSpelling(String wrong) {
    // get all elements
    List<Element> all = autokorrektur.getRootElement().getChildren();
    // create an iterator
    Iterator<Element> i = all.iterator();
    // go through list
    while (i.hasNext()) {
        // get element
        Element el = i.next();
        // get attribute value
        String att = el.getAttributeValue("id");
        // check for existing attribute
        if (null==att) {
            return null;
        }
        // get spell-check-word
        String correct = att.toLowerCase();
        // get lower-case word of mistyped wrong word...
        String retval = wrong.toLowerCase();
        // if the element's id equals the requestes string "e", return true
        // i.e. the string e already exists as element
        if (correct.equalsIgnoreCase(wrong)) {
            // now that we found the correct word, we want to see whether
            // the word starts with an upper case letter - and if so, convert
            // the first letter of the return value to upper case as well
            String firstLetter = wrong.substring(0, 1);
            String firstBigLetter = wrong.substring(0, 1).toUpperCase();
            // get return value
            retval = el.getText();
            // if both matches, we have upper case initial letter
            // convert first letter to uppercase
            if (firstLetter.equals(firstBigLetter)) {
                retval = retval.substring(0,1).toUpperCase()+retval.substring(1);
            }
            return retval;
        }
        // when the misspelled phrase starts with an asterisk, we know that we should check the
        // end of or in between the typed word "wrong".
        if (correct.startsWith("*")) {
            // first we remove the asterisk
            correct = correct.substring(1);
            // if the misspelled phrase also ends with an asterisk, we have to check
            // for the phrase in between - that means, "wrong" is not allowed to end or start
            // with "correct"
            if (correct.endsWith(("*"))) {
                // remove trailing asterisk
                correct = correct.substring(0, correct.length()-1);
                // if the mistyped word "wrong" does not start and end with "correct", we know
                // that we have a correction in between
                if (retval.contains(correct)) {
                    // return correct word for wrong spelling
                    return correctWithCase(retval,correct,el.getText(),wrong);
                }
            }
            // if the mistyped word "wrong" does not end with "correct", we know
            // that
            else if (retval.endsWith(correct) && retval.contains(correct)) {
                // return correct word for wrong spelling
                return correctWithCase(retval,correct,el.getText(),wrong);
            }
        }
        else if (correct.endsWith("*")) {
            // get lower-case word of mistyped wrong word...
            retval = wrong.toLowerCase();
            // if the mistyped word "wrong" does not end with "correct", we know
            // that we have the correction at thr word beginning
            if (retval.startsWith(correct) && retval.contains(correct)) {
                // return correct word for wrong spelling
                return correctWithCase(retval,correct,el.getText(),wrong);
            }
        }
    }
    // return null, no correct word found
    return null;
}
 
Example 19
/**
	 * For the route that the scheduleDoc is for reads in all stop times and
	 * puts them into map so that can determine trips.
	 * 
	 * @param scheduleDoc
	 * @return map of stop times, keyed on block ID
	 */
	private static Map<String, List<StopTime>> getStopTimesMap(
			Document scheduleDoc) {
		Map<String, List<StopTime>> stopTimesMap = 
				new HashMap<String, List<StopTime>>();

		List<String> validBlockIdsList = validBlockIds.getValue();
		
		Element rootNode = scheduleDoc.getRootElement();
		Element route = rootNode.getChild("route");

		List<Element> scheduleRows = route.getChildren("tr");
		for (Element scheduleRow : scheduleRows) {
			String blockId = scheduleRow.getAttributeValue("blockID");
			
			// If not one of the configured block IDs then ignore. This is 
			// important because sometimes NextBus leaves old block definitions
			// in the config.
			if (!validBlockIdsList.contains(blockId))
				continue;
			
			// Get list of stops times for this block
			List<StopTime> stopTimesForBlock = stopTimesMap.get(blockId);
			if (stopTimesForBlock == null) {
				stopTimesForBlock = new ArrayList<StopTime>();
				stopTimesMap.put(blockId, stopTimesForBlock);
			}
			
			List<Element> stopsForScheduleRow = scheduleRow.getChildren("stop");
			for (Element stop : stopsForScheduleRow) {
				String stopTag = stop.getAttributeValue("tag");
				String timeStr = stop.getText();
				
				// If stop doesn't have valid time then it is not 
				// considered to be part of trip
				if (!timeStr.contains(":"))
					continue;

//				// KLUDGE! Need west route to start with 1500owen stop instead of
//				// the 1650owen one so that the stop at beginning of trip is only
//				// once in trip. This way can successfully figure out when trip ends.
//				// But the schedule API data only deals with 1650owen stop. So
//				// if encountering stop berr5th_s stop, which is after the owen
//				// stops, then use schedule time for the 1500owen stop instead
//				// of the 1650owen 1500owen one.
//				String routeId = route.getAttributeValue("tag");
//				if (routeId.equals("west")) {
//					if (stopTag.equals("berr5th_s")) {
//						StopTime previousStopTime = 
//								stopTimesForBlock.get(stopTimesForBlock.size()-1);
//						if (previousStopTime.stopId.equals("1650owen")) {
//							// Encountered schedule times for 1650owen and then
//							// berr5th_s so replace the stopId for the 1650owen
//							// schedule time with 1500owen so that it is for the
//							// stop for the beginning of the trip
//							previousStopTime.stopId = "1500owen";
//						}
//					}
//				}
				
				// Arrival stops are a nuisance. Don't really want them because
				// they are not GTFS, but if defined then still need the stop
				// to define the very end of a block. To do that need to use
				// the regular stop tag instead of the arrival one.
				if (stopTag.endsWith("_a"))
					stopTag = stopTag.substring(0, stopTag.length()-2);

				// Add this stop time to the map
				StopTime stopTime = new StopTime(stopTag, timeStr);
				stopTimesForBlock.add(stopTime);
				
				// Turn out the schedule times from the NextBus API can be out 
				// of order so sort them. Yes, it is inefficient to sort every
				// time adding a new time but easier to do it this way.	
				Collections.sort(stopTimesForBlock);
			}
		}
		
		return stopTimesMap;
	}
 
Example 20
/**
 * This methods returns the accelerator key of a given position in the xml-file
 * Following constants should be used as parameters:<br>
 * MAINKEYS<br>
 * NEWENTRYKEYS<br>
 * DESKTOPKEYS<br>
 * SEARCHRESULTSKEYS<br>
 *
 * @param what uses constants, see global field definition at top of source
 * @param actionname the attribute (i.e. the action's name) we want to find
 * @return the string containing the accelerator key or null if nothing was found
 */
public String getAcceleratorKey(int what, String actionname) {
    // retrieve the element
    Element acckey = retrieveElement(what, actionname);
    // if the element was not found, return an empty string
    if (null==acckey) {
        return null;
    }
    // else the value (i.e. the accelerator key string)
    return acckey.getText();
}