Author: andreas
Date: Tue Aug 29 06:10:37 2006
New Revision: 438067
URL: http://svn.apache.org/viewvc?rev=438067&view=rev
Log:
Removed obsolete methods from SiteUtil and replaced occurences with
SiteStructure methods
Modified:
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
lenya/trunk/src/impl/test/org/apache/lenya/cms/publication/DefaultDocumentTest.java
lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java
lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Assets.java
lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Create.java
Modified:
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java?rev=438067&r1=438066&r2=438067&view=diff
==============================================================================
---
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java
(original)
+++
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java
Tue Aug 29 06:10:37 2006
@@ -26,6 +26,7 @@
import org.apache.lenya.cms.repository.RepositoryItem;
import org.apache.lenya.cms.repository.Session;
import org.apache.lenya.cms.repository.UUIDGenerator;
+import org.apache.lenya.cms.site.SiteStructure;
import org.apache.lenya.cms.site.SiteUtil;
/**
@@ -70,15 +71,16 @@
throws DocumentBuildException {
if (getLogger().isDebugEnabled())
- getLogger().debug("DocumentIdentityMap::get() called on
publication ["
- + publication.getId() + "], area [" + area + "], UUID [" +
uuid
- + "], language [" + language + "]");
+ getLogger().debug(
+ "DocumentIdentityMap::get() called on publication [" +
publication.getId()
+ + "], area [" + area + "], UUID [" + uuid + "],
language [" + language
+ + "]");
String key = getKey(publication, area, uuid, language);
if (getLogger().isDebugEnabled())
- getLogger().debug("DocumentIdentityMap::get() got key [" + key
- + "] from DocumentFactory");
+ getLogger().debug(
+ "DocumentIdentityMap::get() got key [" + key + "] from
DocumentFactory");
try {
return (Document) getSession().getRepositoryItem(this, key);
@@ -173,8 +175,7 @@
public boolean isDocument(String webappUrl) throws DocumentBuildException {
try {
- Publication publication =
PublicationUtil.getPublicationFromUrl(this.manager,
- this,
+ Publication publication =
PublicationUtil.getPublicationFromUrl(this.manager, this,
webappUrl);
if (publication.exists()) {
@@ -183,7 +184,8 @@
try {
selector = (ServiceSelector)
this.manager.lookup(DocumentBuilder.ROLE
+ "Selector");
- builder = (DocumentBuilder)
selector.select(publication.getDocumentBuilderHint());
+ builder = (DocumentBuilder) selector.select(publication
+ .getDocumentBuilderHint());
if (builder.isDocument(webappUrl)) {
DocumentLocator locator = builder.getLocator(this,
webappUrl);
return SiteUtil.contains(this.manager, this, locator);
@@ -229,8 +231,7 @@
ServiceSelector selector = null;
DocumentBuilder builder = null;
try {
- Publication publication =
PublicationUtil.getPublicationFromUrl(this.manager,
- this,
+ Publication publication =
PublicationUtil.getPublicationFromUrl(this.manager, this,
webappUrl);
selector = (ServiceSelector)
this.manager.lookup(DocumentBuilder.ROLE + "Selector");
builder = (DocumentBuilder)
selector.select(publication.getDocumentBuilderHint());
@@ -239,7 +240,7 @@
String area = locator.getArea();
String uuid = null;
if (SiteUtil.isDocument(this.manager, this, webappUrl)) {
- uuid = SiteUtil.getUUID(this.manager, this, publication, area,
locator.getPath());
+ uuid =
publication.getArea(area).getSite().getNode(locator.getPath()).getUuid();
} else {
UUIDGenerator generator = (UUIDGenerator)
this.manager.lookup(UUIDGenerator.ROLE);
uuid = generator.nextUUID();
@@ -280,9 +281,7 @@
selector = (ServiceSelector)
this.manager.lookup(DocumentBuilder.ROLE + "Selector");
builder = (DocumentBuilder)
selector.select(publication.getDocumentBuilderHint());
- DocumentIdentifier identifier = new DocumentIdentifier(publication,
- area,
- uuid,
+ DocumentIdentifier identifier = new
DocumentIdentifier(publication, area, uuid,
language);
document = buildDocument(this, identifier, builder);
} catch (Exception e) {
@@ -324,9 +323,7 @@
}
public Document get(DocumentIdentifier identifier) throws
DocumentBuildException {
- return get(identifier.getPublication(),
- identifier.getArea(),
- identifier.getUUID(),
+ return get(identifier.getPublication(), identifier.getArea(),
identifier.getUUID(),
identifier.getLanguage());
}
@@ -337,11 +334,8 @@
public Document get(DocumentLocator locator) throws DocumentBuildException
{
try {
Publication pub = getPublication(locator.getPublicationId());
- String uuid = SiteUtil.getUUID(this.manager,
- this,
- pub,
- locator.getArea(),
- locator.getPath());
+ SiteStructure site = pub.getArea(locator.getArea()).getSite();
+ String uuid = site.getNode(locator.getPath()).getUuid();
return get(pub, locator.getArea(), uuid, locator.getLanguage());
} catch (PublicationException e) {
throw new DocumentBuildException(e);
Modified:
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?rev=438067&r1=438066&r2=438067&view=diff
==============================================================================
---
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
(original)
+++
lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
Tue Aug 29 06:10:37 2006
@@ -240,7 +240,6 @@
}
/**
- * @param targetUuid
* @see
org.apache.lenya.cms.publication.DocumentManager#copyDocument(org.apache.lenya.cms.publication.Document,
* org.apache.lenya.cms.publication.DocumentLocator)
*/
@@ -344,7 +343,7 @@
if (SiteUtil.contains(this.manager, sourceDoc)) {
if (SiteUtil.contains(this.manager, destinationDoc)) {
boolean visible = sourceDoc.getLink().getNode().isVisible();
- SiteUtil.setVisibleInNavigation(this.manager, destinationDoc,
visible);
+ destinationDoc.getLink().getNode().setVisible(visible);
} else {
String path = sourceDoc.getPath();
String label = sourceDoc.getLink().getLabel();
Modified:
lenya/trunk/src/impl/test/org/apache/lenya/cms/publication/DefaultDocumentTest.java
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/impl/test/org/apache/lenya/cms/publication/DefaultDocumentTest.java?rev=438067&r1=438066&r2=438067&view=diff
==============================================================================
---
lenya/trunk/src/impl/test/org/apache/lenya/cms/publication/DefaultDocumentTest.java
(original)
+++
lenya/trunk/src/impl/test/org/apache/lenya/cms/publication/DefaultDocumentTest.java
Tue Aug 29 06:10:37 2006
@@ -80,8 +80,7 @@
protected Document getDocument(DocumentTestSet testSet) throws
PublicationException {
Publication pub = getPublication("test");
- String uuid = SiteUtil.getUUID(getManager(), getFactory(), pub,
testSet.getArea(),
- testSet.getPath());
+ String uuid =
pub.getArea(testSet.getArea()).getSite().getNode(testSet.getPath()).getUuid();
DocumentIdentifier id = new DocumentIdentifier(pub, testSet.getArea(),
uuid, testSet
.getLanguage());
DocumentImpl document = new DocumentImpl(getManager(), getFactory(),
id, getLogger());
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java?rev=438067&r1=438066&r2=438067&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/SiteUtil.java Tue Aug 29
06:10:37 2006
@@ -32,7 +32,6 @@
import org.apache.lenya.cms.publication.DocumentLocator;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.URLInformation;
-import org.apache.lenya.cms.publication.util.DocumentSet;
/**
* Utility to handle site structures.
@@ -87,35 +86,6 @@
}
/**
- * @param manager The service manager.
- * @param factory The document factory.
- * @param map An identity map.
- * @param node A node.
- * @return All existing documents belonging to the node. Empty set if no
documents belong to the
- * node.
- * @throws DocumentBuildException if an error occurs.
- * @throws DocumentException if an error occurs.
- * @throws SiteException
- */
- public static DocumentSet getExistingDocuments(ServiceManager manager,
DocumentFactory factory,
- SiteNode node) throws DocumentBuildException, DocumentException,
SiteException {
- DocumentSet set = new DocumentSet();
-
- final Publication pub = node.getStructure().getPublication();
- final String area = node.getStructure().getArea();
- if (SiteUtil.contains(manager, factory, pub, area, node.getPath())) {
- String uuid = SiteUtil.getUUID(manager, factory, pub, area,
node.getPath());
- Document document = factory.get(pub, area, uuid);
- String[] languages = document.getLanguages();
- for (int i = 0; i < languages.length; i++) {
- Document version = document.getTranslation(languages[i]);
- set.add(version);
- }
- }
- return set;
- }
-
- /**
* Replace the target documents.
*/
public static final int MODE_REPLACE = 0;
@@ -293,7 +263,7 @@
}
/**
- * @see
org.apache.lenya.cms.site.SiteManager#getAvailableDocument(Document)
+ * @see
org.apache.lenya.cms.site.SiteManager#getAvailableLocator(DocumentFactory,
DocumentLocator)
* @param manager The service manager.
* @param factory The factory.
* @param locator The locator.
@@ -310,131 +280,6 @@
siteManager = (SiteManager)
selector.select(pub.getSiteManagerHint());
return siteManager.getAvailableLocator(factory, locator);
} catch (Exception e) {
- throw new SiteException(e);
- } finally {
- if (selector != null) {
- if (siteManager != null) {
- selector.release(siteManager);
- }
- manager.release(selector);
- }
- }
- }
-
- /**
- * @param manager The site manager.
- * @param document The document.
- * @param visible if the document should be visible.
- * @throws SiteException if an error occurs.
- */
- public static void setVisibleInNavigation(ServiceManager manager, Document
document,
- boolean visible) throws SiteException {
- ServiceSelector selector = null;
- SiteManager siteManager = null;
- try {
- selector = (ServiceSelector) manager.lookup(SiteManager.ROLE +
"Selector");
- siteManager = (SiteManager)
selector.select(document.getPublication()
- .getSiteManagerHint());
-
- siteManager.setVisibleInNav(document, visible);
- } catch (Exception e) {
- throw new SiteException(e);
- } finally {
- if (selector != null) {
- if (siteManager != null) {
- selector.release(siteManager);
- }
- manager.release(selector);
- }
- }
- }
-
- /**
- * Returns all documents in a certain area.
- * @param manager The service manager.
- * @param factory The document factory.
- * @param pub The publication.
- * @param area The area.
- * @return An array of documents.
- * @throws SiteException if an error occurs.
- */
- public static Document[] getDocuments(ServiceManager manager,
DocumentFactory factory,
- Publication pub, String area) throws SiteException {
- SiteManager siteManager = null;
- ServiceSelector selector = null;
-
- try {
- selector = (ServiceSelector) manager.lookup(SiteManager.ROLE +
"Selector");
- String siteManagerHint = pub.getSiteManagerHint();
- siteManager = (SiteManager) selector.select(siteManagerHint);
-
- Document[] docs = siteManager.getDocuments(factory, pub, area);
-
- Set foundDocs = new HashSet();
- for (int i = 0; i < docs.length; i++) {
- String hash = getHash(docs[i]);
- if (foundDocs.contains(hash)) {
- throw new SiteException("The document [" + hash
- + "] is contained more than once!");
- }
- foundDocs.add(hash);
- }
-
- return docs;
- } catch (ServiceException e) {
- throw new SiteException(e);
- } finally {
- if (selector != null) {
- if (siteManager != null) {
- selector.release(siteManager);
- }
- manager.release(selector);
- }
- }
- }
-
- protected static String getHash(Document doc) {
- return doc.getPublication().getId() + ":" + doc.getArea() + ":" +
doc.getUUID() + ":"
- + doc.getLanguage();
- }
-
- /**
- * Returns all documents in a certain area which have a certain resource
type.
- * @param manager The service manager.
- * @param factory The document factory.
- * @param pub The publication.
- * @param area The area.
- * @param resourceType The resource type name.
- * @return An array of documents.
- * @throws SiteException if an error occurs.
- */
- public static Document[] getDocuments(ServiceManager manager,
DocumentFactory factory,
- Publication pub, String area, String resourceType) throws
SiteException {
- Document[] docs = getDocuments(manager, factory, pub, area);
- Set documents = new HashSet();
- try {
- for (int i = 0; i < docs.length; i++) {
- if (docs[i].getResourceType().getName().equals(resourceType)) {
- documents.add(docs[i]);
- }
- }
- } catch (DocumentException e) {
- throw new SiteException(e);
- }
- return (Document[]) documents.toArray(new Document[documents.size()]);
- }
-
- public static String getUUID(ServiceManager manager, DocumentFactory
factory, Publication pub,
- String area, String path) throws SiteException {
- SiteManager siteManager = null;
- ServiceSelector selector = null;
-
- try {
- selector = (ServiceSelector) manager.lookup(SiteManager.ROLE +
"Selector");
- String siteManagerHint = pub.getSiteManagerHint();
- siteManager = (SiteManager) selector.select(siteManagerHint);
- return siteManager.getSiteStructure(factory, pub,
area).getNode(path).getUuid();
- } catch (ServiceException e) {
throw new SiteException(e);
} finally {
if (selector != null) {
Modified:
lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Assets.java
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Assets.java?rev=438067&r1=438066&r2=438067&view=diff
==============================================================================
---
lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Assets.java
(original)
+++
lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Assets.java
Tue Aug 29 06:10:37 2006
@@ -25,10 +25,10 @@
import org.apache.cocoon.servlet.multipart.Part;
import org.apache.lenya.ac.User;
import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.Resource;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.cms.repository.Node;
-import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.util.ServletHelper;
@@ -91,12 +91,8 @@
resourcesManager = (ResourcesManager)
this.manager.lookup(ResourcesManager.ROLE);
Resource[] resources =
resourcesManager.getResources(getSourceDocument());
setParameter("assets", Arrays.asList(resources));
-
- Document[] resourceDocs = SiteUtil.getDocuments(this.manager,
- getSourceDocument().getFactory(),
- getSourceDocument().getPublication(),
- getSourceDocument().getArea(),
- "resource");
+
+ Document[] resourceDocs = getResourceDocuments();
setParameter("resourceDocuments", resourceDocs);
User user = getSession().getIdentity().getUser();
@@ -111,6 +107,17 @@
this.manager.release(resourcesManager);
}
}
+ }
+
+ protected Document[] getResourceDocuments() throws DocumentException {
+ List list = new ArrayList();
+ Document[] docs = getSourceDocument().area().getDocuments();
+ for (int i = 0; i < docs.length; i++) {
+ if (docs[i].getResourceType().getName().equals("resource")) {
+ list.add(docs);
+ }
+ }
+ return (Document[]) list.toArray(new Document[list.size()]);
}
/**
Modified:
lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Create.java
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Create.java?rev=438067&r1=438066&r2=438067&view=diff
==============================================================================
---
lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Create.java
(original)
+++
lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Create.java
Tue Aug 29 06:10:37 2006
@@ -33,7 +33,6 @@
import org.apache.lenya.cms.metadata.MetaDataException;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentManager;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationException;
@@ -41,15 +40,17 @@
import org.apache.lenya.cms.publication.ResourceType;
import org.apache.lenya.cms.publication.URLInformation;
import org.apache.lenya.cms.repository.Node;
-import org.apache.lenya.cms.site.SiteException;
import org.apache.lenya.cms.site.SiteStructure;
-import org.apache.lenya.cms.site.SiteUtil;
import org.apache.lenya.cms.usecase.AbstractUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
/**
- * <p>Abstract superclass for usecases to create a document.</p>
- * <p>You can pass the following parameters into the usecase:</p>
+ * <p>
+ * Abstract superclass for usecases to create a document.
+ * </p>
+ * <p>
+ * You can pass the following parameters into the usecase:
+ * </p>
* <ul>
* <li><strong>path</strong> - the path of the document to create
(optional)</li>
* </ul>
@@ -114,7 +115,7 @@
addErrorMessage("Please select a page layout.");
}
}
-
+
String path = getNewDocumentPath();
SiteStructure site = getPublication().getArea(getArea()).getSite();
if (!createVersion() && site.contains(path)) {
@@ -315,37 +316,14 @@
* @return The new document.
*/
protected Document getNewDocument() {
- Document document = null;
- // get new document
- DocumentManager documentManager = null;
- ServiceSelector selector = null;
- ResourceType resourceType = null;
try {
- documentManager = (DocumentManager)
this.manager.lookup(DocumentManager.ROLE);
-
- DocumentFactory factory = getDocumentFactory();
-
String path = getNewDocumentPath();
- String uuid = SiteUtil
- .getUUID(this.manager, factory, getPublication(),
getArea(), path);
-
- document = factory.get(getPublication(), getArea(), uuid,
- getParameterAsString(LANGUAGE));
-
+ String language = getParameterAsString(LANGUAGE);
+ return getPublication().getArea(getArea()).getSite().getNode(path)
+ .getLink(language).getDocument();
} catch (Exception e) {
throw new RuntimeException(e);
- } finally {
- if (documentManager != null) {
- this.manager.release(documentManager);
- }
- if (selector != null) {
- if (resourceType != null) {
- selector.release(resourceType);
- }
- this.manager.release(selector);
- }
}
- return document;
}
/**
@@ -369,8 +347,7 @@
if (this.publication == null) {
try {
this.publication =
PublicationUtil.getPublicationFromUrl(this.manager,
- getDocumentFactory(),
- getSourceURL());
+ getDocumentFactory(), getSourceURL());
} catch (PublicationException e) {
throw new RuntimeException(e);
}
|