001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/content/check/CmsContentCheckResource.java,v $
003: * Date : $Date: 2008-02-27 12:05:42 $
004: * Version: $Revision: 1.5 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.content.check;
033:
034: import org.opencms.file.CmsFile;
035: import org.opencms.file.CmsObject;
036: import org.opencms.file.CmsResource;
037: import org.opencms.main.CmsException;
038: import org.opencms.xml.content.CmsXmlContent;
039: import org.opencms.xml.content.CmsXmlContentFactory;
040:
041: import java.util.ArrayList;
042: import java.util.List;
043:
044: /**
045: * This object encapuslates a CmsResource, its content and unmarshalled xml content
046: * for processing in the content check plugins.<p>
047: *
048: *
049: * @author Michael Emmerich
050: *
051: * @version $Revision: 1.5 $
052: *
053: * @since 6.1.2
054: */
055: public class CmsContentCheckResource {
056:
057: /** Encapsulated content array. */
058: private byte[] m_content;
059:
060: /** List of errors found during content check. */
061: private List m_errors;
062:
063: /** Encapsulated CmsResource. */
064: private CmsResource m_resource;
065:
066: /** List of warnings found during content check. */
067: private List m_warnings;
068:
069: /** Encapsulated unmashalled xml content. */
070: private CmsXmlContent m_xmlcontent;
071:
072: /**
073: * Constructor, creates an CmsContentCheckResource object.<p>
074: *
075: * @param res the CmsResource to encapsulate in the CmsContentCheckResource.
076: */
077: public CmsContentCheckResource(CmsResource res) {
078:
079: m_resource = res;
080: m_content = null;
081: m_xmlcontent = null;
082: m_errors = new ArrayList();
083: m_warnings = new ArrayList();
084: }
085:
086: /** Adds a new error to the list of errors for this resource.<p>
087: *
088: * @param error the error message to be added
089: */
090: public void addError(String error) {
091:
092: m_errors.add(error);
093: }
094:
095: /** Adds a list of errors to the list of errors for this resource.<p>
096: *
097: * @param errors the error messages to be added
098: */
099: public void addErrors(List 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 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 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 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 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 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 = cms.readFile(m_resource).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 = cms.readFile(m_resource);
207: m_xmlcontent = CmsXmlContentFactory.unmarshal(cms, file);
208: }
209: }
210: }
|