You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ed...@apache.org on 2003/09/08 19:09:15 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting RevisionControllerAction.java

edith       2003/09/08 10:09:15

  Modified:    src/java/org/apache/lenya/cms/cocoon/acting
                        RevisionControllerAction.java
  Log:
  hack for the filename for the bitflux editor
  
  Revision  Changes    Path
  1.25      +265 -201  cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java
  
  Index: RevisionControllerAction.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/RevisionControllerAction.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- RevisionControllerAction.java	26 Aug 2003 15:52:31 -0000	1.24
  +++ RevisionControllerAction.java	8 Sep 2003 17:09:15 -0000	1.25
  @@ -1,201 +1,265 @@
  -/*
  -$Id$
  -<License>
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
  -    used to  endorse or promote  products derived from  this software without
  -    prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation and was  originally created by
  - Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
  - ware Foundation, please see <http://www.apache.org/>.
  -
  - Lenya includes software developed by the Apache Software Foundation, W3C,
  - DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  -</License>
  -*/
  -package org.apache.lenya.cms.cocoon.acting;
  -
  -import org.apache.avalon.framework.parameters.Parameters;
  -
  -import org.apache.cocoon.acting.AbstractAction;
  -import org.apache.cocoon.environment.ObjectModelHelper;
  -import org.apache.cocoon.environment.Redirector;
  -import org.apache.cocoon.environment.Request;
  -import org.apache.cocoon.environment.Session;
  -import org.apache.cocoon.environment.SourceResolver;
  -
  -import org.apache.lenya.cms.ac.Identity;
  -import org.apache.lenya.cms.publication.Document;
  -import org.apache.lenya.cms.publication.PageEnvelope;
  -import org.apache.lenya.cms.publication.PageEnvelopeFactory;
  -import org.apache.lenya.cms.publication.Publication;
  -import org.apache.lenya.cms.rc.RCEnvironment;
  -import org.apache.lenya.cms.rc.RevisionController;
  -
  -import java.io.File;
  -
  -import java.util.Map;
  -
  -
  -/**
  - * DOCUMENT ME!
  - *
  - * @author Michael Wechner
  - * @version 2003.1.5
  - */
  -public class RevisionControllerAction extends AbstractAction {
  -    private String rcmlDirectory = null;
  -    private String backupDirectory = null;
  -    private RevisionController rc = null;
  -    private String username = null;
  -    private String filename = null;
  -
  -    /**
  -     * DOCUMENT ME!
  -     *
  -     * @param redirector DOCUMENT ME!
  -     * @param resolver DOCUMENT ME!
  -     * @param objectModel DOCUMENT ME!
  -     * @param src DOCUMENT ME!
  -     * @param parameters DOCUMENT ME!
  -     *
  -     * @return DOCUMENT ME!
  -     *
  -     * @throws Exception DOCUMENT ME!
  -     */
  -    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src,
  -        Parameters parameters) throws Exception {
  -        // Get request object
  -        Request request = ObjectModelHelper.getRequest(objectModel);
  -
  -        if (request == null) {
  -            getLogger().error(".act(): No request object");
  -
  -            return null;
  -        }
  -
  -        PageEnvelope envelope = null;
  -        Publication publication = null;
  -        Document document = null;
  -
  -        try {
  -            envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
  -            publication = envelope.getPublication();
  -			document =envelope.getDocument();
  -        } catch (Exception e) {
  -            getLogger().error("Resolving page envelope failed: ", e);
  -        }
  -
  -        //get Parameters for RC
  -        String publicationPath = publication.getDirectory().getCanonicalPath();
  -        String servletContextPath = publication.getServletContext().getCanonicalPath();
  -		RCEnvironment rcEnvironment = RCEnvironment.getInstance(publication.getServletContext().getAbsolutePath());
  -        rcmlDirectory = rcEnvironment.getRCMLDirectory();
  -        rcmlDirectory = publicationPath + File.separator + rcmlDirectory;
  -        backupDirectory = rcEnvironment.getBackupDirectory();
  -        backupDirectory = publicationPath + File.separator + backupDirectory;
  -
  -        // Initialize Revision Controller
  -        rc = new RevisionController(rcmlDirectory, backupDirectory, publicationPath);
  -        getLogger().debug("revision controller" + rc);
  -
  -        // /Initialize Revision Controller
  -        // Get session
  -        Session session = request.getSession(false);
  -
  -        if (session == null) {
  -            getLogger().error(".act(): No session object");
  -
  -            return null;
  -        }
  -
  -        Identity identity = (Identity) session.getAttribute("org.apache.lenya.cms.ac.Identity");
  -        org.apache.lenya.cms.ac2.Identity identityTwo = (org.apache.lenya.cms.ac2.Identity) session.getAttribute("org.apache.lenya.cms.ac2.Identity");
  -        getLogger().debug(".act(): Identity: " + identity);
  -        getLogger().debug(".act(): Identity: " + identityTwo);
  -
  -		filename = "/" + Publication.CONTENT_PATH +"/"+ document.getArea() +"/"+envelope.getDocumentPath(); 
  -        getLogger().debug(".act(): filename : " + filename );
  -        username = null;
  -
  -        if (identity != null) {
  -            username = identity.getUsername();
  -        } else if (identityTwo != null) {
  -            username = identityTwo.getUser().getId();
  -        } else {
  -            getLogger().error(".act(): No identity yet");
  -        }
  -
  -        getLogger().debug(".act(): Username: " + username);
  -
  -        return null;
  -    }
  -    
  -    /**
  -     * Get the filename.
  -     * 
  -     * @return the filename
  -     */
  -    protected String getFilename() {
  -        return filename;
  -    }
  -
  -    /**
  -     * Get the revision controller.
  -     * 
  -     * @return the revision controller
  -     */
  -    protected RevisionController getRc() {
  -        return rc;
  -    }
  -
  -    /**
  -     * Get the user name.
  -     * 
  -     * @return the user name
  -     */
  -    protected String getUsername() {
  -        return username;
  -    }
  -
  -}
  +/*
  +$Id$
  +<License>
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
  +    used to  endorse or promote  products derived from  this software without
  +    prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation and was  originally created by
  + Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
  + ware Foundation, please see <http://www.apache.org/>.
  +
  + Lenya includes software developed by the Apache Software Foundation, W3C,
  + DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  +</License>
  +*/
  +package org.apache.lenya.cms.cocoon.acting;
  +
  +import org.apache.avalon.framework.parameters.Parameters;
  +
  +import org.apache.cocoon.acting.AbstractAction;
  +import org.apache.cocoon.environment.ObjectModelHelper;
  +import org.apache.cocoon.environment.Redirector;
  +import org.apache.cocoon.environment.Request;
  +import org.apache.cocoon.environment.Session;
  +import org.apache.cocoon.environment.SourceResolver;
  +
  +import org.apache.lenya.cms.ac.Identity;
  +import org.apache.lenya.cms.publication.DefaultDocumentBuilder;
  +import org.apache.lenya.cms.publication.Document;
  +import org.apache.lenya.cms.publication.DocumentBuildException;
  +import org.apache.lenya.cms.publication.PageEnvelope;
  +import org.apache.lenya.cms.publication.PageEnvelopeFactory;
  +import org.apache.lenya.cms.publication.Publication;
  +import org.apache.lenya.cms.rc.RCEnvironment;
  +import org.apache.lenya.cms.rc.RevisionController;
  +
  +import java.io.File;
  +
  +import java.util.Map;
  +
  +/**
  + * DOCUMENT ME!
  + *
  + * @author Michael Wechner
  + * @version 2003.1.5
  + */
  +public class RevisionControllerAction extends AbstractAction {
  +	private String rcmlDirectory = null;
  +	private String backupDirectory = null;
  +	private RevisionController rc = null;
  +	private String username = null;
  +	private String filename = null;
  +
  +	/**
  +	 * DOCUMENT ME!
  +	 *
  +	 * @param redirector DOCUMENT ME!
  +	 * @param resolver DOCUMENT ME!
  +	 * @param objectModel DOCUMENT ME!
  +	 * @param src DOCUMENT ME!
  +	 * @param parameters DOCUMENT ME!
  +	 *
  +	 * @return DOCUMENT ME!
  +	 *
  +	 * @throws Exception DOCUMENT ME!
  +	 */
  +	public Map act(
  +		Redirector redirector,
  +		SourceResolver resolver,
  +		Map objectModel,
  +		String src,
  +		Parameters parameters)
  +		throws Exception {
  +		// Get request object
  +		Request request = ObjectModelHelper.getRequest(objectModel);
  +
  +		if (request == null) {
  +			getLogger().error(".act(): No request object");
  +
  +			return null;
  +		}
  +
  +		PageEnvelope envelope = null;
  +		Publication publication = null;
  +		Document document = null;
  +
  +		try {
  +			envelope =
  +				PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
  +			publication = envelope.getPublication();
  +			document = envelope.getDocument();
  +		} catch (Exception e) {
  +			getLogger().error("Resolving page envelope failed: ", e);
  +		}
  +
  +		//get Parameters for RC
  +		String publicationPath = publication.getDirectory().getCanonicalPath();
  +		String servletContextPath =
  +			publication.getServletContext().getCanonicalPath();
  +		RCEnvironment rcEnvironment =
  +			RCEnvironment.getInstance(
  +				publication.getServletContext().getAbsolutePath());
  +		rcmlDirectory = rcEnvironment.getRCMLDirectory();
  +		rcmlDirectory = publicationPath + File.separator + rcmlDirectory;
  +		backupDirectory = rcEnvironment.getBackupDirectory();
  +		backupDirectory = publicationPath + File.separator + backupDirectory;
  +
  +		// Initialize Revision Controller
  +		rc =
  +			new RevisionController(
  +				rcmlDirectory,
  +				backupDirectory,
  +				publicationPath);
  +		getLogger().error("revision controller" + rc);
  +
  +		// /Initialize Revision Controller
  +		// Get session
  +		Session session = request.getSession(false);
  +
  +		if (session == null) {
  +			getLogger().error(".act(): No session object");
  +
  +			return null;
  +		}
  +
  +		Identity identity =
  +			(Identity) session.getAttribute("org.apache.lenya.cms.ac.Identity");
  +		org.apache.lenya.cms.ac2.Identity identityTwo =
  +			(org.apache.lenya.cms.ac2.Identity) session.getAttribute(
  +				"org.apache.lenya.cms.ac2.Identity");
  +		getLogger().debug(".act(): Identity: " + identity);
  +		getLogger().debug(".act(): Identity: " + identityTwo);
  +
  +		//FIXME: hack because of the uri for the editor bitflux. The filename cannot be get from the page-envelope 
  +
  +		String documentid = document.getId();
  +		int bx = documentid.lastIndexOf("-bxeng");
  +
  +		if (bx > 0) {
  +			String language = document.getLanguage();
  +
  +			int l = documentid.length();
  +			int bxLength = "-bxeng".length();
  +			int lang = documentid.lastIndexOf("_", bx);
  +			int langLength = bx - lang;
  +
  +			if (bx > 0 && bx + bxLength <= l) {
  +				documentid =
  +					documentid.substring(0, bx)
  +						+ documentid.substring(bx + bxLength, l);
  +
  +				if (lang > 0 && langLength + lang < l) {
  +					language =
  +						documentid.substring(lang + 1, lang + langLength);
  +					documentid =
  +						documentid.substring(0, lang)
  +							+ documentid.substring(
  +								lang + langLength,
  +								l - bxLength);
  +				}
  +			}
  +
  +			DefaultDocumentBuilder builder =
  +				DefaultDocumentBuilder.getInstance();
  +
  +			String srcUrl =
  +				builder.buildCanonicalUrl(
  +					publication,
  +					document.getArea(),
  +					documentid,
  +					language);
  +			Document srcDoc = builder.buildDocument(publication, srcUrl);
  +			File newFile = srcDoc.getFile();
  +			filename = newFile.getAbsolutePath();
  +
  +		} else {
  +			filename = document.getFile().getAbsolutePath();
  +		}
  +
  +		filename = filename.substring(publicationPath.length());
  +		getLogger().debug("filename :" + filename);
  +
  +		username = null;
  +
  +		if (identity != null) {
  +			username = identity.getUsername();
  +		} else if (identityTwo != null) {
  +			username = identityTwo.getUser().getId();
  +		} else {
  +			getLogger().error(".act(): No identity yet");
  +		}
  +
  +		getLogger().debug(".act(): Username: " + username);
  +
  +		return null;
  +	}
  +
  +	/**
  +	 * Get the filename.
  +	 * 
  +	 * @return the filename
  +	 */
  +	protected String getFilename() {
  +		return filename;
  +	}
  +
  +	/**
  +	 * Get the revision controller.
  +	 * 
  +	 * @return the revision controller
  +	 */
  +	protected RevisionController getRc() {
  +		return rc;
  +	}
  +
  +	/**
  +	 * Get the user name.
  +	 * 
  +	 * @return the user name
  +	 */
  +	protected String getUsername() {
  +		return username;
  +	}
  +
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org