KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > component > SolutionManagerUIComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * Created Dec 29, 2005
14  * @author wseyler
15  */

16
17 package org.pentaho.ui.component;
18
19 import java.io.File JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import org.apache.commons.fileupload.DiskFileUpload;
24 import org.apache.commons.fileupload.FileItem;
25 import org.apache.commons.fileupload.FileUploadException;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.dom4j.Document;
29 import org.pentaho.ui.XmlComponent;
30 import org.pentaho.core.repository.ISolutionRepository;
31 import org.pentaho.core.session.IPentahoSession;
32 import org.pentaho.core.solution.HttpRequestParameterProvider;
33 import org.pentaho.core.system.PentahoSystem;
34 import org.pentaho.core.ui.IPentahoUrlFactory;
35 import org.pentaho.messages.Messages;
36
37 public class SolutionManagerUIComponent extends XmlComponent {
38     /**
39      *
40      */

41     private static final long serialVersionUID = 5322450732426274853L;
42
43     private static final Log logger = LogFactory.getLog(SolutionManagerUIComponent.class);
44
45     private static final String JavaDoc PATH_STR = "path"; //$NON-NLS-1$
46

47     private static final String JavaDoc EMPTY_STR = ""; //$NON-NLS-1$
48

49     private static final String JavaDoc REQUEST_STR = "request"; //$NON-NLS-1$
50

51     private static final String JavaDoc BASE_URL_STR = "baseUrl"; //$NON-NLS-1$
52

53     private IPentahoSession session = null;
54
55     public SolutionManagerUIComponent(IPentahoUrlFactory urlFactory, List JavaDoc messages, IPentahoSession session) {
56         super(urlFactory, messages, null);
57         this.session = session;
58         setXsl("text/xml", "copy.xsl"); //$NON-NLS-1$ //$NON-NLS-2$
59
}
60
61     public Document doGetSolutionStructure() {
62         ISolutionRepository repository = PentahoSystem.getSolutionRepository(session);
63         Document doc = repository.getSolutionStructure(ISolutionRepository.ACTION_ADMIN);
64         return doc;
65     }
66
67     public Document doFileUpload() {
68         String JavaDoc baseUrl = PentahoSystem.getApplicationContext().getSolutionPath(EMPTY_STR);
69         ISolutionRepository repository = PentahoSystem.getSolutionRepository(session);
70         String JavaDoc path = this.getParameter(PATH_STR, null);
71         HttpServletRequest JavaDoc request = ((HttpRequestParameterProvider) getParameterProviders().get(REQUEST_STR)).getRequest();
72         String JavaDoc contentType = request.getContentType();
73         if ((contentType == null) || (contentType.indexOf("multipart/form-data") < 0 && contentType.indexOf("multipart/mixed stream") < 0)) { //$NON-NLS-1$ //$NON-NLS-2$
74
return doGetSolutionStructure();
75         }
76         DiskFileUpload uploader = new DiskFileUpload();
77         try {
78             List JavaDoc fileList = uploader.parseRequest(request);
79             Iterator JavaDoc iter = fileList.iterator();
80             while (iter.hasNext()) {
81                 FileItem fi = (FileItem) iter.next();
82
83                 // Check if not form field so as to only handle the file inputs
84
if (!fi.isFormField()) {
85                     File JavaDoc tempFileRef = new File JavaDoc(fi.getName());
86                     repository.addSolutionFile(baseUrl, path, tempFileRef.getName(), fi.get(), true);
87                     logger.info(Messages.getString("SolutionManagerUIComponent.INFO_0001_FILE_SAVED") + path + "/" + tempFileRef.getName()); //$NON-NLS-1$ //$NON-NLS-2$
88
}
89             }
90         } catch (FileUploadException e) {
91             logger.error(e.toString());
92         } catch (Exception JavaDoc e) {
93             // TODO Auto-generated catch block
94
e.printStackTrace();
95         }
96
97         return doGetSolutionStructure();
98     }
99
100     public Document getXmlContent() {
101         setXslProperty(BASE_URL_STR, urlFactory.getDisplayUrlBuilder().getUrl());
102         return doFileUpload();
103     }
104
105     public Log getLogger() {
106         return logger;
107     }
108
109     public boolean validate() {
110         return true;
111     }
112 }
113
Popular Tags