com.bluexml.xforms.servlets.DeleteServlet.java Source code

Java tutorial

Introduction

Here is the source code for com.bluexml.xforms.servlets.DeleteServlet.java

Source

/*
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 com.bluexml.xforms.controller.alfresco.AlfrescoController;
import com.bluexml.xforms.controller.alfresco.AlfrescoTransaction;
import com.bluexml.xforms.messages.MsgId;

/**
 * The Class DeleteServlet. via GET method @ http://HostAndPort/xforms/delete?...<br>
 */
public class DeleteServlet extends AbstractServlet {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = -7533187086201472710L;

    /* (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 {
        delete(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 {
        delete(req);
    }

    /**
     * Delete.
     * 
     * @param req
     *            the req
     * @throws ServletException
     *             the servlet exception
     */
    protected void delete(HttpServletRequest req) throws ServletException {
        AlfrescoController controller = AlfrescoController.getInstance();
        try {
            String dataId = StringUtils.trimToNull(req.getParameter(DATA_ID));
            dataId = controller.patchDataId(dataId);
            String userName = req.getParameter(MsgId.PARAM_USER_NAME.getText());
            AlfrescoTransaction transaction = createTransaction(controller, userName);
            controller.delete(transaction, dataId);
            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 - DeleteServlet initialized.");
    }

}