Source Code Cross Referenced for CreateDocument.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » site » usecases » 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 » apache lenya 2.0 » org.apache.lenya.cms.site.usecases 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.lenya.cms.site.usecases;
019:
020:        import java.util.Arrays;
021:
022:        import org.apache.lenya.cms.publication.Document;
023:        import org.apache.lenya.cms.publication.DocumentBuilder;
024:        import org.apache.lenya.cms.publication.DocumentException;
025:        import org.apache.lenya.cms.publication.DocumentLocator;
026:        import org.apache.lenya.cms.publication.Publication;
027:
028:        /**
029:         * Usecase to create a document.
030:         * 
031:         * @version $Id: CreateDocument.java 568678 2007-08-22 16:12:12Z andreas $
032:         */
033:        public class CreateDocument extends Create {
034:
035:            protected static final String PARENT_PATH = "parentPath";
036:
037:            protected static final String DOCUMENT_TYPE = "doctype";
038:
039:            protected static final String RELATION = "relation";
040:            protected static final String RELATIONS = "relations";
041:            protected static final String RELATION_CHILD = "child";
042:            protected static final String RELATION_BEFORE = "sibling before";
043:            protected static final String RELATION_AFTER = "sibling after";
044:            protected static final String PATH_PROVIDED = "pathProvided";
045:
046:            /**
047:             * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
048:             */
049:            protected void initParameters() {
050:                super .initParameters();
051:
052:                Document parent = getSourceDocument();
053:                if (parent == null) {
054:                    setParameter(PARENT_PATH, "");
055:                } else {
056:                    try {
057:                        setParameter(PARENT_PATH, parent.getPath());
058:                    } catch (DocumentException e) {
059:                        throw new RuntimeException(e);
060:                    }
061:                }
062:
063:                String[] languages = getPublication().getLanguages();
064:                if (languages.length == 0) {
065:                    addErrorMessage("The publication doesn't contain any languages!");
066:                }
067:                setParameter(LANGUAGES, languages);
068:
069:                Document sourceDoc = getSourceDocument();
070:                String[] childOnly = { RELATION_CHILD };
071:                String[] childAndAfter = { RELATION_CHILD, RELATION_AFTER };
072:                String[] relations = sourceDoc == null ? childOnly
073:                        : childAndAfter;
074:
075:                setParameter(RELATIONS, relations);
076:                setParameter(RELATION, RELATION_CHILD);
077:
078:                String path = getParameterAsString(PATH);
079:                boolean provided = path != null && !path.equals("");
080:                setParameter(PATH_PROVIDED, Boolean.valueOf(provided));
081:            }
082:
083:            /**
084:             * Override this method to support other relations.
085:             * @return The supported relations.
086:             */
087:            protected String[] getSupportedRelations() {
088:                return new String[] { RELATION_CHILD, RELATION_AFTER };
089:            }
090:
091:            /**
092:             * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
093:             */
094:            protected void doCheckExecutionConditions() throws Exception {
095:                super .doCheckExecutionConditions();
096:
097:                String relation = getParameterAsString(RELATION);
098:
099:                if (!Arrays.asList(getSupportedRelations()).contains(relation)) {
100:                    addErrorMessage("The relation '" + relation
101:                            + "' is not supported.");
102:                }
103:
104:                Publication pub = getPublication();
105:
106:                DocumentBuilder builder = pub.getDocumentBuilder();
107:                boolean provided = getParameterAsBoolean(PATH_PROVIDED, false);
108:
109:                if (provided) {
110:                    String newPath = getNewDocumentPath();
111:                    if (pub.getArea(getArea()).getSite().contains(newPath)) {
112:                        String[] params = { newPath };
113:                        addErrorMessage("path-already-exists", params);
114:                    }
115:                } else {
116:                    String nodeName = getNodeName();
117:                    if (nodeName.equals("")) {
118:                        addErrorMessage("missing-node-name");
119:                    } else if (!builder.isValidDocumentName(nodeName)) {
120:                        addErrorMessage("node-name-special-characters");
121:                    }
122:                }
123:            }
124:
125:            protected String getNodeName() {
126:                return getParameterAsString(NODE_NAME).trim();
127:            }
128:
129:            protected boolean isPathValid() {
130:                String nodeName = getNewDocumentName();
131:                DocumentBuilder builder = getPublication().getDocumentBuilder();
132:                return !nodeName.trim().equals("")
133:                        && builder.isValidDocumentName(nodeName);
134:            }
135:
136:            /**
137:             * @see Create#getNewDocumentName()
138:             */
139:            protected String getNewDocumentName() {
140:                String nodeName;
141:                if (getParameterAsBoolean(PATH_PROVIDED, false)) {
142:                    final String path = getParameterAsString(PATH);
143:                    nodeName = path.substring(path.lastIndexOf("/") + 1);
144:                } else {
145:                    nodeName = getNodeName();
146:                }
147:                return nodeName;
148:            }
149:
150:            /**
151:             * @return The relation between the source document and the created
152:             *         document.
153:             */
154:            protected String getRelation() {
155:                return getParameterAsString(RELATION);
156:            }
157:
158:            /**
159:             * @see Create#getNewDocumentPath()
160:             */
161:            protected String getNewDocumentPath() {
162:                if (getParameterAsBoolean(PATH_PROVIDED, false)) {
163:                    return getParameterAsString(PATH);
164:                } else {
165:                    String relation = getRelation();
166:                    Document sourceDoc = getSourceDocument();
167:                    if (sourceDoc == null) {
168:                        return "/" + getNewDocumentName();
169:                    } else {
170:                        DocumentLocator sourceLoc = getSourceDocument()
171:                                .getLocator();
172:                        if (relation.equals(RELATION_CHILD)) {
173:                            return sourceLoc.getChild(getNewDocumentName())
174:                                    .getPath();
175:                        } else if (relation.equals(RELATION_BEFORE)
176:                                || relation.equals(RELATION_AFTER)) {
177:                            return sourceLoc.getParent().getChild(
178:                                    getNewDocumentName()).getPath();
179:                        } else {
180:                            throw new IllegalStateException(
181:                                    "unsupported relation " + relation);
182:                        }
183:                    }
184:                }
185:            }
186:
187:            /**
188:             * @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
189:             */
190:            protected String getDocumentTypeName() {
191:                return getParameterAsString(DOCUMENT_TYPE);
192:            }
193:
194:            protected String getSourceExtension() {
195:                return "xml";
196:            }
197:
198:            protected boolean createVersion() {
199:                return false;
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.