001/* 002 * (C) Copyright 2006-2012 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 * Thomas Roger 018 * Florent Guillaume 019 */ 020package org.nuxeo.ecm.platform.publisher.impl.service; 021 022import java.io.Serializable; 023import java.util.HashMap; 024import java.util.List; 025import java.util.Map; 026 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.ecm.core.api.UnrestrictedSessionRunner; 029import org.nuxeo.ecm.platform.query.api.PageProvider; 030import org.nuxeo.ecm.platform.query.api.PageProviderService; 031import org.nuxeo.ecm.platform.query.nxql.CoreQueryDocumentPageProvider; 032import org.nuxeo.runtime.api.Framework; 033 034/** 035 * Finds the domains for a session. 036 */ 037public class DomainsFinder extends UnrestrictedSessionRunner { 038 039 public static final String PUBLISHING_DOMAINS_PROVIDER = "domains_for_publishing"; 040 041 protected List<DocumentModel> domains; 042 043 public DomainsFinder(String repositoryName) { 044 super(repositoryName); 045 } 046 047 @Override 048 public void run() { 049 domains = getDomainsFiltered(); 050 } 051 052 @SuppressWarnings("unchecked") 053 protected List<DocumentModel> getDomainsFiltered() { 054 PageProviderService pps = Framework.getService(PageProviderService.class); 055 Map<String, Serializable> props = new HashMap<String, Serializable>(); 056 props.put(CoreQueryDocumentPageProvider.CORE_SESSION_PROPERTY, (Serializable) session); 057 PageProvider<DocumentModel> pageProvider = (PageProvider<DocumentModel>) pps.getPageProvider( 058 PUBLISHING_DOMAINS_PROVIDER, null, null, null, props, 059 new Object[] { session.getRootDocument().getId() }); 060 return pageProvider.getCurrentPage(); 061 } 062 063 public List<DocumentModel> getDomains() { 064 if (domains == null) { 065 runUnrestricted(); 066 } 067 return domains; 068 } 069 070}