001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Jean-Marc Orliaguet, Chalmers 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.theme.webengine.negotiation.perspective; 016 017import org.nuxeo.ecm.webengine.model.Resource; 018import org.nuxeo.ecm.webengine.model.WebContext; 019import org.nuxeo.theme.ApplicationType; 020import org.nuxeo.theme.Manager; 021import org.nuxeo.theme.ViewDef; 022import org.nuxeo.theme.negotiation.Scheme; 023import org.nuxeo.theme.perspectives.PerspectiveManager; 024import org.nuxeo.theme.types.TypeFamily; 025import org.nuxeo.theme.types.TypeRegistry; 026 027public final class ViewId implements Scheme { 028 029 public String getOutcome(final Object context) { 030 WebContext webContext = (WebContext) context; 031 final TypeRegistry typeRegistry = Manager.getTypeRegistry(); 032 final ApplicationType application = (ApplicationType) typeRegistry.lookup(TypeFamily.APPLICATION, 033 webContext.getModulePath(), webContext.getModule().getName()); 034 if (application == null) { 035 return null; 036 } 037 038 Resource targetObject = webContext.getTargetObject(); 039 if (targetObject == null) { 040 return null; 041 } 042 final String rootPath = webContext.getRoot().getPath(); 043 final String viewId = targetObject.getPath().substring(rootPath.length()); 044 045 final ViewDef view = application.getViewById(viewId); 046 if (view == null) { 047 return null; 048 } 049 final String perspectiveName = view.getPerspective(); 050 if (PerspectiveManager.hasPerspective(perspectiveName)) { 051 return perspectiveName; 052 } 053 return null; 054 } 055}