You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/11/09 22:43:39 UTC
svn commit: r473082 - in /lenya/trunk/src/modules/export: ./ config/
config/cocoon-xconf/ java/ java/src/ java/src/org/ java/src/org/apache/
java/src/org/apache/lenya/ java/src/org/apache/lenya/cms/
java/src/org/apache/lenya/cms/export/ usecases/ xslt/
Author: andreas
Date: Thu Nov 9 13:43:38 2006
New Revision: 473082
URL: http://svn.apache.org/viewvc?view=rev&rev=473082
Log:
Adding export/import module
Added:
lenya/trunk/src/modules/export/
lenya/trunk/src/modules/export/config/
lenya/trunk/src/modules/export/config/cocoon-xconf/
lenya/trunk/src/modules/export/config/cocoon-xconf/usecase-import.xconf
lenya/trunk/src/modules/export/java/
lenya/trunk/src/modules/export/java/src/
lenya/trunk/src/modules/export/java/src/org/
lenya/trunk/src/modules/export/java/src/org/apache/
lenya/trunk/src/modules/export/java/src/org/apache/lenya/
lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/
lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/
lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Import.java
lenya/trunk/src/modules/export/module.xml
lenya/trunk/src/modules/export/sitemap.xmap
lenya/trunk/src/modules/export/usecases/
lenya/trunk/src/modules/export/usecases/import.jx
lenya/trunk/src/modules/export/xslt/
lenya/trunk/src/modules/export/xslt/dir2xhtml.xsl
Added: lenya/trunk/src/modules/export/config/cocoon-xconf/usecase-import.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/config/cocoon-xconf/usecase-import.xconf?view=auto&rev=473082
==============================================================================
--- lenya/trunk/src/modules/export/config/cocoon-xconf/usecase-import.xconf (added)
+++ lenya/trunk/src/modules/export/config/cocoon-xconf/usecase-import.xconf Thu Nov 9 13:43:38 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut $ -->
+<!--
+ This file defines the publication specific use-cases
+-->
+
+ <xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'export.import']">
+ <component-instance name="export.import" logger="lenya.export"
+ class="org.apache.lenya.cms.export.Import">
+ <view template="modules/export/usecases/import.jx" menu="false"/>
+ </component-instance>
+ </xconf>
Added: lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Import.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Import.java?view=auto&rev=473082
==============================================================================
--- lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Import.java (added)
+++ lenya/trunk/src/modules/export/java/src/org/apache/lenya/cms/export/Import.java Thu Nov 9 13:43:38 2006
@@ -0,0 +1,196 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.export;
+
+import java.io.File;
+
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.metadata.MetaData;
+import org.apache.lenya.cms.publication.Area;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentManager;
+import org.apache.lenya.cms.publication.PublicationException;
+import org.apache.lenya.cms.publication.ResourceType;
+import org.apache.lenya.cms.publication.URLInformation;
+import org.apache.lenya.cms.site.SiteNode;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.cms.site.tree.DefaultSiteTree;
+import org.apache.lenya.cms.usecase.AbstractUsecase;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.w3c.dom.Element;
+
+public class Import extends AbstractUsecase {
+
+ protected void initParameters() {
+ super.initParameters();
+ Area area = getArea();
+ String pubPath = area.getPublication().getDirectory().getAbsolutePath();
+ String path = pubPath.replace(File.separatorChar, '/') + "/example-content/authoring";
+ setParameter("path", path);
+ }
+
+ protected void doCheckPreconditions() throws Exception {
+ super.doCheckPreconditions();
+ Area area = getArea();
+ if (area.getDocuments().length > 0) {
+ addErrorMessage("You can't import anything because this publication already contains content.");
+ }
+ }
+
+ protected Area getArea() {
+ String url = getSourceURL();
+ URLInformation info = new URLInformation(url);
+ String pubId = info.getPublicationId();
+ String areaName = info.getArea();
+ Area area;
+ try {
+ area = getDocumentFactory().getPublication(pubId).getArea(areaName);
+ } catch (PublicationException e) {
+ throw new RuntimeException(e);
+ }
+ return area;
+ }
+
+ protected void doCheckExecutionConditions() throws Exception {
+ super.doCheckExecutionConditions();
+ String path = getParameterAsString("path");
+ String baseUri = "file://" + path;
+ String sitetreeUri = baseUri + "/sitetree.xml";
+ if (!SourceUtil.exists(sitetreeUri, this.manager)) {
+ addErrorMessage("The sitetree file does not exist in this directory.");
+ }
+ }
+
+ protected void doExecute() throws Exception {
+ super.doExecute();
+ doImport();
+ }
+
+ protected void doImport() throws Exception {
+
+ Area area = getArea();
+ getLogger().info("Importing documents into area [" + area + "]");
+
+ String path = getParameterAsString("path");
+ String baseUri = "file://" + path;
+ String sitetreeUri = baseUri + "/sitetree.xml";
+
+ org.w3c.dom.Document xml = SourceUtil.readDOM(sitetreeUri, this.manager);
+ NamespaceHelper helper = new NamespaceHelper(DefaultSiteTree.NAMESPACE_URI, "", xml);
+
+ Element siteElement = xml.getDocumentElement();
+ importChildren(area, helper, siteElement, baseUri, "");
+
+ }
+
+ protected void importElement(Area area, NamespaceHelper helper, Element element,
+ String baseUri, String parentPath) {
+ String path = parentPath + "/" + element.getAttribute("id");
+
+ boolean visible = true;
+ String visibleString = element.getAttribute("visibleinnav");
+ if (visibleString != null && !visibleString.equals("")) {
+ visible = Boolean.parseBoolean(visibleString);
+ }
+
+ Element[] labelElements = helper.getChildren(element, "label");
+ for (int i = 0; i < labelElements.length; i++) {
+ importDocument(area, labelElements[i], baseUri, path, visible);
+ }
+ importChildren(area, helper, element, baseUri, path);
+ }
+
+ protected void importDocument(Area area, Element element, String baseUri, String path,
+ boolean visibleInNav) {
+ String language = element.getAttribute("xml:lang");
+ String navigationTitle = DocumentHelper.getSimpleElementText(element);
+
+ String contentUri = baseUri + path + "/index_" + language;
+ String metaUri = contentUri + ".meta";
+
+ DocumentManager docManager = null;
+ ServiceSelector selector = null;
+ ResourceType resourceType = null;
+ SourceResolver resolver = null;
+ try {
+
+ org.w3c.dom.Document xml = SourceUtil.readDOM(metaUri, this.manager);
+ NamespaceHelper helper = new NamespaceHelper(
+ "http://apache.org/cocoon/lenya/page-envelope/1.0", "", xml);
+ Element metaElement = helper.getFirstChild(xml.getDocumentElement(), "meta");
+ Element internalElement = helper.getFirstChild(metaElement, "internal");
+ Element resourceTypeElement = helper.getFirstChild(internalElement, "resourceType");
+ String resourceTypeName = DocumentHelper.getSimpleElementText(resourceTypeElement);
+
+ selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
+ resourceType = (ResourceType) selector.select(resourceTypeName);
+
+ docManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
+ Document newDoc;
+ SiteStructure site = area.getSite();
+ if (!site.contains(path) || site.getNode(path).getLanguages().length == 0) {
+ newDoc = docManager.add(getDocumentFactory(), resourceType, contentUri, area.getPublication(),
+ area.getName(), path, language, ".html", navigationTitle, visibleInNav);
+ }
+ else {
+ SiteNode node = site.getNode(path);
+ Document doc = node.getLink(node.getLanguages()[0]).getDocument();
+ newDoc = docManager.addVersion(doc, area.getName(), language, true);
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ SourceUtil.copy(resolver, contentUri, newDoc.getSourceURI());
+ }
+
+ String dcNamespace = "http://purl.org/dc/elements/1.1/";
+
+ Element dcElement = helper.getFirstChild(metaElement, "dc");
+ NamespaceHelper dcHelper = new NamespaceHelper(dcNamespace, "dc", xml);
+ Element[] dcElements = dcHelper.getChildren(dcElement);
+
+ MetaData meta = newDoc.getMetaData(dcNamespace);
+ for (int i = 0; i < dcElements.length; i++) {
+ String key = dcElements[i].getLocalName();
+ String value = DocumentHelper.getSimpleElementText(dcElements[i]);
+ meta.setValue(key, value);
+ }
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (docManager != null) {
+ this.manager.release(docManager);
+ }
+ if (selector != null) {
+ this.manager.release(selector);
+ }
+ if (resolver != null) {
+ this.manager.release(resolver);
+ }
+ }
+ }
+
+ protected void importChildren(Area area, NamespaceHelper helper, Element element,
+ String baseUri, String path) {
+ Element[] elements = helper.getChildren(element, "node");
+ for (int i = 0; i < elements.length; i++) {
+ importElement(area, helper, elements[i], baseUri, path);
+ }
+ }
+
+}
Added: lenya/trunk/src/modules/export/module.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/module.xml?view=auto&rev=473082
==============================================================================
--- lenya/trunk/src/modules/export/module.xml (added)
+++ lenya/trunk/src/modules/export/module.xml Thu Nov 9 13:43:38 2006
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Id: publication.xml 374687 2006-02-03 15:24:55Z michi $ -->
+
+<module xmlns="http://apache.org/lenya/module/1.0">
+ <id>org.apache.lenya.modules.export</id>
+ <depends module="org.apache.lenya.modules.usecase"/>
+ <depends module="org.apache.lenya.modules.sitetree"/>
+ <package>org.apache.lenya.modules</package>
+ <version>0.1-dev</version>
+ <name>Export and import</name>
+ <lenya-version>@lenya.version@</lenya-version>
+ <description>Export and import documents</description>
+</module>
Added: lenya/trunk/src/modules/export/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/sitemap.xmap?view=auto&rev=473082
==============================================================================
--- lenya/trunk/src/modules/export/sitemap.xmap (added)
+++ lenya/trunk/src/modules/export/sitemap.xmap Thu Nov 9 13:43:38 2006
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Id$ -->
+
+<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+ <map:pipelines>
+
+ <map:pipeline>
+ <map:match pattern="directory/**:*">
+ <map:generate type="directory" src="/{1}"/>
+ <map:transform src="xslt/dir2xhtml.xsl">
+ <map:parameter name="path" value="{1}"/>
+ <map:parameter name="continuationId" value="{2}"/>
+ <map:parameter name="uri" value="{request:contextPath}{request:requestUri}"/>
+ </map:transform>
+ <map:serialize type="xml"/>
+ </map:match>
+ </map:pipeline>
+
+ </map:pipelines>
+
+</map:sitemap>
Added: lenya/trunk/src/modules/export/usecases/import.jx
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/usecases/import.jx?view=auto&rev=473082
==============================================================================
--- lenya/trunk/src/modules/export/usecases/import.jx (added)
+++ lenya/trunk/src/modules/export/usecases/import.jx Thu Nov 9 13:43:38 2006
@@ -0,0 +1,61 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id: forms.jx 416646 2006-06-23 09:02:03Z andreas $ -->
+<page:page
+ xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
+ xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
+ xmlns:ci="http://apache.org/cocoon/include/1.0"
+ >
+
+ <page:title><i18n:text>Import</i18n:text></page:title>
+ <page:body>
+
+ <jx:import uri="fallback://lenya/usecases/templates/messages.jx"/>
+
+ <form method="post">
+ <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+ <input type="hidden" name="lenya.usecase" value="${usecase.getName()}"/>
+
+ <jx:choose>
+ <jx:when test="${! usecase.hasErrors()}">
+ <p><i18n:text>Select import directory</i18n:text>:</p>
+ <p style="margin-bottom: 0">
+ <jx:set var="path" value="${usecase.getParameter('path')}"/>
+ <jx:set var="lastIndex" value="${path.lastIndexOf('/')}"/>
+ <jx:if test="${lastIndex > -1}">
+ <a href="?lenya.usecase=${usecase.getName()}&lenya.continuation=${continuation.id}&path=${path.substring(0, lastIndex)}">..</a>
+ </jx:if>
+ </p>
+ <ci:include src="cocoon://modules/export/directory/${usecase.getParameter('path')}:${continuation.id}"/>
+ <p>
+ <input type="submit" name="submit" value="Import" i18n:attr="value"/>
+ <input type="submit" value="Cancel" i18n:attr="value"/>
+ </p>
+ </jx:when>
+ <jx:otherwise>
+ <p>
+ <input type="submit" value="Cancel" i18n:attr="value"/>
+ </p>
+ </jx:otherwise>
+ </jx:choose>
+
+ </form>
+
+ </page:body>
+</page:page>
\ No newline at end of file
Added: lenya/trunk/src/modules/export/xslt/dir2xhtml.xsl
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/export/xslt/dir2xhtml.xsl?view=auto&rev=473082
==============================================================================
--- lenya/trunk/src/modules/export/xslt/dir2xhtml.xsl (added)
+++ lenya/trunk/src/modules/export/xslt/dir2xhtml.xsl Thu Nov 9 13:43:38 2006
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!--
+ Copyright 1999-2004 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Id: xinclude.xsl 123414 2004-12-27 14:52:24Z gregor $ -->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:dir="http://apache.org/cocoon/directory/2.0"
+ xmlns="http://www.w3.org/1999/xhtml"
+ >
+
+ <xsl:param name="path"/>
+ <xsl:param name="uri"/>
+ <xsl:param name="continuationId"/>
+
+
+ <xsl:template match="/dir:directory">
+ <p style="margin-bottom: 0">
+ <xsl:value-of select="$path"/>
+ </p>
+ <xsl:call-template name="children"/>
+ </xsl:template>
+
+
+ <xsl:template match="dir:directory">
+ <li>
+ <a href="{$uri}?lenya.usecase=export.import&lenya.continuation={$continuationId}&path={$path}/{@name}"><xsl:value-of select="@name"/></a>
+ </li>
+ <xsl:if test="*">
+ <xsl:call-template name="children"/>
+ </xsl:if>
+ </xsl:template>
+
+
+ <xsl:template name="children">
+ <ul style="margin-top: 0; margin-bottom: 0; list-style-type: none;">
+ <xsl:apply-templates select="*">
+ <xsl:sort/>
+ </xsl:apply-templates>
+ </ul>
+ </xsl:template>
+
+
+</xsl:stylesheet>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org