KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > threads > CmsXmlDocumentLinkValidatorThread


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/threads/CmsXmlDocumentLinkValidatorThread.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.6 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.threads;
33
34 import org.opencms.db.CmsPublishList;
35 import org.opencms.file.CmsObject;
36 import org.opencms.main.CmsLog;
37 import org.opencms.report.A_CmsReportThread;
38 import org.opencms.workplace.CmsWorkplaceSettings;
39
40 import org.apache.commons.logging.Log;
41
42 /**
43  * A report thread for the HTML link validator.<p>
44  *
45  * @version $Revision: 1.6 $
46  *
47  * @since 6.0.0
48  */

49 public class CmsXmlDocumentLinkValidatorThread extends A_CmsReportThread {
50
51     /** The log object for this class. */
52     private static final Log LOG = CmsLog.getLog(CmsXmlDocumentLinkValidatorThread.class);
53
54     /** A list of cms resources to be published directly.<p> */
55     private CmsPublishList m_publishList;
56
57     /** Flag that indicates whether the publish list should be svaed in the workplace settings. */
58     private boolean m_savePublishList;
59
60     /** The current user's workplace settings.<p> */
61     private CmsWorkplaceSettings m_settings;
62
63     /**
64      * Creates a thread that validates the HTML links (hrefs and images) in all unpublished Cms
65      * files of the current (offline) project, if the files resource types implement the interface
66      * {@link org.opencms.validation.I_CmsXmlDocumentLinkValidatable}.<p>
67      *
68      * Please refer to the Javadoc of the I_CmsHtmlLinkValidatable interface to see which classes
69      * implement this interface (and so, which file types get validated by the HTML link
70      * validator).<p>
71      *
72      * The generated Cms publish list is *NOT* saved in the current user's workplace settings.<p>
73      *
74      * @param cms the current OpenCms context object
75      * @see org.opencms.file.CmsObject#getPublishList()
76      */

77     public CmsXmlDocumentLinkValidatorThread(CmsObject cms) {
78
79         super(cms, Messages.get().getBundle().key(
80             Messages.GUI_HTML_LINK_VALIDATOR_THREAD_NAME_1,
81             new Object JavaDoc[] {cms.getRequestContext().currentProject().getName()}));
82
83         m_publishList = null;
84         m_savePublishList = false;
85         m_settings = null;
86
87         initHtmlReport(cms.getRequestContext().getLocale());
88         start();
89     }
90
91     /**
92      * Creates a thread that validates the HTML links (hrefs and images) in the list of unpublished Cms
93      * file(s) of the current (offline) project, if the file's resource type implements the interface
94      * {@link org.opencms.validation.I_CmsXmlDocumentLinkValidatable}.<p>
95      *
96      * Please refer to the Javadoc of the I_CmsHtmlLinkValidatable interface to see which classes
97      * implement this interface (and so, which file types get validated by the HTML link
98      * validator).<p>
99      *
100      * The Cms publish list *IS* saved in the current user's workplace settings for
101      * further processing by other threads. The last thread processing this publish list *MUST*
102      * ensure that the publish list gets removed from the current user's workplace settings!<p>
103      *
104      * @param cms the current OpenCms context object
105      * @param publishList the list of resources which will be directly published
106      * @param settings the current user's workplace settings
107      */

108     public CmsXmlDocumentLinkValidatorThread(CmsObject cms, CmsPublishList publishList, CmsWorkplaceSettings settings) {
109
110         super(cms, Messages.get().getBundle().key(
111             Messages.GUI_HTML_LINK_VALIDATOR_THREAD_NAME_1,
112             new Object JavaDoc[] {cms.getRequestContext().currentProject().getName()}));
113         m_publishList = publishList;
114         m_savePublishList = true;
115         m_settings = settings;
116
117         initHtmlReport(cms.getRequestContext().getLocale());
118         start();
119     }
120
121     /**
122      * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
123      */

124     public String JavaDoc getReportUpdate() {
125
126         return getReport().getReportUpdate();
127     }
128
129     /**
130      * @see java.lang.Runnable#run()
131      */

132     public void run() {
133
134         CmsPublishList publishList = null;
135
136         try {
137             // get the list of resources that actually get published
138
if (m_publishList == null) {
139                 publishList = getCms().getPublishList();
140             } else {
141                 publishList = m_publishList;
142             }
143
144             // validate the HTML links in these resources
145
getCms().validateHtmlLinks(publishList, getReport());
146
147             if (m_savePublishList && m_settings != null) {
148                 // save the publish list optionally to be processed by further workplace threads
149
m_settings.setPublishList(publishList);
150             }
151         } catch (Exception JavaDoc e) {
152             if (m_savePublishList && m_settings != null) {
153                 // overwrite the publish list in any case with null
154
m_settings.setPublishList(null);
155             }
156
157             getReport().println(e);
158             LOG.error(Messages.get().getBundle().key(Messages.ERR_LINK_VALIDATION_0), e);
159         }
160     }
161 }
Popular Tags