Source Code Cross Referenced for BlogGenerator.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » generation » 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.cocoon.generation 
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:        package org.apache.cocoon.generation;
018:
019:        import java.io.IOException;
020:        import java.util.Arrays;
021:        import java.util.Comparator;
022:        import java.util.Date;
023:        import java.util.Map;
024:
025:        import org.apache.avalon.framework.parameters.Parameters;
026:        import org.apache.avalon.framework.service.ServiceSelector;
027:        import org.apache.cocoon.ProcessingException;
028:        import org.apache.cocoon.environment.ObjectModelHelper;
029:        import org.apache.cocoon.environment.Request;
030:        import org.apache.cocoon.environment.SourceResolver;
031:        import org.apache.lenya.cms.publication.Document;
032:        import org.apache.lenya.cms.publication.DocumentException;
033:        import org.apache.lenya.cms.publication.DocumentFactory;
034:        import org.apache.lenya.cms.publication.DocumentUtil;
035:        import org.apache.lenya.cms.publication.Publication;
036:        import org.apache.lenya.cms.publication.PublicationUtil;
037:        import org.apache.lenya.cms.repository.RepositoryUtil;
038:        import org.apache.lenya.cms.repository.Session;
039:        import org.apache.lenya.cms.site.SiteManager;
040:        import org.xml.sax.SAXException;
041:        import org.xml.sax.helpers.AttributesImpl;
042:
043:        /**
044:         * Blog entry generator
045:         */
046:        public class BlogGenerator extends ServiceableGenerator {
047:
048:            /** The URI of the namespace of this generator. */
049:            protected static final String URI = "http://apache.org/cocoon/blog/1.0";
050:
051:            /** The namespace prefix for this namespace. */
052:            protected static final String PREFIX = "blog";
053:
054:            /** Node and attribute names */
055:            protected static final String BLOG_NODE_NAME = "blog";
056:
057:            protected static final String ENTRY_NODE_NAME = "entry";
058:
059:            protected static final String PATH_ATTR_NAME = "path";
060:
061:            protected static final String LASTMOD_ATTR_NAME = "lastModified";
062:
063:            /**
064:             * Convenience object, so we don't need to create an AttributesImpl for every element.
065:             */
066:            protected AttributesImpl attributes;
067:
068:            /**
069:             * The Lenya-Area where the generator should work on
070:             */
071:            protected String area;
072:
073:            protected boolean recent;
074:
075:            /**
076:             * Only generate the #numrecent entries
077:             */
078:            protected int numrecent;
079:
080:            /**
081:             * Set the request parameters. Must be called before the generate method.
082:             * 
083:             * @param resolver the SourceResolver object
084:             * @param objectModel a <code>Map</code> containing model object
085:             * @param src the source URI (ignored)
086:             * @param par configuration parameters
087:             */
088:            public void setup(SourceResolver resolver, Map objectModel,
089:                    String src, Parameters par) throws ProcessingException,
090:                    SAXException, IOException {
091:                super .setup(resolver, objectModel, src, par);
092:
093:                area = par.getParameter("area", null);
094:                if (area == null)
095:                    throw new ProcessingException("no area specified");
096:                if (area.equals(Publication.LIVE_AREA))
097:                    numrecent = 16;
098:                else
099:                    numrecent = 0;
100:
101:                this .attributes = new AttributesImpl();
102:            }
103:
104:            /**
105:             * Generate XML data.
106:             * 
107:             * @throws SAXException if an error occurs while outputting the document
108:             */
109:            public void generate() throws SAXException, ProcessingException {
110:
111:                this .contentHandler.startDocument();
112:                this .contentHandler.startPrefixMapping(PREFIX, URI);
113:                attributes.clear();
114:
115:                this .contentHandler.startElement(URI, BLOG_NODE_NAME, PREFIX
116:                        + ':' + BLOG_NODE_NAME, attributes);
117:
118:                ServiceSelector selector = null;
119:                SiteManager siteManager = null;
120:                try {
121:                    Request request = ObjectModelHelper
122:                            .getRequest(this .objectModel);
123:                    Session session = RepositoryUtil.getSession(this .manager,
124:                            request);
125:                    DocumentFactory map = DocumentUtil.createDocumentFactory(
126:                            this .manager, session);
127:                    Publication publication = PublicationUtil.getPublication(
128:                            this .manager, request);
129:
130:                    selector = (ServiceSelector) this .manager
131:                            .lookup(SiteManager.ROLE + "Selector");
132:                    siteManager = (SiteManager) selector.select(publication
133:                            .getSiteManagerHint());
134:
135:                    Document[] docs = siteManager.getDocuments(map,
136:                            publication, area);
137:                    Arrays.sort((Object[]) docs, new Comparator() {
138:                        public int compare(Object o1, Object o2) {
139:                            try {
140:                                Date d1 = new Date(((Document) o2)
141:                                        .getLastModified());
142:                                Date d2 = new Date(((Document) o1)
143:                                        .getLastModified());
144:                                return d2.compareTo(d1);
145:                            } catch (DocumentException e) {
146:                                throw new RuntimeException(e);
147:                            }
148:                        }
149:                    });
150:
151:                    for (int i = 0; i < docs.length; i++) {
152:                        if (numrecent > 0 && numrecent <= i)
153:                            break;
154:                        String path = docs[i].getPath();
155:                        if (path.startsWith("/entries/")) {
156:                            attributes.clear();
157:                            attributes.addAttribute("", PATH_ATTR_NAME,
158:                                    PATH_ATTR_NAME, "CDATA", path);
159:                            attributes
160:                                    .addAttribute("", LASTMOD_ATTR_NAME,
161:                                            LASTMOD_ATTR_NAME, "CDATA", String
162:                                                    .valueOf(docs[i]
163:                                                            .getLastModified()));
164:
165:                            this .contentHandler.startElement(URI,
166:                                    ENTRY_NODE_NAME, PREFIX + ':'
167:                                            + ENTRY_NODE_NAME, attributes);
168:                            this .contentHandler.endElement(URI,
169:                                    ENTRY_NODE_NAME, PREFIX + ':'
170:                                            + ENTRY_NODE_NAME);
171:                        }
172:                    }
173:
174:                } catch (Exception e) {
175:                    throw new RuntimeException(e);
176:                } finally {
177:                    if (selector != null) {
178:                        if (siteManager != null) {
179:                            selector.release(siteManager);
180:                        }
181:                        this .manager.release(selector);
182:                    }
183:                }
184:
185:                this .contentHandler.endElement(URI, BLOG_NODE_NAME, PREFIX
186:                        + ':' + BLOG_NODE_NAME);
187:
188:                this.contentHandler.endPrefixMapping(PREFIX);
189:                this.contentHandler.endDocument();
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.