|
|
Choosing A Webhost: |
svn commit: r427132 - in /lenya/trunk/src: impl/java/org/apache/lenya/cms/p: msg#00283cms.lenya.cvs
Author: andreas Date: Mon Jul 31 07:49:53 2006 New Revision: 427132 URL: http://svn.apache.org/viewvc?rev=427132&view=rev Log: introduce DocumentFactory.exists() method Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentIdentifier.java lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeNodeID.java lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/MoveSubsite.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=427132&r1=427131&r2=427132&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 Mon Jul 31 07:49:53 2006 @@ -16,12 +16,16 @@ */ package org.apache.lenya.cms.publication; +import java.io.IOException; +import java.net.MalformedURLException; + import org.apache.avalon.framework.container.ContainerUtil; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.ServiceSelector; +import org.apache.lenya.cms.cocoon.source.SourceUtil; import org.apache.lenya.cms.repository.RepositoryException; import org.apache.lenya.cms.repository.RepositoryItem; import org.apache.lenya.cms.repository.Session; @@ -326,6 +330,14 @@ return get(pub, locator.getArea(), uuid, locator.getLanguage()); } catch (PublicationException e) { throw new DocumentBuildException(e); + } + } + + public boolean exists(DocumentIdentifier identifier) { + try { + return SourceUtil.exists(identifier.getSourceURI(), this.manager); + } catch (Exception e) { + throw new RuntimeException(e); } } } Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java?rev=427132&r1=427131&r2=427132&view=diff ============================================================================== --- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java (original) +++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java Mon Jul 31 07:49:53 2006 @@ -477,38 +477,6 @@ protected static final String IDENTIFIABLE_TYPE = "document"; - /** - * @see org.apache.lenya.cms.publication.Document#getSourceURI() - */ - public String getSourceURI() { - String path = getPublication().getPathMapper().getPath(getId(), getLanguage()); - return getPublication().getSourceURI() + "/content/" + getArea() + "/" + path; - } - - /** - * @see org.apache.lenya.cms.publication.Document#getRepositoryNode() - */ - public Node getRepositoryNode() { - Node node = null; - SourceResolver resolver = null; - RepositorySource documentSource = null; - try { - resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE); - documentSource = (RepositorySource) resolver.resolveURI(getSourceURI()); - node = documentSource.getNode(); - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - if (resolver != null) { - if (documentSource != null) { - resolver.release(documentSource); - } - this.manager.release(resolver); - } - } - return node; - } - private ResourceType resourceType; /** @@ -612,5 +580,13 @@ public String getPath() { return getLocator().getPath(); + } + + public String getSourceURI() { + return getIdentifier().getSourceURI(); + } + + public Node getRepositoryNode() { + return getIdentifier().getRepositoryNode(this.manager); } } Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java?rev=427132&r1=427131&r2=427132&view=diff ============================================================================== --- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java (original) +++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentFactory.java Mon Jul 31 07:49:53 2006 @@ -104,5 +104,12 @@ * @throws DocumentBuildException if an error occurs. */ Document get(DocumentLocator locator) throws DocumentBuildException; + + /** + * Checks if a document exists. + * @param identifier the identifier of the document. + * @return A boolean value. + */ + boolean exists(DocumentIdentifier identifier); } Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentIdentifier.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentIdentifier.java?rev=427132&r1=427131&r2=427132&view=diff ============================================================================== --- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentIdentifier.java (original) +++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentIdentifier.java Mon Jul 31 07:49:53 2006 @@ -16,6 +16,11 @@ */ package org.apache.lenya.cms.publication; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.excalibur.source.SourceResolver; +import org.apache.lenya.cms.cocoon.source.RepositorySource; +import org.apache.lenya.cms.repository.Node; + /** * Value object to identify documents. */ @@ -30,7 +35,7 @@ * Ctor. * @param publication The publication. * @param area The area. - * @param id The document ID. + * @param uuid The document UUID. * @param language The language. * @param uuid The UUID. */ @@ -39,10 +44,6 @@ this.area = area; this.language = language; this.uuid = uuid; - - if (uuid.equals("/copied")) { - throw new NullPointerException(); - } } /** @@ -88,4 +89,55 @@ public String toString() { return getKey(); } + + /** + * Returns a version of this identifier from another area. + * @param area The area. + * @return A document identifier. + */ + public DocumentIdentifier getAreaVersion(String area) { + return new DocumentIdentifier(getPublication(), area, getUUID(), getLanguage()); + } + + /** + * Returns a version of this identifier in a different language. + * @param language The language. + * @return A document identifier. + */ + public DocumentIdentifier getLanguageVersion(String language) { + return new DocumentIdentifier(getPublication(), getArea(), getUUID(), language); + } + + /** + * @see org.apache.lenya.cms.publication.Document#getRepositoryNode() + */ + public Node getRepositoryNode(ServiceManager manager) { + Node node = null; + SourceResolver resolver = null; + RepositorySource documentSource = null; + try { + resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE); + documentSource = (RepositorySource) resolver.resolveURI(getSourceURI()); + node = documentSource.getNode(); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + if (resolver != null) { + if (documentSource != null) { + resolver.release(documentSource); + } + manager.release(resolver); + } + } + return node; + } + + /** + * @see org.apache.lenya.cms.publication.Document#getSourceURI() + */ + public String getSourceURI() { + String path = getPublication().getPathMapper().getPath(getUUID(), getLanguage()); + return getPublication().getSourceURI() + "/content/" + getArea() + "/" + path; + } + } Modified: lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeNodeID.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeNodeID.java?rev=427132&r1=427131&r2=427132&view=diff ============================================================================== --- lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeNodeID.java (original) +++ lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/ChangeNodeID.java Mon Jul 31 07:49:53 2006 @@ -22,10 +22,12 @@ import java.util.Map; import org.apache.avalon.framework.service.ServiceSelector; +import org.apache.cocoon.components.source.SourceUtil; import org.apache.lenya.cms.publication.Document; import org.apache.lenya.cms.publication.DocumentBuildException; import org.apache.lenya.cms.publication.DocumentBuilder; import org.apache.lenya.cms.publication.DocumentException; +import org.apache.lenya.cms.publication.DocumentIdentifier; import org.apache.lenya.cms.publication.DocumentLocator; import org.apache.lenya.cms.publication.DocumentManager; import org.apache.lenya.cms.publication.Publication; @@ -108,10 +110,9 @@ if (!getSourceDocument().getArea().equals(Publication.AUTHORING_AREA)) { addErrorMessage("This usecase can only be invoked in the authoring area!"); } else { - DocumentLocator liveLoc = getSourceDocument().getLocator() + DocumentIdentifier liveVersion = getSourceDocument().getIdentifier() .getAreaVersion(Publication.LIVE_AREA); - Document liveVersion = getDocumentFactory().get(liveLoc); - if (liveVersion.exists()) { + if (getDocumentFactory().exists(liveVersion)) { addErrorMessage("This usecase cannot be invoked when the live version exists!"); } } Modified: lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/MoveSubsite.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/MoveSubsite.java?rev=427132&r1=427131&r2=427132&view=diff ============================================================================== --- lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/MoveSubsite.java (original) +++ lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/MoveSubsite.java Mon Jul 31 07:49:53 2006 @@ -27,6 +27,7 @@ import org.apache.lenya.cms.publication.DocumentBuildException; import org.apache.lenya.cms.publication.DocumentException; import org.apache.lenya.cms.publication.DocumentFactory; +import org.apache.lenya.cms.publication.DocumentIdentifier; import org.apache.lenya.cms.publication.DocumentLocator; import org.apache.lenya.cms.publication.DocumentManager; import org.apache.lenya.cms.publication.Publication; @@ -74,14 +75,13 @@ } else { Document document = getSourceDocument(); - DocumentFactory identityMap = getDocumentFactory(); DocumentSet set = SiteUtil.getSubSite(this.manager, document); Document[] documents = set.getDocuments(); for (int i = 0; i < documents.length; i++) { - DocumentLocator loc = documents[i].getLocator().getAreaVersion(Publication.LIVE_AREA); - Document liveVersion = identityMap.get(loc); - if (liveVersion.exists()) { + DocumentIdentifier liveVersion = documents[i].getIdentifier().getAreaVersion( + Publication.LIVE_AREA); + if (getDocumentFactory().exists(liveVersion)) { addErrorMessage("delete-doc-live", new String[] { liveVersion.toString() }); } } @@ -111,9 +111,7 @@ Document doc = getSourceDocument(); try { DocumentSet sources = SiteUtil.getSubSite(this.manager, doc); - Map targets = SiteUtil.getTransferedSubSite(this.manager, - doc, - getTargetArea(), + Map targets = SiteUtil.getTransferedSubSite(this.manager, doc, getTargetArea(), SiteUtil.MODE_CHANGE_ID); Document[] docs = sources.getDocuments(); @@ -123,9 +121,7 @@ Document target = (Document) targets.get(docs[i]); nodes.add(target.getRepositoryNode()); - nodes.addAll(AssetUtil.getCopiedAssetNodes(docs[i], - target, - this.manager, + nodes.addAll(AssetUtil.getCopiedAssetNodes(docs[i], target, this.manager, getLogger())); } @@ -138,14 +134,13 @@ } nodes.add(SiteUtil.getSiteStructure(this.manager, doc).getRepositoryNode()); - nodes.add(SiteUtil.getSiteStructure(this.manager, - getDocumentFactory(), - doc.getPublication(), - getTargetArea()).getRepositoryNode()); + nodes.add(SiteUtil.getSiteStructure(this.manager, getDocumentFactory(), + doc.getPublication(), getTargetArea()).getRepositoryNode()); } catch (Exception e) { throw new UsecaseException(e); } - return (org.apache.lenya.cms.repository.Node[]) nodes.toArray(new org.apache.lenya.cms.repository.Node[nodes.size()]); + return (org.apache.lenya.cms.repository.Node[]) nodes + .toArray(new org.apache.lenya.cms.repository.Node[nodes.size()]); } /** @@ -174,11 +169,13 @@ SiteUtil.sortAscending(this.manager, docsToCopy); Document[] targetDocs = docsToCopy.getDocuments(); for (int i = 0; i < targetDocs.length; i++) { - DocumentLocator sourceLoc = targetDocs[i].getLocator().getAreaVersion(doc.getArea()); + DocumentLocator sourceLoc = targetDocs[i].getLocator() + .getAreaVersion(doc.getArea()); Document sourceDoc = map.get(sourceLoc); Document existingSourceDoc = DocumentHelper.getExistingLanguageVersion(sourceDoc, doc.getLanguage()); - DocumentLocator targetLoc = existingSourceDoc.getLocator().getAreaVersion(getTargetArea()); + DocumentLocator targetLoc = existingSourceDoc.getLocator().getAreaVersion( + getTargetArea()); documentManager.copyDocument(existingSourceDoc, targetLoc); if (!targetLoc.getArea().equals(Publication.AUTHORING_AREA)) { Document targetDoc = getDocumentFactory().get(targetLoc); @@ -186,9 +183,7 @@ } } - Map targetMap = SiteUtil.getTransferedSubSite(this.manager, - doc, - getTargetArea(), + Map targetMap = SiteUtil.getTransferedSubSite(this.manager, doc, getTargetArea(), SiteUtil.MODE_CHANGE_ID); DocumentSet targets = new DocumentSet(); Document[] docs = sources.getDocuments(); @@ -239,10 +234,8 @@ SiteNode node = NodeFactory.getNode(doc); SiteNode[] requiredNodes = siteManager.getRequiredResources(map, node); for (int i = 0; i < requiredNodes.length; i++) { - Document targetDoc = map.get(getSourceDocument().getPublication(), - getTargetArea(), - requiredNodes[i].getPath(), - doc.getLanguage()); + Document targetDoc = map.get(getSourceDocument().getPublication(), getTargetArea(), + requiredNodes[i].getPath(), doc.getLanguage()); if (!siteManager.containsInAnyLanguage(targetDoc)) { docsToCopy.add(targetDoc); } @@ -285,7 +278,8 @@ SiteNode node = requiredSourceNodes[i]; boolean delete = true; - Document requiredDoc = map.get(node.getPublication(), node.getArea(), node.getPath()); + Document requiredDoc = map.get(node.getPublication(), node.getArea(), node + .getPath()); String[] languages = requiredDoc.getLanguages(); for (int l = 0; l < languages.length; l++) { Document langVersion = map.getLanguageVersion(requiredDoc, languages[l]); @@ -293,9 +287,9 @@ delete = false; } } - + SiteNode[] requiringNodes = siteManager.getRequiringResources(map, node); - + for (int j = 0; j < requiringNodes.length; j++) { SiteNode n = requiringNodes[j]; Document reqDoc = map.get(n.getPublication(), n.getArea(), n.getPath()); @@ -332,5 +326,5 @@ } return docsToDelete; } - + }
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |