Package org.jdom.contrib.input

Examples of org.jdom.contrib.input.ResultSetBuilder


    Namespace ns = Namespace.getNamespace("xhtml", "http://w3.org/etc");

    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(
      "select id, name, home_url || contact_phone from rsbd");
    ResultSetBuilder builder = new ResultSetBuilder(rs);
    builder.setAsElement(3, "num3");
    //builder.setNamespace(ns);
    //builder.setAsElement("id", "newid");
    //builder.setAsElement("home_url", "newhome_url");
    //builder.setAsElement(4, "some4");
    //builder.setAsAttribute(4, "some4");
    //builder.setAsAttribute("state_flag");
    builder.setAsAttribute("created_time", "ctime");
    Document doc = builder.build();
    XMLOutputter outputter = new XMLOutputter();
    outputter.output(doc, System.out);
  }
View Full Code Here


    // Execute SQL Query
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);

    // Create a ResultSetBuilder
    ResultSetBuilder builder = new ResultSetBuilder(rs);

    // Configure some parameters...

    if (root != null) {
      builder.setRootName(root);
    }

    if (row != null) {
      builder.setRowName(row);
    }

    if (ns != null) {
      String namespace = null;
      String url = null;
      int sep = ns.indexOf("/");

      if (sep > 0) {
        namespace = ns.substring(0, sep);
        url = ns.substring(sep+1);
        builder.setNamespace(Namespace.getNamespace(namespace, url));
      }
    }

    if (maxRows > 0) {
      builder.setMaxRows(maxRows);
    }

    for (int i=0; i < attributes.size(); i++) {
      String colName = (String) attributes.get(i);
      String attrName = null;

      if (colName.indexOf("/") >= 0) {
        String col = colName;
        int sep = col.indexOf("/");
        colName = col.substring(0, sep);
        attrName = col.substring(sep+1);
      }

      try {    // If it looks like an integer, is the column number
        int colNum = Integer.parseInt(colName);

        if (attrName == null) {
          builder.setAsAttribute(colNum);    // attrName = column Name
        }
        else {
          builder.setAsAttribute(colNum, attrName);
        }
      }
      catch (NumberFormatException e) {
        // Otherwise it's the column name
        if (attrName == null) {
          builder.setAsAttribute(colName); // attrName = column Name
        }
        else {
          builder.setAsAttribute(colName, attrName);
        }
      }
    }

    // Rename element
    for (int i=0; i < elements.size(); i++) {
      String colName = (String) elements.get(i);
      String elemName = null;

      if (colName.indexOf("/") >= 0) {
        String col = colName;
        int sep = col.indexOf("/");
        colName = col.substring(0, sep);
        elemName = col.substring(sep+1);
      }

      try {    // If it looks like an integer, is the column number
        int colNum = Integer.parseInt(colName);

        if (elemName != null) {  // It must have an element name
          builder.setAsElement(colNum, elemName);
        }
      }
      catch (NumberFormatException e) {
        // Otherwise it's the column name
        if (elemName != null) {  // It must have an element name
          builder.setAsElement(colName, elemName);
        }
      }
    }

    // Build a JDOM tree
    Document doc = builder.build();

    // Convert the result to XML (as String)
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    outputter.output(doc, output);
View Full Code Here

TOP

Related Classes of org.jdom.contrib.input.ResultSetBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.