KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > configuration > CmsConfigurationCopyResource


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/configuration/CmsConfigurationCopyResource.java,v $
3  * Date : $Date: 2005/06/27 23:22:20 $
4  * Version: $Revision: 1.7 $
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.configuration;
33
34 import org.opencms.file.CmsResource;
35 import org.opencms.file.types.A_CmsResourceType;
36 import org.opencms.util.CmsMacroResolver;
37
38 /**
39  * Describes a resource to copy during the creation of a new resource.<p>
40  *
41  * Usually used in folder types to copy some default resources to the folder,
42  * but also usable for file resources.<p>
43  *
44  * @author Alexander Kandzior
45  *
46  * @version $Revision: 1.7 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsConfigurationCopyResource {
51
52     /** Indicates "copy resources" should be copied with type {@link CmsResource#COPY_AS_NEW}. */
53     public static final String JavaDoc COPY_AS_NEW = "new";
54
55     /** Indicates "copy resources" should be copied with type {@link CmsResource#COPY_PRESERVE_SIBLING}. */
56     public static final String JavaDoc COPY_AS_PRESERVE = "preserve";
57
58     /** Indicates "copy resources" should be copied with type {@link CmsResource#COPY_AS_SIBLING}. */
59     public static final String JavaDoc COPY_AS_SIBLING = "sibling";
60
61     /** The source resource. */
62     private String JavaDoc m_source;
63
64     /** The target resource (may contain macros). */
65     private String JavaDoc m_target;
66
67     /** Indicates that the original configured target was <code>null</code>.*/
68     private boolean m_targetWasNull;
69
70     /** The type of the copy, for example "as new", "as sibling" etc.*/
71     private int m_type;
72
73     /** Indicates that the original configured type setting was <code>null</code>.*/
74     private boolean m_typeWasNull;
75
76     /**
77      * Creates a new copy resource info container.<p>
78      *
79      * If target is <code>null</code>, the macro {@link A_CmsResourceType#MACRO_RESOURCE_FOLDER_PATH} is used as default.
80      * If type is <code>null</code>, the copy type {@link CmsResource#COPY_AS_NEW} is used as default.<p>
81      *
82      * @param source the source resource
83      * @param target the target resource (may contain macros)
84      * @param type the type of the copy, for example "as new", "as sibling" etc
85      */

86     public CmsConfigurationCopyResource(String JavaDoc source, String JavaDoc target, String JavaDoc type) {
87
88         m_source = source;
89
90         if (target == null) {
91             m_target = CmsMacroResolver.formatMacro(A_CmsResourceType.MACRO_RESOURCE_FOLDER_PATH);
92             m_targetWasNull = true;
93         } else {
94             m_target = target;
95         }
96
97         m_type = CmsResource.COPY_AS_NEW;
98         if (type != null) {
99             if (type.equalsIgnoreCase(CmsConfigurationCopyResource.COPY_AS_SIBLING)) {
100                 m_type = CmsResource.COPY_AS_SIBLING;
101             } else if (type.equalsIgnoreCase(CmsConfigurationCopyResource.COPY_AS_PRESERVE)) {
102                 m_type = CmsResource.COPY_PRESERVE_SIBLING;
103             }
104         } else {
105             m_typeWasNull = true;
106         }
107     }
108
109     /**
110      * Returns the source resource.<p>
111      *
112      * @return the source resource
113      */

114     public String JavaDoc getSource() {
115
116         return m_source;
117     }
118
119     /**
120      * Returns the target resource (may contain macros).<p>
121      *
122      * @return the target resource (may contain macros)
123      */

124     public String JavaDoc getTarget() {
125
126         return m_target;
127     }
128
129     /**
130      * Returns the type of the copy, for example "as new", "as sibling" etc.<p>
131      *
132      * Possible types are {@link org.opencms.file.CmsResource#COPY_AS_NEW}, {@link org.opencms.file.CmsResource#COPY_AS_SIBLING},
133      * {@link org.opencms.file.CmsResource#COPY_PRESERVE_SIBLING}.<p>
134      *
135      * @return the type of the copy, for example "as new", "as sibling" etc
136      */

137     public int getType() {
138
139         return m_type;
140     }
141
142     /**
143      * Returns the copy type as String.<p>
144      *
145      * @see #getType()
146      *
147      * @return the copy type as String
148      */

149     public String JavaDoc getTypeString() {
150
151         if (CmsResource.COPY_AS_SIBLING == m_type) {
152             return CmsConfigurationCopyResource.COPY_AS_SIBLING;
153         } else if (CmsResource.COPY_PRESERVE_SIBLING == m_type) {
154             return CmsConfigurationCopyResource.COPY_AS_PRESERVE;
155         }
156         return CmsConfigurationCopyResource.COPY_AS_NEW;
157     }
158
159     /**
160      * Returns <code>true</code> if the orginal target configuration was <code>null</code>.<p>
161      *
162      * @return <code>true</code> if the orginal target configuration was <code>null</code>
163      */

164     public boolean isTargetWasNull() {
165
166         return m_targetWasNull;
167     }
168
169     /**
170      * Returns <code>true</code> if the orginal type configuration was <code>null</code>.<p>
171      *
172      * @return <code>true</code> if the orginal type configuration was <code>null</code>
173      */

174     public boolean isTypeWasNull() {
175
176         return m_typeWasNull;
177     }
178
179     /**
180      * @see java.lang.Object#toString()
181      */

182     public String JavaDoc toString() {
183
184         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
185
186         result.append("[");
187         result.append(this.getClass().getName());
188         result.append(", source=");
189         result.append(getSource());
190         result.append(", target=");
191         result.append(getTarget());
192         result.append(", type=");
193         result.append(getTypeString());
194         result.append("]");
195
196         return result.toString();
197     }
198 }
Popular Tags