Ejemplo n.º 1
0
  /**
   * Returns the value of an element's child element reached by the given path. Traverses the DOM
   * tree from the parent until the child is reached.
   *
   * @param parent the parent <code>Element</code>
   * @param childPath a path to the root of the elements. Paths are specified as element names,
   *     separated by a "/". Namespaces are allowed. e.g. "aaa:bbb/ccc:ddd/eee".
   * @return the value of the child. <br>
   *     If <code>parent</code> is <code>null</code>, returns <code>null</code>. If <code>childPath
   *     </code> is null, returns the value of the parent.
   */
  public static String getElementValue(final Element parent, final String childPath) {

    if (parent == null) {
      return null;
    } else {
      Element child = getLeafChild(parent, childPath);
      return (child == null) ? null : child.getTextTrim();
    }
  }
Ejemplo n.º 2
0
 private void replaceOperators(final Element element, final Map<String, String> replacements) {
   assert element != null && replacements != null;
   List<Element> operatorsToReplace = new ArrayList<Element>();
   for (Element operator : element.getDescendants(new ElementFilter(OPERATOR, MATHMLNS))) {
     if (replacements.containsKey(operator.getTextTrim())) {
       operatorsToReplace.add(operator);
     }
   }
   for (Element operator : operatorsToReplace) {
     final String oldOperator = operator.getTextTrim();
     final String newOperator = replacements.get(oldOperator);
     operator.setText(newOperator);
     LOGGER.log(
         Level.FINE,
         "Operator ''{0}'' was replaced by ''{1}''",
         new Object[] {oldOperator, newOperator});
   }
 }
Ejemplo n.º 3
0
 @Override
 public void load(Element element, InteractionGraphLoader loader) throws Exception {
   if (!element.getChildren().isEmpty()) {
     throw new IllegalArgumentException("ClearSelectedAction does not allow children");
   }
   String text = element.getTextTrim();
   String[] classes = text.split("\\|");
   for (String s : classes) {
     set.add(ObjectClass.valueOf(s));
   }
 }
Ejemplo n.º 4
0
 /**
  * Returns the values of the specified sub-elements of the child parent element. This is useful in
  * cases where an element has several children.
  *
  * @param parent the parent <code>Element</code>
  * @param children An array of child element names. May contain namespace specifiers.
  * @return an array containing the value of each child element. <br>
  *     If <code>parent</code> or <code>children</code> is <code>null</code>, returns <code>null
  *     </code>.
  */
 public static String[] getElementValues(final Element parent, final String[] children) {
   if ((parent == null) || (children == null)) {
     return null;
   } else {
     int numValues = children.length;
     String[] elementValues = new String[numValues];
     for (int i = 0; i < numValues; ++i) {
       Element child = getChild(parent, children[i]);
       elementValues[i] = (child == null) ? null : child.getTextTrim();
     }
     return elementValues;
   }
 }
Ejemplo n.º 5
0
 private void operatorsToIdentifiers(final Element ancestor, final Set<String> identifiers) {
   assert ancestor != null && identifiers != null;
   final List<Element> toReplace = new ArrayList<Element>();
   for (Element element : ancestor.getDescendants(new ElementFilter(OPERATOR, MATHMLNS))) {
     if (identifiers.contains(element.getTextTrim())) {
       toReplace.add(element);
     }
   }
   for (Element element : toReplace) {
     LOGGER.log(Level.FINE, "Creating an identifier from {0}", element.getText());
     replaceElement(element, IDENTIFIER);
   }
 }
Ejemplo n.º 6
0
 private void replaceIdentifiers(final Element ancestor, final Set<String> operators) {
   assert ancestor != null && operators != null;
   final List<Element> toReplace = new ArrayList<Element>();
   for (Element element : ancestor.getDescendants(new ElementFilter(IDENTIFIER, MATHMLNS))) {
     // TODO: control whole ranges of symbols rather than listed ones
     if (operators.contains(element.getTextTrim())) {
       toReplace.add(element);
     }
   }
   for (Element element : toReplace) {
     LOGGER.log(Level.FINE, "Creating an operator from {0}", element.getText());
     replaceElement(element, OPERATOR);
   }
 }
Ejemplo n.º 7
0
  @Override
  public void load(Element element) {
    super.load(element);

    Element body = element.getChild("Body", MM7Message.ENVELOPE);
    Element req = body.getChild("DeliverReq", namespace);

    Element sender = req.getChild("Sender", namespace);

    if (sender != null) {
      if (sender.getChildren() != null && sender.getChildren().size() > 0) {
        Address a = new Address();
        a.load((Element) sender.getChildren().get(0));
        setSender(a);
      } else {
        setSender(new Address(sender.getTextTrim()));
      }

    } else {
      setSender(null);
    }

    setLinkedId(req.getChildTextTrim("LinkedID", namespace));
    setSenderSPI(req.getChildTextTrim("SenderSPI", namespace));
    setRecipientSPI(req.getChildTextTrim("RecipientSPI", namespace));
    setReplyChargingId(req.getChildTextTrim("ReplyChargingID", namespace));
    setSubject(req.getChildTextTrim("Subject", namespace));
    setApplicId(req.getChildTextTrim("ApplicID", namespace));
    setReplyApplicId(req.getChildTextTrim("ReplyApplicID", namespace));
    setAuxApplicInfo(req.getChildTextTrim("AuxApplicInfo", namespace));
    if (req.getChildTextTrim("Priority", namespace) == null
        || "".equals(req.getChildTextTrim("Priority", namespace))) {
      setPriority(Priority.HIGH);
    } else {
      setPriority(Priority.valueOf(req.getChildTextTrim("Priority", namespace).toUpperCase()));
    }

    setTimeStamp(new RelativeDate(req.getChildTextTrim("TimeStamp", namespace)).toDate());
  }
Ejemplo n.º 8
0
 private boolean isSpareOperator(final Element operator, final Collection<String> spareOperators) {
   assert operator != null && spareOperators != null && isOperator(operator);
   return (isEnabled(REMOVE_EMPTY_OPERATORS) && operator.getText().isEmpty())
       || (spareOperators.contains(operator.getTextTrim()));
 }