/**
  * Get the value of a node as a string.
  *
  * @param n Node to be converted to a string. May be null.
  * @return value of n as a string, or an empty string if n is null.
  */
 public String toString(org.w3c.dom.Node n) {
   // %REVIEW% You can't get much uglier than this...
   int nodeHandle = getDTMHandleFromNode(n);
   DTM dtm = getDTM(nodeHandle);
   XMLString strVal = dtm.getStringValue(nodeHandle);
   return strVal.toString();
 }
Exemple #2
0
 /**
  * Compares this string to the specified object. The result is <code>true</code> if and only if
  * the argument is not <code>null</code> and is a <code>String</code> object that represents the
  * same sequence of characters as this object.
  *
  * @param obj2 the object to compare this <code>String</code> against.
  * @return <code>true</code> if the <code>String </code>are equal; <code>false</code> otherwise.
  * @see java.lang.String#compareTo(java.lang.String)
  * @see java.lang.String#equalsIgnoreCase(java.lang.String)
  */
 public boolean equals(XMLString obj2) {
   if (obj2 != null) {
     if (!obj2.hasString()) {
       return obj2.equals(str());
     } else {
       return str().equals(obj2.toString());
     }
   }
   return false;
 }
Exemple #3
0
  /**
   * Convert a string to a double -- Allowed input is in fixed notation ddd.fff.
   *
   * @return A double value representation of the string, or return Double.NaN if the string can not
   *     be converted.
   */
  public double toDouble() {
    /* XMLCharacterRecognizer.isWhiteSpace(char c) methods treats the following
     * characters as white space characters.
     * ht - horizontal tab, nl - newline , cr - carriage return and sp - space
     * trim() methods by default also takes care of these white space characters
     * So trim() method is used to remove leading and trailing white spaces.
     */
    XMLString s = trim();
    double result = Double.NaN;
    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      if (c != '-' && c != '.' && (c < 0X30 || c > 0x39)) {
        // The character is not a '-' or a '.' or a digit
        // then return NaN because something is wrong.
        return result;
      }
    }
    try {
      result = Double.parseDouble(s.toString());
    } catch (NumberFormatException e) {
    }

    return result;
  }
Exemple #4
0
 /**
  * Returns the index within this string of the first occurrence of the specified substring. The
  * integer returned is the smallest value <i>k</i> such that:
  *
  * <blockquote>
  *
  * <pre>
  * this.startsWith(str, <i>k</i>)
  * </pre>
  *
  * </blockquote>
  *
  * is <code>true</code>.
  *
  * @param str any string.
  * @return if the string argument occurs as a substring within this object, then the index of the
  *     first character of the first such substring is returned; if it does not occur as a
  *     substring, <code>-1</code> is returned.
  * @exception java.lang.NullPointerException if <code>str</code> is <code>null</code>.
  */
 public int indexOf(XMLString str) {
   return str().indexOf(str.toString());
 }