KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > content > check > CmsContentCheckResource


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/content/check/CmsContentCheckResource.java,v $
3  * Date : $Date: 2006/03/27 14:52:54 $
4  * Version: $Revision: 1.2 $
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.tools.content.check;
33
34 import org.opencms.file.CmsFile;
35 import org.opencms.file.CmsObject;
36 import org.opencms.file.CmsResource;
37 import org.opencms.main.CmsException;
38 import org.opencms.xml.content.CmsXmlContent;
39 import org.opencms.xml.content.CmsXmlContentFactory;
40
41 import java.util.ArrayList JavaDoc;
42 import java.util.List JavaDoc;
43
44 /**
45  * This object encapuslates a CmsResource, its content and unmarshalled xml content
46  * for processing in the content check plugins.<p>
47  *
48  *
49  * @author Michael Emmerich
50  *
51  * @version $Revision: 1.2 $
52  *
53  * @since 6.1.2
54  */

55 public class CmsContentCheckResource {
56
57     /** Encapsulated content array. */
58     private byte[] m_content;
59
60     /** List of errors found during content check. */
61     private List JavaDoc m_errors;
62
63     /** Encapsulated CmsResource. */
64     private CmsResource m_resource;
65
66     /** List of warnings found during content check. */
67     private List JavaDoc m_warnings;
68
69     /** Encapsulated unmashalled xml content. */
70     private CmsXmlContent m_xmlcontent;
71
72     /**
73      * Constructor, creates an CmsContentCheckResource object.<p>
74      *
75      * @param res the CmsResource to encapsulate in the CmsContentCheckResource.
76      */

77     public CmsContentCheckResource(CmsResource res) {
78
79         m_resource = res;
80         m_content = null;
81         m_xmlcontent = null;
82         m_errors = new ArrayList JavaDoc();
83         m_warnings = new ArrayList JavaDoc();
84     }
85
86     /** Adds a new error to the list of errors for this resource.<p>
87      *
88      * @param error the error message to be added
89      */

90     public void addError(String JavaDoc error) {
91
92         m_errors.add(error);
93     }
94
95     /** Adds a list of errors to the list of errors for this resource.<p>
96      *
97      * @param errors the error messages to be added
98      */

99     public void addErrors(List JavaDoc errors) {
100
101         m_errors.addAll(errors);
102     }
103
104     /** Adds a new warning to the list of warnings for this resource.<p>
105      *
106      * @param warning the warning message to be added
107      */

108     public void addWarning(String JavaDoc warning) {
109
110         m_warnings.add(warning);
111     }
112
113     /** Adds a list of warnings to the list of warnings for this resource.<p>
114      *
115      * @param warnings the error messages to be added
116      */

117     public void addWarnings(List JavaDoc warnings) {
118
119         m_warnings.addAll(warnings);
120     }
121
122     /**
123      * Gets the encapuslated file content.<p>
124      *
125      * @return the byte array holding the file content
126      */

127     public byte[] getContent() {
128
129         return m_content;
130     }
131
132     /**
133      * Gets the list of all errors found during the content checks for this resource.<p>
134      * @return List of erros, delivered as strings
135      */

136     public List JavaDoc getErrors() {
137
138         return m_errors;
139     }
140
141     /**
142      * Gets the encapsulated CmsResource.<p>
143      *
144      * @return the CmsResource
145      */

146     public CmsResource getResource() {
147
148         return m_resource;
149     }
150
151     /**
152      * Gets the root path of the encapsulated CmsResource.<p>
153      *
154      * @return root path of the encapsulated CmsResource
155      */

156     public String JavaDoc getResourceName() {
157
158         return m_resource.getRootPath();
159     }
160
161     /**
162      * Gets the list of all warnings found during the content checks for this resource.<p>
163      * @return List of warnings, delivered as strings
164      */

165     public List JavaDoc getWarnings() {
166
167         return m_warnings;
168     }
169
170     /**
171      * Gets the encapuslated and unmarshalled xml content.<p>
172      *
173      * @return the unmarshalled xml content
174      */

175     public CmsXmlContent getXmlContent() {
176
177         return m_xmlcontent;
178     }
179
180     /**
181      * Loads the content of the encapsulated CmsResource and stores it within the
182      * CmsContentCheckResource. If the content is already existing, it is not loaded
183      * again.<p>
184      *
185      * @param cms the CmsObject
186      * @throws CmsException if loading of the content fails
187      */

188     public void upgradeContent(CmsObject cms) throws CmsException {
189
190         if (m_content == null) {
191             m_content = CmsFile.upgrade(m_resource, cms).getContents();
192         }
193     }
194
195     /**
196      * Unmarshalls the content of the encapsulated CmsResource and stores it within the
197      * CmsContentCheckResource. If the xmlcontent is already existing, it is not unmarshalled
198      * again.<p>
199      *
200      * @param cms the CmsObject
201      * @throws CmsException if loading of the content fails
202      */

203     public void upgradeXmlContent(CmsObject cms) throws CmsException {
204
205         if (m_xmlcontent == null) {
206             CmsFile file = CmsFile.upgrade(m_resource, cms);
207             m_xmlcontent = CmsXmlContentFactory.unmarshal(cms, file);
208         }
209     }
210 }
211
Popular Tags