svn commit: r705950 [1/2] - in /xml/xindice/trunk/java/examples/addressbook: config/ src/java/addressbook/ src/jsp/

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: natalia
Date: Sat Oct 18 18:57:36 2008
New Revision: 705950

URL: http://svn.apache.org/viewvc?rev=705950&view=rev
Log:
Addressbook example updated to make it easier to use the application

Added:
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/CollectionCheck.java   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/GetContact.java   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Layout.java   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SaveContact.java
      - copied, changed from r703899, xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/EditContact.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Setup.java   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/jsp/addressbook.css   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/jsp/contactForm.jsp
      - copied, changed from r703899, xml/xindice/trunk/java/examples/addressbook/src/jsp/editContactForm.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/initialize.jsp   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/jsp/layout.jsp   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/jsp/listResults.jsp   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/jsp/listing.jsp   (with props)
    xml/xindice/trunk/java/examples/addressbook/src/jsp/setup.jsp   (with props)
Removed:
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/AddContact.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/EditContact.java
    xml/xindice/trunk/java/examples/addressbook/src/jsp/addContact.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/editContactForm.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/footer.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/header.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/showAllContactInfo.jsp
Modified:
    xml/xindice/trunk/java/examples/addressbook/config/web.xml
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Action.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DBConnection.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DeleteContact.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Group.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/ListContacts.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Person.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SearchContacts.java
    xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Task.java
    xml/xindice/trunk/java/examples/addressbook/src/jsp/error.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/index.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/listContacts.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/searchContacts.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/showContact.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/showXML.jsp
    xml/xindice/trunk/java/examples/addressbook/src/jsp/showXMLInfo.jsp

Modified: xml/xindice/trunk/java/examples/addressbook/config/web.xml
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/config/web.xml?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/config/web.xml (original)
+++ xml/xindice/trunk/java/examples/addressbook/config/web.xml Sat Oct 18 18:57:36 2008
@@ -19,23 +19,82 @@
   - $Id$
   -->
 
-<!DOCTYPE web-app
-    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
-    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
-
 <!--
   - Version: $Revision$ $Date$
   - Authors: Kimbro Staken ([email protected])
   -          Vladimir R. Bossicard ([email protected])
   -->
 
-<web-app>
+<web-app xmlns='http://java.sun.com/xml/ns/j2ee'
+         xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+         xsi:schemaLocation='http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd'
+         version='2.4'>
+  <welcome-file-list>
+    <welcome-file>index.jsp</welcome-file>
+  </welcome-file-list>
+
+  <display-name>
+    Xindice AddressBook
+  </display-name>
+
+  <context-param>
+    <param-name>default_collection_hostname</param-name>
+    <param-value>localhost</param-value>
+  </context-param>
+
+  <context-param>
+    <param-name>default_collection_port</param-name>
+    <param-value>8888</param-value>
+  </context-param>
+
   <servlet>
     <servlet-name>Task</servlet-name>
     <servlet-class>addressbook.Task</servlet-class>
   </servlet>
+
+  <servlet>
+    <servlet-name>Setup</servlet-name>
+    <servlet-class>addressbook.Setup</servlet-class>
+  </servlet>
+
   <servlet-mapping>
     <servlet-name>Task</servlet-name>
     <url-pattern>/Task</url-pattern>
   </servlet-mapping>
+
+  <servlet-mapping>
+    <servlet-name>Setup</servlet-name>
+    <url-pattern>/Setup</url-pattern>
+  </servlet-mapping>
+
+  <filter>
+    <filter-name>CollectionCheck</filter-name>
+    <filter-class>addressbook.CollectionCheck</filter-class>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>CollectionCheck</filter-name>
+    <url-pattern>*.jsp</url-pattern>
+  </filter-mapping>
+
+  <filter-mapping>
+    <filter-name>CollectionCheck</filter-name>
+    <url-pattern>/Task</url-pattern>
+  </filter-mapping>
+
+  <filter>
+    <filter-name>Layout</filter-name>
+    <filter-class>addressbook.Layout</filter-class>
+    <init-param>
+      <param-name>layout</param-name>
+      <param-value>/layout.jsp</param-value>
+    </init-param>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>Layout</filter-name>
+    <url-pattern>*.jsp</url-pattern>
+    <dispatcher>REQUEST</dispatcher>
+    <dispatcher>FORWARD</dispatcher>
+  </filter-mapping>
 </web-app>

Modified: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Action.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Action.java?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Action.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Action.java Sat Oct 18 18:57:36 2008
@@ -19,127 +19,144 @@
  * $Id$
  */
 
-import java.util.Hashtable;
-import java.util.Vector;
+import org.xmldb.api.base.Collection;
+import org.xmldb.api.base.XMLDBException;
+import org.xmldb.api.modules.XMLResource;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import org.w3c.dom.Node;
+import org.apache.xpath.XPathAPI;
 
-import javax.servlet.http.HttpServlet;
+import javax.xml.transform.TransformerException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.xpath.XPathAPI;
-import org.apache.xpath.objects.XObject;
-import org.w3c.dom.Node;
-import org.xmldb.api.base.Collection;
-import org.xmldb.api.base.ResourceIterator;
-import org.xmldb.api.modules.XMLResource;
-
 /**
- * Common class for the Addressbook
+ * Common class for the Addressbook action
  */
