Source Code Cross Referenced for PublicationTypesFormHelper.java in  » Content-Management-System » daisy » org » outerj » daisy » books » frontend » 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.books.frontend 
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.books.frontend;
017:
018:        import org.apache.cocoon.forms.event.ActionListener;
019:        import org.apache.cocoon.forms.event.ActionEvent;
020:        import org.apache.cocoon.forms.formmodel.Form;
021:        import org.apache.cocoon.forms.formmodel.Repeater;
022:        import org.apache.cocoon.forms.formmodel.Field;
023:        import org.apache.cocoon.forms.formmodel.Action;
024:        import org.apache.cocoon.forms.datatype.SelectionList;
025:        import org.apache.cocoon.forms.datatype.Datatype;
026:        import org.apache.cocoon.forms.datatype.StaticSelectionList;
027:        import org.apache.cocoon.forms.util.StringMessage;
028:        import org.apache.avalon.framework.service.ServiceManager;
029:        import org.outerj.daisy.books.publisher.BookPublisher;
030:        import org.outerj.daisy.books.publisher.PublicationSpec;
031:        import org.outerj.daisy.books.publisher.PublicationTypeInfo;
032:        import org.outerx.daisy.x10Bookpubspecs.PublicationSpecsDocument;
033:
034:        import java.util.Map;
035:        import java.util.Arrays;
036:
037:        public class PublicationTypesFormHelper {
038:            private static class AddPublicationTypeAction implements 
039:                    ActionListener {
040:                private final PublicationTypeInfo[] publicationTypeInfos;
041:                private final ServiceManager serviceManager;
042:
043:                public AddPublicationTypeAction(
044:                        PublicationTypeInfo[] publicationTypeInfos,
045:                        ServiceManager serviceManager) {
046:                    this .publicationTypeInfos = publicationTypeInfos;
047:                    this .serviceManager = serviceManager;
048:                }
049:
050:                public void actionPerformed(ActionEvent actionEvent) {
051:                    Form form = actionEvent.getSourceWidget().getForm();
052:                    String typeName = (String) form.lookupWidget(
053:                            "editors/gui/availablePublicationTypes").getValue();
054:                    Repeater publicationsRepeater = (Repeater) form
055:                            .lookupWidget("editors/gui/publications");
056:                    Repeater.RepeaterRow row = publicationsRepeater.addRow();
057:                    String typeLabel = getPublicationTypeLabel(typeName,
058:                            publicationTypeInfos);
059:                    row.getChild("typeLabel").setValue(typeLabel);
060:                    row.getChild("typeName").setValue(typeName);
061:                    row.getChild("outputName").setValue(typeName);
062:                    row.getChild("outputLabel").setValue(typeLabel);
063:
064:                    loadDefaultProperties(row, typeName, serviceManager);
065:                }
066:            }
067:
068:            private static String getPublicationTypeLabel(String name,
069:                    PublicationTypeInfo[] publicationTypeInfos) {
070:                for (PublicationTypeInfo publicationTypeInfo : publicationTypeInfos) {
071:                    if (publicationTypeInfo.getName().equals(name)) {
072:                        return publicationTypeInfo.getLabel();
073:                    }
074:                }
075:                return "(error: specified publication type unknown)";
076:            }
077:
078:            private static void loadDefaultProperties(Repeater.RepeaterRow row,
079:                    String publicationTypeName, ServiceManager serviceManager) {
080:                Map<String, String> properties;
081:                BookPublisher bookPublisher = null;
082:                try {
083:                    bookPublisher = (BookPublisher) serviceManager
084:                            .lookup(BookPublisher.ROLE);
085:                    properties = bookPublisher
086:                            .getDefaultProperties(publicationTypeName);
087:                } catch (Exception e) {
088:                    throw new RuntimeException(e);
089:                } finally {
090:                    if (bookPublisher != null)
091:                        serviceManager.release(bookPublisher);
092:                }
093:                Field defaultPropertiesField = (Field) row
094:                        .getChild("defaultProperties");
095:                defaultPropertiesField
096:                        .setSelectionList(buildDefaultPropertiesSelectionList(
097:                                properties, defaultPropertiesField
098:                                        .getDatatype()));
099:                defaultPropertiesField.setAttribute("properties", properties);
100:            }
101:
102:            private static SelectionList buildDefaultPropertiesSelectionList(
103:                    Map<String, String> properties, Datatype datatype) {
104:                StaticSelectionList selectionList = new StaticSelectionList(
105:                        datatype);
106:                for (Map.Entry<String, String> entry : properties.entrySet()) {
107:                    selectionList.addItem(entry.getKey(), new StringMessage(
108:                            entry.getKey() + " = " + entry.getValue()));
109:                }
110:                return selectionList;
111:            }
112:
113:            private static PublicationTypeInfo[] getPublicationTypeInfos(
114:                    ServiceManager serviceManager) throws Exception {
115:                BookPublisher bookPublisher = null;
116:                try {
117:                    bookPublisher = (BookPublisher) serviceManager
118:                            .lookup(BookPublisher.ROLE);
119:                    return bookPublisher.getAvailablePublicationTypes();
120:                } finally {
121:                    if (bookPublisher != null)
122:                        serviceManager.release(bookPublisher);
123:                }
124:            }
125:
126:            public static void initPublicationsForm(Form form,
127:                    ServiceManager serviceManager) throws Exception {
128:                PublicationTypeInfo[] publicationTypeInfos = getPublicationTypeInfos(serviceManager);
129:                Arrays.sort(publicationTypeInfos);
130:                Field availablePublicationTypesField = (Field) form
131:                        .lookupWidget("editors/gui/availablePublicationTypes");
132:                availablePublicationTypesField.setSelectionList(
133:                        publicationTypeInfos, "name", "label");
134:                ((Action) form.lookupWidget("editors/gui/addPublicationType"))
135:                        .addActionListener(new AddPublicationTypeAction(
136:                                publicationTypeInfos, serviceManager));
137:            }
138:
139:            public static void loadPublicationSpecs(Form form,
140:                    PublicationSpec[] specs, ServiceManager serviceManager)
141:                    throws Exception {
142:                PublicationTypeInfo[] publicationTypeInfos = getPublicationTypeInfos(serviceManager);
143:                Repeater repeater = (Repeater) form
144:                        .lookupWidget("editors/gui/publications");
145:                repeater.clear(); // clear in case this is called on an existing form
146:                for (PublicationSpec spec : specs) {
147:                    Repeater.RepeaterRow row = repeater.addRow();
148:                    row.getChild("typeLabel").setValue(
149:                            getPublicationTypeLabel(spec
150:                                    .getPublicationTypeName(),
151:                                    publicationTypeInfos));
152:                    row.getChild("typeName").setValue(
153:                            spec.getPublicationTypeName());
154:                    row.getChild("outputName").setValue(
155:                            spec.getPublicationOutputName());
156:                    row.getChild("outputLabel").setValue(
157:                            spec.getPublicationOutputLabel());
158:                    Repeater propertiesRepeater = (Repeater) row
159:                            .getChild("properties");
160:                    for (Map.Entry<String, String> entry : spec
161:                            .getPublicationProperties().entrySet()) {
162:                        Repeater.RepeaterRow propRow = propertiesRepeater
163:                                .addRow();
164:                        propRow.getChild("name").setValue(entry.getKey());
165:                        propRow.getChild("value").setValue(entry.getValue());
166:                    }
167:                    loadDefaultProperties(row, spec.getPublicationTypeName(),
168:                            serviceManager);
169:                }
170:            }
171:
172:            public static PublicationSpecsDocument getXml(Form form) {
173:                PublicationSpecsDocument publicationSpecsDocument = PublicationSpecsDocument.Factory
174:                        .newInstance();
175:                PublicationSpecsDocument.PublicationSpecs publicationSpecsXml = publicationSpecsDocument
176:                        .addNewPublicationSpecs();
177:
178:                Repeater repeater = (Repeater) form
179:                        .lookupWidget("editors/gui/publications");
180:                for (int i = 0; i < repeater.getSize(); i++) {
181:                    Repeater.RepeaterRow row = repeater.getRow(i);
182:                    String typeName = (String) row.getChild("typeName")
183:                            .getValue();
184:                    String outputName = (String) row.getChild("outputName")
185:                            .getValue();
186:                    String outputLabel = (String) row.getChild("outputLabel")
187:                            .getValue();
188:
189:                    PublicationSpecsDocument.PublicationSpecs.PublicationSpec publicationSpecXml = publicationSpecsXml
190:                            .addNewPublicationSpec();
191:                    publicationSpecXml.setName(outputName);
192:                    publicationSpecXml.setType(typeName);
193:                    publicationSpecXml.setLabel(outputLabel);
194:
195:                    Repeater propertiesRepeater = (Repeater) row
196:                            .getChild("properties");
197:                    if (propertiesRepeater.getSize() > 0) {
198:                        PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Properties propertiesXml = publicationSpecXml
199:                                .addNewProperties();
200:                        for (int k = 0; k < propertiesRepeater.getSize(); k++) {
201:                            Repeater.RepeaterRow propRow = propertiesRepeater
202:                                    .getRow(k);
203:                            String name = (String) propRow.getChild("name")
204:                                    .getValue();
205:                            String value = (String) propRow.getChild("value")
206:                                    .getValue();
207:                            if (name != null) {
208:                                PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Properties.Entry entryXml = propertiesXml
209:                                        .addNewEntry();
210:                                entryXml.setKey(name);
211:                                if (value != null)
212:                                    entryXml.setStringValue(value);
213:                            }
214:                        }
215:                    }
216:                }
217:
218:                return publicationSpecsDocument;
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.