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 2005/05/17 15:59:31 UTC
svn commit: r170596 - in
/lenya/trunk/src/java/org/apache/lenya/cms/site/simple: ./
DocumentStore.java DocumentStoreFactory.java SimpleSiteManager.java
Author: andreas
Date: Tue May 17 06:59:30 2005
New Revision: 170596
URL: http://svn.apache.org/viewcvs?rev=170596&view=rev
Log:
added SimpleSiteManager
Added:
lenya/trunk/src/java/org/apache/lenya/cms/site/simple/
lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java
lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java
lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteManager.java
Added: lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java?rev=170596&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java Tue May 17 06:59:30 2005
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.site.simple;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.cocoon.source.RepositorySource;
+import org.apache.lenya.cms.cocoon.source.SourceUtil;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.util.CollectionImpl;
+import org.apache.lenya.cms.repository.Node;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.w3c.dom.Element;
+
+/**
+ * Site structure object which stores a list of documents.
+ *
+ * @version $Id:$
+ */
+public class DocumentStore extends CollectionImpl implements SiteStructure {
+
+ protected static final String DOCUMENT_ID = "/site";
+
+ /**
+ * The identifiable type.
+ */
+ public static final String IDENTIFIABLE_TYPE = "documentstore";
+
+ /**
+ * @param manager The service manager.
+ * @param map The identity map.
+ * @param publication The publication.
+ * @param area The area.
+ * @param _logger The logger.
+ * @throws DocumentException if an error occurs.
+ */
+ public DocumentStore(ServiceManager manager, DocumentIdentityMap map, Publication publication,
+ String area, Logger _logger) throws DocumentException {
+ super(manager, map, publication, DOCUMENT_ID, area, _logger);
+ }
+
+ protected static final String ATTRIBUTE_LANGUAGE = "xml:lang";
+
+ /**
+ * @see org.apache.lenya.cms.publication.util.CollectionImpl#createDocumentElement(org.apache.lenya.cms.publication.Document,
+ * org.apache.lenya.xml.NamespaceHelper)
+ */
+ protected Element createDocumentElement(Document document, NamespaceHelper helper)
+ throws DocumentException {
+ Element element = super.createDocumentElement(document, helper);
+ element.setAttribute(ATTRIBUTE_LANGUAGE, document.getLanguage());
+ return element;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.publication.util.CollectionImpl#loadDocument(org.w3c.dom.Element)
+ */
+ protected Document loadDocument(Element documentElement) throws DocumentBuildException {
+ String documentId = documentElement.getAttribute(ATTRIBUTE_ID);
+ String language = documentElement.getAttribute(ATTRIBUTE_LANGUAGE);
+ Document document = getIdentityMap().get(getPublication(), getArea(), documentId, language);
+ return document;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteStructure#getRepositoryNode()
+ */
+ public Node getRepositoryNode() {
+ SourceResolver resolver = null;
+ RepositorySource documentSource = null;
+ Node node = null;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ documentSource = (RepositorySource) resolver.resolveURI(getSourceURI());
+ node = documentSource.getNode();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (documentSource != null) {
+ resolver.release(documentSource);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ return node;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.publication.Document#exists()
+ */
+ public boolean exists() throws DocumentException {
+ try {
+ return SourceUtil.exists(getSourceURI(), this.manager);
+ } catch (Exception e) {
+ throw new DocumentException(e);
+ }
+ }
+}
\ No newline at end of file
Added: lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java?rev=170596&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStoreFactory.java Tue May 17 06:59:30 2005
@@ -0,0 +1,85 @@
+/*
+ * 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.site.simple;
+
+import java.io.File;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceUtil;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationFactory;
+import org.apache.lenya.transaction.Identifiable;
+import org.apache.lenya.transaction.IdentityMap;
+import org.apache.lenya.transaction.IdentifiableFactory;
+
+/**
+ * Factory for sitetree objects.
+ *
+ * @version $Id:$
+ */
+public class DocumentStoreFactory extends AbstractLogEnabled implements IdentifiableFactory {
+
+ protected ServiceManager manager;
+
+ /**
+ * Ctor.
+ * @param manager The service manager.
+ */
+ public DocumentStoreFactory(ServiceManager manager) {
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.apache.lenya.transaction.IdentifiableFactory#build(org.apache.lenya.transaction.IdentityMap,
+ * java.lang.String)
+ */
+ public Identifiable build(IdentityMap map, String key) throws Exception {
+ String[] snippets = key.split(":");
+ String publicationId = snippets[0];
+ String area = snippets[1];
+
+ SourceResolver resolver = null;
+ Source source = null;
+ DocumentStore store;
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI("context://");
+ File servletContext = SourceUtil.getFile(source);
+
+ PublicationFactory factory = PublicationFactory.getInstance(getLogger());
+ Publication publication = factory.getPublication(publicationId, servletContext
+ .getAbsolutePath());
+
+ store = new DocumentStore(this.manager, (DocumentIdentityMap) map, publication, area,
+ getLogger());
+
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
+ return store;
+ }
+
+}
\ No newline at end of file
Added: lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteManager.java?rev=170596&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteManager.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteManager.java Tue May 17 06:59:30 2005
@@ -0,0 +1,234 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.lenya.cms.site.simple;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.publication.DocumentIdentityMap;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.site.AbstractSiteManager;
+import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteStructure;
+import org.apache.lenya.transaction.IdentifiableFactory;
+
+/**
+ * Simple site manager which does not imply structural information. The documents are stored in
+ * collections.
+ *
+ * @version $Id:$
+ */
+public class SimpleSiteManager extends AbstractSiteManager implements Serviceable {
+
+ private ServiceManager manager;
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#requires(org.apache.lenya.cms.publication.Document,
+ * org.apache.lenya.cms.publication.Document)
+ */
+ public boolean requires(Document dependingResource, Document requiredResource)
+ throws SiteException {
+ return false;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#getRequiredResources(org.apache.lenya.cms.publication.Document)
+ */
+ public Document[] getRequiredResources(Document resource) throws SiteException {
+ return new Document[0];
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#getRequiringResources(org.apache.lenya.cms.publication.Document)
+ */
+ public Document[] getRequiringResources(Document resource) throws SiteException {
+ return new Document[0];
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#add(org.apache.lenya.cms.publication.Document)
+ */
+ public void add(Document document) throws SiteException {
+
+ DocumentStore store = getStore(document);
+ try {
+ store.add(document);
+ } catch (DocumentException e) {
+ throw new SiteException(e);
+ }
+ }
+
+ /**
+ * @param document The document.
+ * @return The store of the document.
+ */
+ private DocumentStore getStore(Document document) {
+ Publication publication = document.getPublication();
+ String area = document.getArea();
+ DocumentIdentityMap map = document.getIdentityMap();
+ return getStore(map, publication, area);
+ }
+
+ /**
+ * @param map The identity map.
+ * @param publication The publication.
+ * @param area The area.
+ * @return A document store.
+ */
+ protected DocumentStore getStore(DocumentIdentityMap map, Publication publication, String area) {
+ String key = getKey(publication, area);
+ DocumentStore store;
+ IdentifiableFactory factory = map.getFactory(DocumentStore.IDENTIFIABLE_TYPE);
+ if (factory == null) {
+ factory = new DocumentStoreFactory(this.manager);
+ ContainerUtil.enableLogging(factory, getLogger());
+ map.setFactory(DocumentStore.IDENTIFIABLE_TYPE, factory);
+ }
+ store = (DocumentStore) map.get(DocumentStore.IDENTIFIABLE_TYPE, key);
+
+ return store;
+ }
+
+ /**
+ * @param publication The publication.
+ * @param area The area.
+ * @return The key to store sitetree objects in the identity map.
+ */
+ protected String getKey(Publication publication, String area) {
+ return publication.getId() + ":" + area;
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#contains(org.apache.lenya.cms.publication.Document)
+ */
+ public boolean contains(Document resource) throws SiteException {
+
+ if (resource.getId().equals(DocumentStore.DOCUMENT_ID)) {
+ return true;
+ }
+
+ try {
+ return getStore(resource).contains(resource);
+ } catch (DocumentException e) {
+ throw new SiteException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#containsInAnyLanguage(org.apache.lenya.cms.publication.Document)
+ */
+ public boolean containsInAnyLanguage(Document resource) throws SiteException {
+ try {
+ boolean contains = false;
+
+ String[] languages = resource.getPublication().getLanguages();
+ for (int i = 0; i < languages.length; i++) {
+ Document doc = resource.getIdentityMap().getLanguageVersion(resource, languages[i]);
+ DocumentStore store = getStore(doc);
+ contains = contains || store.contains(doc);
+ }
+
+ return getStore(resource).contains(resource);
+ } catch (Exception e) {
+ throw new SiteException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#copy(org.apache.lenya.cms.publication.Document,
+ * org.apache.lenya.cms.publication.Document)
+ */
+ public void copy(Document sourceDocument, Document destinationDocument) throws SiteException {
+ DocumentStore destinationStore = getStore(destinationDocument);
+ try {
+ if (!destinationStore.contains(destinationDocument)) {
+ destinationStore.add(destinationDocument);
+ }
+ } catch (Exception e) {
+ throw new SiteException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#delete(org.apache.lenya.cms.publication.Document)
+ */
+ public void delete(Document document) throws SiteException {
+ DocumentStore store = getStore(document);
+ try {
+ if (!store.contains(document)) {
+ store.remove(document);
+ }
+ } catch (Exception e) {
+ throw new SiteException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#getLabel(org.apache.lenya.cms.publication.Document)
+ */
+ public String getLabel(Document document) throws SiteException {
+ return "";
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#setLabel(org.apache.lenya.cms.publication.Document,
+ * java.lang.String)
+ */
+ public void setLabel(Document document, String label) throws SiteException {
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#getDocuments(org.apache.lenya.cms.publication.DocumentIdentityMap,
+ * org.apache.lenya.cms.publication.Publication, java.lang.String)
+ */
+ public Document[] getDocuments(DocumentIdentityMap identityMap, Publication publication,
+ String area) throws SiteException {
+ DocumentStore store = getStore(identityMap, publication, area);
+ try {
+ return store.getDocuments();
+ } catch (DocumentException e) {
+ throw new SiteException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#getSiteStructure(org.apache.lenya.cms.publication.DocumentIdentityMap,
+ * org.apache.lenya.cms.publication.Publication, java.lang.String)
+ */
+ public SiteStructure getSiteStructure(DocumentIdentityMap map, Publication publication,
+ String area) throws SiteException {
+ return getStore(map, publication, area);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.site.SiteManager#getAvailableDocument(org.apache.lenya.cms.publication.Document)
+ */
+ public Document getAvailableDocument(Document document) throws SiteException {
+ return document;
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org