|
|
Choosing A Webhost: |
svn commit: r511787 - in /lenya/trunk/src/modules/blog: config/cocoon-xconf: msg#00140cms.lenya.cvs
Author: andreas Date: Mon Feb 26 03:35:31 2007 New Revision: 511787 URL: http://svn.apache.org/viewvc?view=rev&rev=511787 Log: Move blog's publish usecase to a different package, this resolves a name clash Added: lenya/trunk/src/modules/blog/java/src/org/apache/lenya/blog/cms/usecases/Publish.java Removed: lenya/trunk/src/modules/blog/java/src/org/apache/lenya/cms/workflow/usecases/Publish.java Modified: lenya/trunk/src/modules/blog/config/cocoon-xconf/usecases-workflow-publish.xconf Modified: lenya/trunk/src/modules/blog/config/cocoon-xconf/usecases-workflow-publish.xconf URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/blog/config/cocoon-xconf/usecases-workflow-publish.xconf?view=diff&rev=511787&r1=511786&r2=511787 ============================================================================== --- lenya/trunk/src/modules/blog/config/cocoon-xconf/usecases-workflow-publish.xconf (original) +++ lenya/trunk/src/modules/blog/config/cocoon-xconf/usecases-workflow-publish.xconf Mon Feb 26 03:35:31 2007 @@ -21,7 +21,7 @@ <xconf xpath="/cocoon/usecases" unless="/cocoon/usecases/component-instance[@name = 'blog/workflow.publish']"> <component-instance name="blog/workflow.publish" logger="lenya.workflow" - class="org.apache.lenya.cms.workflow.usecases.Publish"> + class="org.apache.lenya.blog.cms.usecases.Publish"> <view template="modules/blog/usecases/workflow/publish.jx"/> </component-instance> </xconf> Added: lenya/trunk/src/modules/blog/java/src/org/apache/lenya/blog/cms/usecases/Publish.java URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/blog/java/src/org/apache/lenya/blog/cms/usecases/Publish.java?view=auto&rev=511787 ============================================================================== --- lenya/trunk/src/modules/blog/java/src/org/apache/lenya/blog/cms/usecases/Publish.java (added) +++ lenya/trunk/src/modules/blog/java/src/org/apache/lenya/blog/cms/usecases/Publish.java Mon Feb 26 03:35:31 2007 @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.blog.cms.usecases; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.lenya.cms.publication.Area; +import org.apache.lenya.cms.publication.Document; +import org.apache.lenya.cms.publication.DocumentManager; +import org.apache.lenya.cms.publication.Publication; +import org.apache.lenya.cms.publication.util.DocumentSet; +import org.apache.lenya.cms.repository.Node; +import org.apache.lenya.cms.site.NodeSet; +import org.apache.lenya.cms.site.SiteUtil; +import org.apache.lenya.cms.usecase.DocumentUsecase; +import org.apache.lenya.cms.usecase.UsecaseException; +import org.apache.lenya.cms.workflow.WorkflowUtil; +import org.apache.lenya.cms.workflow.usecases.UsecaseWorkflowHelper; +import org.apache.lenya.workflow.Version; +import org.apache.lenya.workflow.Workflowable; +import org.apache.lenya.xml.DocumentHelper; +import org.apache.xpath.XPathAPI; +import org.w3c.dom.Element; + +/** + * Publish usecase handler. + * + * @version $Id: Publish.java 209612 2005-07-07 16:52:44Z chestnut $ + */ +public class Publish extends DocumentUsecase { + + protected static final String MISSING_DOCUMENTS = "missingDocuments"; + + /** + * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock() + */ + protected Node[] getNodesToLock() throws UsecaseException { + try { + List nodes = new ArrayList(); + DocumentSet set = new DocumentSet(); + + Document doc = getSourceDocument(); + NodeSet subsite = SiteUtil.getSubSite(this.manager, doc.getLink().getNode()); + set.addAll(new DocumentSet(subsite.getDocuments())); + + Document[] documents = set.getDocuments(); + for (int i = 0; i < documents.length; i++) { + nodes.add(documents[i].getRepositoryNode()); + } + + Area live = doc.getPublication().getArea(Publication.LIVE_AREA); + nodes.add(live.getSite().getRepositoryNode()); + return (Node[]) nodes.toArray(new Node[nodes.size()]); + + } catch (Exception e) { + throw new UsecaseException(e); + } + } + + /** + * Checks if the workflow event is supported and the parent of the document + * exists in the live area. + * + * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions() + */ + protected void doCheckPreconditions() throws Exception { + super.doCheckPreconditions(); + if (!hasErrors()) { + + String event = getEvent(); + Document document = getSourceDocument(); + + if (!document.getArea().equals(Publication.AUTHORING_AREA)) { + addErrorMessage("This usecase can only be invoked from the authoring area."); + return; + } + + UsecaseWorkflowHelper.checkWorkflow(this.manager, this, event, document, getLogger()); + } + } + + /** + * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute() + */ + protected void doExecute() throws Exception { + DocumentManager documentManager = null; + try { + Document authoringDocument = getSourceDocument(); + if (authoringDocument.getResourceType().getName().equals("entry")) { + updateBlogEntry(authoringDocument); + } + updateFeed(); + documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE); + documentManager.copyToArea(authoringDocument, Publication.LIVE_AREA); + WorkflowUtil.invoke(this.manager, getSession(), getLogger(), authoringDocument, + getEvent()); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + if (documentManager != null) { + this.manager.release(documentManager); + } + } + } + + protected void updateFeed() throws Exception { + + Document[] docs = new Document[2]; + org.w3c.dom.Document[] doms = new org.w3c.dom.Document[2]; + + Publication pub = getSourceDocument().getPublication(); + Area authoring = pub.getArea(Publication.AUTHORING_AREA); + Area live = pub.getArea(Publication.LIVE_AREA); + String path = "/feeds/all/index"; + String language = pub.getDefaultLanguage(); + + docs[0] = live.getSite().getNode(path).getLink(language).getDocument(); + docs[1] = authoring.getSite().getNode(path).getLink(language).getDocument(); + + DateFormat datefmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + DateFormat ofsfmt = new SimpleDateFormat("Z"); + Date date = new Date(); + + String dateofs = ofsfmt.format(date); + String datestr = datefmt.format(date) + dateofs.substring(0, 3) + ":" + + dateofs.substring(3, 5); + + for (int i = 0; i < 2; i++) { + doms[i] = DocumentHelper.readDocument(docs[i].getInputStream()); + Element parent = doms[i].getDocumentElement(); + // set modified date on publish + Element element = (Element) XPathAPI.selectSingleNode(parent, + "/*[local-name() = 'feed']/*[local-name() = 'modified']"); + DocumentHelper.setSimpleElementText(element, datestr); + DocumentHelper.writeDocument(doms[i], docs[i].getOutputStream()); + } + } + + protected void updateBlogEntry(Document doc) throws Exception { + org.w3c.dom.Document dom = DocumentHelper.readDocument(doc.getInputStream()); + Element parent = dom.getDocumentElement(); + + DateFormat datefmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + DateFormat ofsfmt = new SimpleDateFormat("Z"); + Date date = new Date(); + + String dateofs = ofsfmt.format(date); + String datestr = datefmt.format(date) + dateofs.substring(0, 3) + ":" + + dateofs.substring(3, 5); + + // set modified date on re-publish + Element element = (Element) XPathAPI.selectSingleNode(parent, + "/*[local-name() = 'entry']/*[local-name() = 'modified']"); + DocumentHelper.setSimpleElementText(element, datestr); + + // set issued date on first time publish + Workflowable dw = WorkflowUtil.getWorkflowable(this.manager, this.getSession(), this + .getLogger(), doc); + Version versions[] = dw.getVersions(); + boolean wasLive = false; + for (int i = 0; i < versions.length; i++) { + if (versions[i].getValue("is_live")) { + wasLive = true; + break; + } + } + if (!wasLive) { + element = (Element) XPathAPI.selectSingleNode(parent, + "/*[local-name() = 'entry']/*[local-name() = 'issued']"); + DocumentHelper.setSimpleElementText(element, datestr); + } + + DocumentHelper.writeDocument(dom, doc.getOutputStream()); + } + + /** + * @return The event to invoke. + */ + private String getEvent() { + return "publish"; + } + +} \ No newline at end of file
|
|
| <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 |