KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > xml > types > CmsXmlVfsFileValue


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/xml/types/CmsXmlVfsFileValue.java,v $
3  * Date : $Date: 2005/06/27 23:22:25 $
4  * Version: $Revision: 1.18 $
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.types;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.CmsIllegalArgumentException;
36 import org.opencms.main.CmsRuntimeException;
37 import org.opencms.staticexport.CmsLink;
38 import org.opencms.staticexport.CmsLinkManager;
39 import org.opencms.staticexport.CmsLinkTable;
40 import org.opencms.util.CmsStringUtil;
41 import org.opencms.xml.I_CmsXmlDocument;
42
43 import java.util.Locale JavaDoc;
44
45 import org.dom4j.Element;
46
47 /**
48  * Describes the XML content type "OpenCmsVfsFile".<p>
49  *
50  * @author Andreas Zahner
51  *
52  * @version $Revision: 1.18 $
53  *
54  * @since 6.0.0
55  */

56 public class CmsXmlVfsFileValue extends A_CmsXmlContentValue {
57
58     /** Value to mark that no link is defined, "none". */
59     public static final String JavaDoc NO_LINK = "none";
60
61     /** The name of this type as used in the XML schema. */
62     public static final String JavaDoc TYPE_NAME = "OpenCmsVfsFile";
63
64     /** The String value of the element node. */
65     private String JavaDoc m_stringValue;
66
67     /**
68      * Creates a new, empty schema type descriptor of type "OpenCmsVfsFile".<p>
69      */

70     public CmsXmlVfsFileValue() {
71
72         // empty constructor is required for class registration
73
}
74
75     /**
76      * Creates a new XML content value of type "OpenCmsVfsFile".<p>
77      *
78      * @param document the XML content instance this value belongs to
79      * @param element the XML element that contains this value
80      * @param locale the locale this value is created for
81      * @param type the type instance to create the value for
82      */

83     public CmsXmlVfsFileValue(I_CmsXmlDocument document, Element element, Locale JavaDoc locale, I_CmsXmlSchemaType type) {
84
85         super(document, element, locale, type);
86         m_stringValue = element.getText();
87     }
88
89     /**
90      * Creates a new schema type descriptor for the type "OpenCmsVfsFile".<p>
91      *
92      * @param name the name of the XML node containing the value according to the XML schema
93      * @param minOccurs minimum number of occurences of this type according to the XML schema
94      * @param maxOccurs maximum number of occurences of this type according to the XML schema
95      */

96     public CmsXmlVfsFileValue(String JavaDoc name, String JavaDoc minOccurs, String JavaDoc maxOccurs) {
97
98         super(name, minOccurs, maxOccurs);
99     }
100
101     /**
102      * @see org.opencms.xml.types.A_CmsXmlContentValue#createValue(I_CmsXmlDocument, org.dom4j.Element, Locale)
103      */

104     public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale JavaDoc locale) {
105
106         return new CmsXmlVfsFileValue(document, element, locale, this);
107     }
108
109     /**
110      * Returns the link table of this XML page element.<p>
111      *
112      * @return the link table of this XML page element
113      */

114     public CmsLinkTable getLinkTable() {
115
116         CmsLinkTable linkTable = new CmsLinkTable();
117         if (!NO_LINK.equals(m_element.getText())) {
118             CmsLink link = new CmsLink("link0", "vfs", m_element.getText(), true);
119             linkTable.addLink(link);
120         }
121         return linkTable;
122     }
123
124     /**
125      * @see org.opencms.xml.types.I_CmsXmlSchemaType#getSchemaDefinition()
126      */

127     public String JavaDoc getSchemaDefinition() {
128
129         return "<xsd:simpleType name=\"" + TYPE_NAME + "\"><xsd:restriction base=\"xsd:string\" /></xsd:simpleType>";
130     }
131
132     /**
133      * @see org.opencms.xml.types.I_CmsXmlContentValue#getStringValue(CmsObject)
134      */

135     public String JavaDoc getStringValue(CmsObject cms) throws CmsRuntimeException {
136
137         if (cms != null && CmsStringUtil.isNotEmpty(m_stringValue) && !NO_LINK.equals(m_stringValue)) {
138             return cms.getRequestContext().removeSiteRoot(m_stringValue);
139         } else {
140             return m_stringValue;
141         }
142     }
143
144     /**
145      * @see org.opencms.xml.types.A_CmsXmlContentValue#getTypeName()
146      */

147     public String JavaDoc getTypeName() {
148
149         return TYPE_NAME;
150     }
151
152     /**
153      * @see org.opencms.xml.types.A_CmsXmlContentValue#newInstance(java.lang.String, java.lang.String, java.lang.String)
154      */

155     public I_CmsXmlSchemaType newInstance(String JavaDoc name, String JavaDoc minOccurs, String JavaDoc maxOccurs) {
156
157         return new CmsXmlVfsFileValue(name, minOccurs, maxOccurs);
158     }
159
160     /**
161      * @see org.opencms.xml.types.A_CmsXmlContentValue#setStringValue(org.opencms.file.CmsObject, java.lang.String)
162      */

163     public void setStringValue(CmsObject cms, String JavaDoc value) throws CmsIllegalArgumentException {
164
165         if (cms != null && !NO_LINK.equals(value)) {
166             // add site path if required
167
value = CmsLinkManager.getSitePath(cms, null, value);
168         }
169
170         // now update the XML node
171
m_element.clearContent();
172         if (CmsStringUtil.isNotEmpty(value)) {
173             m_element.addText(value);
174             m_stringValue = value;
175         } else {
176             m_stringValue = null;
177         }
178     }
179 }
Popular Tags