|
|
Choosing A Webhost: |
svn commit: r427143 - in /lenya/trunk/src: impl/java/org/apache/lenya/cms/p: msg#00285cms.lenya.cvs
Author: andreas Date: Mon Jul 31 08:36:28 2006 New Revision: 427143 URL: http://svn.apache.org/viewvc?rev=427143&view=rev Log: Added methods to Document to retrieve a version in a different area+language Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java 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=427143&r1=427142&r2=427143&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 08:36:28 2006 @@ -652,4 +652,21 @@ return pub.getSourceURI() + "/content/" + area + "/" + path; } + public boolean existsVersion(String area, String language) { + String sourceUri = getSourceURI(getPublication(), area, getUUID(), language); + try { + return SourceUtil.exists(sourceUri, this.manager); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public Document getVersion(String area, String language) throws DocumentException { + try { + return getFactory().get(getPublication(), area, getUUID(), language); + } catch (DocumentBuildException e) { + throw new DocumentException(e); + } + } + } Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java?rev=427143&r1=427142&r2=427143&view=diff ============================================================================== --- lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java (original) +++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java Mon Jul 31 08:36:28 2006 @@ -285,4 +285,21 @@ */ Document getAreaVersion(String area) throws DocumentException; + /** + * Checks if a translation of this document exists in a certain area. + * @param area The area. + * @param language The language. + * @return A boolean value. + */ + boolean existsVersion(String area, String language); + + /** + * Returns a translation of this document in a certain area. + * @param area The area. + * @param language The language. + * @return A document. + * @throws DocumentException if the area version doesn't exist. + */ + Document getVersion(String area, String language) throws DocumentException; + } Modified: lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java?rev=427143&r1=427142&r2=427143&view=diff ============================================================================== --- lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java (original) +++ lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Deactivate.java Mon Jul 31 08:36:28 2006 @@ -64,26 +64,30 @@ String event = getEvent(); boolean allowSingle = true; - if (!WorkflowUtil.canInvoke(this.manager, - getSession(), - getLogger(), - getSourceDocument(), - event)) { - allowSingle = false; - addInfoMessage("The single document cannot be deactivated because the workflow event cannot be invoked."); - } - - DocumentFactory map = getSourceDocument().getFactory(); - Document liveDoc = map.getAreaVersion(getSourceDocument(), Publication.LIVE_AREA); - DocumentSet subSite = SiteUtil.getSubSite(this.manager, liveDoc); - SiteNode node = NodeFactory.getNode(liveDoc); - subSite.removeAll(SiteUtil.getExistingDocuments(map, node)); - - if (!subSite.isEmpty()) { - allowSingle = false; - addInfoMessage("You have to deactivate the whole subtree because descendants are live."); + if (!getSourceDocument().existsAreaVersion(Publication.LIVE_AREA)) { + addErrorMessage("This usecase can only be invoked when the live version exists."); + } else { + if (!WorkflowUtil.canInvoke(this.manager, + getSession(), + getLogger(), + getSourceDocument(), + event)) { + allowSingle = false; + addInfoMessage("The single document cannot be deactivated because the workflow event cannot be invoked."); + } + + DocumentFactory map = getSourceDocument().getFactory(); + Document liveDoc = getSourceDocument().getAreaVersion(Publication.LIVE_AREA); + DocumentSet subSite = SiteUtil.getSubSite(this.manager, liveDoc); + SiteNode node = NodeFactory.getNode(liveDoc); + subSite.removeAll(SiteUtil.getExistingDocuments(map, node)); + + if (!subSite.isEmpty()) { + allowSingle = false; + addInfoMessage("You have to deactivate the whole subtree because descendants are live."); + } + setParameter(Publish.ALLOW_SINGLE_DOCUMENT, Boolean.toString(allowSingle)); } - setParameter(Publish.ALLOW_SINGLE_DOCUMENT, Boolean.toString(allowSingle)); } } @@ -98,13 +102,13 @@ Document doc = getSourceDocument(); set.addAll(SiteUtil.getSubSite(this.manager, doc)); - Document liveDoc = doc.getFactory().getAreaVersion(doc, Publication.LIVE_AREA); + Document liveDoc = doc.getAreaVersion(Publication.LIVE_AREA); set.addAll(SiteUtil.getSubSite(this.manager, liveDoc)); Document[] documents = set.getDocuments(); for (int i = 0; i < documents.length; i++) { nodes.add(documents[i].getRepositoryNode()); - nodes.addAll(AssetUtil.getAssetNodes(documents[i], this.manager, getLogger())); + nodes.addAll(AssetUtil.getAssetNodes(documents[i], this.manager, getLogger())); } nodes.add(SiteUtil.getSiteStructure(this.manager, liveDoc).getRepositoryNode()); @@ -137,11 +141,10 @@ boolean success = false; DocumentManager documentManager = null; - SourceResolver resolver = null; - Source source = null; + SourceResolver resolver = null; + Source source = null; try { - Document liveDocument = authoringDocument.getFactory() - .getAreaVersion(authoringDocument, Publication.LIVE_AREA); + Document liveDocument = authoringDocument.getAreaVersion(Publication.LIVE_AREA); documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE); documentManager.delete(liveDocument); @@ -156,12 +159,12 @@ } catch (Exception e) { throw new RuntimeException(e); } finally { - if (resolver != null) { - if (source != null) { - resolver.release(source); - } - this.manager.release(resolver); - } + if (resolver != null) { + if (source != null) { + resolver.release(source); + } + this.manager.release(resolver); + } if (getLogger().isDebugEnabled()) { getLogger().debug("Deactivate document [" + authoringDocument + "]. Success: [" + success + "]"); @@ -243,16 +246,16 @@ WorkflowException { String[] languages = document.getPublication().getLanguages(); for (int i = 0; i < languages.length; i++) { - Document version = document.getFactory().getLanguageVersion(document, languages[i]); - if (version.exists() - && WorkflowUtil.canInvoke(this.manager, - getSession(), - getLogger(), - version, - getEvent())) { - deactivate(version); + if (document.existsVersion(Publication.LIVE_AREA, languages[i])) { + Document version = document.getVersion(Publication.LIVE_AREA, languages[i]); + if (WorkflowUtil.canInvoke(this.manager, + getSession(), + getLogger(), + version, + getEvent())) { + deactivate(version); + } } } } - } Modified: lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java?rev=427143&r1=427142&r2=427143&view=diff ============================================================================== --- lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java (original) +++ lenya/trunk/src/pubs/default/modules/defaultusecases/java/src/org/apache/lenya/defaultpub/cms/usecases/Publish.java Mon Jul 31 08:36:28 2006 @@ -31,7 +31,7 @@ import org.apache.lenya.ac.Identifiable; import org.apache.lenya.ac.User; import org.apache.lenya.cms.publication.Document; -import org.apache.lenya.cms.publication.DocumentBuildException; +import org.apache.lenya.cms.publication.DocumentException; import org.apache.lenya.cms.publication.DocumentFactory; import org.apache.lenya.cms.publication.DocumentLocator; import org.apache.lenya.cms.publication.DocumentManager; @@ -40,9 +40,9 @@ import org.apache.lenya.cms.publication.PublicationException; import org.apache.lenya.cms.publication.util.DocumentSet; import org.apache.lenya.cms.publication.util.DocumentVisitor; -import org.apache.lenya.cms.site.SiteNode; import org.apache.lenya.cms.site.NodeFactory; import org.apache.lenya.cms.site.SiteManager; +import org.apache.lenya.cms.site.SiteNode; import org.apache.lenya.cms.site.SiteUtil; import org.apache.lenya.cms.site.usecases.AssetUtil; import org.apache.lenya.cms.usecase.DocumentUsecase; @@ -151,8 +151,6 @@ Publication publication = document.getPublication(); DocumentFactory map = document.getFactory(); - Document liveDocument = map.getAreaVersion(document, Publication.LIVE_AREA); - List missingDocuments = new ArrayList(); ServiceSelector selector = null; @@ -161,7 +159,10 @@ selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector"); siteManager = (SiteManager) selector.select(publication.getSiteManagerHint()); - SiteNode liveNode = NodeFactory.getNode(liveDocument); + String path = SiteUtil.getPath(this.manager, document); + SiteNode liveNode = NodeFactory.getNode(document.getPublication(), + Publication.LIVE_AREA, + path); SiteNode[] requiredNodes = siteManager.getRequiredResources(map, liveNode); for (int i = 0; i < requiredNodes.length; i++) { @@ -174,8 +175,8 @@ if (authoringDoc.exists()) { missingDocuments.add(authoringDoc); } else { - missingDocuments.add(map.getLanguageVersion(authoringDoc, - authoringDoc.getPublication().getDefaultLanguage())); + missingDocuments.add(authoringDoc.getTranslation(authoringDoc.getPublication() + .getDefaultLanguage())); } } @@ -268,12 +269,11 @@ } } - protected void sendNotification(Document authoringDocument) throws DocumentBuildException, - NotificationException { + protected void sendNotification(Document authoringDocument) throws NotificationException, + DocumentException { User sender = getSession().getIdentity().getUser(); Identifiable[] recipients = { sender }; - Document liveVersion = getDocumentFactory().getAreaVersion(authoringDocument, - Publication.LIVE_AREA); + Document liveVersion = authoringDocument.getAreaVersion(Publication.LIVE_AREA); String url; @@ -353,8 +353,7 @@ Document parent = document.getFactory().get(parentLocator); boolean publish = true; if (parent != null) { - Document liveParent = parent.getFactory().getAreaVersion(parent, - Publication.LIVE_AREA); + Document liveParent = parent.getAreaVersion(Publication.LIVE_AREA); if (!liveParent.exists()) { publish = false; } @@ -380,9 +379,8 @@ try { for (int i = 0; i < languages.length; i++) { - Document version = document.getFactory().getLanguageVersion(document, - languages[i]); - if (version.exists()) { + if (document.existsTranslation(languages[i])) { + Document version = document.getTranslation(languages[i]); if (WorkflowUtil.canInvoke(this.manager, getSession(), getLogger(),
|
|
| <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 |