2 * Copyright 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server.rest;
21 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
22 import gr.ebs.gss.client.exceptions.RpcException;
23 import gr.ebs.gss.server.domain.User;
25 import java.io.IOException;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.json.JSONArray;
37 * A class that handles operations on the 'tags' namespace.
41 public class TagsHandler extends RequestHandler {
45 private static Log logger = LogFactory.getLog(TagsHandler.class);
48 * Serve the tags defined by the user.
50 * @param req The servlet request we are processing
51 * @param resp The servlet response we are processing
52 * @throws IOException if an input/output error occurs
54 void serveTags(HttpServletRequest req, HttpServletResponse resp) throws IOException {
55 String path = getInnerPath(req, PATH_TAGS);
59 if (path.equals("/")) {
62 User user = getUser(req);
63 User owner = getOwner(req);
64 if (!owner.equals(user)) {
65 resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
68 tags = getService().getUserTags(user.getId());
69 } catch (ObjectNotFoundException e) {
70 logger.error("User not found", e);
71 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
73 } catch (RpcException e) {
75 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
78 JSONArray json = new JSONArray();
79 for (String tag: tags)
82 sendJson(req, resp, json.toString());
84 resp.sendError(HttpServletResponse.SC_NOT_FOUND);