/**
   * Converts an XML element into an <code>EppResponseDataRenewXriNumber</code> object. The caller
   * of this method must make sure that the root node is the resData element of EPP responseType for
   * creating an EPP XRI I-Number object
   *
   * @param root root node for an <code>EppResponseDataRenewXriNumber</code> object in XML format
   * @return an <code>EppResponseDataRenewXriNumber</code> object, or null if the node is invalid
   */
  public static EppEntity fromXML(Node root) {
    String i_number = null;
    Calendar exDate = null;
    NodeList list = root.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
      Node node = list.item(i);
      String name = node.getLocalName();
      if (name == null) {
        continue;
      } else if (name.equals("inumber")) {
        i_number = EppUtil.getText(node);
      } else if (name.equals("exDate")) {
        exDate = EppUtil.getDate(node);
      }
    }

    return new EppResponseDataRenewXriNumber(i_number, exDate);
  }
Пример #2
0
  /** Prints the specified node, recursively. */
  public String print(Node node) {

    // is there anything to do?
    if (node == null) {
      return sb.toString();
    }

    int type = node.getNodeType();
    switch (type) {
        // print document
      case Node.DOCUMENT_NODE:
        {
          return print(((Document) node).getDocumentElement());
          // out.flush();
          // break;
        }

        // print element with attributes
      case Node.ELEMENT_NODE:
        {
          sb.append('<');
          sb.append(node.getNodeName());
          Attr attrs[] = sortAttributes(node.getAttributes());
          for (int i = 0; i < attrs.length; i++) {
            Attr attr = attrs[i];
            sb.append(' ');
            sb.append(attr.getNodeName());
            sb.append("=\"");
            sb.append(normalize(attr.getNodeValue()));
            sb.append('"');
          }
          sb.append('>');
          NodeList children = node.getChildNodes();
          if (children != null) {
            int len = children.getLength();
            for (int i = 0; i < len; i++) {
              print(children.item(i));
            }
          }
          break;
        }

        // handle entity reference nodes
      case Node.ENTITY_REFERENCE_NODE:
        {
          if (canonical) {
            NodeList children = node.getChildNodes();
            if (children != null) {
              int len = children.getLength();
              for (int i = 0; i < len; i++) {
                print(children.item(i));
              }
            }
          } else {
            sb.append('&');
            sb.append(node.getNodeName());
            sb.append(';');
          }
          break;
        }

        // print cdata sections
      case Node.CDATA_SECTION_NODE:
        {
          if (canonical) {
            sb.append(normalize(node.getNodeValue()));
          } else {
            sb.append("<![CDATA[");
            sb.append(node.getNodeValue());
            sb.append("]]>");
          }
          break;
        }

        // print text
      case Node.TEXT_NODE:
        {
          sb.append(normalize(node.getNodeValue()));
          break;
        }

        // print processing instruction
      case Node.PROCESSING_INSTRUCTION_NODE:
        {
          sb.append("<?");
          sb.append(node.getNodeName());
          String data = node.getNodeValue();
          if (data != null && data.length() > 0) {
            sb.append(' ');
            sb.append(data);
          }
          sb.append("?>");
          break;
        }
        // handle entity reference nodes
      case Node.DOCUMENT_FRAGMENT_NODE:
        {
          NodeList children = node.getChildNodes();
          if (children != null) {
            int len = children.getLength();
            for (int i = 0; i < len; i++) {
              print(children.item(i));
            }
          }
          break;
        }
    }

    if (type == Node.ELEMENT_NODE) {
      sb.append("</");
      sb.append(node.getNodeName());
      sb.append('>');
    }

    return sb.toString();
  } // print(Node)