-public abstract class Action extends HttpServlet {
-
-   // Version of the XMLDB Api that we are using
-   public final static String XMLDBAPIVERSION = "1.0";
-
-   // Singleton class used to hold connnection to database
-   protected static DBConnection connection = new DBConnection();
+public abstract class Action {
+    /**
+     * Collection name to be used for addressbook. Must be canonical name.
+     */
+    public static final String COLLECTION_NAME = "/db/addressbook";
+    protected DBConnection connection = new DBConnection();
+
+    /**
+     * Return a collection object for the addressbook
+     * @return Addressbook collection instance
+     * @throws Exception Collection could not be obtained
+     */
+    protected Collection getCollection() throws Exception {
+        return connection.getCollectionInstance(COLLECTION_NAME);
+    }
+
+    /**
+     * Process request and render the result page depending on request parameters.
+     * @param request HTTP request
+     * @param response HTTP response
+     * @throws Exception There was a problem during request processing
+     */
+    public abstract void process(HttpServletRequest request, HttpServletResponse response) throws Exception;
+
+    /**
+     * Create a XML document from Person object
+     * @param person Person object
+     * @param handler SAX ContentHandler that will process events and build document
+     * @throws SAXException if there was a problem building a document
+     */
+    protected void personToXml(Person person, ContentHandler handler) throws SAXException {
+        handler.startDocument();
+
+        handler.startElement("", "person", "person", new AttributesImpl());
+
+        createElement(handler, "fname", person.getFname());
+        createElement(handler, "lname", person.getLname());
+
+        createElement(handler, "phone", person.getWorkPhone(), "type", "work");
+        createElement(handler, "phone", person.getHomePhone(), "type", "home");
+        createElement(handler, "phone", person.getCellPhone(), "type", "cell");
+
+        createElement(handler, "email", person.getHomeEmail(), "type", "home");
+        createElement(handler, "email", person.getWorkEmail(), "type", "work");
+
+        createElement(handler, "address", person.getHomeAddress(), "type", "home");
+        createElement(handler, "address", person.getWorkAddress(), "type", "work");
+
+        handler.endElement("", "person", "person");
+
+        handler.endDocument();
+    }
+
+    protected Person xmlToPerson(XMLResource resource) throws XMLDBException, TransformerException {
+        Person person = new Person();
+
+        // Convert to DOM Node
+        Node node = resource.getContentAsDOM();
+
+        // Get the document key for this node for later use
+        person.setDocKey(resource.getDocumentId());
+
+        // Use Xalan xpath parser to extract data, store into hastable
+        person.setFname(XPathAPI.eval(node, "/person/fname").toString());
+        person.setLname(XPathAPI.eval(node, "/person/lname").toString());
+        person.setWorkPhone(XPathAPI.eval(node, "/person/phone[@type='work']").toString());
+        person.setHomePhone(XPathAPI.eval(node, "/person/phone[@type='home']").toString());
+        person.setCellPhone(XPathAPI.eval(node, "/person/phone[@type='cell']").toString());
+        person.setHomeEmail(XPathAPI.eval(node, "/person/email[@type='home']").toString());
+        person.setWorkEmail(XPathAPI.eval(node, "/person/email[@type='work']").toString());
+        person.setHomeAddress(XPathAPI.eval(node, "/person/address[@type='home']").toString());
+        person.setWorkAddress(XPathAPI.eval(node, "/person/address[@type='work']").toString());
+
+        return person;
+    }
+
+    private void createElement(ContentHandler handler, String name, String data) throws SAXException {
+        handler.startElement("", name, name, new AttributesImpl());
+        handler.characters(data.toCharArray(), 0, data.length());
+        handler.endElement("", name, name);
+    }
+
+    private void createElement(ContentHandler handler, String elemName, String elemData, String attrName, String attrData) throws SAXException {
+        AttributesImpl attr = new AttributesImpl();
+        attr.addAttribute("", attrName, attrName, null, attrData);
+
+        handler.startElement("", elemName, elemName, attr);
+        handler.characters(elemData.toCharArray(), 0, elemData.length());
+        handler.endElement("", elemName, elemName);
+    }
+
+    /**
+     * Converts input string by escaping symbols that have special meaning in HTML
+     * @param value input string
+     * @return escaped string
+     */
+    public static String escapeHtml(String value) {
+        StringBuffer buf = new StringBuffer();
+
+        for (int i = 0; i < value.length(); i++) {
+            char ch = value.charAt(i);
+            switch (ch) {
+                case '&':
+                    buf.append("&amp;");
+                    break;
+                case '\"':
+                    buf.append("&quot;");
+                    break;
+                case '<':
+                    buf.append("&lt;");
+                    break;
+                case '>':
+                    buf.append("&gt;");
+                    break;
+                default:
+                    buf.append(ch);
+                    break;
+            }
 
-   /**
-    * Return a collection object for the addressbook
-    */
-   public Collection getCollection(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
-      return connection.getCollectionInstance(request, response);
-   }
-
-   /**
-    * Return a vector of hashtables populated with all elements in
-    * ResourceIterator
-    */
-   public Vector getContactVectorFromIterator(ResourceIterator results) {
-
-      // new Vector instance to be returned
-      Vector vector = new Vector();
-      try {
-         while (results.hasMoreResources()) {
-
-            // Create an XObject to be used in Xpath query
-            XObject xo = new XObject();
-            // Create a new hastable to store into vector
-            Hashtable table = new Hashtable();
-
-            // Retrieve the next node
-            XMLResource resource = (XMLResource) results.nextResource();
-            Node originalnode = resource.getContentAsDOM();
-
-            // Get the document key for this node for later use
-            String dockey = resource.getDocumentId();
-            table.put("dockey", dockey);
-
-            // Use Xalan xpath parser to extract data, store into hastable
-            xo = XPathAPI.eval(originalnode, "/person/fname");
-            table.put("fname", xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/lname");
-            table.put("lname", xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/phone[@type='work']");
-            table.put("workphone", xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/phone[@type='home']");
-            table.put("homephone", xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/phone[@type='cell']");
-            table.put("cellphone", xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/email[@type='home']");
-            table.put("homeemail", xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/email[@type='work']");
-            table.put("workemail", xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/address[@type='home']");
-            table.put("homeaddress", xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/address[@type='work']");
-            table.put("workaddress", xo.toString());
-
-            // Add hashtable to vector to pass on to JSP page
-            vector.add(table);
-         }
-
-      }
-      catch (Exception e) {
-         e.printStackTrace();
-      }
-
-      return vector;
-   }
-
-   /**
-    * Create a String XML document from passed in parameters
-    */
-   public String toXml(String fname, String lname, String workphone,
-         String homephone, String cellphone, String homeemail, String workemail,
-         String homeaddress, String workaddress) {
-
-      String ourdoc;
-
-      // Build up the string to represent our document
-      ourdoc = "<person>";
-      ourdoc = ourdoc + "<fname>" + fname + "</fname>";
-      ourdoc = ourdoc + "<lname>" + lname + "</lname>";
-      ourdoc = ourdoc + "<phone type='work'>" + workphone + "</phone>";
-      ourdoc = ourdoc + "<phone type='home'>" + homephone + "</phone>";
-      ourdoc = ourdoc + "<phone type='cell'>" + cellphone + "</phone>";
-      ourdoc = ourdoc + "<email type='home'>" + homeemail + "</email>";
-      ourdoc = ourdoc + "<email type='work'>" + workemail + "</email>";
-      ourdoc = ourdoc + "<address type='home'>" + homeaddress + "</address>";
-      ourdoc = ourdoc + "<address type='work'>" + workaddress + "</address>";
-      ourdoc = ourdoc + "</person>";
-
-      // Return the created XML string
-      return ourdoc;
-   }
+        }
 
+        return buf.toString();
+    }
 }
 

Added: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/CollectionCheck.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/CollectionCheck.java?rev=705950&view=auto
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/CollectionCheck.java (added)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/CollectionCheck.java Sat Oct 18 18:57:36 2008
@@ -0,0 +1,92 @@
+package addressbook;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+import org.xmldb.api.base.ErrorCodes;
+import org.xmldb.api.base.XMLDBException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+
+/**
+ * CollectionCheck verifies that application can access Xindice database and
+ * collection exists. Normally, functionality like this is not needed,
+ * an application supposed to be configured correctly before being deployed.
+ * However, this class helps reduce number of steps necessary to get the
+ * Address Book example working.
+ *
+ */
+public class CollectionCheck implements Filter {
+    private boolean success;
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+        String hostname = filterConfig.getServletContext().getInitParameter("default_collection_hostname");
+        String port = filterConfig.getServletContext().getInitParameter("default_collection_port");
+
+        DBConnection.setup(hostname, port);
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+        if (success) {
+            chain.doFilter(request, response);
+            return;
+        }
+
+        DBConnection connection = new DBConnection();
+        try {
+            connection.getCollectionInstance(Action.COLLECTION_NAME);
+
+            success = true;
+            chain.doFilter(request, response);
+        } catch (XMLDBException e) {
+
+            switch (e.errorCode) {
+                case ErrorCodes.INVALID_URI:
+                case ErrorCodes.UNKNOWN_ERROR:
+                    // could not connect to database
+                    request.getRequestDispatcher("/setup.jsp").forward(request, response);
+                    break;
+                case ErrorCodes.NO_SUCH_DATABASE:
+                case ErrorCodes.NO_SUCH_COLLECTION:
+                    // collection has not been created
+                    request.getRequestDispatcher("/initialize.jsp").forward(request, response);
+                    break;
+                default:
+                    request.setAttribute("error", e);
+                    request.getRequestDispatcher("/error.jsp").forward(request, response);
+                    break;
+            }
+
+        } catch (ServletException e) {
+            throw e;
+        } catch (Exception e) {
+            request.setAttribute("error", e);
+            request.getRequestDispatcher("/error.jsp").forward(request, response);
+        }
+    }
+
+    public void destroy() {
+    }
+}

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/CollectionCheck.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/CollectionCheck.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/CollectionCheck.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Modified: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DBConnection.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DBConnection.java?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DBConnection.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DBConnection.java Sat Oct 18 18:57:36 2008
@@ -18,59 +18,82 @@
  *
  * $Id$
  */
- 
-import java.net.URLEncoder;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.xmldb.api.DatabaseManager;
 import org.xmldb.api.base.Collection;
 import org.xmldb.api.base.Database;
+import org.xmldb.api.base.XMLDBException;
+import org.xmldb.api.base.ErrorCodes;
 
 /**
-Singleton class used to hold system wide instances of database connection
-and Collection object
-*/
-public class DBConnection extends HttpServlet {
-
-   // Collection manager path to instantiate
-   public static final String XINDICEURI="xindice:///db/";
-   public static final String COLLECTIONURI="xmldb:" + XINDICEURI;
-   String colstring = COLLECTIONURI + "addressbook";
-   
-   protected static DBConnection connection = new DBConnection();
-   protected static Database db = null;
-   protected static Collection collection = null;
-
-   public Collection getCollectionInstance(HttpServletRequest request, HttpServletResponse response ) throws javax.servlet.ServletException, java.io.IOException {
-   
-      try {
-         if ( db == null ) {
+ * Class used to hold system wide instances of database connection
+ * and Collection object
+ */
+public class DBConnection {
+    // Xindice DB hostname
+    private static String hostname;
+    // Xindice DB port
+    private static String port;
+
+    private static Database db = null;
+    private Collection collection = null;
+
+    public static void setup(String host, String port) {
+        hostname = host;
+        DBConnection.port = port;
+    }
+
+    public static String getHostname() {
+        return hostname;
+    }
+
+    public static String getPort() {
+        return port;
+    }
+
+    // Get full addressbook collection URL
+    public static String getCollectionURL() {
+        return "xmldb:xindice://" + hostname + ':' + port + Action.COLLECTION_NAME;
+    }
+
+    // Get URL of parent collection
+    public static String getParentCollectionURL() {
+        return "xmldb:xindice://" + hostname + ':' + port + splitCollectionName(Action.COLLECTION_NAME)[0];
+    }
+
+    public static String[] splitCollectionName(String collectionName) {
+        String[] names = collectionName.split("/", 0);
+
+        if (names.length < 3) {
+            throw new IllegalArgumentException("Collection name must be canonical and include database name");
+        }
+
+        StringBuffer buf = new StringBuffer();
+        for(int i = 1; i < names.length - 1; i++) {
+            buf.append('/').append(names[i]);
+        }
+
+        return new String[] { buf.toString(), names[names.length - 1]};
+    }
+
+    public Collection getCollectionInstance(String colPath) throws Exception {
+        if (collection == null) {
+            if (db != null) {
+                DatabaseManager.deregisterDatabase(db);
+            }
             
             // Register the dbxml database handler
-            db = (Database)Class.forName("org.apache.xindice.client.xmldb.DatabaseImpl").newInstance();
+            db = (Database) Class.forName("org.apache.xindice.client.xmldb.DatabaseImpl").newInstance();
             DatabaseManager.registerDatabase(db);
+
             // Get a collection instance
-            collection = DatabaseManager.getCollection( colstring );
-         }
-   
-      } catch ( Exception e) {
-         e.printStackTrace();
-
-	  // there's not much else we can do if the response is committed
-	  if (response.isCommitted())
-	     return collection;
-
-         // Catch the exception and send the user to the error page
-         if (e.getMessage() != null ) {
-            response.sendRedirect("/addressbook/error.jsp?error=" + URLEncoder.encode(e.getMessage(), "UTF-8"));
-         } else {
-            response.sendRedirect("/addressbook/error.jsp");
-         }
-      }
-      
-      return collection;
-   }
+            collection = DatabaseManager.getCollection("xmldb:xindice://" + hostname + ':' + port + colPath);
+
+            if (collection == null) {
+                throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION);
+            }
+        }
+
+        return collection;
+    }
 }

Modified: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DeleteContact.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DeleteContact.java?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DeleteContact.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/DeleteContact.java Sat Oct 18 18:57:36 2008
@@ -18,61 +18,30 @@
  *
  * $Id$
  */
- 
-import java.io.IOException;
-import java.net.URLEncoder;
 
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
 
 import org.xmldb.api.base.Collection;
+import org.xmldb.api.modules.XMLResource;
 
-// Class for deleting records from the database
+/**
+ * Class for deleting records from the database
+ */
 public class DeleteContact extends Action {
 
-   // Delete the document with a key value of request.index
-   public boolean delete(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
-   
-      Collection col;
-      try {
-         // Get a reference to the session
-         HttpSession session = request.getSession(true);
-   
-         // Get a collection instance
-         col = getCollection(request,response);
-                  
-         // Get the index we are going to delete
-         int index = Integer.parseInt(request.getParameter("index"));
-         
-         // Pull the Group out of the session, and get the Person instance at the Index
-         Group group = (Group)session.getAttribute("group");
-         Person person = group.getPersonAt(index);
-         
-         // Get the documentKey for this particular Person
-         String dockey = person.getDocKey();
-         
-         // Delete the document
-         col.removeResource(col.getResource(dockey) );
-         
-      } catch (Exception e) {
-          e.printStackTrace();
-
-          // there's not much else we can do if the response is committed
-          if (response.isCommitted()) {
-              return true;
-          }
-
-         // Catch the exception and send the user to the error page
-         if (e.getMessage() != null ) {
-            response.sendRedirect("/addressbook/error.jsp?error=" + URLEncoder.encode(e.getMessage(), "UTF-8"));
-         } else {
-            response.sendRedirect("/addressbook/error.jsp");
-         }
-      }
+    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // Get a collection instance
+        Collection col = getCollection();
+
+        // Get the document key of the resource we are going to delete
+        String key = request.getParameter("key");
+
+        // Delete the document
+        XMLResource resource = (XMLResource) col.createResource(key, "XMLResource");
+        col.removeResource(resource);
 
-      return true;
-   }
+        response.sendRedirect("Task?action=listcontacts");
+    }
 }
 

Added: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/GetContact.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/GetContact.java?rev=705950&view=auto
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/GetContact.java (added)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/GetContact.java Sat Oct 18 18:57:36 2008
@@ -0,0 +1,55 @@
+package addressbook;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+import org.xmldb.api.base.Collection;
+import org.xmldb.api.modules.XMLResource;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Class to retrieve a contact from the database
+ */
+public class GetContact extends Action {
+
+    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // Get a collection instance
+        Collection col = getCollection();
+
+        // Get the document key of the resource requested
+        String key = request.getParameter("key");
+        XMLResource resource = (XMLResource) col.getResource(key);
+
+        if (resource == null) {
+            throw new Exception("Resource '" + key + "' does not exist in " + COLLECTION_NAME);
+        }
+        request.setAttribute("person", xmlToPerson(resource));
+
+        String action = request.getParameter("action").toLowerCase();
+        if (action.equals("editcontact")) {
+            request.getRequestDispatcher("/contactForm.jsp").forward(request, response);
+        } else if (action.equals("showxml")) {
+            request.getRequestDispatcher("/showXML.jsp").forward(request, response);
+        } else {
+            request.getRequestDispatcher("/showContact.jsp").forward(request, response);
+        }
+    }
+}

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/GetContact.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/GetContact.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/GetContact.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Modified: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Group.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Group.java?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Group.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Group.java Sat Oct 18 18:57:36 2008
@@ -19,144 +19,42 @@
  * $Id$
  */
 
-import java.util.Vector;
-
-import org.apache.xpath.XPathAPI;
-import org.apache.xpath.objects.XObject;
-import org.w3c.dom.Node;
-import org.xmldb.api.base.ResourceIterator;
-import org.xmldb.api.modules.XMLResource;
+import java.util.ArrayList;
+import java.util.Iterator;
 
 /**
  * Class for holding groups of the Person class
  */
 public class Group {
 
-   private Vector personList = new Vector();
-   private int index = 0;
-
-   /**
-    * Returns current index
-    */
-   public int getIndex() {
-      return index - 1;
-   }
-
-   /**
-    * Return the next person from the list
-    */
-   public Person getNext() {
-      Person person = (Person) personList.get(index);
-      index = index + 1;
-      return person;
-   }
-
-   /**
-    * Return the person element at a certain index
-    */
-   public Person getPersonAt(int i) {
-      return (Person) personList.get(i);
-   }
-
-   /**
-    * Add person to Group
-    */
-   public void add(Person person) {
-      personList.add(person);
-   }
-
-   /**
-    * Add Persons from Result set
-    */
-   public void addResults(ResourceIterator results) {
-      try {
-         while (results.hasMoreResources()) {
-
-            // Create a new person instance to add to Group
-            Person person = new Person();
-
-            // Retrieve the next node
-            XMLResource resource = (XMLResource) results.nextResource();
-            // Cast to Dom Node
-            Node originalnode = resource.getContentAsDOM();
-
-            // Get the document key for this node for later use
-            String dockey = resource.getDocumentId();
-            person.setDocKey(dockey);
-
-            // Use Xalan xpath parser to extract data, store into hastable
-            XObject xo = new XObject();
-
-            xo = XPathAPI.eval(originalnode, "/person/fname");
-            person.setFname(xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/lname");
-            person.setLname(xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/phone[@type='work']");
-            person.setWorkPhone(xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/phone[@type='home']");
-            person.setHomePhone(xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/phone[@type='cell']");
-            person.setCellPhone(xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/email[@type='home']");
-            person.setHomeEmail(xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/email[@type='work']");
-            person.setWorkEmail(xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/address[@type='home']");
-            person.setHomeAddress(xo.toString());
-
-            xo = XPathAPI.eval(originalnode, "/person/address[@type='work']");
-            person.setWorkAddress(xo.toString());
-
-            // Add person to group
-            this.add(person);
-         }
-      }
-      catch (Exception e) {
-         e.printStackTrace();
-      }
-
-   }
-
-   /**
-    * Remove Person from Group
-    */
-   public void remove(int i) {
-      personList.remove(i);
-   }
-
-   /**
-    * Remove all Persons from Group
-    */
-   public void removeAll() {
-      personList.removeAllElements();
-   }
-
-   /**
-    * Return the size of the Group
-    */
-   public int sizeOf() {
-      return personList.size();
-   }
-
-   /**
-    * Reset counter for Person retrieval
-    */
-   public void reset() {
-      index = 0;
-   }
-
-   /**
-    * Return true if more persons exist
-    */
-   public boolean hasMorePersons() {
-      return index < personList.size();
-   }
+    private ArrayList personList = new ArrayList();
+    /**
+     * Add person to Group
+     */
+    public void add(Person person) {
+        personList.add(person);
+    }
+
+    /**
+     * Get iterator for the group
+     * @return iterator
+     */
+    public Iterator iterator() {
+        return personList.iterator();
+    }
+
+    /**
+     * Remove all Persons from Group
+     */
+    public void clear() {
+        personList.clear();
+    }
+
+    /**
+     * Return the size of the Group
+     */
+    public int size() {
+        return personList.size();
+    }
 }
 

Added: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Layout.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Layout.java?rev=705950&view=auto
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Layout.java (added)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Layout.java Sat Oct 18 18:57:36 2008
@@ -0,0 +1,52 @@
+package addressbook;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.FilterChain;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+/**
+ * Filter to render layout for the page.
+ */
+public class Layout implements javax.servlet.Filter {
+    private String layout;
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+        layout = filterConfig.getInitParameter("layout");
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+        String path = ((HttpServletRequest) request).getServletPath();
+        if (!layout.equals(path) && !response.isCommitted()) {
+            request.setAttribute("content", path);
+            request.getRequestDispatcher(layout).forward(request, response);
+        } else {
+            chain.doFilter(request, response);
+        }
+    }
+
+    public void destroy() {
+    }
+}

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Layout.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Layout.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Layout.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Modified: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/ListContacts.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/ListContacts.java?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/ListContacts.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/ListContacts.java Sat Oct 18 18:57:36 2008
@@ -18,66 +18,32 @@
  *
  * $Id$
  */
- 
-import java.io.IOException;
-import java.net.URLEncoder;
 
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
 
 import org.xmldb.api.base.Collection;
-import org.xmldb.api.base.ResourceIterator;
-import org.xmldb.api.base.ResourceSet;
-import org.xmldb.api.modules.XPathQueryService;
+import org.xmldb.api.modules.XMLResource;
 
 /**
  * Class to list all contacts in the database
  */
 public class ListContacts extends Action {
 
-   public boolean list(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
-   
-      Collection col;
-      try {
-         // Get a reference to the session
-         HttpSession session = request.getSession(true);
-   
-         // Retrieve the Group instance from the session
-         Group group = (Group)session.getAttribute("group");
-   
-         // Get a collection instance
-         col = getCollection(request,response);
-   
-         XPathQueryService service = (XPathQueryService)col.getService("XPathQueryService",XMLDBAPIVERSION);
-   
-         // Get all Person elements from the database
-         ResourceSet resultSet = service.query("/person");
-         ResourceIterator results = resultSet.getIterator();
-         
-         // Clear out group object...
-         group.removeAll();
-         
-         // Add results of the Xpath query to the Group instance
-         group.addResults(results);
-         
-      } catch (Exception e) {
-          e.printStackTrace();
-
-          // there's not much else we can do if the response is committed
-          if (response.isCommitted()) {
-              return true;
-          }
-
-         // Catch the exception and send the user to the error page
-         if (e.getMessage() != null ) {
-            response.sendRedirect("/addressbook/error.jsp?error=" + URLEncoder.encode(e.getMessage(), "UTF-8"));
-         } else {
-            response.sendRedirect("/addressbook/error.jsp");
-         }
-      }
-            
-      return true;
-   }
+    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // Get a collection instance
+        Collection col = getCollection();
+
+        String[] resources = col.listResources();
+
+        // Add results to the Group instance
+        Group group = new Group();
+        for (int i = 0; i < resources.length; i++) {
+            XMLResource resource = (XMLResource) col.getResource(resources[i]);
+            group.add(xmlToPerson(resource));
+        }
+
+        request.setAttribute("group", group);
+        request.getRequestDispatcher("/listContacts.jsp").forward(request, response);
+    }
 }

Modified: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Person.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Person.java?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Person.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Person.java Sat Oct 18 18:57:36 2008
@@ -19,29 +19,31 @@
  * $Id$
  */
 
-// Class to hold individual contact data
+/**
+ * Class to hold individual contact data
+ */
 public class Person {
 
-   String dockey = null;
-   String fname = null;
-   String lname = null;
-   String workphone = null;
-   String homephone = null;
-   String cellphone = null;
-   String homeemail = null;
-   String workemail = null;
-   String homeaddress = null;
-   String workaddress = null;
-   
+    String dockey = "";
+    String fname = "";
+    String lname = "";
+    String workphone = "";
+    String homephone = "";
+    String cellphone = "";
+    String homeemail = "";
+    String workemail = "";
+    String homeaddress = "";
+    String workaddress = "";
+
    // Document Key
    public void setDocKey(String key) {
       dockey = key;
    }
-   
+
    public String getDocKey() {
       return dockey;
    }
-   
+
    // First Name
    public void setFname(String name) {
       fname = name;
@@ -50,77 +52,76 @@
    public String getFname() {
       return fname;
    }
-   
+
    // Last Name
    public void setLname(String name) {
       lname = name;
    }
-   
+
    public String getLname() {
       return lname;
    }
-   
+
    // Work Phone
    public void setWorkPhone(String phone) {
       workphone = phone;
    }
-   
+
    public String getWorkPhone() {
       return workphone;
    }
-   
+
    // Home Phone
    public void setHomePhone(String phone) {
       homephone = phone;
    }
-   
+
    public String getHomePhone() {
       return homephone;
    }
-   
+
    // Cell Phone
    public void setCellPhone(String phone) {
       cellphone = phone;
    }
-   
+
    public String getCellPhone() {
       return cellphone;
    }
-   
+
    // Home email
    public void setHomeEmail(String email) {
       homeemail = email;
    }
-   
+
    public String getHomeEmail() {
       return homeemail;
    }
-   
+
    // Work Email
    public void setWorkEmail(String email) {
       workemail = email;
    }
-   
+
    public String getWorkEmail() {
       return workemail;
    }
-   
+
    // Home Address
    public void setHomeAddress(String address) {
       homeaddress = address;
    }
-   
+
    public String getHomeAddress() {
       return homeaddress;
    }
-   
+
    // Work Address
    public void setWorkAddress(String address) {
       workaddress = address;
    }
-   
+
    public String getWorkAddress() {
       return workaddress;
    }
-
 }

Copied: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SaveContact.java (from r703899, xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/EditContact.java)
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SaveContact.java?p2=xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SaveContact.java&p1=xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/EditContact.java&r1=703899&r2=705950&rev=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/EditContact.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SaveContact.java Sat Oct 18 18:57:36 2008
@@ -18,73 +18,70 @@
  *
  * $Id$
  */
- 
-import java.io.IOException;
-import java.net.URLEncoder;
 
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.xmldb.api.base.Collection;
 import org.xmldb.api.modules.XMLResource;
+import org.xml.sax.ContentHandler;
 
 /**
-Class for editing contact records in the database
-Record contents are replaced with values from form post.
-
-Future versions will use Xupdate to perform this function
-*/
-public class EditContact extends Action {
-
-   public boolean edit(HttpServletRequest request, HttpServletResponse response )
-         throws ServletException, IOException {
-         
-      Collection col;
-      String ourdoc;
-      try {
-         // Get the collection instance
-         col = getCollection(request,response);
-         
-         // Grab all parameters from form, store as strings
-         String dockey = request.getParameter("DOCKEY");
-         String fname = request.getParameter("FNAME");
-         String lname = request.getParameter("LNAME");
-         String workphone = request.getParameter("WORKPHONE");
-         String homephone = request.getParameter("HOMEPHONE");
-         String cellphone = request.getParameter("CELLPHONE");
-         String homeemail = request.getParameter("HOMEEMAIL");
-         String workemail = request.getParameter("WORKEMAIL");
-         String homeaddress = request.getParameter("HOMEADDRESS");
-         String workaddress = request.getParameter("WORKADDRESS");
-         
-         
-         // Create xml string from form values
-         ourdoc = toXml(fname,lname,workphone,homephone,cellphone,homeemail,workemail,
-                           homeaddress,workaddress);
-      
-         // Get the XMLResource and replace the content
-         XMLResource resource = (XMLResource) col.getResource(dockey);
-         resource.setContent(ourdoc);
-         col.storeResource(resource);
-         
-      } catch ( Exception e) {
-         e.printStackTrace();
-
-          // there's not much else we can do if the response is committed
-          if (response.isCommitted()) {
-              return true;
-          }
-
-         // Catch the exception and send the user to the error page
-         if (e.getMessage() != null ) {
-            response.sendRedirect("/addressbook/error.jsp?error=" + URLEncoder.encode(e.getMessage(), "UTF-8"));
-         } else {
-            response.sendRedirect("/addressbook/error.jsp");
-         }
-      }
+ * Class for editing/creating contact records in the database.
+ */
+public class SaveContact extends Action {
 
-      return true;
-   }
+    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // Get a copy of the collection instance
+        Collection col = getCollection();
+
+        // Grab all parameters from the form, store as strings
+        String docKey = request.getParameter("dockey");
+        String fname = request.getParameter("fname");
+        String lname = request.getParameter("lname");
+        String workphone = request.getParameter("workphone");
+        String homephone = request.getParameter("homephone");
+        String cellphone = request.getParameter("cellphone");
+        String homeemail = request.getParameter("homeemail");
+        String workemail = request.getParameter("workemail");
+        String homeaddress = request.getParameter("homeaddress");
+        String workaddress = request.getParameter("workaddress");
+
+        Person person = new Person();
+        person.setDocKey(docKey);
+        person.setFname(fname);
+        person.setLname(lname);
+        person.setWorkPhone(workphone);
+        person.setHomePhone(homephone);
+        person.setCellPhone(cellphone);
+        person.setHomeEmail(homeemail);
+        person.setWorkEmail(workemail);
+        person.setHomeAddress(homeaddress);
+        person.setWorkAddress(workaddress);
+
+        if ((fname == null || fname.length() == 0) && (lname == null || lname.length() == 0)) {
+            // person must have at least last of first name, otherwise UI won't show link to
+            // person's detailed information
+            request.setAttribute("person", person);
+            request.setAttribute("msg", "At least first or last name of a person is required");
+            request.getRequestDispatcher("/contactForm.jsp").forward(request, response);
+        } else {
+            // Create the XMLResource. If it was an existing record, document key will be set
+            // to the same value and the record will be updated. For the new record, document
+            // key will be empty and Xindice will generate unique key for that record.
+            XMLResource resource = (XMLResource) col.createResource(person.getDocKey(), "XMLResource");
+
+            // The content of the resource can be set as a String, as DOM object, or using SAX.
+            // The SAX and DOM content will be serialized by Xindice, adding necessary escaping,
+            // for example, converting symbol '<' to &lt;. If the content set as a string, it
+            // must contain valid XML document, meaning that all special symbols have to be escaped
+            // by client code. In this case, it is easier to use SAX.
+            ContentHandler handler = resource.setContentAsSAX();
+            personToXml(person, handler);
+            col.storeResource(resource);
+
+            response.sendRedirect("Task?action=listcontacts");
+        }
+    }
 }
 

Modified: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SearchContacts.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SearchContacts.java?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SearchContacts.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/SearchContacts.java Sat Oct 18 18:57:36 2008
@@ -18,129 +18,150 @@
  *
  * $Id$
  */
- 
-import java.io.IOException;
-import java.net.URLEncoder;
 
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
 
 import org.xmldb.api.base.Collection;
 import org.xmldb.api.base.ResourceIterator;
 import org.xmldb.api.base.ResourceSet;
 import org.xmldb.api.modules.XPathQueryService;
+import org.xmldb.api.modules.XMLResource;
+import org.w3c.dom.Element;
 
-// Class used to search the database using an Xpath query
+import java.util.LinkedList;
+import java.util.Iterator;
+
+/**
+ * Class used to search the database using an XPath query
+ */
 public class SearchContacts extends Action {
+    private static final String QUERY_NS = "http://xml.apache.org/xindice/Query";
+
+    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+        // Get a collection instance
+        Collection col = getCollection();
+
+        XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
 
-   public boolean attributeSearch(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
-   
-      Collection col;
-      String xpath = null;
-      try {
-          HttpSession session = request.getSession(true);
-   
-          // Get a collection instance
-          col = getCollection(request,response);
-   
-          XPathQueryService service = (XPathQueryService)col.getService("XPathQueryService",XMLDBAPIVERSION);
-         
-          // Get the seach parameters from the form
-          String searchtype = request.getParameter("SEARCHTYPE");
-          String searchstring = request.getParameter("SEARCHSTRING");
-         
-          // Setup xpath string depending on search type
-          if ( searchtype.equals("fname") || searchtype.equals("lname") ) {
-              xpath = "/person[" + searchtype + "='" + searchstring + "']";
-          } else if ( searchtype.equals("workphone")) {
-              xpath = "/person[phone/@type='work' and phone/text() = '" + searchstring + "' ]" ;
-          } else if ( searchtype.equals("homephone")) {
-              xpath = "/person[phone/@type='home' and phone/text() = '" + searchstring + "' ]" ;
-          } else if ( searchtype.equals("cellphone")) {
-              xpath = "/person[phone/@type='cell' and phone/text() = '" + searchstring + "' ]" ;
-          } else if ( searchtype.equals("homeemail")) {
-              xpath = "/person[email/@type='home' and email/text() = '" + searchstring + "' ]" ;
-          } else if ( searchtype.equals("workemail")) {
-              xpath = "/person[email/@type='work' and email/text() = '" + searchstring + "' ]" ;
-          } else if ( searchtype.equals("homeaddress")) {
-              xpath = "/person[address/@type='home' and address/text() = '" + searchstring + "' ]" ;
-          } else if ( searchtype.equals("workaddress")) {
-              xpath = "/person[address/@type='work' and address/text() = '" + searchstring + "' ]" ;
-          }
-         
-          ResourceSet resultSet = service.query(xpath);
-          ResourceIterator results = resultSet.getIterator();
-         
-          Group group = (Group)session.getAttribute("group");
-         
-          // Clear out group object...
-          group.removeAll();
-         
-          // Add results to Group instance
-          group.addResults(results);
-         
-      } catch(Exception e) {
-          e.printStackTrace();
-
-          // there's not much else we can do if the response is committed
-          if (response.isCommitted()) {
-              return true;
-          }
-
-          // Catch the exception and send the user to the error page
-          if (e.getMessage() != null ) {
-              response.sendRedirect("/addressbook/error.jsp?error=" + URLEncoder.encode(e.getMessage(), "UTF-8"));
-          } else {
-              response.sendRedirect("/addressbook/error.jsp");
-          }
-      }
-      
-      return true;
-   }
-
-   public boolean xpathSearch(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
-   
-       Collection col;
-       try {
-           HttpSession session = request.getSession(true);
-   
-           // Get a collection instance
-           col = getCollection(request,response);
-
-           XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", XMLDBAPIVERSION);
-
-           // Get the seach parameters from the form
-           String searchstring = request.getParameter("SEARCHSTRING");
-         
-           ResourceSet resultSet = service.query(searchstring);
-           ResourceIterator results = resultSet.getIterator();
-         
-           Group group = (Group)session.getAttribute("group");
-         
-           // Clear out group object...
-           group.removeAll();
-         
-           // Add results to Group instance
-           group.addResults(results);
-         
-       } catch(Exception e) {
-           e.printStackTrace();
-
-           // there's not much else we can do if the response is committed
-           if (response.isCommitted()) {
-               return true;
-           }
-
-           // Catch the exception and send the user to the error page
-           if (e.getMessage() != null ) {
-               response.sendRedirect("/addressbook/error.jsp?error=" + URLEncoder.encode(e.getMessage(), "UTF-8"));
-           } else {
-               response.sendRedirect("/addressbook/error.jsp");
-           }
-       }
-      
-       return true;
-   }
+        // Get the seach parameters from the form
+        String searchtype = request.getParameter("searchtype");
+        String searchstring = request.getParameter("searchstring");
+
+        String xpath = null;
+
+        // Generate XPath query string depending on search type
+        if (searchtype != null) {
+            // element value search
+
+            /*
+            Information recieved from the client (such as browser) must be sanitized if used as
+            part of the query to avoid XPath injection vulnerability and to make query work
+            if user enters string containing single-quote. See escape method for more info.
+            */
+            if (searchtype.equals("fname") || searchtype.equals("lname")) {
+                xpath = "/person[" + searchtype + " = " + escapeQuery(searchstring) + "]";
+            } else if (searchtype.equals("workphone")) {
+                xpath = "/person[phone/@type = 'work' and phone/text() = " + escapeQuery(searchstring) + "]";
+            } else if (searchtype.equals("homephone")) {
+                xpath = "/person[phone/@type = 'home' and phone/text() = " + escapeQuery(searchstring) + "]";
+            } else if (searchtype.equals("cellphone")) {
+                xpath = "/person[phone/@type = 'cell' and phone/text() = " + escapeQuery(searchstring) + "]";
+            } else if (searchtype.equals("homeemail")) {
+                xpath = "/person[email/@type = 'home' and email/text() = " + escapeQuery(searchstring) + "]";
+            } else if (searchtype.equals("workemail")) {
+                xpath = "/person[email/@type = 'work' and email/text() = " + escapeQuery(searchstring) + "]";
+            } else if (searchtype.equals("homeaddress")) {
+                xpath = "/person[address/@type = 'home' and address/text() = " + escapeQuery(searchstring) + "]";
+            } else if (searchtype.equals("workaddress")) {
+                xpath = "/person[address/@type = 'work' and address/text() = " + escapeQuery(searchstring) + "]";
+            }
+        } else {
+            // full XPath query
+            xpath = searchstring;
+        }
+
+        ResourceSet resultSet = service.query(xpath);
+        ResourceIterator results = resultSet.getIterator();
+
+        // Add results to Group instance
+        Group group = new Group();
+        while (results.hasMoreResources()) {
+            XMLResource resource = (XMLResource) results.nextResource();
+
+            /*
+            Check if search was for <person> element, such as "/person[phone/@type = 'work']",
+            as opposed to a query that searches for any other node, such as "/person/lname".
+            Application only knows how to show person records, so if any other node is found,
+            find corresponding person record by the key.
+            */
+            Element root = resource.getContentAsDOM().getOwnerDocument().getDocumentElement();
+            if (!"person".equals(root.getNodeName())) {
+                String key = root.getAttributeNS(QUERY_NS, "key");
+                resource = (XMLResource) col.getResource(key);
+            }
+
+            group.add(xmlToPerson(resource));
+        }
+
+        request.setAttribute("group", group);
+        request.setAttribute("xpath", xpath);
+        request.getRequestDispatcher("/listResults.jsp").forward(request, response);
+    }
+
+    /**
+     * Escape query parameter of type string. XPath uses single or double quotes to
+     * delimit strings, so any single or double quotes inside the string may cause
+     * problems. Unfortunately, XPath 1.0 does not define a way to escape a symbol,
+     * which means it cannot have literal string that contain both single and double
+     * quote.<br/>
+     * For strings that contain quotes, the following workaround is used: parameter
+     * string is split to pieces and every piece gets appropriate quotation
+     * delimiters. Resulting string then concatenated together using built-in XPath
+     * function concat().<br/>
+     * Examples:<br/>
+     * foo -> foo<br/>
+     * foo "bar" -> concat("foo ", '"', "bar", '"')<br/>
+     * foo 'bar" -> concat("foo ", "'", "bar", '"')<br/>
+     *
+     * @param param Query parameter of type string
+     * @return Escaped parameter
+     */
+    private String escapeQuery(String param) {
+        LinkedList list = new LinkedList();
+
+        int idx = 0;
+        do {
+            int idxApos = param.indexOf('\'', idx);
+            int idxQuot = param.indexOf('\"', idx);
+
+            int i = (idxQuot < 0 || (idxApos < idxQuot && idxApos >= 0)) ? idxApos : idxQuot;
+            if (i >= 0) {
+                list.add("\'" + param.substring(idx, i) + "\'");
+
+                char ch = param.charAt(i);
+                list.add(ch == '\"' ? "\'" + ch + "\'" : "\"" + ch + "\"");
+                idx = i + 1;
+            } else {
+                list.add("\'" + param.substring(idx) + "\'");
+                idx = param.length();
+            }
+        } while (idx < param.length());
+
+        if (list.size() == 1) {
+            return (String) list.getFirst();
+        } else {
+            StringBuffer buf = new StringBuffer("concat(");
+            for (Iterator i = list.iterator(); i.hasNext(); ) {
+                buf.append(i.next());
+                if (i.hasNext()) {
+                    buf.append(", ");
+                }
+            }
+            buf.append(')');
+
+            return buf.toString();
+        }
+    }
 }

Added: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Setup.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Setup.java?rev=705950&view=auto
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Setup.java (added)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Setup.java Sat Oct 18 18:57:36 2008
@@ -0,0 +1,77 @@
+package addressbook;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+import org.xmldb.api.base.Collection;
+import org.apache.xindice.client.xmldb.services.CollectionManager;
+import org.apache.xindice.xml.dom.DOMParser;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+/**
+ * Servlet to setup the database connection and initialize collection
+ */
+public class Setup extends HttpServlet {
+    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+        String action = request.getParameter("action");
+
+        if ("initialize".equals(action)) {
+            // create collection with basic configuration
+            String[] names = DBConnection.splitCollectionName(Action.COLLECTION_NAME);
+
+            try {
+                Collection parent = new DBConnection().getCollectionInstance(names[0]);
+                CollectionManager service = (CollectionManager) parent.getService("CollectionManager", "1.0");
+                String config = "<collection compressed='true' name='" + names[1] + "'>"
+                                + "<filer class='org.apache.xindice.core.filer.BTreeFiler'/>"
+                                + "</collection>";
+
+                service.createCollection(names[1], DOMParser.toDocument(config));
+                response.sendRedirect("index.jsp");
+            } catch (Exception e) {
+                request.setAttribute("error", e);
+                request.getRequestDispatcher("/error.jsp").forward(request, response);
+            }
+        } else {
+            // change connection parameters
+            String hostname = request.getParameter("hostname");
+            String port = request.getParameter("port");
+
+            if (hostname == null || hostname.length() == 0 || port == null || port.length() == 0) {
+                request.setAttribute("hostname", hostname);
+                request.setAttribute("port", port);
+                request.setAttribute("msg", "Please enter both host name and port number.");
+                request.getRequestDispatcher("/setup.jsp").forward(request, response);
+            } else {
+                DBConnection.setup(hostname, port);
+                response.sendRedirect("index.jsp");
+            }
+        }
+    }
+
+    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        doPost(request, response);
+    }
+}

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Setup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Setup.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Setup.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Modified: xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Task.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Task.java?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Task.java (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/java/addressbook/Task.java Sat Oct 18 18:57:36 2008
@@ -19,147 +19,57 @@
  * $Id$
  */
 
-import java.beans.Beans;
 import java.io.IOException;
-import java.net.URLEncoder;
+import java.util.HashMap;
 
-import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
+import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.servlet.jsp.JspFactory;
-import javax.servlet.jsp.PageContext;
 
 /**
-Servlet class for the addressbook
-
-This class acts as a controller, forwarding HTML request onto the correct class/jsp page
-depending on the value of request.action
-
-*/
+ * Main servlet class for the addressbook
+ * <p/>
+ * This class acts as a controller, forwarding HTML request onto the correct class/jsp page
+ * depending on the value of action parameter in the HTTP request
+ */
 public class Task extends HttpServlet {
+    // map of the actions that are executed depending on action parameter in request
+    private HashMap actions = new HashMap();
 
-   public void doPost(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
-
-       JspFactory jspFactory;
-       PageContext pageContext;
-       Group group;
-       String action;
-       try {
-           // If the Group bean hasn't been added to the session alerady, add it
-           // this allows the user to go directly to ANY page
-           jspFactory = JspFactory.getDefaultFactory();
-           pageContext = jspFactory.getPageContext(this, request, response, "/error.jsp", true, 8192, true );
-
-           group = (Group)pageContext.getAttribute("group",PageContext.SESSION_SCOPE);
-           if (group == null) {
-               group=(Group)Beans.instantiate(this.getClass().getClassLoader(), "addressbook.Group" );
-               pageContext.setAttribute("group", group, PageContext.SESSION_SCOPE );
-           }
-
-
-           // Since case matters, we need to check for both....
-           if ( request.getParameter("action") != null ) {
-               action = request.getParameter("action");
-           }
-           else {
-               action = request.getParameter("ACTION");
-           }
-
-           // Decide where to send the user depending on value of action
-           if ( action != null ) {
-               // Add a Contact
-               if ( action.equalsIgnoreCase("addform") ) {
-                   gotoPage("/addContact.jsp",request,response);
-               } else if ( action.equalsIgnoreCase("addcontact") ) {
-                   AddContact contact = new AddContact();
-                   contact.add(request,response);
-
-                   ListContacts lcontact = new ListContacts();
-                   lcontact.list(request,response);
-                   gotoPage("/listContacts.jsp",request,response);
-
-                   // List all contacts
-               } else if ( action.equalsIgnoreCase("listcontacts") ) {
-                   ListContacts contact = new ListContacts();
-                   contact.list(request,response);
-                   gotoPage("/listContacts.jsp",request,response);
-
-                   // Show individual Contact detail
-               } else if ( action.equalsIgnoreCase("showcontact") ) {
-                   gotoPage("/showContact.jsp",request,response);
-
-                   // Show individual XML file
-               } else if ( action.equalsIgnoreCase("showxml") ) {
-                   gotoPage("/showXML.jsp",request,response);
-
-                   // Edit a contact
-               } else if ( action.equalsIgnoreCase("editcontactform") ) {
-                   gotoPage("/editContactForm.jsp",request,response);
-               } else if ( action.equalsIgnoreCase("editcontact") ) {
-                   EditContact contact = new EditContact();
-                   contact.edit(request,response);
-
-                   ListContacts lcontact = new ListContacts();
-                   lcontact.list(request,response);
-                   gotoPage("/listContacts.jsp",request,response);
-
-                   // Search for a contact
-               } else if ( action.equalsIgnoreCase("searchform") ) {
-                   gotoPage("/searchContacts.jsp",request,response);
-               } else if ( action.equalsIgnoreCase("attributesearch") ) {
-                   SearchContacts contact = new SearchContacts();
-                   contact.attributeSearch(request,response);
-                   gotoPage("/listContacts.jsp",request,response);
-               } else if ( action.equalsIgnoreCase("xpathsearch") ) {
-                   SearchContacts contact = new SearchContacts();
-                   contact.xpathSearch(request,response);
-                   gotoPage("/listContacts.jsp",request,response);
-
-                   // Delete a contact
-               } else if ( action.equalsIgnoreCase("deletecontact") ) {
-                   DeleteContact contact = new DeleteContact();
-                   contact.delete(request,response);
-
-                   ListContacts lcontact = new ListContacts();
-                   lcontact.list(request,response);
-                   gotoPage("/listContacts.jsp",request,response);
-
-               } else gotoPage("/error.jsp",request,response);
-           }
-           else {
-               gotoPage("/error.jsp",request,response);
-           }
-
-       } catch (Exception e) {
-           e.printStackTrace();
-
-           // there's not much else we can do if the response is committed
-           if (response.isCommitted())
-               return;
-
-           // Catch the exception and send the user to the error page
-           if (e.getMessage() != null) {
-               response.sendRedirect("/addressbook/error.jsp?error=" + URLEncoder.encode(e.getMessage(), "UTF-8"));
-           } else {
-               response.sendRedirect("/addressbook/error.jsp");
-           }
-       }
-   }
-
-    // Treat a form-get as a post, seding user to doPost
-    public void doGet(HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
-
-        doPost(request,response);
+    public void init(ServletConfig servletConfig) throws ServletException {
+        super.init(servletConfig);
 
+        // initialize actions
+        actions.put("listcontacts", new ListContacts());
+        actions.put("getcontact", new GetContact());
+        actions.put("editcontact", new GetContact());
+        actions.put("showxml", new GetContact());
+        actions.put("deletecontact", new DeleteContact());
+        actions.put("savecontact", new SaveContact());
+        actions.put("xpathsearch", new SearchContacts());
     }
 
-    // Forward the user on to the pages specified in address
-    private void gotoPage( String address, HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
-
-        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(address);
-        dispatcher.forward(request, response);
+    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        try {
+            String action = request.getParameter("action").toLowerCase();
+
+            if (actions.containsKey(action)) {
+                ((Action) actions.get(action)).process(request, response);
+            } else {
+                request.getRequestDispatcher("/error.jsp").forward(request, response);
+            }
+        } catch (ServletException e) {
+            throw e;
+        } catch (Exception e) {
+            request.setAttribute("error", e);
+            request.getRequestDispatcher("/error.jsp").forward(request, response);
+        }
+    }
 
+    // Treat a form-get as a post, seding user to doPost
+    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        doPost(request, response);
     }
 }

Added: xml/xindice/trunk/java/examples/addressbook/src/jsp/addressbook.css
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/jsp/addressbook.css?rev=705950&view=auto
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/jsp/addressbook.css (added)
+++ xml/xindice/trunk/java/examples/addressbook/src/jsp/addressbook.css Sat Oct 18 18:57:36 2008
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id: editContactForm.jsp 511428 2007-02-25 03:30:52Z vgritsenko $
+ */
+
+:visited {
+    color: #5555FF;
+}
+
+:link {
+    color: #5555FF;
+}
+
+h1 {
+    text-align: center;
+    background-color: #C8C8FF;
+    border: 1px solid #5555FF;
+    font-weight: bold;
+    margin-bottom: 2px;
+    font-size: medium;
+}
+
+h2 {
+    text-align: center;
+    font-weight: bold;
+    margin-bottom: 1em;
+    font-size: medium;
+    color: gray;
+}
+
+h3 {
+    text-align: left;
+    font-weight: bold;
+    margin-bottom: 2px;
+    font-size: medium;
+    color: gray;
+}
+
+div.title {
+    text-align: center;
+    background-color: #C8C8FF;
+    border-bottom: 1px solid #5555FF;
+    font-weight: bold;
+    font-size:medium;
+}
+
+#menu {
+    float: left;
+    background-color: #F0F0FF;
+    border: 1px solid #5555FF;
+    width: 195px;
+}
+
+#menu a {
+    margin: 10px 20px 10px 10px;
+    display: block;
+}
+
+#content {
+    display: block;
+    vertical-align:top;
+    background-color: #F0F0FF;
+    border: 1px solid #5555FF;
+    margin-left: 200px;
+    min-height: 500px;
+    padding: 10px 10px 30px 10px;
+}
+
+.msg {
+    background-color: #F0F0FF;
+    border: 1px solid #5555FF;
+    float: left;
+    clear: left;
+    width: 175px;
+    margin-top: 2px;
+    font-weight: bold;
+    padding: 10px;
+    color: red;
+}
+
+p.introduction {
+    font-weight: bold;
+}
+
+table.list {
+    width: 95%;
+    border-collapse: collapse;
+    margin: auto;
+}
+
+table.list th {
+    text-align: left;
+    font-weight: normal;
+    background-color: #C8C8FF;
+}
+
+table.list td {
+    border-bottom: 1px solid #C8C8C8;
+    padding: 0px 5px 1px 5px;
+}
+
+select {
+    min-width: 100px;
+    border: 1px solid #C8C8FF;
+}
+
+div.property {
+    display: block;
+    margin-bottom: 5px;
+    border-bottom: 1px solid #C8C8C8;
+}
+
+span.label, label {
+    display: inline-block;
+    font-weight: bold;
+    padding-right: 5px;
+    width: 130px;
+    white-space: pre;
+}
+
+span.value {
+    display: inline;
+}
+
+.note {
+    font-style: italic;
+}
+
+.error {
+    white-space: pre;
+}
+
+.code {
+    font-weight:bolder;
+    white-space: nowrap;
+}
+
+.actions a {
+    padding-right: 20px;
+}

Propchange: xml/xindice/trunk/java/examples/addressbook/src/jsp/addressbook.css
------------------------------------------------------------------------------
    svn:executable = *

Copied: xml/xindice/trunk/java/examples/addressbook/src/jsp/contactForm.jsp (from r703899, xml/xindice/trunk/java/examples/addressbook/src/jsp/editContactForm.jsp)
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/jsp/contactForm.jsp?p2=xml/xindice/trunk/java/examples/addressbook/src/jsp/contactForm.jsp&p1=xml/xindice/trunk/java/examples/addressbook/src/jsp/editContactForm.jsp&r1=703899&r2=705950&rev=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/jsp/editContactForm.jsp (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/jsp/contactForm.jsp Sat Oct 18 18:57:36 2008
@@ -19,75 +19,52 @@
  */
 %>
 
-<%@ include file="header.jsp" %>
+<jsp:useBean id="person" class="addressbook.Person" scope="request"/>
 
-<%@ page session="true" %>
-<%@ page import="javax.servlet.http.HttpSession, java.io.* , java.util.*" %>
+<h2>Contact Information</h2>
 
+<form action="Task" method="post">
+    <div>
+        <input type="hidden" name="action" value="savecontact">
+        <input type="hidden" name="dockey" value="<%=person.getDocKey()%>">
+        <div class="property">
+            <label for="fname">First Name</label>
+            <span class="value"><input id="fname" type="text" name="fname" value="<%=person.getFname()%>" size="40"></span>
+        </div>
+        <div class="property">
+            <label for="lname">Last Name</label>
+            <span class="value"><input id="lname" type="text" name="lname" value="<%=person.getLname()%>" size="40"></span>
+        </div>
+        <div class="property">
+            <label for="workphone">Work Phone</label>
+            <span class="value"><input id="workphone" type="text" name="workphone" value="<%=person.getWorkPhone()%>" size="18"></span>
+        </div>
+        <div class="property">
+            <label for="homephone">Home Phone</label>
+            <span class="value"><input id="homephone" type="text" name="homephone" value="<%=person.getHomePhone()%>" size="18"></span>
+        </div>
+        <div class="property">
+            <label for="cellphone">Cell Phone</label>
+            <span class="value"><input id="cellphone" type="text" name="cellphone" value="<%=person.getCellPhone()%>" size="18"></span>
+        </div>
+        <div class="property">
+            <label for="homeemail">Home Email</label>
+            <span class="value"><input id="homeemail" type="text" name="homeemail" value="<%=person.getHomeEmail()%>" size="25"></span>
+        </div>
+        <div class="property">
+            <label for="workemail">Work Email</label>
+            <span class="value"><input id="workemail" type="text" name="workemail" value="<%=person.getWorkEmail()%>" size="25"></span>
+        </div>
+        <div class="property">
+            <label for="homeaddress">Home Address</label>
+            <span class="value"><input id="homeaddress" type="text" name="homeaddress" value="<%=person.getHomeAddress()%>" size="50"></span>
+        </div>
+        <div class="property">
+            <label for="workaddress">Work Address</label>
+            <span class="value"><input id="workaddress" type="text" name="workaddress" value="<%=person.getWorkAddress()%>" size="50"></span>
+        </div>
+
+        <input type="submit" name="action" value="Save">
+    </div>
+</form>
 
-<%
-   int index = Integer.parseInt((String)request.getParameter("index"));
-
-   person = group.getPersonAt(index);
-%>
-
-<FONT SIZE="+2">
-   <CENTER>Edit Contact Information</CENTER>
-</FONT>
-
-
-<FORM NAME="editcontact" ACTION="/addressbook/Task" METHOD="POST">
-   <INPUT TYPE="HIDDEN" NAME="ACTION" VALUE="EDITCONTACT">
-   <INPUT TYPE="HIDDEN" NAME="DOCKEY" VALUE="<%= person.getDocKey() %>" >
-   <TABLE>
-      <TR>
-         <TD>&nbsp;</TD>
-      </TR>
-      <TR>
-         <TD>First Name</TD>
-         <TD> <INPUT TYPE="TEXT" VALUE="<%= person.getFname() %>" NAME="FNAME" SIZE="40"> </TD>
-      </TR>
-      <TR>
-         <TD>Last Name</TD>
-         <TD><INPUT TYPE="TEXT" VALUE="<%= person.getLname() %>" NAME="LNAME" SIZE="40"></TD>
-      </TR>
-      <TR>
-         <TD>Work Phone</TD>
-         <TD><INPUT TYPE="TEXT" VALUE="<%= person.getWorkPhone() %>" NAME="WORKPHONE" SIZE="18"></TD>
-      </TR>
-      <TR>
-         <TD>Home Phone</TD>
-         <TD><INPUT TYPE="TEXT" VALUE="<%= person.getHomePhone() %> "NAME="HOMEPHONE" SIZE="18"></TD>
-      </TR>
-      <TR>
-         <TD>Cell Phone</TD>
-         <TD><INPUT TYPE="TEXT" VALUE="<%= person.getCellPhone() %>" NAME="CELLPHONE" SIZE="18"></TD>
-      </TR>
-      <TR>
-         <TD>Home Email</TD>
-         <TD><INPUT TYPE="TEXT" VALUE="<%= person.getHomeEmail() %>" NAME="HOMEEMAIL" SIZE="25"></TD>
-      </TR>
-      <TR>
-         <TD>Work Email</TD>
-         <TD><INPUT TYPE="TEXT" VALUE="<%= person.getWorkEmail() %>" NAME="WORKEMAIL" SIZE="25"></TD>
-      </TR>
-      <TR>
-         <TD>Home Address</TD>
-         <TD><INPUT TYPE="TEXT" VALUE="<%= person.getHomeAddress() %>" NAME="HOMEADDRESS" SIZE="50"></TD>
-      </TR>
-      <TR>
-         <TD>Work Address</TD>
-         <TD><INPUT TYPE="TEXT" VALUE="<%= person.getWorkAddress() %>" NAME="WORKADDRESS" SIZE="50"></TD>
-      </TR>
-      <TR>
-         <TD>
-            &nbsp;
-         </TD>
-      </TR>
-      <TR>
-         <TD><INPUT TYPE="SUBMIT" NAME="ACTION" VALUE="SAVE"></TD>
-      </TR>
-   </TABLE>
-</FORM>
-
-<%@ include file="footer.jsp" %>

Modified: xml/xindice/trunk/java/examples/addressbook/src/jsp/error.jsp
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/examples/addressbook/src/jsp/error.jsp?rev=705950&r1=705949&r2=705950&view=diff
==============================================================================
--- xml/xindice/trunk/java/examples/addressbook/src/jsp/error.jsp (original)
+++ xml/xindice/trunk/java/examples/addressbook/src/jsp/error.jsp Sat Oct 18 18:57:36 2008
@@ -18,22 +18,16 @@
  * $Id$
  */
 %>
-
-<%@ include file="header.jsp" %>
-
-   <FONT SIZE="+1">
-      <CENTER>
-         <FONT COLOR="RED">An ERROR has occured!!!</FONT>
-         <BR>
-         <BR>
-         <%
-            String error = request.getParameter("error") ;
-            if ( error != null ) {
-               out.println( error );
-            }
-         %>
-
-      </CENTER>
-   </FONT>
-   
-<%@ include file="footer.jsp" %>
+<p>An error has occured while processing the request.</p>
+<%
+    Exception error = (Exception) request.getAttribute("error") ;
+    if (error != null) {
+%>
+<div class="error">
+<%
+    out.flush(); error.printStackTrace(response.getWriter());
+%>
+</div>
+<%
+    }
+%>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.