]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/server/jcr/mvc/JcrBrowserController.java
Add create calendar utility
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jcr / src / main / java / org / argeo / server / jcr / mvc / JcrBrowserController.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.server.jcr.mvc;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
22
23 import javax.jcr.Item;
24 import javax.jcr.NodeIterator;
25 import javax.jcr.RepositoryException;
26 import javax.jcr.Session;
27 import javax.jcr.Value;
28 import javax.jcr.query.Query;
29 import javax.jcr.query.QueryResult;
30 import javax.jcr.query.Row;
31 import javax.jcr.query.RowIterator;
32
33 import org.springframework.stereotype.Controller;
34 import org.springframework.web.bind.annotation.RequestMapping;
35 import org.springframework.web.bind.annotation.RequestParam;
36 import org.springframework.web.context.request.RequestAttributes;
37 import org.springframework.web.context.request.WebRequest;
38
39 @Controller
40 public class JcrBrowserController implements JcrMvcConstants {
41
42 @RequestMapping("/getJcrItem.*")
43 public Item getJcrItem(WebRequest webRequest,
44 @RequestParam("path") String path) throws RepositoryException {
45 return ((Session) webRequest.getAttribute(REQUEST_ATTR_SESSION,
46 RequestAttributes.SCOPE_REQUEST)).getItem(path);
47 }
48
49 @RequestMapping("/queryJcrNodes.*")
50 public List<String> queryJcrNodes(WebRequest webRequest,
51 @RequestParam("statement") String statement,
52 @RequestParam("language") String language)
53 throws RepositoryException {
54 Session session = ((Session) webRequest.getAttribute(
55 REQUEST_ATTR_SESSION, RequestAttributes.SCOPE_REQUEST));
56 Query query = session.getWorkspace().getQueryManager().createQuery(
57 statement, language);
58 NodeIterator nit = query.execute().getNodes();
59 List<String> paths = new ArrayList<String>();
60 while (nit.hasNext()) {
61 paths.add(nit.nextNode().getPath());
62 }
63 return paths;
64 }
65
66 @RequestMapping("/queryJcrTable.*")
67 public List<List<String>> queryJcrTable(WebRequest webRequest,
68 @RequestParam("statement") String statement,
69 @RequestParam("language") String language)
70 throws RepositoryException {
71 Session session = ((Session) webRequest.getAttribute(
72 REQUEST_ATTR_SESSION, RequestAttributes.SCOPE_REQUEST));
73 Query query = session.getWorkspace().getQueryManager().createQuery(
74 statement, language);
75 QueryResult queryResult = query.execute();
76 List<List<String>> results = new ArrayList<List<String>>();
77 results.add(Arrays.asList(queryResult.getColumnNames()));
78 RowIterator rit = queryResult.getRows();
79
80 while (rit.hasNext()) {
81 Row row = rit.nextRow();
82 List<String> lst = new ArrayList<String>();
83 for (Value value : row.getValues()) {
84 lst.add(value.getString());
85 }
86 }
87 return results;
88 }
89 }