Source Code Cross Referenced for UploadPartEditor.java in  » Content-Management-System » daisy » org » outerj » daisy » frontend » editor » 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 » daisy » org.outerj.daisy.frontend.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 Outerthought bvba and Schaubroeck nv
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.outerj.daisy.frontend.editor;
017:
018:        import org.apache.cocoon.forms.formmodel.Form;
019:        import org.apache.cocoon.forms.formmodel.Upload;
020:        import org.apache.cocoon.forms.formmodel.Field;
021:        import org.apache.cocoon.forms.formmodel.Widget;
022:        import org.apache.cocoon.forms.validation.WidgetValidator;
023:        import org.apache.cocoon.forms.validation.ValidationError;
024:        import org.apache.cocoon.forms.util.I18nMessage;
025:        import org.apache.cocoon.forms.FormsConstants;
026:        import org.apache.cocoon.forms.event.*;
027:        import org.apache.avalon.framework.service.ServiceManager;
028:        import org.apache.avalon.framework.context.Context;
029:        import org.outerj.daisy.frontend.util.FormHelper;
030:        import org.outerj.daisy.frontend.DaisyException;
031:        import org.outerj.daisy.frontend.RequestUtil;
032:        import org.outerj.daisy.repository.Part;
033:        import org.outerj.daisy.repository.Document;
034:        import org.outerj.daisy.repository.Repository;
035:        import org.outerj.daisy.repository.schema.PartType;
036:        import org.outerj.daisy.repository.schema.PartTypeUse;
037:
038:        import java.util.Map;
039:        import java.util.HashMap;
040:
041:        public class UploadPartEditor implements  PartEditor {
042:            private final ServiceManager serviceManager;
043:
044:            private UploadPartEditor(ServiceManager serviceManager) {
045:                this .serviceManager = serviceManager;
046:            }
047:
048:            public static class Factory implements  PartEditorFactory {
049:                public PartEditor getPartEditor(Map properties,
050:                        ServiceManager serviceManager, Context context) {
051:                    return new UploadPartEditor(serviceManager);
052:                }
053:            }
054:
055:            public Form getForm(PartTypeUse partTypeUse,
056:                    DocumentEditorForm documentEditorForm, Repository repository)
057:                    throws Exception {
058:                final Form form = FormHelper.createForm(serviceManager,
059:                        "resources/form/parteditor_upload_definition.xml");
060:                form.addValidator(new UploadValidator(documentEditorForm,
061:                        partTypeUse.isRequired()));
062:
063:                Upload upload = (Upload) form.getChild("upload-part");
064:                upload.addValueChangedListener(new ValueChangedListener() {
065:                    public void valueChanged(ValueChangedEvent valueChangedEvent) {
066:                        org.apache.cocoon.servlet.multipart.Part part = (org.apache.cocoon.servlet.multipart.Part) valueChangedEvent
067:                                .getSourceWidget().getValue();
068:                        if (part != null) {
069:                            form.getChild("upload-part-mimetype").setValue(
070:                                    part.getMimeType());
071:                            form.getChild("upload-part-filename").setValue(
072:                                    RequestUtil
073:                                            .removePathFromUploadFileName(part
074:                                                    .getUploadName()));
075:                        }
076:                    }
077:                });
078:
079:                return form;
080:            }
081:
082:            public String getFormTemplate() {
083:                return "resources/form/parteditor_upload_template.xml";
084:            }
085:
086:            public void load(Form form, Document document, Part part,
087:                    Repository repository) throws Exception {
088:                Upload upload = (Upload) form.getChild("upload-part");
089:
090:                Map headers = new HashMap();
091:                headers.put("filename", "existing data");
092:                upload.setValue(new ExistingPart(headers));
093:                form.getChild("upload-part-filename").setValue(
094:                        part.getFileName());
095:                form.getChild("upload-part-mimetype").setValue(
096:                        part.getMimeType());
097:            }
098:
099:            public void save(Form form, Document document) throws Exception {
100:                Upload upload = (Upload) form.getChild("upload-part");
101:                long partTypeId = ((PartType) form.getAttribute("partType"))
102:                        .getId();
103:                org.apache.cocoon.servlet.multipart.Part part = (org.apache.cocoon.servlet.multipart.Part) upload
104:                        .getValue();
105:                if (part != null) {
106:                    if (!(part instanceof  ExistingPart)) {
107:                        if (part.getSize() < 0)
108:                            throw new DaisyException(
109:                                    "Uploaded part has a negative size: "
110:                                            + part.getSize());
111:                        document.setPart(partTypeId, part.getMimeType(),
112:                                new UploadPartDataSource(part));
113:                    }
114:                    Field mimeTypeField = (Field) form
115:                            .getChild("upload-part-mimetype");
116:                    Field fileNameField = (Field) form
117:                            .getChild("upload-part-filename");
118:                    document.setPartFileName(partTypeId, (String) fileNameField
119:                            .getValue());
120:                    document.setPartMimeType(partTypeId, (String) mimeTypeField
121:                            .getValue());
122:                } else {
123:                    document.deletePart(partTypeId);
124:                }
125:            }
126:
127:            class UploadValidator implements  WidgetValidator {
128:                private DocumentEditorForm documentEditorForm;
129:                private boolean isRequired;
130:
131:                public UploadValidator(DocumentEditorForm documentEditorForm,
132:                        boolean isRequired) {
133:                    this .documentEditorForm = documentEditorForm;
134:                    this .isRequired = isRequired;
135:                }
136:
137:                public boolean validate(Widget widget) {
138:                    boolean success = true;
139:                    if (documentEditorForm.getValidateOnSave() && isRequired) {
140:                        Form form = widget.getForm();
141:                        Upload upload = (Upload) form.getChild("upload-part");
142:                        Field partMimeType = (Field) form
143:                                .getChild("upload-part-mimetype");
144:                        if (upload.getValue() == null) {
145:                            upload.setValidationError(new ValidationError(
146:                                    "editdoc.part-required", true));
147:                            success = false;
148:                        } else if (upload.getValue() != null
149:                                && partMimeType.getValue() == null) {
150:                            partMimeType
151:                                    .setValidationError(new ValidationError(
152:                                            new I18nMessage(
153:                                                    "general.field-required",
154:                                                    FormsConstants.I18N_CATALOGUE)));
155:                            success = false;
156:                        }
157:                    }
158:                    return success;
159:                }
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.