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/11/18 18:03:33 UTC
svn commit: r345523 [1/2] - in /lenya/trunk/src:
java/org/apache/lenya/cms/migration/ java/org/apache/lenya/cms/repo/
java/org/apache/lenya/cms/repo/impl/
modules/jcr/java/src/org/apache/lenya/cms/jcr/
modules/jcr/java/src/org/apache/lenya/cms/jcr/meta...
Author: andreas
Date: Fri Nov 18 09:02:43 2005
New Revision: 345523
URL: http://svn.apache.org/viewcvs?rev=345523&view=rev
Log:
Improved repo interfaces and JCR-based implementation, added JCRRepositoryTest, updated migration class accordingly
Added:
lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentType.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentTypeRegistry.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/
lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeRegistryImpl.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/BuilderParameters.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/ResolvingNodeWrapperBuilder.java
lenya/trunk/src/modules/jcr/java/test/
lenya/trunk/src/modules/jcr/java/test/org/
lenya/trunk/src/modules/jcr/java/test/org/apache/
lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/
lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/cms/
lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/cms/jcr/
lenya/trunk/src/modules/jcr/java/test/org/apache/lenya/cms/jcr/JCRRepositoryTest.java
lenya/trunk/src/modules/jcr/targets/
lenya/trunk/src/modules/jcr/targets/test-build.xml
Removed:
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRArea.java
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java
lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNode.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSiteNodeBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapper.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperBuilder.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/NodeWrapperManager.java
lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/metadata/JCRMetaData.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/migration/Migrate14.java Fri Nov 18 09:02:43 2005
@@ -18,9 +18,8 @@
import java.io.File;
import java.io.FileFilter;
+import java.util.Arrays;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -28,19 +27,23 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.lenya.cms.metadata.LenyaMetaData;
import org.apache.lenya.cms.repo.Area;
import org.apache.lenya.cms.repo.ContentNode;
import org.apache.lenya.cms.repo.Document;
+import org.apache.lenya.cms.repo.DocumentType;
import org.apache.lenya.cms.repo.Publication;
import org.apache.lenya.cms.repo.Repository;
import org.apache.lenya.cms.repo.RepositoryException;
import org.apache.lenya.cms.repo.RepositoryManager;
import org.apache.lenya.cms.repo.Session;
import org.apache.lenya.cms.repo.SiteNode;
+import org.apache.lenya.cms.repo.impl.DocumentTypeImpl;
+import org.apache.lenya.cms.repo.impl.DocumentTypeRegistryImpl;
import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
import org.apache.tools.ant.BuildException;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.helpers.DefaultHandler;
+import org.w3c.dom.Element;
/**
* Migrate Lenya 1.4-dev content.
@@ -111,6 +114,10 @@
static final String CONFIGURATION_FILE = CONFIGURATION_PATH + File.separator
+ "publication.xconf";
+ /**
+ * Executes the migration.
+ * @throws BuildException if an error occurs.
+ */
public void execute() throws BuildException {
try {
@@ -149,7 +156,12 @@
protected void importPublication(File pubDir) throws RepositoryException {
String pubId = pubDir.getName();
- Publication pub = getSession().getPublication(pubId);
+ Publication pub;
+ if (getSession().existsPublication(pubId)) {
+ pub = getSession().getPublication(pubId);
+ } else {
+ pub = getSession().addPublication(pubId);
+ }
File contentDir = new File(pubDir, "content");
File[] areaDirs = contentDir.listFiles(directoryFilter);
@@ -160,7 +172,12 @@
protected void importContent(File contentDir, Publication pub) throws RepositoryException {
String area = contentDir.getName();
- Area repoArea = pub.getArea(area);
+ Area repoArea;
+ if (pub.existsArea(area)) {
+ repoArea = pub.getArea(area);
+ } else {
+ repoArea = pub.addArea(area);
+ }
importChildren(contentDir, repoArea, null);
}
@@ -171,19 +188,52 @@
parentPath = parent.getPath();
}
String documentPath = parentPath + "/" + nodeId;
- System.out.println("Importing [" + documentPath + "]");
+ System.out.println("Importing [" + area + "] - [" + documentPath + "]");
- SiteNode siteNode;
- ContentNode contentNode = area.getContent().addNode(nodeId);
- if (parent == null) {
- siteNode = area.getSite().addChild(nodeId, contentNode);
- } else {
- siteNode = parent.addChild(nodeId, contentNode);
- }
+ File[] metaFiles = docDir.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ return file.isFile() && file.getName().startsWith("index_")
+ && file.getName().endsWith(".xml.meta");
+ }
+ });
+ if (metaFiles.length > 0) {
- importDocuments(docDir, contentNode);
+ File metaFile = metaFiles[0];
+ org.w3c.dom.Document xmlDoc;
+ try {
+ xmlDoc = DocumentHelper.readDocument(metaFile);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ NamespaceHelper helper = new NamespaceHelper(LenyaMetaData.NAMESPACE, "", xmlDoc);
+ Element metaElement = helper.getFirstChild(xmlDoc.getDocumentElement(), "meta");
+ Element internalElement = helper.getFirstChild(metaElement, "internal");
+ Element resourceTypeElement = helper.getFirstChild(internalElement,
+ LenyaMetaData.ELEMENT_RESOURCE_TYPE);
+ String resourceType = DocumentHelper.getSimpleElementText(resourceTypeElement);
+ DocumentType doctype;
+
+ DocumentTypeRegistryImpl registry = (DocumentTypeRegistryImpl) getRepository().getDocumentTypeRegistry();
+ String[] names = registry.getDocumentTypeNames();
+ if (!Arrays.asList(names).contains(resourceType)) {
+ doctype = new DocumentTypeImpl(resourceType, null, false, "application/xml");
+ registry.register(doctype);
+ } else {
+ doctype = registry.getDocumentType(resourceType);
+ }
- importChildren(docDir, area, siteNode);
+ SiteNode siteNode;
+ String contentNodeId = documentPath.replace('/', '_');
+ ContentNode contentNode = area.getContent().addNode(contentNodeId, doctype);
+ if (parent == null) {
+ siteNode = area.getSite().addChild(nodeId, contentNode);
+ } else {
+ siteNode = parent.addChild(nodeId, contentNode);
+ }
+
+ importDocuments(docDir, contentNode);
+ importChildren(docDir, area, siteNode);
+ }
}
protected void importDocuments(File docDir, ContentNode contentNode) throws RepositoryException {
@@ -203,7 +253,7 @@
String suffix = fileName.substring("index_".length());
String language = suffix.substring(0, suffix.length() - ".xml".length());
System.out.println(" language [" + language + "]");
-
+
Document document = contentNode.addDocument(language);
try {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Content.java Fri Nov 18 09:02:43 2005
@@ -27,17 +27,20 @@
* @throws RepositoryException if an error occurs.
*/
ContentNode getNode(String id) throws RepositoryException;
-
+
/**
* @return All content nodes in this area.
+ * @throws RepositoryException if an error occurs.
*/
- ContentNode[] getNodes();
-
+ ContentNode[] getNodes() throws RepositoryException;
+
/**
* @param id The node ID.
+ * @param documentType The document type.
* @return The added node.
- * @throws RepositoryException if an error occurs.
+ * @throws RepositoryException if a node with this ID already exists or the document type is not
+ * registered.
*/
- ContentNode addNode(String id) throws RepositoryException;
-
+ ContentNode addNode(String id, DocumentType documentType) throws RepositoryException;
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/ContentNode.java Fri Nov 18 09:02:43 2005
@@ -16,14 +16,43 @@
*/
package org.apache.lenya.cms.repo;
+/**
+ * Content node.
+ */
public interface ContentNode {
-
+
+ /**
+ * @return The documents belonging to this node.
+ * @throws RepositoryException if an error occurs.
+ */
Document[] getDocuments() throws RepositoryException;
-
+
+ /**
+ * Adds a document.
+ * @param language The language of the document.
+ * @return the added document.
+ * @throws RepositoryException if the language version already exists.
+ */
Document addDocument(String language) throws RepositoryException;
-
+
+ /**
+ * @param document The document.
+ * @throws RepositoryException
+ */
void removeDocument(Document document) throws RepositoryException;
-
+
+ /**
+ * Returns a document of a specific language.
+ * @param language The document's language.
+ * @return A document.
+ * @throws RepositoryException if the language version does not exist.
+ */
Document getDocument(String language) throws RepositoryException;
+ /**
+ * @return The document type which this node's documents belong to.
+ * @throws RepositoryException if an error occurs.
+ */
+ DocumentType getDocumentType() throws RepositoryException;
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Document.java Fri Nov 18 09:02:43 2005
@@ -19,20 +19,52 @@
import java.io.InputStream;
import java.io.OutputStream;
+/**
+ * Document.
+ */
public interface Document {
+ /**
+ * @return The document's language code.
+ * @throws RepositoryException if an error occurs.
+ */
String getLanguage() throws RepositoryException;
+ /**
+ * @param language The document's language code.
+ * @throws RepositoryException if an error occurs.
+ */
void setLanguage(String language) throws RepositoryException;
+ /**
+ * @return The input stream to obtain the document's content from.
+ * @throws RepositoryException if an error occurs.
+ */
InputStream getInputStream() throws RepositoryException;
+ /**
+ * <p>
+ * Returns an output stream which can be used to write content to the document.
+ * </p>
+ * <p>
+ * If the content node's document type is validating and has a schema attached,
+ * the content is validated after it has been written.
+ * </p>
+ * @return The output stream to write the document's content to.
+ * @throws RepositoryException if an error occurs.
+ */
OutputStream getOutputStream() throws RepositoryException;
+ /**
+ * @return The content length.
+ * @throws RepositoryException if an error occurs.
+ */
long getContentLength() throws RepositoryException;
- String getMimeType() throws RepositoryException;
-
+ /**
+ * @return The last modification date of the document.
+ * @throws RepositoryException if an error occurs.
+ */
long getLastModified() throws RepositoryException;
}
Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentType.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentType.java?rev=345523&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentType.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentType.java Fri Nov 18 09:02:43 2005
@@ -0,0 +1,48 @@
+/*
+ * 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.repo;
+
+import org.apache.lenya.xml.Schema;
+
+/**
+ * @version $Id:$
+ */
+public interface DocumentType {
+
+ /**
+ * Returns the name of this document type.
+ * @return A string value.
+ */
+ String getName();
+
+ /**
+ * @return The source URI of the RelaxNG schema.
+ */
+ Schema getSchema();
+
+ /**
+ * @return If documents belonging to this document type should be validated upon writing.
+ */
+ boolean isValidating();
+
+ /**
+ * @return The mime type of the document type.
+ * @throws RepositoryException if an error occurs.
+ */
+ String getMimeType() throws RepositoryException;
+
+}
\ No newline at end of file
Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentTypeRegistry.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentTypeRegistry.java?rev=345523&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentTypeRegistry.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/DocumentTypeRegistry.java Fri Nov 18 09:02:43 2005
@@ -0,0 +1,37 @@
+/*
+ * 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.repo;
+
+/**
+ * Document type registry.
+ */
+public interface DocumentTypeRegistry {
+
+ /**
+ * @return All available document type names.
+ * @throws RepositoryException if an error occurs.
+ */
+ String[] getDocumentTypeNames() throws RepositoryException;
+
+ /**
+ * @param name The name of the document type.
+ * @return The document type.
+ * @throws RepositoryException if no document type exists with this name.
+ */
+ DocumentType getDocumentType(String name) throws RepositoryException;
+
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Publication.java Fri Nov 18 09:02:43 2005
@@ -16,8 +16,37 @@
*/
package org.apache.lenya.cms.repo;
+/**
+ * A publication.
+ */
public interface Publication {
+ /**
+ * @param area The area ID.
+ * @return The area object.
+ * @throws RepositoryException if the area does not exist.
+ */
Area getArea(String area) throws RepositoryException;
+
+ /**
+ * @param area The area ID.
+ * @return The area object.
+ * @throws RepositoryException if the area already exists.
+ */
+ Area addArea(String area) throws RepositoryException;
+
+ /**
+ * Checks if an area exists in this publication.
+ * @param area The area.
+ * @return A boolean value.
+ * @throws RepositoryException of an error occurs.
+ */
+ boolean existsArea(String area) throws RepositoryException;
+
+ /**
+ * @return The publication ID.
+ * @throws RepositoryException if an error occurs.
+ */
+ String getPublicationId() throws RepositoryException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Repository.java Fri Nov 18 09:02:43 2005
@@ -1,7 +1,36 @@
+/*
+ * 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.repo;
+/**
+ * Repository.
+ */
public interface Repository {
+ /**
+ * @return A session.
+ * @throws RepositoryException if an error occurs.
+ */
Session createSession() throws RepositoryException;
+
+ /**
+ * @return The document type registry.
+ * @throws RepositoryException if an error occurs.
+ */
+ DocumentTypeRegistry getDocumentTypeRegistry() throws RepositoryException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryException.java Fri Nov 18 09:02:43 2005
@@ -16,31 +16,33 @@
*/
package org.apache.lenya.cms.repo;
+/**
+ * Repository exception.
+ */
public class RepositoryException extends Exception {
/**
- *
+ * Ctor.
*/
public RepositoryException() {
super();
- // TODO Auto-generated constructor stub
}
/**
- * @param arg0
- * @param arg1
+ * Ctor.
+ * @param arg0 The message.
+ * @param arg1 The cause.
*/
public RepositoryException(String arg0, Throwable arg1) {
super(arg0, arg1);
- // TODO Auto-generated constructor stub
}
/**
- * @param arg0
+ * Ctor.
+ * @param arg0 The message.
*/
public RepositoryException(String arg0) {
super(arg0);
- // TODO Auto-generated constructor stub
}
/**
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/RepositoryManager.java Fri Nov 18 09:02:43 2005
@@ -18,8 +18,17 @@
import java.io.File;
+/**
+ * Repository manager.
+ */
public class RepositoryManager {
+ /**
+ * @param webappPath The directory of the web application.
+ * @param repositoryFactoryClass The class of the repository factory.
+ * @return A repository.
+ * @throws RepositoryException if the repository object could not be generated.
+ */
public static Repository getRepository(String webappPath, String repositoryFactoryClass)
throws RepositoryException {
try {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Session.java Fri Nov 18 09:02:43 2005
@@ -1,9 +1,53 @@
+/*
+ * 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.repo;
+/**
+ * Repository session.
+ */
public interface Session {
+ /**
+ * @param id The publication ID.
+ * @return A publication.
+ * @throws RepositoryException if the publication does not exist.
+ */
Publication getPublication(String id) throws RepositoryException;
+ /**
+ * Adds a publication.
+ * @param id The publication ID.
+ * @return The added publication.
+ * @throws RepositoryException if the publication already exists.
+ */
+ Publication addPublication(String id) throws RepositoryException;
+
+ /**
+ * Checks if a publication exists.
+ * @param id The publication ID.
+ * @return A boolean value.
+ * @throws RepositoryException if an error occurs.
+ */
+ boolean existsPublication(String id) throws RepositoryException;
+
+ /**
+ * Saves the session.
+ * @throws RepositoryException if an error occurs.
+ */
public void save() throws RepositoryException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/Site.java Fri Nov 18 09:02:43 2005
@@ -37,8 +37,15 @@
* @param name The name.
* @param contentNode The content node which the site node refers to.
* @return a site node.
- * @throws RepositoryException if an error occurs.
+ * @throws RepositoryException if a child with this name already exists.
*/
SiteNode addChild(String name, ContentNode contentNode) throws RepositoryException;
+
+ /**
+ * @param name The name.
+ * @return a site node.
+ * @throws RepositoryException if the child does not exist.
+ */
+ SiteNode getChild(String name) throws RepositoryException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/SiteNode.java Fri Nov 18 09:02:43 2005
@@ -53,4 +53,16 @@
* @throws RepositoryException if an error occurs.
*/
String getPath() throws RepositoryException;
+
+ /**
+ * @return The referenced content node.
+ * @throws RepositoryException if an error occurs.
+ */
+ ContentNode getContentNode() throws RepositoryException;
+
+ /**
+ * @return The parent node or <code>null</code> if this is a top-level node.
+ * @throws RepositoryException if an error occurs.
+ */
+ SiteNode getParent() throws RepositoryException;
}
Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeImpl.java?rev=345523&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeImpl.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeImpl.java Fri Nov 18 09:02:43 2005
@@ -0,0 +1,63 @@
+/*
+ * 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.repo.impl;
+
+import org.apache.lenya.cms.repo.DocumentType;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.xml.Schema;
+
+/**
+ * Document type implementation.
+ */
+public class DocumentTypeImpl implements DocumentType {
+
+ private String name;
+ private Schema schema;
+ private boolean isValidating;
+ private String mimeType;
+
+ /**
+ * Ctor.
+ * @param name The name of the document type.
+ * @param schema The schema to use. Can be <code>null</code>.
+ * @param isValidating If the documents should be validated upon writing.
+ * @param mimeType The mime type.
+ */
+ public DocumentTypeImpl(String name, Schema schema, boolean isValidating, String mimeType) {
+ this.name = name;
+ this.schema = schema;
+ this.isValidating = isValidating;
+ this.mimeType = mimeType;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public Schema getSchema() {
+ return this.schema;
+ }
+
+ public boolean isValidating() {
+ return this.isValidating;
+ }
+
+ public String getMimeType() throws RepositoryException {
+ return this.mimeType;
+ }
+
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeRegistryImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeRegistryImpl.java?rev=345523&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeRegistryImpl.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/impl/DocumentTypeRegistryImpl.java Fri Nov 18 09:02:43 2005
@@ -0,0 +1,60 @@
+/*
+ * 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.repo.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lenya.cms.repo.DocumentType;
+import org.apache.lenya.cms.repo.DocumentTypeRegistry;
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * Document type registry implementation.
+ */
+public class DocumentTypeRegistryImpl implements DocumentTypeRegistry {
+
+ private Map documentTypes = new HashMap();
+
+ /**
+ * Registers a document type.
+ * @param type The document type.
+ * @throws RepositoryException if the document type is already registered.
+ */
+ public void register(DocumentType type) throws RepositoryException {
+ if (this.documentTypes.containsKey(type.getName())) {
+ throw new RepositoryException("The document type [" + type.getName()
+ + "] is already registered.");
+ }
+ this.documentTypes.put(type.getName(), type);
+ }
+
+ public String[] getDocumentTypeNames() throws RepositoryException {
+ Set names = this.documentTypes.keySet();
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+
+ public DocumentType getDocumentType(String name) throws RepositoryException {
+ if (this.documentTypes.containsKey(name)) {
+ return (DocumentType) this.documentTypes.get(name);
+ } else {
+ throw new RepositoryException("The document type [" + name + "] is not registered.");
+ }
+ }
+
+}
Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java?rev=345523&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/AbstractNodeWrapperBuilder.java Fri Nov 18 09:02:43 2005
@@ -0,0 +1,26 @@
+package org.apache.lenya.cms.jcr;
+
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * Abstract node wrapper builder.
+ */
+public abstract class AbstractNodeWrapperBuilder implements NodeWrapperBuilder {
+
+ protected abstract NodeWrapper getNodeInternal(JCRSession session, BuilderParameters parameters)
+ throws RepositoryException;
+
+ public NodeWrapper getNode(JCRSession session, BuilderParameters parameters)
+ throws RepositoryException {
+ NodeWrapper node = getNodeInternal(session, parameters);
+ if (node == null) {
+ throw new RepositoryException("The node does not exist.");
+ }
+ return node;
+ }
+
+ public boolean existsNode(JCRSession session, BuilderParameters parameters) throws RepositoryException {
+ return getNodeInternal(session, parameters) != null;
+ }
+
+}
Added: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/BuilderParameters.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/BuilderParameters.java?rev=345523&view=auto
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/BuilderParameters.java (added)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/BuilderParameters.java Fri Nov 18 09:02:43 2005
@@ -0,0 +1,24 @@
+/*
+ * 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.jcr;
+
+/**
+ * Marker interface. See parameter object pattern.
+ */
+public interface BuilderParameters {
+
+}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContent.java Fri Nov 18 09:02:43 2005
@@ -20,6 +20,7 @@
import org.apache.lenya.cms.repo.Content;
import org.apache.lenya.cms.repo.ContentNode;
+import org.apache.lenya.cms.repo.DocumentType;
import org.apache.lenya.cms.repo.RepositoryException;
/**
@@ -29,40 +30,49 @@
/**
* Ctor.
+ * @param session The session.
* @param node The JCR node.
* @param area The area.
*/
- public JCRContent(Node node, JCRArea area) {
+ public JCRContent(JCRSession session, Node node, JCRPublicationNode area) {
super(node);
this.area = area;
- this.nodeManager = new NodeWrapperManager(area.getPublication().getSession());
+ this.nodeManager = new NodeWrapperManager(session, this.builder);
}
- private JCRArea area;
+ private JCRPublicationNode area;
- protected JCRArea getArea() {
+ protected JCRPublicationNode getArea() {
return this.area;
}
private NodeWrapperManager nodeManager;
+ private JCRContentNodeBuilder builder = new JCRContentNodeBuilder();
public ContentNode getNode(String id) throws RepositoryException {
- NodeWrapperBuilder builder = new JCRContentNodeBuilder(this, id);
- ContentNode node = (ContentNode) this.nodeManager.getNode(id, builder, false);
+ BuilderParameters params = builder.createParameters(this, id);
+ ContentNode node = (ContentNode) this.nodeManager.getNode(id, params, false);
if (node == null) {
throw new RepositoryException("The content node [" + id + "]Êdoes not exist.");
}
return node;
}
- public ContentNode[] getNodes() {
- // TODO Auto-generated method stub
- return null;
+ public ContentNode[] getNodes() throws RepositoryException {
+
+ String[] keys = this.nodeManager.getKeys(getNode());
+ ContentNode[] contentNodes = new ContentNode[keys.length];
+ for (int i = 0; i < contentNodes.length; i++) {
+ BuilderParameters params = this.builder.createParameters(this, keys[i]);
+ contentNodes[i] = (ContentNode) this.nodeManager.getNode(keys[i], params);
+ }
+
+ return contentNodes;
}
- public ContentNode addNode(String id) throws RepositoryException {
- NodeWrapperBuilder builder = new JCRContentNodeBuilder(this, id);
- return (ContentNode) this.nodeManager.getNode(id, builder, true);
+ public ContentNode addNode(String id, DocumentType documentType) throws RepositoryException {
+ BuilderParameters params = builder.createParameters(this, id, documentType);
+ return (ContentNode) this.nodeManager.addNode(id, params);
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentBuilder.java Fri Nov 18 09:02:43 2005
@@ -23,38 +23,78 @@
/**
* JCR content builder.
*/
-public class JCRContentBuilder implements NodeWrapperBuilder {
-
- private JCRArea area;
-
+public class JCRContentBuilder extends AbstractNodeWrapperBuilder {
+
/**
* Ctor.
- * @param area The area.
*/
- public JCRContentBuilder(JCRArea area) {
- this.area = area;
+ public JCRContentBuilder() {
}
protected static final String NODE_NAME = "lenya:content";
- public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+ public NodeWrapper addNode(JCRSession session, BuilderParameters parameters) throws RepositoryException {
try {
-
- Node pubNode = this.area.getPublicationNode().getNode();
+
+ JCRContentBuilderParameters params = (JCRContentBuilderParameters) parameters;
+ Node pubNode = params.getArea().getNode();
JCRContent wrapper = null;
Node contentNode;
if (pubNode.hasNode(NODE_NAME)) {
- contentNode = pubNode.getNode(NODE_NAME);
- wrapper = new JCRContent(contentNode, area);
- }
- else if (create) {
+ throw new RepositoryException("The node [" + params.getArea() + "] already exists.");
+ } else {
contentNode = pubNode.addNode(NODE_NAME);
- wrapper = new JCRContent(contentNode, area);
+ wrapper = new JCRContent(session, contentNode, params.getArea());
}
-
return wrapper;
} catch (Exception e) {
throw new RepositoryException(e);
+ }
+ }
+
+ protected NodeWrapper getNodeInternal(JCRSession session, BuilderParameters parameters) throws RepositoryException {
+ try {
+ JCRContentBuilderParameters params = (JCRContentBuilderParameters) parameters;
+ Node pubNode = params.getArea().getNode();
+ JCRContent wrapper = null;
+ Node contentNode;
+ if (pubNode.hasNode(NODE_NAME)) {
+ contentNode = pubNode.getNode(NODE_NAME);
+ wrapper = new JCRContent(session, contentNode, params.getArea());
+ }
+ return wrapper;
+ } catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * @param area The area.
+ * @return A parameters object.
+ */
+ public BuilderParameters createParameters(JCRPublicationNode area) {
+ return new JCRContentBuilderParameters(area);
+ }
+
+ /**
+ * Parameter object.
+ */
+ public static class JCRContentBuilderParameters implements BuilderParameters {
+ private JCRPublicationNode area;
+
+ /**
+ * Ctor.
+ * @param area The area.
+ */
+ public JCRContentBuilderParameters(JCRPublicationNode area) {
+ this.area = area;
+ }
+
+ /**
+ * @return The area.
+ */
+ public JCRPublicationNode getArea() {
+ return this.area;
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNode.java Fri Nov 18 09:02:43 2005
@@ -24,6 +24,8 @@
import org.apache.lenya.cms.repo.ContentNode;
import org.apache.lenya.cms.repo.Document;
+import org.apache.lenya.cms.repo.DocumentType;
+import org.apache.lenya.cms.repo.Repository;
import org.apache.lenya.cms.repo.RepositoryException;
/**
@@ -32,14 +34,25 @@
public class JCRContentNode extends NodeWrapper implements ContentNode {
private NodeWrapperManager documentManager;
+ private JCRDocumentBuilder builder = new JCRDocumentBuilder();
private JCRContent content;
+ private JCRSession session;
- public JCRContentNode(JCRContent content, Node node) {
+ /**
+ * Ctor.
+ * @param session The session.
+ * @param content The content object.
+ * @param node The JCR node.
+ */
+ public JCRContentNode(JCRSession session, JCRContent content, Node node) {
super(node);
+ this.session = session;
this.content = content;
- this.documentManager = new NodeWrapperManager(content.getArea()
- .getPublication()
- .getSession());
+ this.documentManager = new NodeWrapperManager(session, this.builder);
+ }
+
+ protected JCRContent getContent() {
+ return this.content;
}
public Document[] getDocuments() throws RepositoryException {
@@ -58,9 +71,8 @@
}
public Document addDocument(String language) throws RepositoryException {
- NodeWrapperBuilder builder = new JCRDocumentBuilder(this, language);
- return (Document) builder.buildNode(this.content.getArea().getPublication().getSession(),
- true);
+ BuilderParameters params = builder.createParameters(this, language);
+ return (Document) this.documentManager.getNode(language, params, true);
}
public void removeDocument(Document document) throws RepositoryException {
@@ -72,8 +84,20 @@
}
public Document getDocument(String language) throws RepositoryException {
- NodeWrapperBuilder builder = new JCRDocumentBuilder(this, language);
- return (Document) builder.buildNode(this.content.getArea().getPublication().getSession(), false);
+ BuilderParameters params = builder.createParameters(this, language);
+ return (Document) this.documentManager.getNode(language, params, false);
+ }
+
+ public DocumentType getDocumentType() throws RepositoryException {
+ Repository repo = this.session.getRepository();
+ String doctypeName;
+ try {
+ doctypeName = getNode().getProperty(JCRContentNodeBuilder.DOCUMENT_TYPE_PROPERTY)
+ .getString();
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
+ return repo.getDocumentTypeRegistry().getDocumentType(doctypeName);
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRContentNodeBuilder.java Fri Nov 18 09:02:43 2005
@@ -16,52 +16,178 @@
*/
package org.apache.lenya.cms.jcr;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import javax.jcr.Node;
import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.ValueFormatException;
+import org.apache.lenya.cms.repo.DocumentType;
import org.apache.lenya.cms.repo.RepositoryException;
/**
* JCR content node builder.
*/
-public class JCRContentNodeBuilder implements NodeWrapperBuilder {
-
- protected static final String NODE_NAME = "lenya:contentnode";
- protected static final String ID_ATTRIBUTE = "lenya:id";
+public class JCRContentNodeBuilder extends AbstractNodeWrapperBuilder implements
+ ResolvingNodeWrapperBuilder {
- private String id;
- private JCRContent content;
+ protected static final String NODE_NAME = "lenya:contentNode";
+ protected static final String NODE_TYPE = "lnt:contentNode";
+ protected static final String ID_PROPERTY = "lenya:id";
+ protected static final String DOCUMENT_TYPE_PROPERTY = "lenya:documentType";
/**
* Ctor.
- * @param content The content.
- * @param id The id.
*/
- public JCRContentNodeBuilder(JCRContent content, String id) {
- this.id = id;
- this.content = content;
+ public JCRContentNodeBuilder() {
}
- public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+ public NodeWrapper addNode(JCRSession session, BuilderParameters parameters)
+ throws RepositoryException {
try {
+ JCRContentNodeBuilderParameters params = (JCRContentNodeBuilderParameters) parameters;
JCRContentNode jcrContentNode = null;
- Node contentNode = null;
- Node content = this.content.getNode();
- for (NodeIterator nodes = content.getNodes(NODE_NAME); nodes.hasNext();) {
- Node node = nodes.nextNode();
- if (node.getProperty(ID_ATTRIBUTE).getString().equals(this.id)) {
- contentNode = node;
+ Node content = params.getContent().getNode();
+ Node contentNode = getNode(params, content);
+ if (contentNode == null) {
+
+ String names[] = session.getRepository()
+ .getDocumentTypeRegistry()
+ .getDocumentTypeNames();
+ if (params.getDocumentType() == null) {
+ throw new RepositoryException("The document type must not be null.");
+ } else if (!Arrays.asList(names).contains(params.getDocumentType())) {
+ throw new RepositoryException("The document type [" + params.getDocumentType()
+ + "] is not registered.");
}
+
+ contentNode = content.addNode(NODE_NAME, NODE_TYPE);
+ contentNode.setProperty(ID_PROPERTY, params.getId());
+ contentNode.setProperty(DOCUMENT_TYPE_PROPERTY, params.getDocumentType());
+ jcrContentNode = new JCRContentNode(session, params.getContent(), contentNode);
+ } else {
+ throw new RepositoryException("The node already exists!");
}
- if (contentNode == null && create) {
- contentNode = content.addNode(NODE_NAME);
- contentNode.setProperty(ID_ATTRIBUTE, this.id);
+
+ return jcrContentNode;
+ } catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ protected Node getNode(JCRContentNodeBuilderParameters params, Node content)
+ throws javax.jcr.RepositoryException, ValueFormatException, PathNotFoundException,
+ RepositoryException {
+ Node contentNode = null;
+ for (NodeIterator nodes = content.getNodes(NODE_NAME); nodes.hasNext();) {
+ Node node = nodes.nextNode();
+ if (getKey(node).equals(params.getId())) {
+ contentNode = node;
}
+ }
+ return contentNode;
+ }
+
+ public NodeWrapper getNodeInternal(JCRSession session, BuilderParameters parameters)
+ throws RepositoryException {
+ try {
+ JCRContentNodeBuilderParameters params = (JCRContentNodeBuilderParameters) parameters;
+ JCRContentNode jcrContentNode = null;
+ Node content = params.getContent().getNode();
+ Node contentNode = getNode(params, content);
if (contentNode != null) {
- jcrContentNode = new JCRContentNode(this.content, contentNode);
+ jcrContentNode = new JCRContentNode(session, params.getContent(), contentNode);
}
-
return jcrContentNode;
+ } catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public String getKey(Node node) throws RepositoryException {
+ try {
+ return node.getProperty(ID_PROPERTY).getString();
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * @param content The content.
+ * @param id The id.
+ * @param documentType The document type.
+ * @return A parameters object.
+ */
+ public BuilderParameters createParameters(JCRContent content, String id,
+ DocumentType documentType) {
+ return new JCRContentNodeBuilderParameters(content, id, documentType);
+ }
+
+ /**
+ * @param content The content.
+ * @param id The id.
+ * @return A parameters object.
+ */
+ public BuilderParameters createParameters(JCRContent content, String id) {
+ return new JCRContentNodeBuilderParameters(content, id, null);
+ }
+
+ /**
+ * Parameters.
+ */
+ public static class JCRContentNodeBuilderParameters implements BuilderParameters {
+
+ private JCRContent content;
+ private String id;
+ private String documentType;
+
+ /**
+ * @param content The content.
+ * @param id The node ID.
+ * @param documentType The document type.
+ */
+ public JCRContentNodeBuilderParameters(JCRContent content, String id,
+ DocumentType documentType) {
+ this.content = content;
+ this.id = id;
+ this.documentType = documentType.getName();
+ }
+
+ /**
+ * @return The content.
+ */
+ public JCRContent getContent() {
+ return content;
+ }
+
+ /**
+ * @return The node ID.
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @return The document type name.
+ */
+ public String getDocumentType() {
+ return this.documentType;
+ }
+
+ }
+
+ public String[] getKeys(JCRSession session, Node content) throws RepositoryException {
+ try {
+ List keys = new ArrayList();
+ for (NodeIterator nodes = content.getNodes(NODE_NAME); nodes.hasNext();) {
+ Node node = nodes.nextNode();
+ String key = getKey(node);
+ keys.add(key);
+ }
+ return (String[]) keys.toArray(new String[keys.size()]);
} catch (Exception e) {
throw new RepositoryException(e);
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocument.java Fri Nov 18 09:02:43 2005
@@ -89,7 +89,7 @@
}
}
- public String getMimeType() throws RepositoryException {
+ protected String getMimeType() throws RepositoryException {
try {
return getResourceNode().getProperty("jcr:mimeType").getString();
} catch (javax.jcr.RepositoryException e) {
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRDocumentBuilder.java Fri Nov 18 09:02:43 2005
@@ -16,6 +16,10 @@
*/
package org.apache.lenya.cms.jcr;
+import java.util.ArrayList;
+import java.util.GregorianCalendar;
+import java.util.List;
+
import javax.jcr.Node;
import javax.jcr.NodeIterator;
@@ -24,49 +28,138 @@
/**
* JCR document builder.
*/
-public class JCRDocumentBuilder implements NodeWrapperBuilder {
+public class JCRDocumentBuilder extends AbstractNodeWrapperBuilder implements
+ ResolvingNodeWrapperBuilder {
protected static final String LANGUAGE_ATTRIBUTE = "xml:lang";
protected static final String NODE_NAME = "lenya:document";
+ protected static final String NODE_TYPE = "lnt:document";
protected static final String RESOURCE_NODE_NAME = "lenya:resource";
+ protected static final String RESOURCE_NODE_TYPE = "lnt:resource";
+
+ /**
+ * Parameters.
+ */
+ public static class JCRDocumentBuilderParameters implements BuilderParameters {
- private String language;
- private JCRContentNode contentNode;
+ private String language;
+ private JCRContentNode contentNode;
+
+ /**
+ * Ctor.
+ * @param contentNode The content node.
+ * @param language The language.
+ */
+ public JCRDocumentBuilderParameters(JCRContentNode contentNode, String language) {
+ this.contentNode = contentNode;
+ this.language = language;
+ }
+
+ /**
+ * @return The content node.
+ */
+ public JCRContentNode getContentNode() {
+ return this.contentNode;
+ }
+
+ /**
+ * @return The language.
+ */
+ public String getLanguage() {
+ return this.language;
+ }
+
+ }
/**
- * Ctor.
* @param contentNode The content node.
* @param language The language.
+ * @return The parameters object.
*/
- public JCRDocumentBuilder(JCRContentNode contentNode, String language) {
- this.contentNode = contentNode;
- this.language = language;
+ public BuilderParameters createParameters(JCRContentNode contentNode, String language) {
+ return new JCRDocumentBuilderParameters(contentNode, language);
}
- public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+ public NodeWrapper addNode(JCRSession session, BuilderParameters parameters)
+ throws RepositoryException {
try {
+
+ JCRDocumentBuilderParameters params = (JCRDocumentBuilderParameters) parameters;
+
JCRDocument document = null;
- Node contentNodeNode = this.contentNode.getNode();
+ Node contentNodeNode = params.getContentNode().getNode();
- Node documentNode = null;
- for (NodeIterator i = contentNodeNode.getNodes(NODE_NAME); i.hasNext();) {
- Node node = i.nextNode();
- if (node.getProperty(LANGUAGE_ATTRIBUTE).getString().equals(this.language)) {
- documentNode = node;
- }
+ Node documentNode = getNode(params, contentNodeNode);
+
+ if (documentNode == null) {
+ documentNode = contentNodeNode.addNode(NODE_NAME, NODE_TYPE);
+ documentNode.setProperty(LANGUAGE_ATTRIBUTE, params.getLanguage());
+ Node resourceNode = documentNode.addNode(RESOURCE_NODE_NAME, RESOURCE_NODE_TYPE);
+ resourceNode.setProperty("jcr:mimeType", params.getContentNode()
+ .getDocumentType()
+ .getMimeType());
+ resourceNode.setProperty("jcr:data", "");
+ resourceNode.setProperty("jcr:lastModified", new GregorianCalendar());
+ } else {
+ throw new RepositoryException("The node already exists!");
}
- if (documentNode == null && create) {
- documentNode = contentNodeNode.addNode(NODE_NAME);
- documentNode.setProperty(LANGUAGE_ATTRIBUTE, this.language);
- documentNode.addNode(RESOURCE_NODE_NAME);
+ if (documentNode != null) {
+ document = new JCRDocument(documentNode);
}
+ return document;
+ } catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+ protected Node getNode(JCRDocumentBuilderParameters params, Node contentNodeNode)
+ throws javax.jcr.RepositoryException, RepositoryException {
+ Node documentNode = null;
+ for (NodeIterator i = contentNodeNode.getNodes(NODE_NAME); i.hasNext();) {
+ Node node = i.nextNode();
+ if (getKey(node).equals(params.getLanguage())) {
+ documentNode = node;
+ }
+ }
+ return documentNode;
+ }
+
+ protected NodeWrapper getNodeInternal(JCRSession session, BuilderParameters parameters)
+ throws RepositoryException {
+ try {
+
+ JCRDocumentBuilderParameters params = (JCRDocumentBuilderParameters) parameters;
+
+ JCRDocument document = null;
+ Node contentNodeNode = params.getContentNode().getNode();
+ Node documentNode = getNode(params, contentNodeNode);
if (documentNode != null) {
document = new JCRDocument(documentNode);
}
return document;
} catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public String[] getKeys(JCRSession session, Node reference) throws RepositoryException {
+ List keys = new ArrayList();
+ try {
+ for (NodeIterator i = reference.getNodes(NODE_NAME); i.hasNext();) {
+ Node node = i.nextNode();
+ keys.add(getKey(node));
+ }
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
+ return (String[]) keys.toArray(new String[keys.size()]);
+ }
+
+ public String getKey(Node node) throws RepositoryException {
+ try {
+ return node.getProperty(LANGUAGE_ATTRIBUTE).getString();
+ } catch (javax.jcr.RepositoryException e) {
throw new RepositoryException(e);
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublication.java Fri Nov 18 09:02:43 2005
@@ -16,9 +16,6 @@
*/
package org.apache.lenya.cms.jcr;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.lenya.cms.repo.Area;
import org.apache.lenya.cms.repo.Publication;
import org.apache.lenya.cms.repo.RepositoryException;
@@ -41,7 +38,7 @@
this.session = session;
}
- protected String getPublicationId() {
+ public String getPublicationId() {
return this.pubId;
}
@@ -49,15 +46,16 @@
return this.session;
}
- private Map areas = new HashMap();
-
public Area getArea(String area) throws RepositoryException {
- JCRArea jcrArea = (JCRArea) this.areas.get(area);
- if (jcrArea == null) {
- jcrArea = new JCRArea(this, area);
- this.areas.put(area, jcrArea);
- }
- return jcrArea;
+ return getSession().getArea(this, area);
+ }
+
+ public Area addArea(String area) throws RepositoryException {
+ return getSession().addArea(this, area);
+ }
+
+ public boolean existsArea(String area) throws RepositoryException {
+ return getSession().existsArea(this, area);
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNode.java Fri Nov 18 09:02:43 2005
@@ -18,17 +18,70 @@
import javax.jcr.Node;
+import org.apache.lenya.cms.repo.Area;
+import org.apache.lenya.cms.repo.Content;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.Site;
+
/**
* Publication node.
*/
-public class JCRPublicationNode extends NodeWrapper {
+public class JCRPublicationNode extends NodeWrapper implements Area {
/**
* Ctor.
+ * @param session
* @param node The JCR node.
*/
- public JCRPublicationNode(Node node) {
+ public JCRPublicationNode(JCRSession session, Node node) {
super(node);
+ this.contentManager = new NodeWrapperManager(session, this.contentBuilder);
+ this.siteManager = new NodeWrapperManager(session, this.siteBuilder);
+ }
+
+ private NodeWrapperManager contentManager;
+ private NodeWrapperManager siteManager;
+
+ private JCRContentBuilder contentBuilder = new JCRContentBuilder();
+ private JCRSiteBuilder siteBuilder = new JCRSiteBuilder();
+
+ protected String getPublicationId() throws RepositoryException {
+ try {
+ return getNode().getProperty(JCRPublicationNodeBuilder.ID_ATTRIBUTE).getString();
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ protected String getArea() throws RepositoryException {
+ try {
+ return getNode().getSession().getWorkspace().getName();
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public Content getContent() throws org.apache.lenya.cms.repo.RepositoryException {
+ BuilderParameters params = this.contentBuilder.createParameters(this);
+ return (Content) this.contentManager.getNode(JCRContentBuilder.NODE_NAME, params, true);
+ }
+
+ public Site getSite() throws org.apache.lenya.cms.repo.RepositoryException {
+ BuilderParameters params = this.siteBuilder.createParameters(this);
+ return (Site) this.siteManager.getNode(JCRSiteBuilder.NODE_NAME, params, true);
+ }
+
+ public void clear() throws org.apache.lenya.cms.repo.RepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String toString() {
+ try {
+ return getArea();
+ } catch (RepositoryException e) {
+ throw new RuntimeException(e);
+ }
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRPublicationNodeBuilder.java Fri Nov 18 09:02:43 2005
@@ -16,55 +16,171 @@
*/
package org.apache.lenya.cms.jcr;
+import java.util.HashSet;
+import java.util.Set;
+
import javax.jcr.Node;
import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.ValueFormatException;
+import org.apache.jackrabbit.core.WorkspaceImpl;
import org.apache.lenya.cms.repo.RepositoryException;
/**
* JCR publication node builder.
*/
-public class JCRPublicationNodeBuilder implements NodeWrapperBuilder {
+public class JCRPublicationNodeBuilder extends AbstractNodeWrapperBuilder implements
+ ResolvingNodeWrapperBuilder {
+
+ private JCRSession session;
/**
* Ctor.
+ * @param session The JCR session.
+ */
+ public JCRPublicationNodeBuilder(JCRSession session) {
+ this.session = session;
+ }
+
+ /**
+ * Parameters.
+ */
+ public static class JCRPublicationNodeBuilderParameters implements BuilderParameters {
+
+ /**
+ * Ctor.
+ * @param pubId The publication ID.
+ * @param area The area.
+ */
+ public JCRPublicationNodeBuilderParameters(String pubId, String area) {
+ this.pubId = pubId;
+ this.area = area;
+ }
+
+ private String pubId;
+ private String area;
+
+ /**
+ * @return The publication ID.
+ */
+ public String getPublicationId() {
+ return this.pubId;
+ }
+
+ /**
+ * @return The area.
+ */
+ public String getArea() {
+ return this.area;
+ }
+
+ }
+
+ /**
* @param pubId The publication ID.
* @param area The area.
+ * @return A parameters object.
*/
- public JCRPublicationNodeBuilder(String pubId, String area) {
- this.pubId = pubId;
- this.area = area;
+ public BuilderParameters createParameters(String pubId, String area) {
+ return new JCRPublicationNodeBuilderParameters(pubId, area);
}
- private String pubId;
- private String area;
-
protected static final String NODE_NAME = "lenya:publication";
+ protected static final String NODE_TYPE = "lnt:publication";
protected static final String ID_ATTRIBUTE = "lenya:id";
- public NodeWrapper buildNode(JCRSession session, boolean create) throws RepositoryException {
+ public NodeWrapper addNode(JCRSession session, BuilderParameters parameters)
+ throws RepositoryException {
try {
- JCRPublicationNode wrapper = null;
- Node rootNode = session.getSession(area).getRootNode();
+ JCRPublicationNodeBuilderParameters params = (JCRPublicationNodeBuilderParameters) parameters;
- Node pubNode = null;
+ JCRPublicationNode wrapper = null;
+ Node rootNode = session.getSession(params.getArea()).getRootNode();
- for (NodeIterator pubNodes = rootNode.getNodes(NODE_NAME); pubNodes.hasNext();) {
- Node node = pubNodes.nextNode();
- if (node.getProperty(ID_ATTRIBUTE).getString().equals(pubId)) {
- pubNode = node;
- }
+ Node pubNode = getNode(params, rootNode);
+ if (pubNode != null) {
+ throw new RepositoryException("The node already exists!");
}
- if (pubNode == null && create) {
- pubNode = rootNode.addNode(NODE_NAME);
- pubNode.setProperty(ID_ATTRIBUTE, pubId);
+ pubNode = rootNode.addNode(NODE_NAME, NODE_TYPE);
+ pubNode.setProperty(ID_ATTRIBUTE, params.getPublicationId());
+ wrapper = new JCRPublicationNode(session, pubNode);
+
+ return wrapper;
+ } catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ protected Node getNode(JCRPublicationNodeBuilderParameters params, Node rootNode)
+ throws javax.jcr.RepositoryException, ValueFormatException, PathNotFoundException {
+ Node pubNode = null;
+ for (NodeIterator pubNodes = rootNode.getNodes(NODE_NAME); pubNodes.hasNext();) {
+ Node node = pubNodes.nextNode();
+ if (node.getProperty(ID_ATTRIBUTE).getString().equals(params.getPublicationId())) {
+ pubNode = node;
}
+ }
+ return pubNode;
+ }
+ public NodeWrapper getNodeInternal(JCRSession session, BuilderParameters parameters)
+ throws RepositoryException {
+ try {
+ JCRPublicationNodeBuilderParameters params = (JCRPublicationNodeBuilderParameters) parameters;
+ JCRPublicationNode wrapper = null;
+ Node rootNode = session.getSession(params.getArea()).getRootNode();
+ Node pubNode = getNode(params, rootNode);
if (pubNode != null) {
- wrapper = new JCRPublicationNode(pubNode);
+ wrapper = new JCRPublicationNode(session, pubNode);
}
return wrapper;
} catch (Exception e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public String[] getKeys(JCRSession session, Node reference) throws RepositoryException {
+
+ Set keys = new HashSet();
+
+ WorkspaceImpl defaultWorkspace = getDefaultWorkspace();
+ try {
+ String[] workspaces = defaultWorkspace.getAccessibleWorkspaceNames();
+ for (int i = 0; i < workspaces.length; i++) {
+ Session areaSession = this.session.getRepository()
+ .getRepository()
+ .login(new SimpleCredentials("john", "".toCharArray()));
+ for (NodeIterator pubNodes = areaSession.getRootNode().getNodes(NODE_NAME); pubNodes.hasNext();) {
+ Node node = pubNodes.nextNode();
+ keys.add(node.getProperty(ID_ATTRIBUTE).getString() + ":" + workspaces[i]);
+ }
+ }
+ return (String[]) keys.toArray(new String[keys.size()]);
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public String getKey(Node node) throws RepositoryException {
+ try {
+ return node.getProperty(ID_ATTRIBUTE) + ":"
+ + node.getSession().getWorkspace().getName();
+ } catch (javax.jcr.RepositoryException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
+ protected WorkspaceImpl getDefaultWorkspace() throws RepositoryException {
+ try {
+ Session defaultWorkspaceSession = this.session.getRepository()
+ .getRepository()
+ .login(new SimpleCredentials("john", "".toCharArray()));
+ WorkspaceImpl defaultWorkspace = (WorkspaceImpl) defaultWorkspaceSession.getWorkspace();
+ return defaultWorkspace;
+ } catch (javax.jcr.RepositoryException e) {
throw new RepositoryException(e);
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRRepository.java Fri Nov 18 09:02:43 2005
@@ -21,6 +21,9 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import org.apache.lenya.cms.repo.DocumentTypeRegistry;
+import org.apache.lenya.cms.repo.impl.DocumentTypeRegistryImpl;
+
/**
* Facade to the JCR repository, providing Lenya-specific access.
*/
@@ -57,6 +60,15 @@
child = parent.addNode(childName);
}
return child;
+ }
+
+ private DocumentTypeRegistry documentTypeRegistry;
+
+ public DocumentTypeRegistry getDocumentTypeRegistry() throws org.apache.lenya.cms.repo.RepositoryException {
+ if (this.documentTypeRegistry == null) {
+ this.documentTypeRegistry = new DocumentTypeRegistryImpl();
+ }
+ return this.documentTypeRegistry;
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSession.java Fri Nov 18 09:02:43 2005
@@ -18,10 +18,15 @@
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
+import javax.jcr.LoginException;
import javax.jcr.NamespaceRegistry;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
@@ -40,6 +45,9 @@
*/
public JCRSession(JCRRepository repository) {
this.repository = repository;
+
+ this.publicationNodeBuilder = new JCRPublicationNodeBuilder(this);
+ this.publicationNodeManager = new NodeWrapperManager(this, this.publicationNodeBuilder);
}
private JCRRepository repository;
@@ -49,28 +57,37 @@
}
private Map area2session = new HashMap();
-
+
+ private NodeWrapperManager publicationNodeManager;
+ private JCRPublicationNodeBuilder publicationNodeBuilder;
+
protected Session getSession(String area) throws RepositoryException {
Session session = (Session) this.area2session.get(area);
if (session == null) {
- Session defaultWorkspaceSession = getRepository().getRepository()
- .login(new SimpleCredentials("john", "".toCharArray()));
+ boolean create = false;
- WorkspaceImpl defaultWorkspace = (WorkspaceImpl) defaultWorkspaceSession.getWorkspace();
+ WorkspaceImpl defaultWorkspace = getDefaultWorkspace();
String[] workspaces = defaultWorkspace.getAccessibleWorkspaceNames();
if (!Arrays.asList(workspaces).contains(area)) {
defaultWorkspace.createWorkspace(area);
+ create = true;
}
session = getRepository().getRepository().login(new SimpleCredentials("john",
"".toCharArray()),
area);
- NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry();
- String uri = "http://apache.org/cocoon/lenya/jcr/1.0";
- if (!Arrays.asList(registry.getURIs()).contains(uri)) {
- registry.registerNamespace("lenya", uri);
+ if (create) {
+ NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry();
+ String uri = "http://apache.org/cocoon/lenya/jcr/1.0";
+ if (!Arrays.asList(registry.getURIs()).contains(uri)) {
+ registry.registerNamespace("lenya", uri);
+ }
+ uri = "http://apache.org/cocoon/lenya/jcr/nodetype/1.0";
+ if (!Arrays.asList(registry.getURIs()).contains(uri)) {
+ registry.registerNamespace("lnt", uri);
+ }
}
this.area2session.put(area, session);
}
@@ -78,6 +95,14 @@
return session;
}
+ protected WorkspaceImpl getDefaultWorkspace() throws LoginException, RepositoryException {
+ Session defaultWorkspaceSession = getRepository().getRepository()
+ .login(new SimpleCredentials("john", "".toCharArray()));
+
+ WorkspaceImpl defaultWorkspace = (WorkspaceImpl) defaultWorkspaceSession.getWorkspace();
+ return defaultWorkspace;
+ }
+
public void save() throws org.apache.lenya.cms.repo.RepositoryException {
try {
for (Iterator i = this.area2session.keySet().iterator(); i.hasNext();) {
@@ -90,16 +115,117 @@
}
}
- private Map publications = new HashMap();
+ protected void initPublications() throws org.apache.lenya.cms.repo.RepositoryException {
+
+ if (this.publications == null) {
+ this.publications = new HashMap();
+ try {
+ Set pubIds = new HashSet();
+
+ WorkspaceImpl defaultWorkspace = getDefaultWorkspace();
+ String[] workspaces = defaultWorkspace.getAccessibleWorkspaceNames();
+
+ for (int i = 0; i < workspaces.length; i++) {
+
+ Session session = getSession(workspaces[i]);
+ Node rootNode = session.getRootNode();
+
+ for (NodeIterator pubNodes = rootNode.getNodes(JCRPublicationNodeBuilder.NODE_NAME); pubNodes.hasNext();) {
+ Node node = pubNodes.nextNode();
+
+ String pubId = node.getProperty(JCRPublicationNodeBuilder.ID_ATTRIBUTE)
+ .getString();
+ Publication pub = (Publication) this.publications.get(pubId);
+ if (pub == null) {
+ pub = new JCRPublication(this, pubId);
+ this.publications.put(pubId, pub);
+ }
+ pubIds.add(pubId);
+ }
+ }
+
+ } catch (RepositoryException e) {
+ throw new org.apache.lenya.cms.repo.RepositoryException(e);
+ }
+ }
+ }
+
+ private Map publications;
public Publication getPublication(String id)
throws org.apache.lenya.cms.repo.RepositoryException {
- Publication pub = (Publication) this.publications.get(id);
- if (pub == null) {
- pub = new JCRPublication(this, id);
+
+ initPublications();
+ if (this.publications.keySet().contains(id)) {
+ return (Publication) this.publications.get(id);
+ } else {
+ throw new org.apache.lenya.cms.repo.RepositoryException("The publication [" + id
+ + "] does not exist.");
+ }
+ }
+
+ public Publication addPublication(String id)
+ throws org.apache.lenya.cms.repo.RepositoryException {
+ initPublications();
+ if (this.publications.keySet().contains("id")) {
+ throw new org.apache.lenya.cms.repo.RepositoryException("The publication [" + id
+ + "]Êalready exists.");
+ } else {
+ Publication pub = new JCRPublication(this, id);
this.publications.put(id, pub);
+ return pub;
}
- return pub;
+ }
+
+ protected JCRPublicationNode addArea(JCRPublication publication, String area)
+ throws org.apache.lenya.cms.repo.RepositoryException {
+
+ BuilderParameters params = this.publicationNodeBuilder.createParameters(publication.getPublicationId(),
+ area);
+ if (this.publicationNodeBuilder.existsNode(this, params)) {
+ throw new org.apache.lenya.cms.repo.RepositoryException("The node already exists!");
+ } else {
+ return (JCRPublicationNode) this.publicationNodeManager.addNode(publication.getPublicationId()
+ + ":" + area,
+ params);
+ }
+ }
+
+ protected JCRPublicationNode[] getAreas(Publication publication)
+ throws org.apache.lenya.cms.repo.RepositoryException {
+
+ Set pubNodes = new HashSet();
+ String[] keys = this.publicationNodeManager.getKeys(null);
+ for (int i = 0; i < keys.length; i++) {
+ String[] steps = keys[i].split(":");
+ String pubId = steps[0];
+ if (pubId.equals(publication.getPublicationId())) {
+ String area = steps[1];
+ BuilderParameters params = this.publicationNodeBuilder.createParameters(publication.getPublicationId(),
+ area);
+ pubNodes.add(this.publicationNodeManager.getNode(keys[i], params));
+ }
+ }
+ return (JCRPublicationNode[]) pubNodes.toArray(new JCRPublicationNode[pubNodes.size()]);
+ }
+
+ protected JCRPublicationNode getArea(Publication publication, String area)
+ throws org.apache.lenya.cms.repo.RepositoryException {
+ BuilderParameters params = this.publicationNodeBuilder.createParameters(publication.getPublicationId(),
+ area);
+ return (JCRPublicationNode) this.publicationNodeManager.getNode(publication.getPublicationId(),
+ params);
+ }
+
+ protected boolean existsArea(Publication publication, String area) throws org.apache.lenya.cms.repo.RepositoryException {
+ BuilderParameters params = this.publicationNodeBuilder.createParameters(publication.getPublicationId(),
+ area);
+ return this.publicationNodeBuilder.existsNode(this, params);
+ }
+
+ public boolean existsPublication(String id) throws org.apache.lenya.cms.repo.RepositoryException {
+ initPublications();
+ return this.publications.containsKey(id);
}
}
Modified: lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java?rev=345523&r1=345522&r2=345523&view=diff
==============================================================================
--- lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java (original)
+++ lenya/trunk/src/modules/jcr/java/src/org/apache/lenya/cms/jcr/JCRSite.java Fri Nov 18 09:02:43 2005
@@ -32,24 +32,27 @@
*/
public class JCRSite extends NodeWrapper implements Site {
- private JCRArea area;
+ private JCRPublicationNode area;
/**
* Ctor.
+ * @param session The session.
* @param node The node.
* @param area The area.
*/
- public JCRSite(Node node, JCRArea area) {
+ public JCRSite(JCRSession session, Node node, JCRPublicationNode area) {
super(node);
this.area = area;
- this.childManager = new NodeWrapperManager(area.getPublication().getSession());
+ this.builder = new JCRSiteNodeBuilder(this);
+ this.childManager = new NodeWrapperManager(session, this.builder);
}
- protected JCRArea getArea() {
+ protected JCRPublicationNode getArea() {
return this.area;
}
private NodeWrapperManager childManager;
+ private JCRSiteNodeBuilder builder;
public SiteNode[] getChildren() throws RepositoryException {
try {
@@ -66,22 +69,26 @@
}
public SiteNode getChild(String name) throws RepositoryException {
- JCRSiteNodeBuilder builder = new JCRSiteNodeBuilder(this, getNode(), name);
- SiteNode child = (SiteNode) this.childManager.getNode(name, builder, false);
- if (child == null) {
- throw new RepositoryException("The node [" + name + "] does not exist!");
- }
- return child;
+ BuilderParameters params = builder.createParameters(getNode(), name, null);
+ return (SiteNode) this.childManager.getNode(name, params);
}
public SiteNode[] getNodes() throws RepositoryException {
- // TODO Auto-generated method stub
- return null;
+ String[] keys = this.childManager.getKeys(getNode());
+ SiteNode[] nodes = new SiteNode[keys.length];
+ for (int i = 0; i < keys.length; i++) {
+ BuilderParameters params = this.builder.createParameters(getNode(), keys[i], null);
+ nodes[i] = (SiteNode) this.childManager.getNode(keys[i], params);
+ }
+ return nodes;
}
public SiteNode addChild(String name, ContentNode contentNode) throws RepositoryException {
- JCRSiteNodeBuilder builder = new JCRSiteNodeBuilder(this, getNode(), name);
- return (SiteNode) this.childManager.getNode(name, builder, false);
+ BuilderParameters params = builder.createParameters(getNode(),
+ name,
+ (JCRContentNode) contentNode,
+ null);
+ return (SiteNode) this.childManager.addNode(name, params);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org