Source Code Cross Referenced for Manager.java in  » J2EE » Enhydra-Demos » org » enhydra » dm » presentation » 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 » J2EE » Enhydra Demos » org.enhydra.dm.presentation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra super-servlet presentation object
003:         */
004:
005:        package org.enhydra.dm.presentation;
006:
007:        // Enhydra SuperServlet imports
008:        import java.io.BufferedOutputStream;
009:        import java.io.ByteArrayOutputStream;
010:        import java.io.File;
011:        import java.io.IOException;
012:        import java.net.URLEncoder;
013:        import java.text.SimpleDateFormat;
014:        import java.util.Date;
015:        import java.util.Enumeration;
016:        import java.util.Properties;
017:
018:        import javax.activation.MimetypesFileTypeMap;
019:        import javax.servlet.ServletContext;
020:
021:        import org.enhydra.dm.EnhydraDM;
022:        import org.enhydra.dm.api.Document;
023:        import org.enhydra.dm.api.FoDocument;
024:        import org.enhydra.dm.api.exceptions.BaseException;
025:        import org.enhydra.dm.business.exceptions.ActionNotAllowedException;
026:        import org.enhydra.dm.business.exceptions.FileSizeException;
027:        import org.enhydra.dm.util.EnhydraDMConstants;
028:        import org.enhydra.dm.util.MimeUtility;
029:        import org.w3c.dom.Node;
030:        import org.w3c.dom.html.HTMLAnchorElement;
031:        import org.w3c.dom.html.HTMLImageElement;
032:        import org.w3c.dom.html.HTMLInputElement;
033:        import org.w3c.dom.html.HTMLOptionElement;
034:
035:        import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
036:        import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
037:        import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
038:        import com.lutris.appserver.server.httpPresentation.HttpPresentationOutputStream;
039:        import com.lutris.appserver.server.httpPresentation.HttpPresentationResponse;
040:        import com.lutris.logging.Logger;
041:        import com.lutris.mime.ContentHeader;
042:        import com.lutris.mime.MimeHeader;
043:        import com.lutris.mime.MultipartMimeInput;
044:        import com.lutris.mime.MultipartMimeInputStream;
045:
046:        public class Manager extends Base {
047:
048:            /**
049:             * Corresponding XMLC object
050:             */
051:            private ManagerHTML page;
052:
053:            // --------------------------------------------- Presentation Object Methods
054:
055:            public void run(HttpPresentationComms comms) throws Exception {
056:
057:                Properties editableMT = ((EnhydraDM) comms.application)
058:                        .getProperties(
059:                                EnhydraDMConstants.PROP_EDITABLE_MT_FILE_NAME,
060:                                EnhydraDMConstants.PROP_EDITABLE_MT_FILE_NAME);
061:
062:                page = (ManagerHTML) comms.xmlcFactory
063:                        .create(ManagerHTML.class);
064:
065:                comms.request.getHttpServletRequest().setCharacterEncoding(
066:                        EnhydraDMConstants.ENCODING);
067:
068:                String action = comms.request
069:                        .getParameter(EnhydraDMConstants.ACTION);
070:                String documentId = comms.request
071:                        .getParameter(EnhydraDMConstants.DOCUMENT_ID);
072:                String mode = comms.request
073:                        .getParameter(EnhydraDMConstants.MODE);
074:                String templateId = comms.request
075:                        .getParameter(EnhydraDMConstants.TEMPLATE_ID);
076:                String newDocumentName = comms.request
077:                        .getParameter(EnhydraDMConstants.PARAM_NAME);
078:
079:                boolean isTemplate = true;
080:                if (!EnhydraDMConstants.MODE_TEMPLATE.equals(mode)) {
081:                    mode = EnhydraDMConstants.MODE_DOCUMENT;
082:                    isTemplate = false;
083:                }
084:
085:                documentManager = ((EnhydraDM) comms.application)
086:                        .getDocumentManager();
087:                documentStore = ((EnhydraDM) comms.application)
088:                        .getDocumentStore();
089:
090:                boolean doCommit = true;
091:                try {
092:                    initTransaction();
093:                    String user = getUser(comms);
094:
095:                    if (action != null && !"".equals(action)) {
096:
097:                        if (action.equals(EnhydraDMConstants.ACTION_DELETE)) {
098:                            deleteDocument(comms, documentId, user);
099:                        } else if (action
100:                                .equals(EnhydraDMConstants.ACTION_CHECKOUT)) {
101:                            checkoutDocument(comms, documentId, user);
102:                        } else if (action
103:                                .equals(EnhydraDMConstants.ACTION_UNCHECKOUT)) {
104:                            unCheckoutDocument(comms, documentId, user);
105:                        } else if (action
106:                                .equals(EnhydraDMConstants.ACTION_SWITCHVERSIONABLE)) {
107:                            switchVersionable(comms, documentId, user);
108:                        } else if (action
109:                                .equals(EnhydraDMConstants.ACTION_CREATEVERSION)) {
110:                            createVersion(comms, documentId, user);
111:                        } else if (action
112:                                .equals(EnhydraDMConstants.ACTION_SWITCHARCHIVED)) {
113:                            switchArchived(comms, documentId, user);
114:                        } else if (EnhydraDMConstants.ACTION_DOWNLOAD
115:                                .equals(action)) {
116:                            downloadVersionFile(comms, documentId);
117:                            throw new ClientPageRedirectException(
118:                                    EnhydraDMConstants.NAVIG_VERSIONS + "?"
119:                                            + EnhydraDMConstants.DOCUMENT_ID
120:                                            + "=" + documentId + "&"
121:                                            + EnhydraDMConstants.MODE + "="
122:                                            + mode);
123:                        } else if (action
124:                                .equals(EnhydraDMConstants.ACTION_DUPLICATEDOCUMENT)) {
125:                            duplicateDocument(comms, documentId, user);
126:                        } else if (action
127:                                .equals(EnhydraDMConstants.ACTION_LOGOUT)) {
128:                            comms.request.getHttpServletRequest().getSession()
129:                                    .invalidate();
130:                        } else if (action
131:                                .equals(EnhydraDMConstants.ACTION_UPLOAD)) {
132:                            String header = comms.request
133:                                    .getHeader(EnhydraDMConstants.HEAD_CONTENT_TYPE);
134:                            String fileSize = comms.request
135:                                    .getHeader(EnhydraDMConstants.HEAD_CONTENT_LENGTH);
136:                            int fileSizeInt = (new Integer(fileSize))
137:                                    .intValue();
138:                            if (fileSizeInt > EnhydraDM.allowedFileSizeForUpload) {
139:                                throw new FileSizeException(
140:                                        "File you are trying to upload is too big!");
141:                            }
142:                            if (header != null && !"".equals(header)) {
143:                                try {
144:                                    ContentHeader contentHeader = new ContentHeader(
145:                                            header);
146:                                    MultipartMimeInput mInput = new MultipartMimeInput(
147:                                            comms.request.getInputStream(),
148:                                            contentHeader);
149:                                    MultipartMimeInputStream mime = mInput
150:                                            .nextPart(EnhydraDMConstants.ENCODING);
151:                                    String documentName = null;
152:                                    byte[] documentContent = null;
153:                                    while (mime != null) {
154:                                        MimeHeader mh = mime
155:                                                .getHeader(EnhydraDMConstants.HEAD_CONTENT_DISPOSITION);
156:                                        String paramName = mh
157:                                                .getParameter(EnhydraDMConstants.PARAM_NAME);
158:                                        if (EnhydraDMConstants.PARAM_UPLOAD_DOCUMENT
159:                                                .equals(paramName)) {
160:                                            documentName = mh
161:                                                    .getParameter(EnhydraDMConstants.PARAM_FILE_NAME);
162:                                            // set the corresponding (not absolute path) file name (depends
163:                                            // of
164:                                            // the browser)
165:                                            File tmpfile = new File(
166:                                                    documentName);
167:                                            documentName = tmpfile.getName();
168:                                            documentContent = getBinaryContent(mime);
169:                                        } else if (EnhydraDMConstants.ACTION
170:                                                .equals(paramName)) {
171:                                            action = getString(mime);
172:                                        } else if (EnhydraDMConstants.DOCUMENT_ID
173:                                                .equals(paramName)) {
174:                                            documentId = getString(mime);
175:                                        } else if (EnhydraDMConstants.MODE
176:                                                .equals(paramName)) {
177:                                            mode = getString(mime);
178:                                            isTemplate = true;
179:                                            if (!EnhydraDMConstants.MODE_TEMPLATE
180:                                                    .equals(mode)) {
181:                                                mode = EnhydraDMConstants.MODE_DOCUMENT;
182:                                                isTemplate = false;
183:                                            }
184:                                        }
185:                                        mime = mInput.nextPart();
186:                                    }
187:                                    if (documentName != null
188:                                            && documentContent != null) {
189:                                        if (EnhydraDMConstants.ACTION_CHECKIN
190:                                                .equals(action)) {
191:                                            checkinDocument(documentId,
192:                                                    documentName,
193:                                                    documentContent, user);
194:                                        } else {
195:
196:                                            String mimeType = MimeUtility
197:                                                    .mimeTypeMapper(editableMT,
198:                                                            documentName);
199:
200:                                            if (null == mimeType) {
201:                                                ServletContext servletContext = comms.application
202:                                                        .getHttpPresentationManager()
203:                                                        .getServletContext();
204:                                                mimeType = servletContext != null ? servletContext
205:                                                        .getMimeType(documentName)
206:                                                        : "application/octet-stream";
207:                                            }
208:                                            mimeType = mimeType != null ? mimeType
209:                                                    : "application/octet-stream";
210:
211:                                            create(documentName,
212:                                                    documentContent, mimeType,
213:                                                    user, null, isTemplate,
214:                                                    null);
215:                                        }
216:                                    }
217:                                } catch (BaseException e) {
218:                                    if (null != comms.application
219:                                            .getLogChannel()) {
220:                                        comms.application
221:                                                .getLogChannel()
222:                                                .write(
223:                                                        Logger.ERROR,
224:                                                        "Action :"
225:                                                                + action
226:                                                                + " failure! Reason: "
227:                                                                + e
228:                                                                        .getMessage());
229:                                    }
230:                                    throw new Exception(e);
231:                                }
232:                            }
233:                        } else if (EnhydraDMConstants.ACTION_CREATE
234:                                .equals(action)) {
235:                            Document template = documentManager
236:                                    .getDocument(templateId);
237:
238:                            String filepath = template.getFilepath();
239:                            String extension = filepath.substring(filepath
240:                                    .lastIndexOf("."));
241:
242:                            if (!newDocumentName.endsWith(extension)) {
243:                                newDocumentName += extension;
244:                            }
245:
246:                            byte[] documentContent = documentStore
247:                                    .loadDocumentContent(template.getFilepath());
248:                            create(newDocumentName, documentContent, template
249:                                    .getMimeType(), user, null, isTemplate,
250:                                    templateId);
251:                        } else if (EnhydraDMConstants.ACTION_MASS_DELETE
252:                                .equals(action)) {
253:                            massDeleteDocument(comms, user);
254:                        }
255:                        throw new ClientPageRedirectException(
256:                                EnhydraDMConstants.NAVIG_MANAGER + "?"
257:                                        + EnhydraDMConstants.MODE + "=" + mode);
258:                    }
259:                    page.setTextUser("User: " + user);
260:                    page.getElementAllowedExtensions().setValue(
261:                            EnhydraDM.allowedExtensionsForUpload);
262:                    fillFilesetTable(comms, user, isTemplate, editableMT);
263:                    comms.response.writeDOM(page);
264:                } catch (BaseException ex) {
265:                    doCommit = false;
266:                    if (null != comms.application.getLogChannel()) {
267:                        comms.application.getLogChannel().write(
268:                                Logger.ERROR,
269:                                "Action :" + action + " failure! Reason: "
270:                                        + ex.getMessage());
271:                    }
272:                    throw new Exception(ex);
273:                } finally {
274:                    if (doCommit) {
275:                        commitTransaction();
276:                    } else {
277:                        rollbackTransaction();
278:                    }
279:                }
280:            }
281:
282:            private void fillFilesetTable(HttpPresentationComms comms,
283:                    String user, boolean isTemplate, Properties editableMT)
284:                    throws BaseException {
285:                String mode = EnhydraDMConstants.MODE_DOCUMENT;
286:                if (isTemplate) {
287:                    mode = EnhydraDMConstants.MODE_TEMPLATE;
288:                }
289:
290:                Node fileRow = page.getElementDocumentRow();
291:                Document[] documents = null;
292:                documents = documentManager.getDocuments(isTemplate);
293:                SimpleDateFormat sdf = new SimpleDateFormat(
294:                        EnhydraDMConstants.DATE_FORMAT);
295:
296:                HTMLAnchorElement readLink = page.getElementReadLink();
297:                HTMLAnchorElement editLink = page.getElementEditLink();
298:                HTMLAnchorElement logoutLink = page.getElementLogoutLink();
299:                HTMLAnchorElement recycleBinLink = page
300:                        .getElementRecycleBinLink();
301:                HTMLAnchorElement swichModeLink = page
302:                        .getElementSwichModeLink();
303:                HTMLAnchorElement documentDetailLink = page
304:                        .getElementDocumentDetailLink();
305:                HTMLAnchorElement checkoutLink = page.getElementCheckoutLink();
306:                HTMLAnchorElement unCheckoutLink = page
307:                        .getElementUnCheckoutLink();
308:                HTMLAnchorElement checkinLink = page.getElementCheckinLink();
309:                HTMLAnchorElement deleteLink = page.getElementDeleteLink();
310:                HTMLAnchorElement versionsLink = page.getElementVersionsLink();
311:                HTMLAnchorElement createVersLink = page
312:                        .getElementCreateVersionLink();
313:                HTMLAnchorElement swithcVersionableLink = page
314:                        .getElementSwithcVersionableLink();
315:                HTMLAnchorElement archivedLink = page.getElementArchivedLink();
316:                HTMLAnchorElement c2cLink = page.getElementC2cLink();
317:                HTMLAnchorElement saaLink = page.getElementSaaLink();
318:                HTMLAnchorElement sabLink = page.getElementSabLink();
319:                HTMLAnchorElement duplicateLink = page
320:                        .getElementDuplicateLink();
321:                HTMLAnchorElement downloadLink = page.getElementDownloadLink();
322:
323:                HTMLInputElement selectCheckbox = page
324:                        .getElementSelectDocCheckbox();
325:
326:                HTMLImageElement lockImage = page.getElementLockImage();
327:                HTMLImageElement versionableImage = page
328:                        .getElementVersionableImage();
329:                HTMLImageElement isArchivedImage = page
330:                        .getElementIsArchivedImage();
331:                HTMLImageElement editImage = page.getElementEditImage();
332:                HTMLImageElement checkoutImage = page.getElementCheckoutImage();
333:                HTMLImageElement unCheckoutImage = page
334:                        .getElementUnCheckoutImage();
335:                HTMLImageElement checkinImage = page.getElementCheckinImage();
336:                HTMLImageElement deleteImage = page.getElementDeleteImage();
337:                HTMLImageElement versionsImage = page.getElementVersionsImage();
338:                HTMLImageElement createVersImage = page
339:                        .getElementCreateVersionImage();
340:                HTMLImageElement swithcVersionableImage = page
341:                        .getElementSwitchVersionableImage();
342:                HTMLImageElement archivedImage = page.getElementArchivedImage();
343:
344:                logoutLink.setHref(EnhydraDMConstants.NAVIG_MANAGER + "?"
345:                        + EnhydraDMConstants.ACTION + "="
346:                        + EnhydraDMConstants.ACTION_LOGOUT);
347:
348:                if (!isTemplate) {
349:                    page.setTextSwichMode("Templates");
350:                    page.setTextListHeader("Document List");
351:                    swichModeLink.setHref(EnhydraDMConstants.NAVIG_MANAGER
352:                            + "?" + EnhydraDMConstants.MODE + "="
353:                            + EnhydraDMConstants.MODE_TEMPLATE);
354:                } else {
355:                    page.setTextSwichMode("Documents");
356:                    page.setTextListHeader("Template List");
357:                    swichModeLink.setHref(EnhydraDMConstants.NAVIG_MANAGER
358:                            + "?" + EnhydraDMConstants.MODE + "="
359:                            + EnhydraDMConstants.MODE_DOCUMENT);
360:                }
361:
362:                recycleBinLink.setHref(EnhydraDMConstants.NAVIG_RECYCLEBIN
363:                        + "?" + EnhydraDMConstants.MODE + "=" + mode);
364:
365:                page.getElementContentMode().setValue(mode);
366:                page.getElementCreateMode().setValue(mode);
367:
368:                if (documents != null) {
369:
370:                    for (int i = 0; i < documents.length; i++) {
371:                        String documentName = documents[i].getName();
372:                        String documentId = documents[i].getNumber().toString();
373:                        long documentSize = documents[i].getSize();
374:                        FoDocument foDocumentRef = documents[i]
375:                                .getFoDocumentRef();
376:
377:                        boolean documentLoked = documents[i].getLockedBy() != null
378:                                || documents[i].getCheckedOutBy() != null;
379:
380:                        documentDetailLink
381:                                .setHref(EnhydraDMConstants.NAVIG_DETAILS + "?"
382:                                        + EnhydraDMConstants.DOCUMENT_ID + "="
383:                                        + documentId + "&"
384:                                        + EnhydraDMConstants.MODE + "=" + mode);
385:                        page.setTextDocumentName(documentName);
386:                        page.setTextDocumentId(documentId);
387:                        page.setTextDocumentSize(String.valueOf(documentSize));
388:
389:                        Date mainDate = new Date(documents[i]
390:                                .getLastModifiedDate());
391:                        if (mainDate != null) {
392:                            String strMainDate = sdf.format(mainDate);
393:                            page.setTextDocumentLastModifiedDate(strMainDate);
394:                        } else {
395:                            page.setTextDocumentLastModifiedDate("-");
396:                        }
397:                        if (documents[i].isArchived()) {
398:                            isArchivedImage.setSrc("media/isArchived.gif");
399:                            lockImage.setSrc("media/blank.gif");
400:                            versionableImage.setSrc("media/blank.gif");
401:                        } else {
402:                            isArchivedImage.setSrc("media/blank.gif");
403:                            if (documentLoked) {
404:                                lockImage.setSrc("media/lock.gif");
405:                            } else {
406:
407:                                lockImage.setSrc("media/unlock.gif");
408:
409:                            }
410:                            if (documents[i].isAutoversionable()) {
411:                                versionableImage.setSrc("media/gear_ok.gif");
412:                            } else {
413:
414:                                versionableImage
415:                                        .setSrc("media/gear_forbidden.gif");
416:
417:                            }
418:                        }
419:
420:                        String parameters = null;
421:
422:                        parameters = EnhydraDMConstants.ACTION + "="
423:                                + EnhydraDMConstants.ACTION_READ + "&"
424:                                + EnhydraDMConstants.DOCUMENT_ID + "="
425:                                + documentId;
426:
427:                        if (EnhydraDM.desenc != null) {
428:                            parameters = EnhydraDM.desenc.encrypt(parameters);
429:                            parameters = EnhydraDMConstants.PARAM + "="
430:                                    + parameters;
431:                        }
432:
433:                        try {
434:                            parameters = URLEncoder.encode(parameters,
435:                                    EnhydraDMConstants.ENCODING);
436:                        } catch (Exception ex) {
437:
438:                        }
439:
440:                        readLink.setHref(EnhydraDMConstants.NAVIG_WEBDAV + "/"
441:                                + documents[i].getName() + "?" + parameters);
442:
443:                        c2cLink.setHref("javascript: copy2clipboard('"
444:                                + EnhydraDMConstants.NAVIG_WEBDAV + "/"
445:                                + documents[i].getName() + "?" + parameters
446:                                + "');");
447:                        saaLink.setHref("javascript: sendasattachement('"
448:                                + EnhydraDMConstants.NAVIG_WEBDAV + "/"
449:                                + documents[i].getName() + "?" + parameters
450:                                + "');");
451:
452:                        sabLink.setHref("javascript: sendShortcut('"
453:                                + EnhydraDMConstants.NAVIG_WEBDAV + "/"
454:                                + documents[i].getName() + "?" + parameters
455:                                + "');");
456:
457:                        if (!documents[i].isArchived()
458:                                && !documentLoked
459:                                && (MimeUtility.isEditableDocument(editableMT,
460:                                        documents[i].getMimeType()) || foDocumentRef != null)) {
461:                            if (foDocumentRef != null) {
462:                                parameters = EnhydraDMConstants.ACTION + "="
463:                                        + EnhydraDMConstants.ACTION_EDIT + "&"
464:                                        + EnhydraDMConstants.DOCUMENT_ID + "="
465:                                        + documentId + "&"
466:                                        + EnhydraDMConstants.PARAM_NAME + "="
467:                                        + documents[i].getName();
468:                                editLink
469:                                        .setHref(EnhydraDMConstants.NAVIG_FOEDITOR
470:                                                + "?" + parameters);
471:                            } else {
472:                                parameters = EnhydraDMConstants.ACTION + "="
473:                                        + EnhydraDMConstants.ACTION_EDIT + "&"
474:                                        + EnhydraDMConstants.DOCUMENT_ID + "="
475:                                        + documentId + "&"
476:                                        + EnhydraDMConstants.PARAM_NAME + "="
477:                                        + documents[i].getName();
478:                                if (EnhydraDM.desenc != null) {
479:                                    parameters = EnhydraDM.desenc
480:                                            .encrypt(parameters);
481:                                    parameters = EnhydraDMConstants.PARAM + "="
482:                                            + parameters;
483:                                }
484:
485:                                try {
486:                                    parameters = URLEncoder.encode(parameters,
487:                                            EnhydraDMConstants.ENCODING);
488:                                } catch (Exception ex) {
489:
490:                                }
491:
492:                                editLink
493:                                        .setHref(EnhydraDMConstants.NAVIG_WEBDAV
494:                                                + "/"
495:                                                + documents[i].getName()
496:                                                + "?" + parameters);
497:
498:                            }
499:                            editImage.setSrc("media/edit.gif");
500:                        } else {
501:                            editLink.removeAttribute("href");
502:                            editImage.setSrc("media/editDis.gif");
503:                        }
504:
505:                        if (!documentLoked && !documents[i].isArchived()) {
506:
507:                            String value = "javascript:checkoutDocument('"
508:                                    + documentId + "','" + mode + "')";
509:
510:                            checkoutLink.setAttribute("href", value);
511:
512:                            checkoutImage.setSrc("media/checkout.gif");
513:                        } else {
514:                            checkoutLink.removeAttribute("href");
515:
516:                            checkoutImage.setSrc("media/checkoutDis.gif");
517:                        }
518:
519:                        if (!documentLoked && !documents[i].isArchived()
520:                                && !documents[i].isAutoversionable()) {
521:
522:                            String value = EnhydraDMConstants.NAVIG_MANAGER
523:                                    + "?" + EnhydraDMConstants.ACTION + "="
524:                                    + EnhydraDMConstants.ACTION_CREATEVERSION
525:                                    + "&" + EnhydraDMConstants.DOCUMENT_ID
526:                                    + "=" + documentId + "&"
527:                                    + EnhydraDMConstants.MODE + "=" + mode;
528:
529:                            createVersLink.setAttribute("href", value);
530:
531:                            createVersImage.setSrc("media/createVers.gif");
532:                        } else {
533:                            createVersLink.removeAttribute("href");
534:
535:                            createVersImage.setSrc("media/createVersDis.gif");
536:                        }
537:
538:                        String appUser = documents[i].getCheckedOutBy();
539:                        if (appUser != null && appUser.equals(user)) {
540:
541:                            String value = EnhydraDMConstants.NAVIG_MANAGER
542:                                    + "?" + EnhydraDMConstants.ACTION + "="
543:                                    + EnhydraDMConstants.ACTION_UNCHECKOUT
544:                                    + "&" + EnhydraDMConstants.DOCUMENT_ID
545:                                    + "=" + documentId + "&"
546:                                    + EnhydraDMConstants.MODE + "=" + mode;
547:                            unCheckoutLink.setAttribute("href", value);
548:
549:                            unCheckoutImage.setSrc("media/uncheckout.gif");
550:                        } else {
551:                            unCheckoutLink.removeAttribute("href");
552:
553:                            unCheckoutImage.setSrc("media/uncheckoutDis.gif");
554:                        }
555:                        if (appUser != null && appUser.equals(user)) {
556:
557:                            String value = EnhydraDMConstants.NAVIG_UPLOAD
558:                                    + "?" + EnhydraDMConstants.ACTION + "="
559:                                    + EnhydraDMConstants.ACTION_CHECKIN + "&"
560:                                    + EnhydraDMConstants.DOCUMENT_ID + "="
561:                                    + documentId + "&"
562:                                    + EnhydraDMConstants.MODE + "=" + mode;
563:                            checkinLink.setAttribute("href", value);
564:
565:                            checkinImage.setSrc("media/checkin.gif");
566:                        } else {
567:                            checkinLink.removeAttribute("href");
568:                            checkinImage.setSrc("media/checkinDis.gif");
569:                        }
570:                        if (documentLoked || documents[i].isArchived()) {
571:                            deleteLink.removeAttribute("href");
572:                            deleteImage.setSrc("media/deleteDis.gif");
573:                        } else {
574:
575:                            String value = EnhydraDMConstants.NAVIG_MANAGER
576:                                    + "?" + EnhydraDMConstants.ACTION + "="
577:                                    + EnhydraDMConstants.ACTION_DELETE + "&"
578:                                    + EnhydraDMConstants.DOCUMENT_ID + "="
579:                                    + documentId + "&"
580:                                    + EnhydraDMConstants.MODE + "=" + mode;
581:                            deleteLink.setAttribute("href", value);
582:
583:                            deleteImage.setSrc("media/delete.gif");
584:                        }
585:
586:                        if (documents[i].isArchived()) {
587:                            versionsLink.removeAttribute("href");
588:
589:                            versionsImage.setSrc("media/versionsDis.gif");
590:
591:                        } else {
592:
593:                            String value = EnhydraDMConstants.NAVIG_VERSIONS
594:                                    + "?" + EnhydraDMConstants.DOCUMENT_ID
595:                                    + "=" + documentId + "&"
596:                                    + EnhydraDMConstants.MODE + "=" + mode;
597:                            versionsLink.setAttribute("href", value);
598:
599:                            versionsImage.setSrc("media/versions.gif");
600:
601:                        }
602:
603:                        if (documentLoked || documents[i].isArchived()) {
604:                            swithcVersionableLink.removeAttribute("href");
605:                            swithcVersionableImage
606:                                    .setSrc("media/historyDis.gif");
607:                        } else {
608:
609:                            String value = EnhydraDMConstants.NAVIG_MANAGER
610:                                    + "?"
611:                                    + EnhydraDMConstants.ACTION
612:                                    + "="
613:                                    + EnhydraDMConstants.ACTION_SWITCHVERSIONABLE
614:                                    + "&" + EnhydraDMConstants.DOCUMENT_ID
615:                                    + "=" + documentId + "&"
616:                                    + EnhydraDMConstants.MODE + "=" + mode;
617:                            swithcVersionableLink.setAttribute("href", value);
618:
619:                            swithcVersionableImage.setSrc("media/history.gif");
620:                        }
621:                        if (documentLoked) {
622:                            archivedLink.removeAttribute("href");
623:                            archivedImage.setSrc("media/archivedDis.gif");
624:                        } else {
625:
626:                            String value = EnhydraDMConstants.NAVIG_MANAGER
627:                                    + "?" + EnhydraDMConstants.ACTION + "="
628:                                    + EnhydraDMConstants.ACTION_SWITCHARCHIVED
629:                                    + "&" + EnhydraDMConstants.DOCUMENT_ID
630:                                    + "=" + documentId + "&"
631:                                    + EnhydraDMConstants.MODE + "=" + mode;
632:                            archivedLink.setAttribute("href", value);
633:
634:                            archivedImage.setSrc("media/archived.gif");
635:                        }
636:
637:                        selectCheckbox
638:                                .setName(EnhydraDMConstants.HTML_NAME_SELECT_DOC_CHECKBOX
639:                                        + documentId);
640:                        if (!documentLoked && !documents[i].isArchived()) {
641:                            selectCheckbox.setValue(documentId);
642:                        } else {
643:                            selectCheckbox.setValue("");
644:                        }
645:
646:                        duplicateLink
647:                                .setAttribute(
648:                                        "href",
649:                                        EnhydraDMConstants.NAVIG_MANAGER
650:                                                + "?"
651:                                                + EnhydraDMConstants.ACTION
652:                                                + "="
653:                                                + EnhydraDMConstants.ACTION_DUPLICATEDOCUMENT
654:                                                + "&"
655:                                                + EnhydraDMConstants.DOCUMENT_ID
656:                                                + "=" + documentId + "&"
657:                                                + EnhydraDMConstants.MODE + "="
658:                                                + mode);
659:
660:                        downloadLink.setAttribute("href",
661:                                EnhydraDMConstants.NAVIG_MANAGER + "?"
662:                                        + EnhydraDMConstants.ACTION + "="
663:                                        + EnhydraDMConstants.ACTION_DOWNLOAD
664:                                        + "&" + EnhydraDMConstants.DOCUMENT_ID
665:                                        + "=" + documentId + "&"
666:                                        + EnhydraDMConstants.MODE + "=" + mode);
667:
668:                        fileRow.getParentNode().insertBefore(
669:                                fileRow.cloneNode(true), fileRow);
670:                    }
671:                }
672:                fileRow.getParentNode().removeChild(fileRow);
673:
674:                // create from template
675:                HTMLOptionElement templatesComboRow = page
676:                        .getElementTemplatesOption();
677:                documents = documentManager.getDocuments(true);
678:
679:                if (isTemplate) {
680:                    page.getElementNewPdf().setAttribute("class", "hidden");
681:                }
682:
683:                page.setTextTemplateName("Please select");
684:                templatesComboRow.setValue("-1");
685:                templatesComboRow.getParentNode().insertBefore(
686:                        templatesComboRow.cloneNode(true), templatesComboRow);
687:
688:                if (documents != null) {
689:                    for (int i = 0; i < documents.length; i++) {
690:                        String templateName = documents[i].getName();
691:                        String templateOid = documents[i].getNumber()
692:                                .toString();
693:
694:                        if (!isTemplate
695:                                || !documents[i].getMimeType().equals(
696:                                        "application/xml")) {
697:                            page.setTextTemplateName(templateName);
698:                            templatesComboRow.setValue(templateOid);
699:                            templatesComboRow.getParentNode().insertBefore(
700:                                    templatesComboRow.cloneNode(true),
701:                                    templatesComboRow);
702:                        }
703:                    }
704:                }
705:
706:                templatesComboRow.getParentNode()
707:                        .removeChild(templatesComboRow);
708:            }
709:
710:            // --------------------------------------------- Transaction handling Methods
711:
712:            // --------------------------------------------- Multipart parameter handling methods
713:
714:            /**
715:             * Method returns string parameter value
716:             * 
717:             * @param part
718:             * @return parameter value
719:             * @throws IOException
720:             */
721:            private String getString(MultipartMimeInputStream part)
722:                    throws IOException {
723:                byte[] buf = new byte[1024];
724:                StringBuffer res = new StringBuffer(1024);
725:                int b = 0;
726:                while ((b = part.read(buf, 0, buf.length)) != -1) {
727:                    res.append(new String(buf, 0, b,
728:                            EnhydraDMConstants.ENCODING));
729:                }
730:                return res.toString();
731:            }
732:
733:            /**
734:             * Method retrieves binary parameter value
735:             * 
736:             * @param mime
737:             * @return binry content
738:             * @throws Exception
739:             * @throws BaseException
740:             */
741:            private byte[] getBinaryContent(MultipartMimeInputStream mime)
742:                    throws Exception {
743:                byte[] buf = new byte[1024];
744:                ByteArrayOutputStream baos = null;
745:                BufferedOutputStream bos = null;
746:                try {
747:                    baos = new ByteArrayOutputStream();
748:                    bos = new BufferedOutputStream(baos);
749:
750:                    int b = 0;
751:                    while ((b = mime.read(buf, 0, buf.length)) != -1) {
752:                        bos.write(buf, 0, b);
753:                    }
754:                    bos.flush();
755:
756:                    return baos.toByteArray();
757:                } catch (Exception ex) {
758:                    throw ex;
759:                } finally {
760:                    if (baos != null)
761:                        try {
762:                            baos.close();
763:                        } catch (IOException e) {
764:                            e.printStackTrace();
765:                        }
766:                    if (bos != null)
767:                        try {
768:                            bos.close();
769:                        } catch (IOException e) {
770:                            e.printStackTrace();
771:                        }
772:                }
773:
774:            }
775:
776:            // ------ Document Management Methods
777:
778:            private void checkinDocument(String documentId,
779:                    String documentName, byte[] documentContent, String user)
780:                    throws BaseException {
781:
782:                String documentPath = documentStore.saveDocumentContent(
783:                        documentName, documentContent);
784:                documentManager.checkIn(documentId, documentPath, user);
785:
786:            }
787:
788:            private void deleteDocument(HttpPresentationComms comms,
789:                    String documentId, String user) throws BaseException {
790:
791:                documentManager.delete(documentId, user);
792:
793:            }
794:
795:            private void massDeleteDocument(HttpPresentationComms comms,
796:                    String user) throws BaseException,
797:                    HttpPresentationException {
798:
799:                Enumeration en = comms.request.getParameterNames();
800:                while (en.hasMoreElements()) {
801:                    String name = (String) en.nextElement();
802:                    if (name
803:                            .startsWith(EnhydraDMConstants.HTML_NAME_SELECT_DOC_CHECKBOX)) {
804:                        String documentId = comms.request.getParameter(name);
805:                        if (documentId != null && !documentId.equals(""))
806:                            documentManager.delete(documentId, user);
807:                    }
808:                }
809:            }
810:
811:            private void createVersion(HttpPresentationComms comms,
812:                    String documentId, String user) throws BaseException {
813:
814:                documentManager.createVersion(documentId, user);
815:
816:            }
817:
818:            private void checkoutDocument(HttpPresentationComms comms,
819:                    String documentId, String user) throws BaseException {
820:                try {
821:                    Document document = documentManager.checkOut(documentId,
822:                            user);
823:
824:                    HttpPresentationResponse response = comms.response;
825:                    HttpPresentationOutputStream out = response
826:                            .getOutputStream();
827:
828:                    byte[] documentContent = documentStore
829:                            .loadDocumentContent(document.getFilepath());
830:
831:                    response.setContentType(document.getMimeType()
832:                            + "; charset=" + EnhydraDMConstants.ENCODING);
833:                    response
834:                            .setHeader(
835:                                    EnhydraDMConstants.HEAD_CONTENT_DISPOSITION,
836:                                    "attachment; filename=\""
837:                                            + URLEncoder
838:                                                    .encode(
839:                                                            document.getName(),
840:                                                            EnhydraDMConstants.ENCODING)
841:                                            + "\"");
842:                    response
843:                            .setHeader(EnhydraDMConstants.HEAD_PRAGMA, "public");
844:                    response.setHeader(EnhydraDMConstants.HEAD_CACHE_CONTROL,
845:                            "max-age=0");
846:                    response.setStatus(HttpPresentationResponse.SC_OK);
847:
848:                    out.write(documentContent);
849:                    out.flush();
850:                } catch (Exception e) {
851:                    throw new ActionNotAllowedException(e);
852:                }
853:
854:            }
855:
856:            private void unCheckoutDocument(HttpPresentationComms comms,
857:                    String documentId, String user) throws BaseException {
858:
859:                documentManager.unCheckOut(documentId, user);
860:
861:            }
862:
863:            private void switchVersionable(HttpPresentationComms comms,
864:                    String documentId, String user) throws BaseException {
865:
866:                documentManager.switchAutoVersionable(documentId, user);
867:
868:            }
869:
870:            private void switchArchived(HttpPresentationComms comms,
871:                    String documentId, String user) throws BaseException {
872:
873:                documentManager.switchArchived(documentId, user);
874:
875:            }
876:
877:            private void duplicateDocument(HttpPresentationComms comms,
878:                    String documentId, String user) throws BaseException {
879:
880:                Document doc = documentManager.getDocument(documentId);
881:
882:                byte[] documentContent = documentStore.loadDocumentContent(doc
883:                        .getFilepath());
884:                String documentPath = documentStore.saveDocumentContent(doc
885:                        .getName(), documentContent);
886:                documentManager.create(doc.getName(), documentPath, doc
887:                        .getMimeType(), user,
888:                        (null != doc.getFoDocumentRef() ? doc
889:                                .getFoDocumentRef().getId() : null), doc
890:                                .isTemplate(),
891:                        (null != doc.getTemplateRef() ? doc.getTemplateRef()
892:                                .getNumber() : null));
893:
894:            }
895:
896:            private void create(String documentName, byte[] documentContent,
897:                    String mimeType, String user, String foDocumentOid,
898:                    boolean isTemplate, String templateOid)
899:                    throws BaseException {
900:
901:                String documentPath = documentStore.saveDocumentContent(
902:                        documentName, documentContent);
903:                documentManager.create(documentName, documentPath, mimeType,
904:                        user, foDocumentOid, isTemplate, templateOid);
905:
906:            }
907:
908:            private void downloadVersionFile(HttpPresentationComms comms,
909:                    String documentId) throws BaseException {
910:
911:                try {
912:                    if (null != comms.application.getLogChannel()) {
913:                        comms.application.getLogChannel().write(
914:                                Logger.ERROR,
915:                                "Download document version for id: "
916:                                        + documentId + "!");
917:                    }
918:                    Document document = documentManager.getDocument(documentId);
919:                    byte[] fileForDownload = documentStore
920:                            .loadDocumentContent(document.getFilepath());
921:
922:                    HttpPresentationResponse response = comms.response;
923:                    HttpPresentationOutputStream out = response
924:                            .getOutputStream();
925:                    response.setContentType(new MimetypesFileTypeMap()
926:                            .getContentType(document.getName()));
927:                    response.setHeader(
928:                            EnhydraDMConstants.HEAD_CONTENT_DISPOSITION,
929:                            "attachment; filename=\"" + document.getName()
930:                                    + "\"");
931:                    response
932:                            .setHeader(EnhydraDMConstants.HEAD_PRAGMA, "public");
933:                    response.setHeader(EnhydraDMConstants.HEAD_CACHE_CONTROL,
934:                            "max-age=0");
935:                    response.setStatus(HttpPresentationResponse.SC_OK);
936:                    out.write(fileForDownload);
937:                    out.flush();
938:                } catch (BaseException e) {
939:                    throw e;
940:                } catch (HttpPresentationException e) {
941:                    throw new ActionNotAllowedException(e);
942:                } catch (IOException e) {
943:                    throw new ActionNotAllowedException(e);
944:                }
945:
946:            }
947:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.