Source Code Cross Referenced for Importer.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » cms » export » 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.export 
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.lenya.cms.export;
018:
019:        import org.apache.avalon.framework.logger.AbstractLogEnabled;
020:        import org.apache.avalon.framework.logger.Logger;
021:        import org.apache.avalon.framework.service.ServiceManager;
022:        import org.apache.avalon.framework.service.ServiceSelector;
023:        import org.apache.excalibur.source.SourceResolver;
024:        import org.apache.lenya.cms.cocoon.source.SourceUtil;
025:        import org.apache.lenya.cms.linking.LinkConverter;
026:        import org.apache.lenya.cms.metadata.MetaData;
027:        import org.apache.lenya.cms.publication.Area;
028:        import org.apache.lenya.cms.publication.Document;
029:        import org.apache.lenya.cms.publication.DocumentManager;
030:        import org.apache.lenya.cms.publication.Publication;
031:        import org.apache.lenya.cms.publication.ResourceType;
032:        import org.apache.lenya.cms.site.SiteNode;
033:        import org.apache.lenya.cms.site.SiteStructure;
034:        import org.apache.lenya.cms.site.tree.DefaultSiteTree;
035:        import org.apache.lenya.xml.DocumentHelper;
036:        import org.apache.lenya.xml.NamespaceHelper;
037:        import org.w3c.dom.Element;
038:
039:        /**
040:         * Import content.
041:         */
042:        public class Importer extends AbstractLogEnabled {
043:
044:            private ServiceManager manager;
045:
046:            /**
047:             * Ctor.
048:             * @param manager The service manager.
049:             * @param logger The logger.
050:             */
051:            public Importer(ServiceManager manager, Logger logger) {
052:                this .manager = manager;
053:                enableLogging(logger);
054:            }
055:
056:            /**
057:             * Imports content into an area.
058:             * @param area The area.
059:             * @param path The path containing the content.
060:             * @throws Exception if an error occurs.
061:             */
062:            public void importContent(Area area, String path) throws Exception {
063:                importContent(area.getPublication(), area, path);
064:            }
065:
066:            /**
067:             * Imports content from a different publication into an area.
068:             * @param srcPub The source publication.
069:             * @param area The area.
070:             * @param path The path containing the content.
071:             * @throws Exception if an error occurs.
072:             */
073:            public void importContent(Publication srcPub, Area area, String path)
074:                    throws Exception {
075:                getLogger()
076:                        .info("Importing documents into area [" + area + "]");
077:
078:                String baseUri = "file://" + path;
079:                String sitetreeUri = baseUri + "/sitetree.xml";
080:
081:                org.w3c.dom.Document xml = SourceUtil.readDOM(sitetreeUri,
082:                        this .manager);
083:                NamespaceHelper helper = new NamespaceHelper(
084:                        DefaultSiteTree.NAMESPACE_URI, "", xml);
085:
086:                Element siteElement = xml.getDocumentElement();
087:                importChildren(area, helper, siteElement, baseUri, "");
088:
089:                convertLinks(srcPub, area);
090:            }
091:
092:            protected void importElement(Area area, NamespaceHelper helper,
093:                    Element element, String baseUri, String parentPath) {
094:                String path = parentPath + "/" + element.getAttribute("id");
095:
096:                boolean visible = true;
097:                String visibleString = element.getAttribute("visibleinnav");
098:                if (visibleString != null && !visibleString.equals("")) {
099:                    visible = Boolean.valueOf(visibleString).booleanValue();
100:                }
101:
102:                Element[] labelElements = helper.getChildren(element, "label");
103:                for (int i = 0; i < labelElements.length; i++) {
104:                    importDocument(area, labelElements[i], baseUri, path,
105:                            visible);
106:                }
107:                importChildren(area, helper, element, baseUri, path);
108:            }
109:
110:            protected void importDocument(Area area, Element element,
111:                    String baseUri, String path, boolean visibleInNav) {
112:                String language = element.getAttribute("xml:lang");
113:                String navigationTitle = DocumentHelper
114:                        .getSimpleElementText(element);
115:
116:                String contentUri = baseUri + path + "/index_" + language;
117:                String metaUri = contentUri + ".meta";
118:
119:                DocumentManager docManager = null;
120:                ServiceSelector selector = null;
121:                ResourceType resourceType = null;
122:                SourceResolver resolver = null;
123:                try {
124:
125:                    org.w3c.dom.Document xml = SourceUtil.readDOM(metaUri,
126:                            this .manager);
127:                    NamespaceHelper helper = new NamespaceHelper(
128:                            "http://apache.org/cocoon/lenya/page-envelope/1.0",
129:                            "", xml);
130:                    Element metaElement = helper.getFirstChild(xml
131:                            .getDocumentElement(), "meta");
132:                    Element internalElement = helper.getFirstChild(metaElement,
133:                            "internal");
134:                    Element resourceTypeElement = helper.getFirstChild(
135:                            internalElement, "resourceType");
136:                    String resourceTypeName = DocumentHelper
137:                            .getSimpleElementText(resourceTypeElement);
138:
139:                    Element mimeTypeElement = helper.getFirstChild(
140:                            internalElement, "mimeType");
141:                    String mimeType = DocumentHelper
142:                            .getSimpleElementText(mimeTypeElement);
143:
144:                    selector = (ServiceSelector) this .manager
145:                            .lookup(ResourceType.ROLE + "Selector");
146:                    resourceType = (ResourceType) selector
147:                            .select(resourceTypeName);
148:
149:                    docManager = (DocumentManager) this .manager
150:                            .lookup(DocumentManager.ROLE);
151:                    Document newDoc;
152:                    SiteStructure site = area.getSite();
153:                    if (!site.contains(path)
154:                            || site.getNode(path).getLanguages().length == 0) {
155:                        newDoc = docManager.add(area.getPublication()
156:                                .getFactory(), resourceType, contentUri, area
157:                                .getPublication(), area.getName(), path,
158:                                language, "xml", navigationTitle, visibleInNav);
159:                        newDoc.setMimeType(mimeType);
160:                    } else {
161:                        SiteNode node = site.getNode(path);
162:                        Document doc = node.getLink(node.getLanguages()[0])
163:                                .getDocument();
164:                        newDoc = docManager.addVersion(doc, area.getName(),
165:                                language, true);
166:                        resolver = (SourceResolver) this .manager
167:                                .lookup(SourceResolver.ROLE);
168:                        SourceUtil.copy(resolver, contentUri, newDoc
169:                                .getOutputStream());
170:                        newDoc.getLink().setLabel(navigationTitle);
171:                    }
172:
173:                    String dcNamespace = "http://purl.org/dc/elements/1.1/";
174:
175:                    Element dcElement = helper.getFirstChild(metaElement, "dc");
176:                    NamespaceHelper dcHelper = new NamespaceHelper(dcNamespace,
177:                            "dc", xml);
178:                    Element[] dcElements = dcHelper.getChildren(dcElement);
179:
180:                    MetaData meta = newDoc.getMetaData(dcNamespace);
181:                    for (int i = 0; i < dcElements.length; i++) {
182:                        String key = dcElements[i].getLocalName();
183:                        String value = DocumentHelper
184:                                .getSimpleElementText(dcElements[i]);
185:                        meta.setValue(key, value);
186:                    }
187:
188:                } catch (Exception e) {
189:                    throw new RuntimeException(e);
190:                } finally {
191:                    if (docManager != null) {
192:                        this .manager.release(docManager);
193:                    }
194:                    if (selector != null) {
195:                        this .manager.release(selector);
196:                    }
197:                    if (resolver != null) {
198:                        this .manager.release(resolver);
199:                    }
200:                }
201:            }
202:
203:            protected void importChildren(Area area, NamespaceHelper helper,
204:                    Element element, String baseUri, String path) {
205:                Element[] elements = helper.getChildren(element, "node");
206:                for (int i = 0; i < elements.length; i++) {
207:                    importElement(area, helper, elements[i], baseUri, path);
208:                }
209:            }
210:
211:            protected void convertLinks(Publication srcPub, Area area) {
212:                Document[] docs = area.getDocuments();
213:                for (int i = 0; i < docs.length; i++) {
214:                    LinkConverter converter = new LinkConverter(this .manager,
215:                            getLogger());
216:                    converter.convertUrlsToUuids(srcPub, docs[i], false);
217:                }
218:            }
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.