Source Code Cross Referenced for UserFilesComponent.java in  » Report » pentaho-report » org » pentaho » ui » component » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » pentaho report » org.pentaho.ui.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Aug 18, 2005 
014:         * @author James Dixon
015:         */
016:
017:        package org.pentaho.ui.component;
018:
019:        import java.text.SimpleDateFormat;
020:        import java.util.ArrayList;
021:        import java.util.Date;
022:        import java.util.Iterator;
023:        import java.util.List;
024:
025:        import javax.servlet.http.HttpServletRequest;
026:        import javax.servlet.http.HttpServletResponse;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:        import org.dom4j.Document;
031:        import org.dom4j.DocumentHelper;
032:        import org.dom4j.Element;
033:        import org.pentaho.core.repository.IContentItem;
034:        import org.pentaho.core.repository.ISolutionRepository;
035:        import org.pentaho.core.runtime.IBackgroundExecution;
036:        import org.pentaho.core.session.IPentahoSession;
037:        import org.pentaho.core.solution.HttpRequestParameterProvider;
038:        import org.pentaho.core.solution.IActionSequence;
039:        import org.pentaho.core.solution.SimpleParameterProvider;
040:        import org.pentaho.core.system.PentahoSystem;
041:        import org.pentaho.core.ui.IPentahoUrlFactory;
042:        import org.pentaho.messages.Messages;
043:        import org.pentaho.plugin.quartz.QuartzSystemListener;
044:        import org.pentaho.ui.XmlComponent;
045:        import org.quartz.JobDataMap;
046:        import org.quartz.JobDetail;
047:        import org.quartz.Scheduler;
048:
049:        import com.pentaho.repository.subscribe.ISubscriptionRepository;
050:        import com.pentaho.repository.subscribe.Subscription;
051:
052:        public class UserFilesComponent extends XmlComponent {
053:
054:            /**
055:             * 
056:             */
057:            private static final long serialVersionUID = -7404173000559758744L;
058:
059:            protected final static String FILE = "file"; //$NON-NLS-1$
060:
061:            protected final static String NAME = "name"; //$NON-NLS-1$
062:
063:            protected final static String TIMESTAMP = "timestamp"; //$NON-NLS-1$
064:
065:            protected final static String ACTIONS = "actions"; //$NON-NLS-1$
066:
067:            protected final static String ACTION = "action"; //$NON-NLS-1$
068:
069:            protected final static String TITLE = "title"; //$NON-NLS-1$
070:
071:            protected final static String PARAMS = "params"; //$NON-NLS-1$
072:
073:            protected final static String PARAM = "param"; //$NON-NLS-1$
074:
075:            protected final static String PARAM_NAME = "param-name"; //$NON-NLS-1$
076:
077:            protected final static String PARAM_VALUE = "param-value"; //$NON-NLS-1$
078:
079:            protected final static String USER_FILES = "user-files"; //$NON-NLS-1$
080:
081:            protected final static String MIMETYPE = "mimetype"; //$NON-NLS-1$
082:
083:            protected final static String SIZE = "size"; //$NON-NLS-1$
084:
085:            protected HttpServletRequest request;
086:
087:            protected HttpServletResponse response;
088:
089:            private static final Log logger = LogFactory
090:                    .getLog(UserFilesComponent.class);
091:
092:            public Log getLogger() {
093:                return logger;
094:            }
095:
096:            public UserFilesComponent() {
097:                super (null, null, null);
098:                setXsl("text/html", "UserFiles.xsl"); //$NON-NLS-1$ //$NON-NLS-2$
099:            }
100:
101:            public UserFilesComponent(IPentahoUrlFactory urlFactory,
102:                    HttpServletRequest request, HttpServletResponse response,
103:                    List messages) {
104:                super (urlFactory, messages, null);
105:                this .request = request;
106:                this .response = response;
107:                setXsl("text/html", "UserFiles.xsl"); //$NON-NLS-1$ //$NON-NLS-2$
108:            }
109:
110:            public void setRequest(HttpServletRequest request) {
111:                this .request = request;
112:            }
113:
114:            public void setResponse(HttpServletResponse response) {
115:                this .response = response;
116:            }
117:
118:            public boolean validate() {
119:                return true;
120:            }
121:
122:            public Document getXmlContent() {
123:
124:                Document result = DocumentHelper.createDocument();
125:                Element root = result.addElement(USER_FILES);
126:
127:                addFiles(root);
128:                return result;
129:            }
130:
131:            protected void addFiles(Element root) {
132:
133:                addScheduledAndExecuting(root);
134:                addExecutedlist(root);
135:                addSubscriptions(root);
136:            }
137:
138:            protected void addScheduledAndExecuting(Element root) {
139:                Element jobs = root.addElement("scheduled"); //$NON-NLS-1$
140:                IPentahoSession session = getSession();
141:                IBackgroundExecution backgroundExecution = PentahoSystem
142:                        .getBackgroundExecutionHandler(session);
143:                List jobsList = null;
144:                if (backgroundExecution != null) {
145:                    jobsList = backgroundExecution
146:                            .getScheduledAndExecutingBackgroundJobs(session);
147:                } else {
148:                    jobsList = new ArrayList();
149:                    Element errorRoot = root.addElement("error"); //$NON-NLS-1$
150:                    errorRoot
151:                            .addElement("error-message").setText(Messages.getErrorString("UI.USER_ERROR_0003_NO_BACKGROUND_EXECUTION")); //$NON-NLS-1$//$NON-NLS-2$ 
152:                }
153:                if (jobsList != null && jobsList.size() > 0) {
154:                    for (int i = 0; i < jobsList.size(); i++) {
155:
156:                        Element job = jobs.addElement(FILE);
157:
158:                        JobDetail jobDetail = (JobDetail) jobsList.get(i);
159:                        JobDataMap jobDataMap = jobDetail.getJobDataMap();
160:
161:                        job
162:                                .addElement(NAME)
163:                                .setText(
164:                                        jobDataMap
165:                                                .getString(IBackgroundExecution.BACKGROUND_ACTION_NAME_STR));
166:                        job
167:                                .addElement(TIMESTAMP)
168:                                .setText(
169:                                        jobDataMap
170:                                                .getString(IBackgroundExecution.BACKGROUND_SUBMITTED));
171:                        Element actions = job.addElement(ACTIONS);
172:                        Element action = actions.addElement(ACTION);
173:                        action.addElement(TITLE).setText(
174:                                Messages.getString("UI.USER_CANCEL")); //$NON-NLS-1$
175:                        Element params = action.addElement(PARAMS);
176:                        Element param = params.addElement(PARAM);
177:                        param.addElement(PARAM_NAME).setText("del-job-name"); //$NON-NLS-1$
178:                        param.addElement(PARAM_VALUE).setText(
179:                                jobDetail.getName());
180:                        param = params.addElement(PARAM);
181:                        param.addElement(PARAM_NAME).setText("del-job-group"); //$NON-NLS-1$
182:                        param.addElement(PARAM_VALUE).setText(
183:                                jobDetail.getGroup());
184:                        param = params.addElement(PARAM);
185:                        param.addElement(PARAM_NAME).setText("action"); //$NON-NLS-1$
186:                        param.addElement(PARAM_VALUE).setText("cancel-job"); //$NON-NLS-1$
187:                    }
188:                }
189:            }
190:
191:            protected void addExecutedlist(Element root) {
192:                Element jobs = root.addElement("executed"); //$NON-NLS-1$
193:                IPentahoSession session = getSession();
194:                IBackgroundExecution backgroundExecution = PentahoSystem
195:                        .getBackgroundExecutionHandler(session);
196:
197:                List pastExecutionList = null;
198:                if (backgroundExecution != null) {
199:                    pastExecutionList = backgroundExecution
200:                            .getBackgroundExecutedContentList(session);
201:                } else {
202:                    pastExecutionList = new ArrayList();
203:                }
204:                SimpleDateFormat fmt = new SimpleDateFormat();
205:
206:                for (int i = 0; i < pastExecutionList.size(); i++) {
207:                    IContentItem item = (IContentItem) pastExecutionList.get(i);
208:                    Element job = jobs.addElement(FILE);
209:
210:                    job.addElement(NAME).setText(item.getTitle());
211:                    String dateStr = ""; //$NON-NLS-1$
212:                    Date time = item.getFileDateTime();
213:                    if (time != null) {
214:                        dateStr = fmt.format(time);
215:                    }
216:                    job.addElement(TIMESTAMP).setText(dateStr);
217:                    job.addElement(MIMETYPE).setText(item.getMimeType());
218:                    job.addElement(SIZE).setText(
219:                            Long.toString(item.getFileSize()));
220:
221:                    Element actions = job.addElement(ACTIONS);
222:                    Element action = actions.addElement(ACTION);
223:                    action.addElement(TITLE).setText(
224:                            Messages.getString("UI.USER_VIEW")); //$NON-NLS-1$
225:                    Element params = action.addElement(PARAMS);
226:                    Element param = params.addElement(PARAM);
227:                    param.addElement(PARAM_NAME).setText("action"); //$NON-NLS-1$
228:                    param.addElement(PARAM_VALUE).setText("view"); //$NON-NLS-1$
229:
230:                    param = params.addElement(PARAM);
231:                    param.addElement(PARAM_NAME).setText("id"); //$NON-NLS-1$
232:                    param.addElement(PARAM_VALUE).setText(item.getId());
233:
234:                    action = actions.addElement(ACTION);
235:                    action.addElement(TITLE).setText(
236:                            Messages.getString("UI.USER_DELETE")); //$NON-NLS-1$
237:                    params = action.addElement(PARAMS);
238:                    param = params.addElement(PARAM);
239:                    param.addElement(PARAM_NAME).setText("action"); //$NON-NLS-1$
240:                    param.addElement(PARAM_VALUE).setText("delete"); //$NON-NLS-1$
241:
242:                    param = params.addElement(PARAM);
243:                    param.addElement(PARAM_NAME).setText("content-id"); //$NON-NLS-1$
244:                    param.addElement(PARAM_VALUE).setText(item.getId());
245:
246:                }
247:            }
248:
249:            public boolean cancelJob(String jobName, String jobGroup) {
250:
251:                try {
252:                    Scheduler sched = QuartzSystemListener
253:                            .getSchedulerInstance();
254:                    sched.deleteJob(jobName, jobGroup);
255:                    return true;
256:                } catch (Throwable t) {
257:                    error(
258:                            Messages
259:                                    .getErrorString(
260:                                            "Scheduler.ERROR_0001_SCHEDULER_CANNOT_CANCEL", t.getMessage()), t); //$NON-NLS-1$
261:                }
262:                return false;
263:            }
264:
265:            public boolean deleteContent(String contentId) {
266:                try {
267:                    IPentahoSession session = getSession();
268:                    IBackgroundExecution backgroundExecution = PentahoSystem
269:                            .getBackgroundExecutionHandler(session);
270:                    if (backgroundExecution != null) {
271:                        backgroundExecution
272:                                .removeBackgroundExecutedContentForID(
273:                                        contentId, session);
274:                        return true;
275:                    } else {
276:                        return false;
277:                    }
278:                } catch (Throwable t) {
279:                    error(
280:                            Messages
281:                                    .getErrorString(
282:                                            "Scheduler.ERROR_0001_SCHEDULER_CANNOT_CANCEL", t.getMessage()), t); //$NON-NLS-1$
283:                }
284:                return false;
285:            }
286:
287:            protected void addSubscriptions(Element root) {
288:                SubscriptionAdminUIComponent admin = null;
289:                try {
290:                    admin = new SubscriptionAdminUIComponent(urlFactory,
291:                            getMessages()); //$NON-NLS-1
292:                    //    admin.setLoggingLevel( admin.DEBUG );
293:                    admin.validate(getSession(), null);
294:                    SimpleParameterProvider params = new SimpleParameterProvider();
295:
296:                    admin.setParameterProvider(
297:                            HttpRequestParameterProvider.SCOPE_REQUEST, params);
298:
299:                    params
300:                            .setParameter(
301:                                    SubscriptionAdminUIComponent.SCHEDULER_ACTION,
302:                                    SubscriptionAdminUIComponent.ACTION_SUBSCRIPTION_SHOW_LIST);
303:                    params.setParameter("user", getSession().getName()); //$NON-NLS-1$
304:
305:                    Document doc = admin.getXmlContent();
306:
307:                    List subscriptionList = doc
308:                            .selectNodes("listSubscriptions/subscriptions/subscription"); //$NON-NLS-1$
309:                    if (subscriptionList != null) {
310:                        ISubscriptionRepository subscriptionRepository = PentahoSystem
311:                                .getSubscriptionRepository(getSession());
312:                        Iterator it = subscriptionList.iterator();
313:                        while (it.hasNext()) {
314:                            Element node = (Element) it.next();
315:                            String actionRef = node.selectSingleNode(
316:                                    "actionRef").getText(); //$NON-NLS-1$
317:                            ISolutionRepository repo = PentahoSystem
318:                                    .getSolutionRepository(getSession());
319:                            PentahoSystem.ActionInfo actionInfo = PentahoSystem
320:                                    .parseActionString(actionRef);
321:                            IActionSequence action = repo.getActionSequence(
322:                                    actionInfo.getSolutionName(), actionInfo
323:                                            .getPath(), actionInfo
324:                                            .getActionName(), repo
325:                                            .getLoggingLevel(),
326:                                    ISolutionRepository.ACTION_EXECUTE);
327:                            String actionTitle = action.getTitle();
328:                            node
329:                                    .addElement("action-title").setText(actionTitle); //$NON-NLS-1$
330:                            if (subscriptionRepository != null) {
331:                                try {
332:                                    Subscription subscription = subscriptionRepository
333:                                            .getSubscription(
334:                                                    node
335:                                                            .selectSingleNode(
336:                                                                    "@subscriptionId").getText(), getSession()); //$NON-NLS-1$
337:                                    subscriptionRepository
338:                                            .addSubscriptionToDocument(
339:                                                    subscription, node, null,
340:                                                    getSession());
341:                                    //                      subscriptionRepository.addSubscriptionsToDocument(getSession().getName(), actionRef, node, null, getSession());
342:                                } catch (Throwable t) {
343:                                    error(
344:                                            Messages
345:                                                    .getErrorString("PRO_SUBSCRIPTREP.ERROR_0005_GENERAL_ERROR"), t); //$NON-NLS-1$
346:                                }
347:                            }
348:                        }
349:                    }
350:
351:                    Element subsRoot = doc.getRootElement();
352:                    subsRoot.detach();
353:                    root.add(subsRoot);
354:
355:                } catch (Exception e) {
356:                    error(
357:                            Messages
358:                                    .getErrorString("PRO_SUBSCRIPTREP.ERROR_0005_GENERAL_ERROR"), e); //$NON-NLS-1$
359:                }
360:            }
361:
362:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.