001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $
020 */
021
022package org.nuxeo.ecm.webapp.helpers;
023
024import static org.jboss.seam.ScopeType.SESSION;
025
026import java.io.Serializable;
027
028import org.jboss.seam.annotations.Begin;
029import org.jboss.seam.annotations.In;
030import org.jboss.seam.annotations.Name;
031import org.jboss.seam.annotations.web.RequestParameter;
032import org.jboss.seam.annotations.Scope;
033import org.jboss.seam.annotations.Startup;
034import org.nuxeo.ecm.core.api.DocumentRef;
035import org.nuxeo.ecm.platform.ui.web.api.NavigationContext;
036import org.nuxeo.ecm.platform.ui.web.util.DocumentLocator;
037
038@Startup
039@Name("paralleleNavigationHelper")
040@Scope(SESSION)
041public class ParalleleNavigationHelper implements Serializable {
042
043    private static final long serialVersionUID = 16794309876876L;
044
045    public static final String PARALLELE_URL_PREFIX = "/parallele.faces?";
046
047    @In(create = true)
048    protected transient NavigationContext navigationContext;
049
050    @In(create = true)
051    ConversationIdGenerator conversationIdGenerator;
052
053    @RequestParameter
054    String docRef;
055
056    // Start a new Main conversation
057    @Begin(id = "#{conversationIdGenerator.nextMainConversationId}")
058    public String navigateToURL() {
059        if (docRef == null) {
060            return null;
061        }
062        return navigationContext.navigateToURL(docRef);
063    }
064
065    public String getCurrentDocumentFullUrl() {
066        String internalURL = navigationContext.getCurrentDocumentFullUrl();
067        return internalURL.replace(DocumentLocator.URL_PREFIX, PARALLELE_URL_PREFIX);
068    }
069
070    public String getDocumentFullUrl(DocumentRef docRef) {
071        String internalURL = DocumentLocator.getFullDocumentUrl(navigationContext.getCurrentServerLocation(), docRef);
072        return internalURL.replace(DocumentLocator.URL_PREFIX, PARALLELE_URL_PREFIX);
073    }
074
075}