KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > xml > content > CmsXmlContentMappingVisitor


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/xml/content/CmsXmlContentMappingVisitor.java,v $
3  * Date : $Date: 2006/03/27 14:52:36 $
4  * Version: $Revision: 1.11 $
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.xml.content;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.CmsException;
36 import org.opencms.main.CmsLog;
37 import org.opencms.xml.CmsXmlContentDefinition;
38 import org.opencms.xml.types.I_CmsXmlContentValue;
39
40 import org.apache.commons.logging.Log;
41
42 /**
43  * Visitor implementation that resolves the content mappings for all the visited values.<p>
44  *
45  * This class is used when {@link org.opencms.xml.content.CmsXmlContent#validate(CmsObject)}
46  * is called to resolve the mappings of a XML content object.<p>
47  *
48  * @author Alexander Kandzior
49  *
50  * @version $Revision: 1.11 $
51  *
52  * @since 6.0.0
53  */

54 class CmsXmlContentMappingVisitor implements I_CmsXmlContentValueVisitor {
55
56     /** Static reference to the log. */
57     private static final Log LOG = CmsLog.getLog(CmsXmlContentMappingVisitor.class);
58
59     /** The initialized OpenCms user context (required for VFS access). */
60     CmsObject m_cms;
61
62     /** The XML content the mappings are resolved for. */
63     CmsXmlContent m_content;
64
65     /** The "main" content definition, used for all mappings. */
66     CmsXmlContentDefinition m_definition;
67
68     /** The error handler instance that stores the errors and warnings found. */
69     CmsXmlContentErrorHandler m_errorHandler;
70
71     /**
72      * Creates a new error handler node visitor.<p>
73      *
74      * @param cms the initialized OpenCms user context (required for VFS access)
75      * @param content the XML content to resolve the mappings for
76      */

77     public CmsXmlContentMappingVisitor(CmsObject cms, CmsXmlContent content) {
78
79         // store references
80
m_cms = cms;
81         m_content = content;
82         m_definition = content.getContentDefinition();
83     }
84
85     /**
86      * Returns the error handler instance that stores the errors and warnings found.<p>
87      *
88      * @return the error handler instance that stores the errors and warnings found
89      */

90     public CmsXmlContentErrorHandler getErrorHandler() {
91
92         return m_errorHandler;
93     }
94
95     /**
96      * @see org.opencms.xml.content.I_CmsXmlContentValueVisitor#visit(org.opencms.xml.types.I_CmsXmlContentValue)
97      */

98     public void visit(I_CmsXmlContentValue value) {
99
100         if (LOG.isDebugEnabled()) {
101             LOG.debug(Messages.get().getBundle().key(Messages.LOG_XMLCONTENT_VISIT_1, value.getPath()));
102         }
103
104         try {
105             m_definition.getContentHandler().resolveMapping(m_cms, m_content, value);
106         } catch (CmsException e) {
107             LOG.error(Messages.get().getBundle().key(Messages.LOG_XMLCONTENT_RESOLVE_MAPPING_1, value.getPath()), e);
108         }
109     }
110 }
Popular Tags