001: /***********************************************************************************
002: *
003: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: **********************************************************************************/package org.sakaiproject.archive.impl;
018:
019: import java.io.File;
020: import java.util.Collections;
021: import java.util.HashMap;
022: import java.util.HashSet;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Stack;
027: import java.util.Vector;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.archive.api.ArchiveService;
032: import org.sakaiproject.authz.api.AuthzGroup;
033: import org.sakaiproject.authz.api.GroupNotDefinedException;
034: import org.sakaiproject.authz.api.Role;
035: import org.sakaiproject.authz.cover.AuthzGroupService;
036: import org.sakaiproject.authz.cover.SecurityService;
037: import org.sakaiproject.component.api.ServerConfigurationService;
038: import org.sakaiproject.component.cover.ComponentManager;
039: import org.sakaiproject.content.api.ContentHostingService;
040: import org.sakaiproject.entity.api.EntityManager;
041: import org.sakaiproject.entity.api.EntityProducer;
042: import org.sakaiproject.exception.IdInvalidException;
043: import org.sakaiproject.exception.IdUnusedException;
044: import org.sakaiproject.exception.IdUsedException;
045: import org.sakaiproject.exception.InUseException;
046: import org.sakaiproject.exception.PermissionException;
047: import org.sakaiproject.site.api.Site;
048: import org.sakaiproject.site.cover.SiteService;
049: import org.sakaiproject.time.api.Time;
050: import org.sakaiproject.time.cover.TimeService;
051: import org.sakaiproject.user.api.User;
052: import org.sakaiproject.user.api.UserAlreadyDefinedException;
053: import org.sakaiproject.user.api.UserEdit;
054: import org.sakaiproject.user.api.UserIdInvalidException;
055: import org.sakaiproject.user.api.UserNotDefinedException;
056: import org.sakaiproject.user.api.UserPermissionException;
057: import org.sakaiproject.user.cover.UserDirectoryService;
058: import org.sakaiproject.util.Xml;
059: import org.w3c.dom.Document;
060: import org.w3c.dom.Element;
061: import org.w3c.dom.Node;
062: import org.w3c.dom.NodeList;
063:
064: public class ArchiveService2Impl implements ArchiveService {
065: /** Our logger. */
066: private static Log M_log = LogFactory
067: .getLog(ArchiveService2Impl.class);
068:
069: /*******************************************************************************
070: * Dependencies and their setter methods
071: *******************************************************************************/
072:
073: /** Dependency: ServerConfigurationService. */
074: protected ServerConfigurationService m_serverConfigurationService = null;
075:
076: public void setServerConfigurationService(
077: ServerConfigurationService service) {
078: m_serverConfigurationService = service;
079: }
080:
081: /** Dependency: EntityManager. */
082: protected EntityManager m_entityManager = null;
083:
084: public void setEntityManager(EntityManager service) {
085: m_entityManager = service;
086: }
087:
088: /** Dependency: SiteArchiver */
089: protected SiteArchiver m_siteArchiver = null;
090:
091: public void setSiteArchiver(SiteArchiver siteArchiver) {
092: m_siteArchiver = siteArchiver;
093: }
094:
095: /** Dependency: SiteMerger */
096: protected SiteMerger m_siteMerger = null;
097:
098: public void setSiteMerger(SiteMerger siteMerger) {
099: m_siteMerger = siteMerger;
100: }
101:
102: /*********************************************/
103: /* Injected Default Settings */
104: /*********************************************/
105: /** A full path and file name to the storage file. */
106: protected String m_storagePath = "/";
107:
108: public void setStoragePath(String path) {
109: m_storagePath = path;
110: }
111:
112: protected boolean m_filterSakaiServices = false;
113:
114: public void setMergeFilterSakaiServices(boolean filter) {
115: m_filterSakaiServices = filter;
116: }
117:
118: protected boolean m_filterSakaiRoles = false;
119:
120: public void setMergeFilterSakaiRoles(boolean filter) {
121: m_filterSakaiRoles = filter;
122: }
123:
124: protected String[] m_filteredSakaiServices = null;
125:
126: public void setMergeFilteredSakaiServices(String[] filtered) {
127: m_filteredSakaiServices = filtered;
128: }
129:
130: protected String[] m_filteredSakaiRoles = null;
131:
132: public void setMergeFilteredSakaiRoles(String[] filtered) {
133: m_filteredSakaiRoles = filtered;
134: }
135:
136: /*******************************************************************************
137: * Init and Destroy
138: *******************************************************************************/
139: public void init() {
140:
141: if ((m_storagePath != null) && (!m_storagePath.endsWith("/"))) {
142: m_storagePath = m_storagePath + "/";
143: }
144:
145: M_log.info("init(): storage path: " + m_storagePath);
146: }
147:
148: public void destroy() {
149: M_log.info("destroy()");
150: }
151:
152: /**
153: * Create an archive for the resources of a site.
154: * @param siteId The id of the site to archive.
155: * @return A log of messages from the archive.
156: */
157: public String archive(String siteId) {
158: return m_siteArchiver
159: .archive(siteId, m_storagePath, FROM_SAKAI);
160: }
161:
162: /**
163: * Process a merge for the file, or if it's a directory, for all contained files (one level deep).
164: * @param fileName The site name (for the archive file) to read from.
165: * @param mergeId The id string to use to make ids in the merge consistent and unique.
166: * @param creatorId The creator id
167: * If null or blank, the date/time string of the merge is used.
168: */
169: public String merge(String fileName, String siteId, String creatorId) {
170: return m_siteMerger.merge(fileName, siteId, creatorId,
171: m_storagePath, m_filterSakaiServices,
172: m_filteredSakaiServices, m_filterSakaiRoles,
173: m_filteredSakaiRoles);
174: }
175:
176: } // ArchiveService2Impl
|