Source Code Cross Referenced for NewDocWizard.java in  » Content-Management-System » contineo » org » contineo » web » document » 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 » Content Management System » contineo » org.contineo.web.document 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.contineo.web.document;
002:
003:        import org.apache.commons.logging.Log;
004:        import org.apache.commons.logging.LogFactory;
005:
006:        import org.contineo.core.doxter.Storer;
007:        import org.contineo.core.security.Menu;
008:        import org.contineo.core.security.dao.MenuDAO;
009:        import org.contineo.core.text.AnalyzeText;
010:        import org.contineo.core.text.parser.Parser;
011:        import org.contineo.core.text.parser.ParserFactory;
012:
013:        import org.contineo.util.Context;
014:        import org.contineo.util.config.SettingsConfig;
015:
016:        import org.contineo.web.SessionManagement;
017:        import org.contineo.web.i18n.Messages;
018:        import org.contineo.web.navigation.PageContentBean;
019:        import org.contineo.web.upload.InputFileBean;
020:
021:        import java.io.File;
022:        import java.io.FileInputStream;
023:        import java.io.InputStream;
024:
025:        import java.util.Date;
026:
027:        import javax.faces.application.Application;
028:        import javax.faces.application.FacesMessage;
029:        import javax.faces.context.FacesContext;
030:
031:        /**
032:         * Wizard that handled the creation of a new document.
033:         *
034:         * @author Marco Meschieri
035:         * @version $Id: NewDocWizard.java,v 1.9 2006/09/04 15:48:35 marco Exp $
036:         * @since 3.0
037:         */
038:        public class NewDocWizard {
039:            protected static Log log = LogFactory.getLog(NewDocWizard.class);
040:            private boolean showUpload = true;
041:            private DocumentNavigation documentNavigation;
042:
043:            public boolean isShowUpload() {
044:                return showUpload;
045:            }
046:
047:            /**
048:             * Starts the upload process
049:             */
050:            public String start() {
051:                documentNavigation.setSelectedPanel(new PageContentBean(
052:                        "uploadDocument"));
053:
054:                // Remove the uploaded file, if one was uploaded
055:                Application application = FacesContext.getCurrentInstance()
056:                        .getApplication();
057:                InputFileBean inputFile = ((InputFileBean) application
058:                        .createValueBinding("#{inputFile}").getValue(
059:                                FacesContext.getCurrentInstance()));
060:                inputFile.deleteFile();
061:
062:                showUpload = true;
063:
064:                return null;
065:            }
066:
067:            /**
068:             * Acquires the uploaded file and shows the edit form. Gets the file
069:             * uploaded through the HTML form and extracts all necessary data like
070:             * language, keywords, autor, etc. to fill the document form so that the
071:             * user can still edit this data before finally storing the document in
072:             * contineo.
073:             */
074:            public String next() {
075:                showUpload = false;
076:
077:                FacesContext facesContext = FacesContext.getCurrentInstance();
078:                Application application = FacesContext.getCurrentInstance()
079:                        .getApplication();
080:                InputFileBean inputFile = ((InputFileBean) application
081:                        .createValueBinding("#{inputFile}").getValue(
082:                                FacesContext.getCurrentInstance()));
083:                DocumentEditForm docForm = ((DocumentEditForm) application
084:                        .createValueBinding("#{documentForm}").getValue(
085:                                FacesContext.getCurrentInstance()));
086:                docForm.reset();
087:
088:                if (SessionManagement.isValid()) {
089:                    try {
090:                        File file = inputFile.getFile();
091:                        String documentLanguage = inputFile.getLanguage();
092:
093:                        // Get menuParent that called AddDocAction
094:                        MenuDAO mdao = (MenuDAO) Context.getInstance().getBean(
095:                                MenuDAO.class);
096:                        Menu parent = documentNavigation.getSelectedDir()
097:                                .getMenu();
098:
099:                        // Makes menuPath
100:                        String menupath = new StringBuilder(parent
101:                                .getMenuPath()).append("/").append(
102:                                parent.getMenuId()).toString();
103:                        int menuhier = parent.getMenuHier();
104:
105:                        // Makes new Menu
106:                        Menu menu = new Menu();
107:                        menu.setMenuParent(parent.getMenuId());
108:                        menu.setMenuPath(menupath);
109:                        menu.setMenuHier(menuhier++);
110:
111:                        // and stores it
112:                        mdao.store(menu);
113:
114:                        // Gets file to upload name
115:                        String filename = file.getName();
116:
117:                        // Stores the document in the repository
118:                        SettingsConfig settings = (SettingsConfig) Context
119:                                .getInstance().getBean(SettingsConfig.class);
120:                        String path = new StringBuilder(settings
121:                                .getValue("docdir")).append(menupath).append(
122:                                File.separator).append(
123:                                String.valueOf(menu.getMenuId())).append("/")
124:                                .toString();
125:                        String mpath = new StringBuilder(menupath).append(
126:                                File.separator).append(
127:                                String.valueOf(menu.getMenuId())).toString();
128:
129:                        // Get file to upload inputStream
130:                        InputStream stream = new FileInputStream(file);
131:                        Storer storer = (Storer) Context.getInstance().getBean(
132:                                Storer.class);
133:
134:                        // stores it in folder
135:                        try {
136:                            storer.store(stream, mpath, filename, "1.0");
137:                        } finally {
138:                            if (stream != null) {
139:                                stream.close();
140:                            }
141:                        }
142:
143:                        File f = new File(new StringBuilder(path).append(
144:                                filename).toString());
145:
146:                        // Parses the file where it is already stored
147:                        Parser parser = ParserFactory.getParser(f);
148:                        StringBuffer content = null;
149:                        String name = "";
150:                        String author = "";
151:                        String keywords = "";
152:
153:                        // and gets some fields
154:                        if (parser != null) {
155:                            content = parser.getContent();
156:                            name = parser.getTitle();
157:                            author = parser.getAuthor();
158:                            keywords = parser.getKeywords();
159:                        }
160:
161:                        if (content == null) {
162:                            content = new StringBuffer("");
163:                        }
164:
165:                        // source field got from web.xml.
166:                        // This field is required for Lucene to work properly
167:                        String source = (String) facesContext
168:                                .getExternalContext().getApplicationMap().get(
169:                                        "store");
170:
171:                        if (source == null) {
172:                            source = settings.getValue("defaultSource");
173:                        }
174:
175:                        // fills needed fields
176:                        if ((name != null) && (name.length() > 0)) {
177:                            docForm.setDocName(name);
178:                        } else {
179:                            int tmpInt = filename.lastIndexOf(".");
180:
181:                            if (tmpInt != -1) {
182:                                docForm.setDocName(filename
183:                                        .substring(0, tmpInt));
184:                            } else {
185:                                docForm.setDocName(filename);
186:                            }
187:                        }
188:
189:                        docForm.setMenuParent(parent.getMenuId());
190:                        docForm.setSource(source);
191:
192:                        if (author != null) {
193:                            docForm.setSourceAuthor(author);
194:                        }
195:
196:                        docForm.setSourceDate(new Date());
197:                        docForm.setLanguage(documentLanguage);
198:
199:                        if ((keywords != null) && !keywords.trim().equals("")) {
200:                            docForm.setKeywords(keywords);
201:                        } else {
202:                            AnalyzeText analyzer = new AnalyzeText();
203:                            docForm.setKeywords(analyzer.getTerms(5, content
204:                                    .toString(), documentLanguage));
205:                        }
206:
207:                        docForm.setFilename(filename);
208:                        docForm.setMenu(menu);
209:
210:                        // update the file size
211:                        mdao.store(menu);
212:                    } catch (Exception e) {
213:                        String message = Messages
214:                                .getMessage("errors.action.savedoc");
215:                        log.error(message, e);
216:                        Messages.addMessage(FacesMessage.SEVERITY_ERROR,
217:                                message, message);
218:                        showUpload = true;
219:                    }
220:
221:                    return null;
222:                } else {
223:                    return "login";
224:                }
225:            }
226:
227:            public String abort() {
228:                documentNavigation.setSelectedPanel(new PageContentBean(
229:                        "documents"));
230:
231:                // Remove the uploaded file, if one was uploaded
232:                Application application = FacesContext.getCurrentInstance()
233:                        .getApplication();
234:                InputFileBean inputFile = ((InputFileBean) application
235:                        .createValueBinding("#{inputFile}").getValue(
236:                                FacesContext.getCurrentInstance()));
237:                inputFile.deleteFile();
238:
239:                return null;
240:            }
241:
242:            public String save() {
243:                Application application = FacesContext.getCurrentInstance()
244:                        .getApplication();
245:                DocumentEditForm documentForm = ((DocumentEditForm) application
246:                        .createValueBinding("#{documentForm}").getValue(
247:                                FacesContext.getCurrentInstance()));
248:
249:                documentForm.save();
250:                documentNavigation.selectDirectory(documentNavigation
251:                        .getSelectedDir());
252:
253:                return abort();
254:            }
255:
256:            public void setDocumentNavigation(
257:                    DocumentNavigation documentNavigation) {
258:                this.documentNavigation = documentNavigation;
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.