Package addressbook

Source Code of addressbook.EditContact

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: EditContact.java 511428 2007-02-25 03:30:52Z vgritsenko $
*/
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;

/**
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 = null;
      String ourdoc = null;
     
      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()) );
         }
         else {
            response.sendRedirect("/addressbook/error.jsp" );
         }
      }

      return true;
   }
}
TOP

Related Classes of addressbook.EditContact

TOP
Copyright © 2018 www.massapi.com. 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.