001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/database/CmsRemovePubLocksThread.java,v $
003: * Date : $Date: 2008-02-27 12:05:51 $
004: * Version: $Revision: 1.5 $
005: *
006: * This program is part of the Alkacon OpenCms Software library.
007: *
008: * This license applies to all programs, pages, Java classes, parts and
009: * modules of the Alkacon OpenCms Software library published by
010: * Alkacon Software GmbH, unless otherwise noted.
011: *
012: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
013: *
014: * This program is free software; you can redistribute it and/or modify
015: * it under the terms of the GNU General Public License as published by
016: * the Free Software Foundation; either version 2 of the License, or (at
017: * your option) any later version.
018: *
019: * This program is distributed in the hope that it will be useful, but
020: * WITHOUT ANY WARRANTY; without even the implied warranty of
021: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
022: * General Public License for more details.
023: *
024: * You should have received a copy of the GNU General Public License
025: * along with this program; if not, write to the Free Software
026: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
027: *
028: * For further information about Alkacon Software GmbH, please see the
029: * companys website: http://www.alkacon.com.
030: *
031: * For further information about OpenCms, please see the OpenCms project
032: * website: http://www.opencms.org.
033: *
034: * The names "Alkacon", "Alkacon Software GmbH" and "OpenCms" must not be used
035: * to endorse or promote products derived from this software without prior
036: * written permission. For written permission, please contact info@alkacon.com.
037: *
038: * Products derived from this software may not be called "Alkacon",
039: * "Alkacon Software GmbH" or "OpenCms", nor may "Alkacon", "Alkacon Software GmbH"
040: * or "OpenCms" appear in their name, without prior written permission of
041: * Alkacon Software GmbH.
042: *
043: * This program is also available under a commercial non-GPL license. For
044: * pricing and ordering information, please inquire at sales@alkacon.com.
045: */
046:
047: package org.opencms.workplace.tools.database;
048:
049: import org.opencms.file.CmsObject;
050: import org.opencms.file.CmsResource;
051: import org.opencms.file.CmsResourceFilter;
052: import org.opencms.lock.CmsLockFilter;
053: import org.opencms.lock.CmsLockType;
054: import org.opencms.main.OpenCms;
055: import org.opencms.report.A_CmsReportThread;
056: import org.opencms.report.I_CmsReport;
057:
058: import java.util.ArrayList;
059: import java.util.Iterator;
060: import java.util.List;
061:
062: /**
063: * Remove the publish locks.<p>
064: *
065: * @author Michael Moossen
066: *
067: * @version $Revision: 1.5 $
068: *
069: * @since 7.0.2
070: */
071: public class CmsRemovePubLocksThread extends A_CmsReportThread {
072:
073: /** The last error occurred. */
074: private Throwable m_error;
075:
076: /** The list of resource names. */
077: private List m_resources;
078:
079: /**
080: * Creates an Thread to remove the publish locks.<p>
081: *
082: * @param cms the current OpenCms context object
083: * @param resources a list of resource names
084: */
085: public CmsRemovePubLocksThread(CmsObject cms, List resources) {
086:
087: super (cms, Messages.get().getBundle().key(
088: Messages.GUI_DB_PUBLOCKS_THREAD_NAME_0));
089: m_resources = new ArrayList(resources);
090: initHtmlReport(cms.getRequestContext().getLocale());
091: }
092:
093: /**
094: * Returns the last error.<p>
095: *
096: * @see org.opencms.report.A_CmsReportThread#getError()
097: */
098: public Throwable getError() {
099:
100: return m_error;
101: }
102:
103: /**
104: * Updates the report.<p>
105: *
106: * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
107: */
108: public String getReportUpdate() {
109:
110: return getReport().getReportUpdate();
111: }
112:
113: /**
114: * Starts the report thread.<p>
115: *
116: * @see java.lang.Runnable#run()
117: */
118: public void run() {
119:
120: try {
121: getReport().println(
122: Messages.get().container(
123: Messages.RPT_DB_PUBLOCKS_BEGIN_0),
124: I_CmsReport.FORMAT_HEADLINE);
125: CmsObject cms = getCms();
126: CmsLockFilter filter = CmsLockFilter.FILTER_ALL;
127: filter = filter.filterType(CmsLockType.PUBLISH);
128:
129: Iterator it = m_resources.iterator();
130: while (it.hasNext()) {
131: String paramResName = (String) it.next();
132: getReport().println(
133: Messages.get().container(
134: Messages.RPT_DB_PUBLOCKS_READLOCKS_1,
135: paramResName), I_CmsReport.FORMAT_NOTE);
136: Iterator itResources = cms.getLockedResources(
137: paramResName, filter).iterator();
138: while (itResources.hasNext()) {
139: String resName = (String) itResources.next();
140: if (!cms.existsResource(resName,
141: CmsResourceFilter.ALL)) {
142: getReport()
143: .println(
144: Messages
145: .get()
146: .container(
147: Messages.RPT_DB_PUBLOCKS_UNLOCKING_1,
148: resName),
149: I_CmsReport.FORMAT_DEFAULT);
150: OpenCms.getMemoryMonitor().uncacheLock(
151: cms.getRequestContext().addSiteRoot(
152: resName));
153: continue;
154: }
155: Iterator itSiblings = cms.readSiblings(resName,
156: CmsResourceFilter.ALL).iterator();
157: while (itSiblings.hasNext()) {
158: CmsResource res = (CmsResource) itSiblings
159: .next();
160: getReport()
161: .println(
162: Messages
163: .get()
164: .container(
165: Messages.RPT_DB_PUBLOCKS_UNLOCKING_1,
166: cms
167: .getSitePath(res)),
168: I_CmsReport.FORMAT_DEFAULT);
169: OpenCms.getMemoryMonitor().uncacheLock(
170: res.getRootPath());
171: }
172: }
173: }
174: getReport().println(
175: Messages.get().container(
176: Messages.RPT_DB_PUBLOCKS_END_0),
177: I_CmsReport.FORMAT_HEADLINE);
178: } catch (Throwable exc) {
179: getReport().println(
180: Messages.get().container(
181: Messages.RPT_DB_PUBLOCKS_FAILED_0),
182: I_CmsReport.FORMAT_WARNING);
183: getReport().println(exc);
184: m_error = exc;
185: }
186: }
187: }
|