Source Code Cross Referenced for Publish.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » blog » cms » 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.blog.cms.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.blog.cms.usecases;
019:
020:        import java.text.DateFormat;
021:        import java.text.SimpleDateFormat;
022:        import java.util.ArrayList;
023:        import java.util.Date;
024:        import java.util.List;
025:
026:        import org.apache.lenya.cms.publication.Area;
027:        import org.apache.lenya.cms.publication.Document;
028:        import org.apache.lenya.cms.publication.DocumentManager;
029:        import org.apache.lenya.cms.publication.Publication;
030:        import org.apache.lenya.cms.publication.util.DocumentSet;
031:        import org.apache.lenya.cms.repository.Node;
032:        import org.apache.lenya.cms.site.NodeSet;
033:        import org.apache.lenya.cms.site.SiteUtil;
034:        import org.apache.lenya.cms.usecase.DocumentUsecase;
035:        import org.apache.lenya.cms.usecase.UsecaseException;
036:        import org.apache.lenya.cms.workflow.WorkflowUtil;
037:        import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper;
038:        import org.apache.lenya.workflow.Version;
039:        import org.apache.lenya.workflow.Workflowable;
040:        import org.apache.lenya.xml.DocumentHelper;
041:        import org.apache.xpath.XPathAPI;
042:        import org.w3c.dom.Element;
043:
044:        /**
045:         * Publish usecase handler.
046:         * 
047:         * @version $Id: Publish.java 209612 2005-07-07 16:52:44Z chestnut $
048:         */
049:        public class Publish extends DocumentUsecase {
050:
051:            protected static final String MISSING_DOCUMENTS = "missingDocuments";
052:
053:            /**
054:             * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
055:             */
056:            protected Node[] getNodesToLock() throws UsecaseException {
057:                try {
058:                    List nodes = new ArrayList();
059:                    DocumentSet set = new DocumentSet();
060:
061:                    Document doc = getSourceDocument();
062:                    NodeSet subsite = SiteUtil.getSubSite(this .manager, doc
063:                            .getLink().getNode());
064:                    set.addAll(new DocumentSet(subsite.getDocuments()));
065:
066:                    Document[] documents = set.getDocuments();
067:                    for (int i = 0; i < documents.length; i++) {
068:                        nodes.add(documents[i].getRepositoryNode());
069:                    }
070:
071:                    Area live = doc.getPublication().getArea(
072:                            Publication.LIVE_AREA);
073:                    nodes.add(live.getSite().getRepositoryNode());
074:                    return (Node[]) nodes.toArray(new Node[nodes.size()]);
075:
076:                } catch (Exception e) {
077:                    throw new UsecaseException(e);
078:                }
079:            }
080:
081:            /**
082:             * Checks if the workflow event is supported and the parent of the document
083:             * exists in the live area.
084:             * 
085:             * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
086:             */
087:            protected void doCheckPreconditions() throws Exception {
088:                super .doCheckPreconditions();
089:                if (!hasErrors()) {
090:
091:                    String event = getEvent();
092:                    Document document = getSourceDocument();
093:
094:                    if (!document.getArea().equals(Publication.AUTHORING_AREA)) {
095:                        addErrorMessage("This usecase can only be invoked from the authoring area.");
096:                        return;
097:                    }
098:
099:                    UsecaseWorkflowHelper.checkWorkflow(this .manager, this ,
100:                            event, document, getLogger());
101:                }
102:            }
103:
104:            /**
105:             * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
106:             */
107:            protected void doExecute() throws Exception {
108:                DocumentManager documentManager = null;
109:                try {
110:                    Document authoringDocument = getSourceDocument();
111:                    if (authoringDocument.getResourceType().getName().equals(
112:                            "entry")) {
113:                        updateBlogEntry(authoringDocument);
114:                    }
115:                    updateFeed();
116:                    documentManager = (DocumentManager) this .manager
117:                            .lookup(DocumentManager.ROLE);
118:                    documentManager.copyToArea(authoringDocument,
119:                            Publication.LIVE_AREA);
120:                    WorkflowUtil.invoke(this .manager, getSession(),
121:                            getLogger(), authoringDocument, getEvent());
122:                } catch (Exception e) {
123:                    throw new RuntimeException(e);
124:                } finally {
125:                    if (documentManager != null) {
126:                        this .manager.release(documentManager);
127:                    }
128:                }
129:            }
130:
131:            protected void updateFeed() throws Exception {
132:
133:                Document[] docs = new Document[2];
134:                org.w3c.dom.Document[] doms = new org.w3c.dom.Document[2];
135:
136:                Publication pub = getSourceDocument().getPublication();
137:                Area authoring = pub.getArea(Publication.AUTHORING_AREA);
138:                Area live = pub.getArea(Publication.LIVE_AREA);
139:                String path = "/feeds/all/index";
140:                String language = pub.getDefaultLanguage();
141:
142:                docs[0] = live.getSite().getNode(path).getLink(language)
143:                        .getDocument();
144:                docs[1] = authoring.getSite().getNode(path).getLink(language)
145:                        .getDocument();
146:
147:                DateFormat datefmt = new SimpleDateFormat(
148:                        "yyyy-MM-dd'T'HH:mm:ss");
149:                DateFormat ofsfmt = new SimpleDateFormat("Z");
150:                Date date = new Date();
151:
152:                String dateofs = ofsfmt.format(date);
153:                String datestr = datefmt.format(date) + dateofs.substring(0, 3)
154:                        + ":" + dateofs.substring(3, 5);
155:
156:                for (int i = 0; i < 2; i++) {
157:                    doms[i] = DocumentHelper.readDocument(docs[i]
158:                            .getInputStream());
159:                    Element parent = doms[i].getDocumentElement();
160:                    // set modified date on publish
161:                    Element element = (Element) XPathAPI
162:                            .selectSingleNode(parent,
163:                                    "/*[local-name() = 'feed']/*[local-name() = 'modified']");
164:                    DocumentHelper.setSimpleElementText(element, datestr);
165:                    DocumentHelper.writeDocument(doms[i], docs[i]
166:                            .getOutputStream());
167:                }
168:            }
169:
170:            protected void updateBlogEntry(Document doc) throws Exception {
171:                org.w3c.dom.Document dom = DocumentHelper.readDocument(doc
172:                        .getInputStream());
173:                Element parent = dom.getDocumentElement();
174:
175:                DateFormat datefmt = new SimpleDateFormat(
176:                        "yyyy-MM-dd'T'HH:mm:ss");
177:                DateFormat ofsfmt = new SimpleDateFormat("Z");
178:                Date date = new Date();
179:
180:                String dateofs = ofsfmt.format(date);
181:                String datestr = datefmt.format(date) + dateofs.substring(0, 3)
182:                        + ":" + dateofs.substring(3, 5);
183:
184:                // set modified date on re-publish
185:                Element element = (Element) XPathAPI
186:                        .selectSingleNode(parent,
187:                                "/*[local-name() = 'entry']/*[local-name() = 'modified']");
188:                DocumentHelper.setSimpleElementText(element, datestr);
189:
190:                // set issued date on first time publish
191:                Workflowable dw = WorkflowUtil.getWorkflowable(this .manager,
192:                        this .getSession(), this .getLogger(), doc);
193:                Version versions[] = dw.getVersions();
194:                boolean wasLive = false;
195:                for (int i = 0; i < versions.length; i++) {
196:                    if (versions[i].getValue("is_live")) {
197:                        wasLive = true;
198:                        break;
199:                    }
200:                }
201:                if (!wasLive) {
202:                    element = (Element) XPathAPI
203:                            .selectSingleNode(parent,
204:                                    "/*[local-name() = 'entry']/*[local-name() = 'issued']");
205:                    DocumentHelper.setSimpleElementText(element, datestr);
206:                }
207:
208:                DocumentHelper.writeDocument(dom, doc.getOutputStream());
209:            }
210:
211:            /**
212:             * @return The event to invoke.
213:             */
214:            private String getEvent() {
215:                return "publish";
216:            }
217:
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.