BrightSide Workbench Full Report + Source Code
PivotServices.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.pivot.servlet;
19 
20 import java.io.File;
21 import java.io.IOException;
22 import java.net.URL;
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import org.apache.pivot.collections.ArrayList;
27 import org.apache.pivot.collections.adapter.ListAdapter;
28 import org.apache.pivot.io.FileSerializer;
29 import org.apache.pivot.serialization.BinarySerializer;
30 import org.apache.pivot.serialization.Serializer;
31 import org.apache.pivot.web.QueryException;
32 import org.apache.pivot.web.server.QueryServlet;
33 import org.turro.elephant.context.ElephantApplication;
34 import org.turro.wd.entities.AttachWd;
35 import org.turro.wd.entities.ServerFile;
36 
41 public class PivotServices extends QueryServlet {
42 
43  @Override
44  protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
45  request.setAttribute("el_app", new ElephantApplication(request, response));
46  super.service(request, response);
47  }
48 
49  @Override
50  protected Object doGet(Path path) throws QueryException {
51  if("/queryFolders".equals(path.toString())) {
52  return new ArrayList<String>(new ListAdapter(AttachWd.queryFolders(
53  getParameters().get("path"),
54  getParameters().get("user"))));
55  } else if ("/queryFiles".equals(path.toString())) {
56  return new ArrayList<ServerFile>(new ListAdapter<ServerFile>(AttachWd.queryVersionedAttachments(
57  getParameters().get("path"),
58  getParameters().get("user"))));
59  } else if ("/download".equals(path.toString())) {
60  return AttachWd.convertToFile(
61  getParameters().get("path"),
62  getParameters().get("fileName"),
63  getParameters().get("user"),
64  "true".equals(getParameters().get("forEditing")));
65  } else if ("/unlock".equals(path.toString())) {
66  return AttachWd.unlockFile(
67  getParameters().get("path"),
68  getParameters().get("fileName"),
69  getParameters().get("user"));
70  } else {
71 // IContact contact = getContact();
72 // if(contact != null) {
73 // if("userFolders".equals(getParameters().get("action"))) {
74 // ServerFolders sf = new ServerFolders();
75 // sf.setServerDate(new Date());
76 // sf.setServerUser(Base64.encode("root".getBytes()));
77 // sf.setServerPass(Base64.encode("organic1i1".getBytes()));
78 // FolderProperties fp;
79 // if(true) { //app.isInRole("my-documents:list")) {
80 // fp = new FolderProperties(
81 // null,
82 // "My Documents",
83 // null,
84 // null,
85 // "/WEB-INF/mydocuments/" + contact.getId());
86 // sf.getUserFolders().put(fp.getFolderName(), fp);
87 // }
88 // if(true) { //app.isInRole("file-attach:self")) {
89 // fp = new FolderProperties(
90 // contact.getId(),
91 // contact.getName(),
92 // null,
93 // "/Contact",
94 // "/WEB-INF/files/contact/" + contact.getId());
95 // sf.getUserFolders().put(fp.getFolderName(), fp);
96 // fp = new FolderProperties(
97 // contact.getId(),
98 // contact.getName(),
99 // "Publishable",
100 // "/Contact",
101 // "/_internal/files/contact/" + contact.getId());
102 // sf.getUserFolders().put(fp.getFolderName(), fp);
103 // }
104 // // fill
105 // convertPathToAbsolute(sf);
106 // return sf;
107 // }
108 // }
109  }
110  return null;
111  }
112 
113  @Override
114  protected URL doPost(Path path, Object value) throws QueryException {
115  if("/upload".equals(path.toString())) {
116  AttachWd.saveFromFile((File) value,
117  getParameters().get("fileName"),
118  getParameters().get("fileDate"),
119  getParameters().get("path"),
120  getParameters().get("user"),
121  getParameters().get("comment"),
122  "true".equals(getParameters().get("lock")),
123  false);
124  }
125  return null;
126  }
127 
128 
129  @Override
130  protected Serializer<?> createSerializer(Path path) {
131  if("/upload".equals(path.toString()) || "/download".equals(path.toString())) {
132  return new FileSerializer();
133  }
134  return new BinarySerializer();
135  }
136 
137 }
URL doPost(Path path, Object value)
void service(HttpServletRequest request, HttpServletResponse response)
Serializer<?> createSerializer(Path path)
static List< String > queryFolders(String path, String user)
Definition: AttachWd.java:135
static File convertToFile(String path, String fileName, String user, boolean forEditing)
Definition: AttachWd.java:88
static Attachment saveFromFile(File file, String fileName, String fileDate, String path, String user, String comment, boolean lock, boolean validated)
Definition: AttachWd.java:43
static Object unlockFile(String path, String fileName, String user)
Definition: AttachWd.java:175
static List< ServerFile > queryVersionedAttachments(String path, String user)
Definition: AttachWd.java:151