Java tutorial
/* Copyright (C) 2007-2011 BlueXML - www.bluexml.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.bluexml.xforms.servlets; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.w3c.dom.Node; import com.bluexml.xforms.controller.alfresco.AlfrescoController; import com.bluexml.xforms.controller.alfresco.AlfrescoTransaction; import com.bluexml.xforms.messages.MsgId; /** * The Class UpdateServlet. via GET method @ http://HostAndPort/xforms/update?...<br> */ public class UpdateServlet extends AbstractServlet { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 3093330611732814842L; /* (non-Javadoc) * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { update(req); } /* (non-Javadoc) * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException { update(req); } /** * Update. * * @param req * the req * @throws ServletException * the servlet exception */ protected void update(HttpServletRequest req) throws ServletException { AlfrescoController controller = AlfrescoController.getInstance(); try { Node node = getDocumentReq(req); String skipIdStr = StringUtils.trimToNull(req.getParameter(ID_AS_SERVLET)); boolean idAsServlet = !StringUtils.equals(skipIdStr, "false"); String userName = req.getParameter(MsgId.PARAM_USER_NAME.getText()); AlfrescoTransaction transaction = createTransaction(controller, userName); controller.persistClass(transaction, node, idAsServlet, null); transaction.executeBatch(); } catch (Exception e) { throw new ServletException(e); } } /* (non-Javadoc) * @see javax.servlet.GenericServlet#init() */ @Override public void init() throws ServletException { super.init(); System.out.println("BlueXML XForms - UpdateServlet initialized."); } }