+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.argeo.server.jcr.mvc;
import java.util.List;
import java.util.StringTokenizer;
+import javax.jcr.Session;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.WebRequest;
@Controller
-public class JcrManagerController implements MvcConstants {
+public class JcrManagerController implements MvcConstants, JcrMvcConstants {
private final static Log log = LogFactory
.getLog(JcrManagerController.class);
- private JcrResourceAdapter resourceAdapter;
-
// Create a factory for disk-based file items
private FileItemFactory factory = new DiskFileItemFactory();
@SuppressWarnings("unchecked")
@RequestMapping("/upload/**")
@ModelAttribute(ANSWER_MODEL_KEY_AS_HTML)
- public ServerAnswer upload(HttpServletRequest request,
- HttpServletResponse response) throws Exception {
+ public ServerAnswer upload(WebRequest webRequest,
+ HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+
+ Session session = ((Session) webRequest.getAttribute(
+ REQUEST_ATTR_SESSION, RequestAttributes.SCOPE_REQUEST));
+ JcrResourceAdapter resourceAdapter = new JcrResourceAdapter(session);
// Parse the request
List<FileItem> items = upload.parseRequest(request);
return ServerAnswer.ok("File " + path + " imported");
}
- public void setResourceAdapter(JcrResourceAdapter resourceAdapter) {
- this.resourceAdapter = resourceAdapter;
- }
-
}