KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > frontend > templateone > CmsPropertyTemplateOne


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/CmsPropertyTemplateOne.java,v $
3  * Date : $Date: 2006/07/20 10:35:10 $
4  * Version: $Revision: 1.31 $
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.frontend.templateone;
33
34 import org.opencms.file.CmsProperty;
35 import org.opencms.file.CmsPropertyDefinition;
36 import org.opencms.file.CmsResource;
37 import org.opencms.file.CmsResourceFilter;
38 import org.opencms.file.types.CmsResourceTypeBinary;
39 import org.opencms.file.types.CmsResourceTypeImage;
40 import org.opencms.file.types.CmsResourceTypePlain;
41 import org.opencms.file.types.CmsResourceTypeXmlPage;
42 import org.opencms.frontend.templateone.modules.CmsLayoutXmlContentHandler;
43 import org.opencms.i18n.CmsEncoder;
44 import org.opencms.i18n.CmsMessages;
45 import org.opencms.jsp.CmsJspActionElement;
46 import org.opencms.jsp.util.CmsTemplateContentListItem;
47 import org.opencms.main.CmsException;
48 import org.opencms.main.CmsLog;
49 import org.opencms.main.OpenCms;
50 import org.opencms.util.CmsStringUtil;
51 import org.opencms.workplace.CmsDialogSelector;
52 import org.opencms.workplace.CmsWorkplace;
53 import org.opencms.workplace.I_CmsDialogHandler;
54 import org.opencms.workplace.commons.CmsPropertyCustom;
55 import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
56
57 import java.util.ArrayList JavaDoc;
58 import java.util.Iterator JavaDoc;
59 import java.util.List JavaDoc;
60
61 import javax.servlet.http.HttpServletRequest JavaDoc;
62 import javax.servlet.http.HttpServletResponse JavaDoc;
63 import javax.servlet.jsp.JspException JavaDoc;
64 import javax.servlet.jsp.PageContext JavaDoc;
65
66 import org.apache.commons.logging.Log;
67
68 /**
69  * This property dialog is shown specially by files using the OpenCms template one,
70  * and for any folders except system folders.<p>
71  *
72  * @author Armen Markarian
73  * @author Andreas Zahner
74  *
75  * @version $Revision: 1.31 $
76  *
77  * @since 6.0.0
78  */

79 public class CmsPropertyTemplateOne extends CmsPropertyCustom implements I_CmsDialogHandler {
80
81     /**
82      * Contains all properties to set with this customized dialog.<p>
83      *
84      * Loop this to get the HTTP request data and set the property values.<p>
85      */

86     private static final String JavaDoc[] ALL_PROPERTIES = {
87
88         CmsTemplateNavigation.PROPERTY_HEADNAV_USE,
89         CmsTemplateBean.PROPERTY_SHOWHEADIMAGE,
90         CmsTemplateBean.PROPERTY_HEAD_IMGURI,
91         CmsTemplateBean.PROPERTY_HEAD_IMGLINK,
92         CmsTemplateBean.PROPERTY_HEAD_ELEMENTURI,
93         CmsTemplateBean.PROPERTY_SHOW_HEADNAV,
94         CmsTemplateBean.PROPERTY_SHOW_NAVLEFT,
95         CmsTemplateBean.PROPERTY_NAVLEFT_ELEMENTURI,
96         CmsTemplateBean.PROPERTY_SIDE_URI,
97         CmsTemplateBean.PROPERTY_CONFIGPATH,
98         CmsTemplateBean.PROPERTY_LAYOUT_CENTER,
99         CmsTemplateBean.PROPERTY_LAYOUT_RIGHT};
100
101     /**
102      * String Array with default properties.<p>
103      *
104      * Loop this to create form fields or get HTTP request data and set the property values.<p>
105      */

106     private static final String JavaDoc[] DEFAULT_PROPERTIES = {
107
108     CmsPropertyDefinition.PROPERTY_TITLE, CmsPropertyDefinition.PROPERTY_DESCRIPTION};
109
110     /** Mode used for switching between different radio types. */
111     private static final String JavaDoc ENABLE = "enable";
112
113     /** Mode used for switching between different radio types. */
114     private static final String JavaDoc INDIVIDUAL = "individual";
115
116     /** Prefix for the localized keys of the dialog. */
117     private static final String JavaDoc KEY_PREFIX = "templateonedialog.";
118
119     /** The log object for this class. */
120     private static final Log LOG = CmsLog.getLog(CmsPropertyTemplateOne.class);
121
122     /** The module path. */
123     private static final String JavaDoc MODULE_PATH = "/system/modules/org.opencms.frontend.templateone/";
124
125     /** The default parameter value. */
126     private static final String JavaDoc PARAM_DEFAULT = "";
127
128     /** The false parameter value. */
129     private static final String JavaDoc PARAM_FALSE = CmsStringUtil.FALSE;
130
131     /** The true parameter value. */
132     private static final String JavaDoc PARAM_TRUE = CmsStringUtil.TRUE;
133
134     /** The path of the "template one" template. */
135     private static final String JavaDoc TEMPLATE_ONE = "/system/modules/org.opencms.frontend.templateone/templates/main";
136
137     /** The VFS path to the global configuration files for content lists. */
138     private static final String JavaDoc VFS_PATH_CONFIGFILES = CmsWorkplace.VFS_PATH_SYSTEM + "shared/templateone/";
139
140     /** The VFS path to the global configuration files for center content lists. */
141     private static final String JavaDoc VFS_PATH_CONFIGFILES_CENTER = VFS_PATH_CONFIGFILES + "center/";
142
143     /** The VFS path to the global configuration files for right content lists. */
144     private static final String JavaDoc VFS_PATH_CONFIGFILES_RIGHT = VFS_PATH_CONFIGFILES + "right/";
145
146     /**
147      * Default constructor needed for dialog handler implementation.<p>
148      *
149      * Do not use this constructor on JSP pages.<p>
150      */

151     public CmsPropertyTemplateOne() {
152
153         super(null);
154     }
155
156     /**
157      * Public constructor with JSP action element.<p>
158      *
159      * @param jsp an initialized JSP action element
160      */

161     public CmsPropertyTemplateOne(CmsJspActionElement jsp) {
162
163         super(jsp);
164     }
165
166     /**
167      * Public constructor with JSP variables.<p>
168      *
169      * @param context the JSP page context
170      * @param req the JSP request
171      * @param res the JSP response
172      */

173     public CmsPropertyTemplateOne(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
174
175         super(new CmsJspActionElement(context, req, res));
176     }
177
178     /**
179      * Performs the edit properties action, will be called by the JSP page.<p>
180      *
181      * @param request the HttpServletRequest
182      * @throws JspException if problems including sub-elements occur
183      */

184     public void actionEdit(HttpServletRequest JavaDoc request) throws JspException JavaDoc {
185
186         // save initialized instance of this class in request attribute for included sub-elements
187
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
188         try {
189             // save the changes only if resource is properly locked
190
if (isEditable()) {
191                 performEditOperation(request);
192             }
193         } catch (Throwable JavaDoc e) {
194             // Cms checked error defining property, show error dialog
195
includeErrorpage(this, e);
196         }
197     }
198
199     /**
200      * Build the html for a property checkbox.<p>
201      *
202      * @param propertyName the property name
203      * @param propertyValue the property value
204      * @param propertyText the property text
205      *
206      * @return the html for a property checkbox
207      */

208     public String JavaDoc buildCheckBox(String JavaDoc propertyName, String JavaDoc propertyValue, String JavaDoc propertyText) {
209
210         StringBuffer JavaDoc checkbox = new StringBuffer JavaDoc();
211         checkbox.append(buildTableRowStart(key(propertyText)));
212         String JavaDoc checked = "";
213         if (getActiveProperties().containsKey(propertyName)) {
214             // the property is used, so create text field with checkbox and hidden field
215
CmsProperty currentProperty = (CmsProperty)getActiveProperties().get(propertyName);
216
217             String JavaDoc propValue = currentProperty.getValue();
218             if (propValue != null) {
219                 propValue = propValue.trim();
220             }
221             propValue = CmsEncoder.escapeXml(propValue);
222             if (propertyValue.equals(propValue)) {
223                 checked = " checked=\"checked\"";
224             }
225         } else {
226             // check radio if param value is the default
227
if (propertyValue.equals(PARAM_DEFAULT)) {
228                 checked = " checked=\"checked\"";
229             }
230         }
231         checkbox.append("<input type=\"checkbox\" name=\"");
232         checkbox.append(PREFIX_VALUE);
233         checkbox.append(propertyName);
234         checkbox.append("\" value=\"");
235         checkbox.append(propertyValue);
236         checkbox.append("\"");
237         checkbox.append(checked);
238         checkbox.append(">");
239         checkbox.append(buildTableRowEnd());
240
241         return checkbox.toString();
242     }
243
244     /**
245      * Creates the HTML String for the edit properties form.<p>
246      *
247      * @return the HTML output String for the edit properties form
248      */

249     public String JavaDoc buildEditForm() {
250
251         CmsMessages messages = Messages.get().getBundle(getLocale());
252         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
253
254         // check if the properties are editable
255
boolean editable = isEditable();
256
257         // create the column heads
258
result.append("<table border=\"0\">\n");
259         result.append("<tr>\n");
260         result.append("\t<td class=\"textbold\">");
261         result.append(messages.key(Messages.GUI_INPUT_PROPERTY_0));
262         result.append("</td>\n");
263         result.append("\t<td class=\"textbold maxwidth\">");
264         result.append(messages.key(Messages.GUI_LABEL_VALUE_0));
265         result.append("</td>\n");
266         result.append("\t<td class=\"textbold\" style=\"white-space: nowrap;\">");
267         result.append(messages.key(Messages.GUI_USED_PROPERTY_0));
268         result.append("</td>\n");
269         result.append("</tr>\n");
270         result.append("<tr><td colspan=\"3\"><span style=\"height: 6px;\"></span></td></tr>\n");
271
272         // create the text property input rows from m_defaultProperties
273
for (int i = 0; i < DEFAULT_PROPERTIES.length; i++) {
274             result.append(buildPropertyEntry(DEFAULT_PROPERTIES[i], key(KEY_PREFIX + DEFAULT_PROPERTIES[i]), editable));
275         }
276
277         // show navigation properties
278
result.append(buildNavigationProperties(editable));
279
280         // build head nav checkbox
281
result.append(buildCheckBox(CmsTemplateNavigation.PROPERTY_HEADNAV_USE, PARAM_TRUE, KEY_PREFIX
282             + CmsTemplateNavigation.PROPERTY_HEADNAV_USE));
283
284         // build head image radio buttons
285
result.append(buildRadioButtons(
286             CmsTemplateBean.PROPERTY_SHOWHEADIMAGE,
287             INDIVIDUAL,
288             "toggleHeadImageProperties",
289             editable));
290
291         // build image uri search input
292
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_HEAD_IMGURI, KEY_PREFIX
293             + CmsTemplateBean.PROPERTY_HEAD_IMGURI, editable, messages));
294         // build image link search input
295
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_HEAD_IMGLINK, KEY_PREFIX
296             + CmsTemplateBean.PROPERTY_HEAD_IMGLINK, editable, messages));
297
298         // build head element search input
299
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_HEAD_ELEMENTURI, KEY_PREFIX
300             + CmsTemplateBean.PROPERTY_HEAD_ELEMENTURI, editable, messages));
301
302         // build head navigation radio buttons
303
result.append(buildRadioButtons(CmsTemplateBean.PROPERTY_SHOW_HEADNAV, ENABLE, null, editable));
304
305         // build navigation tree radio buttons
306
result.append(buildRadioButtons(CmsTemplateBean.PROPERTY_SHOW_NAVLEFT, ENABLE, null, editable));
307
308         // build navleft element search input
309
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_NAVLEFT_ELEMENTURI, KEY_PREFIX
310             + CmsTemplateBean.PROPERTY_NAVLEFT_ELEMENTURI, editable, messages));
311         // build side uri search input
312
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_SIDE_URI, KEY_PREFIX
313             + CmsTemplateBean.PROPERTY_SIDE_URI, editable, messages));
314
315         // build center layout selector
316
result.append(buildPropertySelectbox(
317             CmsTemplateContentListItem.DISPLAYAREA_CENTER,
318             CmsTemplateBean.PROPERTY_LAYOUT_CENTER,
319             KEY_PREFIX + CmsTemplateBean.PROPERTY_LAYOUT_CENTER,
320             editable));
321         // build right layout selector
322
result.append(buildPropertySelectbox(
323             CmsTemplateContentListItem.DISPLAYAREA_RIGHT,
324             CmsTemplateBean.PROPERTY_LAYOUT_RIGHT,
325             KEY_PREFIX + CmsTemplateBean.PROPERTY_LAYOUT_RIGHT,
326             editable));
327
328         // build configuration path search input
329
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_CONFIGPATH, KEY_PREFIX
330             + CmsTemplateBean.PROPERTY_CONFIGPATH, editable, messages));
331
332         result.append("</table>");
333
334         return result.toString();
335     }
336
337     /**
338      * Builds the JavaScript to set the property form values delayed.<p>
339      *
340      * The values of the properties are not inserted directly in the &lt;input&gt; tag,
341      * because there is a display issue when the property values are very long.
342      * This method creates JavaScript to set the property input field values delayed.
343      * On the JSP, the code which is created from this method has to be executed delayed after
344      * the creation of the html form, e.g. in the &lt;body&gt; tag with the attribute
345      * onload="window.setTimeout('doSet()',50);".<p>
346      *
347      * @return the JavaScript to set the property form values delayed
348      */

349     public String JavaDoc buildSetFormValues() {
350
351         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
352         // loop over the default properties
353
for (int i = 0; i < DEFAULT_PROPERTIES.length; i++) {
354             String JavaDoc curProperty = DEFAULT_PROPERTIES[i];
355             // determine the shown value
356
String JavaDoc shownValue = "";
357             try {
358                 shownValue = getCms().readPropertyObject(getParamResource(), curProperty, false).getValue();
359             } catch (CmsException e) {
360                 e.printStackTrace();
361             }
362             if (!CmsStringUtil.isEmpty(shownValue)) {
363                 // create the JS output for a single property if not empty
364
result.append("\tdocument.getElementById(\"");
365                 result.append(PREFIX_VALUE);
366                 result.append(curProperty);
367                 result.append("\").value = \"");
368                 result.append(CmsStringUtil.escapeJavaScript(shownValue));
369                 result.append("\";\n");
370             }
371         }
372
373         return result.toString();
374     }
375
376     /**
377      * Returns the property value by searching all parent folders.<p>
378      *
379      * @param propertydef the property definition
380      *
381      * @return the property value by searching all parent folders
382      */

383     public String JavaDoc getDefault(String JavaDoc propertydef) {
384
385         try {
386             String JavaDoc parentFolder = CmsResource.getParentFolder(getParamResource());
387             CmsProperty property = getCms().readPropertyObject(parentFolder, propertydef, true);
388             String JavaDoc propertyValue = property.getValue();
389             if (!CmsStringUtil.isEmpty(propertyValue)) {
390                 return property.getValue();
391             }
392         } catch (CmsException e) {
393             if (LOG.isErrorEnabled()) {
394                 LOG.error(e);
395             }
396         }
397
398         return "";
399     }
400
401     /**
402      * @see org.opencms.workplace.I_CmsDialogHandler#getDialogHandler()
403      */

404     public String JavaDoc getDialogHandler() {
405
406         return CmsDialogSelector.DIALOG_PROPERTY;
407     }
408
409     /**
410      * @see org.opencms.workplace.I_CmsDialogHandler#getDialogUri(java.lang.String, CmsJspActionElement)
411      */

412     public String JavaDoc getDialogUri(String JavaDoc resource, CmsJspActionElement jsp) {
413
414         try {
415             String JavaDoc templateOneDialog = MODULE_PATH + "dialogs/property.jsp";
416             boolean dialogPresent = jsp.getCmsObject().existsResource(templateOneDialog);
417
418             CmsResource res = jsp.getCmsObject().readResource(resource, CmsResourceFilter.ALL);
419             String JavaDoc template = jsp.getCmsObject().readPropertyObject(res, CmsPropertyDefinition.PROPERTY_TEMPLATE, true).getValue(
420                 "");
421             if (!res.isFolder()
422                 && res.getTypeId() != CmsResourceTypeBinary.getStaticTypeId()
423                 && res.getTypeId() != CmsResourceTypePlain.getStaticTypeId()
424                 && res.getTypeId() != CmsResourceTypeImage.getStaticTypeId()) {
425                 // file is no plain text, binary or image type, check "template" property
426
if (dialogPresent && TEMPLATE_ONE.equals(template)) {
427                     // display special property dialog for files with "template one" as template
428
return templateOneDialog;
429                 } else if (res.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
430                     // show xmlpage property dialog for xmlpages not using "template one" as template
431
return PATH_WORKPLACE + "editors/dialogs/property.jsp";
432                 }
433             }
434             if (dialogPresent
435                 && res.isFolder()
436                 && TEMPLATE_ONE.equals(template)
437                 && !res.getRootPath().startsWith(CmsResource.VFS_FOLDER_SYSTEM)) {
438                 // display special property dialog also for folders but exclude the system folders
439
return templateOneDialog;
440             }
441             String JavaDoc resTypeName = OpenCms.getResourceManager().getResourceType(res.getTypeId()).getTypeName();
442             // get settings for resource type
443
CmsExplorerTypeSettings settings = getSettingsForType(resTypeName);
444             if (settings.isPropertiesEnabled()) {
445                 // special properties for this type enabled, display customized dialog
446
return URI_PROPERTY_CUSTOM_DIALOG;
447             }
448         } catch (CmsException e) {
449             // should usually never happen
450
if (LOG.isErrorEnabled()) {
451                 LOG.error(e);
452             }
453         }
454         return URI_PROPERTY_DIALOG;
455     }
456
457     /**
458      * Performs the editing of the resources properties.<p>
459      *
460      * @param request the HttpServletRequest
461      * @return true, if the properties were successfully changed, otherwise false
462      * @throws CmsException if editing is not successful
463      */

464     protected boolean performEditOperation(HttpServletRequest JavaDoc request) throws CmsException {
465
466         boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue();
467         try {
468             if (useTempfileProject) {
469                 switchToTempProject();
470             }
471             // loop over the default properties
472
for (int i = 0; i < DEFAULT_PROPERTIES.length; i++) {
473                 String JavaDoc curProperty = DEFAULT_PROPERTIES[i];
474                 String JavaDoc paramValue = request.getParameter(PREFIX_VALUE + curProperty);
475                 String JavaDoc oldValue = request.getParameter(PREFIX_HIDDEN + curProperty);
476                 writeProperty(curProperty, paramValue, oldValue);
477             }
478
479             // loop over all properties
480
for (int i = 0; i < ALL_PROPERTIES.length; i++) {
481                 String JavaDoc curProperty = ALL_PROPERTIES[i];
482                 String JavaDoc paramValue = request.getParameter(PREFIX_VALUE + curProperty);
483                 String JavaDoc oldValue = request.getParameter(PREFIX_HIDDEN + curProperty);
484                 writeProperty(curProperty, paramValue, oldValue);
485             }
486
487             // write the navigation properties
488

489             // get the navigation enabled parameter
490
String JavaDoc paramValue = request.getParameter("enablenav");
491             String JavaDoc oldValue = null;
492             if (Boolean.valueOf(paramValue).booleanValue()) {
493                 // navigation enabled, update params
494
paramValue = request.getParameter("navpos");
495                 if (!"-1".equals(paramValue)) {
496                     // update the property only when it is different from "-1" (meaning no change)
497
oldValue = request.getParameter(PREFIX_HIDDEN + CmsPropertyDefinition.PROPERTY_NAVPOS);
498                     writeProperty(CmsPropertyDefinition.PROPERTY_NAVPOS, paramValue, oldValue);
499                 }
500                 paramValue = request.getParameter(PREFIX_VALUE + CmsPropertyDefinition.PROPERTY_NAVTEXT);
501                 oldValue = request.getParameter(PREFIX_HIDDEN + CmsPropertyDefinition.PROPERTY_NAVTEXT);
502                 writeProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT, paramValue, oldValue);
503             } else {
504                 // navigation disabled, delete property values
505
writeProperty(CmsPropertyDefinition.PROPERTY_NAVPOS, null, null);
506                 writeProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT, null, null);
507             }
508         } finally {
509             if (useTempfileProject) {
510                 switchToCurrentProject();
511             }
512         }
513         return true;
514     }
515
516     /**
517      * Builds the html for a single radio input property.<p>
518      *
519      * @param propertyName the name of the property
520      * @param propertyValue the value of the radio
521      * @param propertyText the nice name of the property
522      * @param JSToggleFunction the javascript toggle function or null
523      * @param editable indicates if the properties are editable
524      *
525      * @return the html for a single radio input property
526      */

527     private StringBuffer JavaDoc buildPropertyRadioEntry(
528         String JavaDoc propertyName,
529         String JavaDoc propertyValue,
530         String JavaDoc propertyText,
531         String JavaDoc JSToggleFunction,
532         boolean editable) {
533
534         String JavaDoc disabled = "";
535         if (!editable) {
536             disabled = " disabled=\"disabled\"";
537         }
538         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
539         // create "disabled" attribute if properties are not editable
540
// to do
541
String JavaDoc checked = "";
542         if (getActiveProperties().containsKey(propertyName)) {
543             // the property is used, so create text field with checkbox and hidden field
544
CmsProperty currentProperty = (CmsProperty)getActiveProperties().get(propertyName);
545
546             String JavaDoc propValue = currentProperty.getValue();
547             if (propValue != null) {
548                 propValue = propValue.trim();
549             }
550             propValue = CmsEncoder.escapeXml(propValue);
551             if (propertyValue.equals(propValue)) {
552                 checked = " checked=\"checked\"";
553             }
554         } else {
555             // check radio if param value is the default
556
if (propertyValue.equals(PARAM_DEFAULT)) {
557                 checked = " checked=\"checked\"";
558             }
559         }
560         // javascript onclick event
561
String JavaDoc onclick = "";
562         if (JSToggleFunction != null) {
563             onclick = "onclick=\"" + JSToggleFunction + "();\" ";
564         }
565         result.append("<input ");
566         result.append(onclick);
567         result.append("type=\"radio\" ");
568         result.append("name=\"");
569         result.append(PREFIX_VALUE);
570         result.append(propertyName);
571         result.append("\" value=\"");
572         result.append(propertyValue);
573         result.append("\"");
574         result.append(checked);
575         result.append(disabled);
576         result.append(">");
577         result.append("&nbsp;");
578         result.append(propertyText);
579
580         return result;
581     }
582
583     /**
584      * Builds the html for a single search text input property row.<p>
585      *
586      * @param propertyName the name of the property
587      * @param propertyTitle the nice name of the property
588      * @param editable indicates if the properties are editable
589      * @param messages the messages to use for localization
590      *
591      * @return the html for a single text input property row
592      */

593     private StringBuffer JavaDoc buildPropertySearchEntry(
594         String JavaDoc propertyName,
595         String JavaDoc propertyTitle,
596         boolean editable,
597         CmsMessages messages) {
598
599         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
600         result.append(buildTableRowStart(key(propertyTitle)));
601         String JavaDoc disabled = "";
602         if (!editable) {
603             disabled = " disabled=\"disabled\"";
604         }
605         String JavaDoc propValue = "";
606         // the property is used, so create text field with checkbox and hidden field
607
CmsProperty currentProperty = (CmsProperty)getActiveProperties().get(propertyName);
608         if (currentProperty != null) {
609             propValue = currentProperty.getValue();
610             if (CmsStringUtil.isEmpty(propValue)) {
611                 if (CmsTemplateBean.PROPERTY_HEAD_IMGURI.equals(propertyName)
612                     || CmsTemplateBean.PROPERTY_HEAD_IMGLINK.equals(propertyName)) {
613                     String JavaDoc tmp = getDefault(propertyName);
614                     if (!CmsStringUtil.isEmpty(tmp)) {
615                         propValue = tmp;
616                     }
617                 }
618             } else {
619                 propValue = propValue.trim();
620             }
621         }
622
623         propValue = CmsEncoder.escapeXml(propValue);
624         result.append("<input type=\"text\" style=\"width: 99%\" class=\"maxwidth\" ");
625         result.append("name=\"");
626         result.append(PREFIX_VALUE);
627         result.append(propertyName);
628         result.append("\" id=\"");
629         result.append(PREFIX_VALUE);
630         result.append(propertyName);
631         result.append("\" value=\"");
632         result.append(propValue);
633         result.append("\"");
634         result.append(disabled);
635         result.append(">");
636         result.append("<input type=\"hidden\" name=\"");
637         result.append(PREFIX_HIDDEN);
638         result.append(propertyName);
639         result.append("\" id=\"");
640         result.append(PREFIX_HIDDEN);
641         result.append(propertyName);
642         result.append("\" value=\"");
643         result.append(propValue);
644         result.append("\">");
645         result.append("</td>\n");
646         result.append("<td>");
647         result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
648         result.append("\t<tr>\n");
649         result.append("<td>&nbsp;&nbsp;</td>");
650         result.append("<td><a HREF=\"#\" onclick=\"javascript:top.openTreeWin('copy', true, 'main', '");
651         result.append(PREFIX_VALUE);
652         result.append(propertyName);
653         result.append("', document);\" class=\"button\" title=\"");
654         result.append(messages.key(Messages.GUI_BUTTON_SEARCH_0));
655         result.append("\"><img class=\"button\" SRC=\"");
656         result.append(getSkinUri());
657         result.append("/buttons/folder.png\" border=\"0\"></a></td>");
658         result.append("</tr>\n");
659         result.append("</table>\n");
660         result.append("</td>\n");
661         result.append("</tr>");
662
663         return result;
664     }
665
666     /**
667      * Builds the html for a single selectbox property row to select the list layout.<p>
668      *
669      * @param listType determines the content list type, "center" or "right"
670      * @param propertyName the name of the property
671      * @param propertyTitle the nice name of the property
672      * @param editable indicates if the properties are editable
673      *
674      * @return the html for a single text input property row
675      */

676     private StringBuffer JavaDoc buildPropertySelectbox(
677         String JavaDoc listType,
678         String JavaDoc propertyName,
679         String JavaDoc propertyTitle,
680         boolean editable) {
681
682         StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
683         result.append(buildTableRowStart(key(propertyTitle)));
684         String JavaDoc disabled = "";
685         if (!editable) {
686             disabled = " disabled=\"disabled\"";
687         }
688         String JavaDoc propValue = "";
689         // get property object from active properties
690
CmsProperty currentProperty = (CmsProperty)getActiveProperties().get(propertyName);
691         String JavaDoc inheritedValue = "";
692         if (currentProperty != null) {
693             // property value is directly set on resource
694
propValue = currentProperty.getValue();
695             inheritedValue = getDefault(propertyName);
696         } else {
697             // property is not set on resource
698
propValue = getDefault(propertyName);
699             if (CmsStringUtil.isEmptyOrWhitespaceOnly(propValue)) {
700                 propValue = "";
701             }
702             inheritedValue = propValue;
703         }
704
705         List JavaDoc resources = getConfigurationFiles(listType);
706         List JavaDoc options = new ArrayList JavaDoc(resources.size() + 1);
707         List JavaDoc values = new ArrayList JavaDoc(resources.size() + 1);
708         int selectedIndex = 0;
709
710         // add the "none" option manually to selectbox
711
options.add(key(KEY_PREFIX + "nolayout"));
712         if ("".equals(propValue)
713             || ("".equals(inheritedValue))
714             || (CmsTemplateBean.PROPERTY_VALUE_NONE.equals(inheritedValue))) {
715             // value is not set anywhere or is inherited from ancestor folder
716
values.add("");
717         } else {
718             values.add(CmsTemplateBean.PROPERTY_VALUE_NONE);
719         }
720
721         for (int i = 0; i < resources.size(); i++) {
722             // loop all found resources defining the layout
723
CmsResource res = (CmsResource)resources.get(i);
724             String JavaDoc path = getCms().getSitePath(res);
725             // determine description to show for layout
726
String JavaDoc description = "";
727             try {
728                 description = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false).getValue(
729                     null);
730                 if (CmsStringUtil.isEmpty(description)) {
731                     description = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue(
732                         path);
733                 }
734             } catch (CmsException e) {
735                 // should never happen
736
if (LOG.isErrorEnabled()) {
737                     LOG.error(e);
738                 }
739             }
740             // try to find a localized key for the description property value
741
String JavaDoc localized = key(description);
742             if (localized.startsWith(CmsMessages.UNKNOWN_KEY_EXTENSION)) {
743                 localized = description;
744             }
745             options.add(localized);
746             // check if this item is selected
747
if (path.equals(propValue)) {
748                 selectedIndex = i + 1;
749             }
750             // determine value to add
751
if (path.equals(inheritedValue)) {
752                 // the current path is like inherited path, so do not write property in this case
753
path = "";
754             }
755             values.add(path);
756         }
757         // create select tag attributes
758
StringBuffer JavaDoc attrs = new StringBuffer JavaDoc(4);
759         attrs.append("name=\"").append(PREFIX_VALUE).append(propertyName).append("\"");
760         attrs.append(" class=\"maxwidth\"");
761         attrs.append(disabled);
762         // create the select box
763
result.append(buildSelect(attrs.toString(), options, values, selectedIndex));
764
765         // build the hidden field with old property value
766
result.append("<input type=\"hidden\" name=\"");
767         result.append(PREFIX_HIDDEN);
768         result.append(propertyName);
769         result.append("\" id=\"");
770         result.append(PREFIX_HIDDEN);
771         result.append(propertyName);
772         result.append("\" value=\"");
773         result.append(propValue);
774         result.append("\">");
775         result.append("</td>\n");
776         result.append("</tr>");
777
778         return result;
779     }
780
781     /**
782      * Builds the HTML for a complete Row with three radio Buttons.<p>
783      *
784      * The propertyName will be translated in workplace.properties
785      *
786      * Schema:
787      * Radio 1: Default (embedded)
788      * Radio 2: Individual or Enable (depends on parameter mode)
789      * Radio 3: Disable (embedded)
790      *
791      * @param propertyName the name of the current property
792      * @param mode the switch mode for the nice name
793      * @param JSToggleFunction the javascript function for onclick handling
794      * @param editable indicates if the properties are editable
795      *
796      * @return the HTML for the row with three radio buttons
797      */

798     private StringBuffer JavaDoc buildRadioButtons(String JavaDoc propertyName, String JavaDoc mode, String JavaDoc JSToggleFunction, boolean editable) {
799
800         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
801         // propertyName will be translated in workplace.properties
802
result.append(buildTableRowStart(key(KEY_PREFIX + propertyName), 2));
803         result.append("\t<table border=\"0\">\n");
804         result.append("\t<tr>\n");
805         result.append("\t<td>\n");
806         result.append(buildPropertyRadioEntry(
807             propertyName,
808             PARAM_DEFAULT,
809             key(KEY_PREFIX + "radio.default"),
810             JSToggleFunction,
811             editable));
812         result.append("</td>\n");
813         result.append("\t<td>\n");
814         result.append(buildPropertyRadioEntry(
815             propertyName,
816             PARAM_TRUE,
817             key(KEY_PREFIX + "radio." + mode),
818             JSToggleFunction,
819             editable));
820         result.append("</td>\n");
821         result.append("\t<td>\n");
822         result.append(buildPropertyRadioEntry(
823             propertyName,
824             PARAM_FALSE,
825             key(KEY_PREFIX + "radio.disable"),
826             JSToggleFunction,
827             editable));
828         result.append("</td>\n");
829         result.append("</tr>\n");
830         result.append("</table>\n");
831         result.append(buildTableRowEnd());
832
833         return result;
834     }
835
836     /**
837      * Builds the HTML for the start of a table row for a single property with colspan.<p>
838      *
839      * Use this e.g. when the checkbox on the right side is not needed
840      *
841      * @param propertyName the name of the current property
842      * @param colspan the number of colspans
843      * @return the HTML code for the start of a table row
844      */

845     private StringBuffer JavaDoc buildTableRowStart(String JavaDoc propertyName, int colspan) {
846
847         StringBuffer JavaDoc result = new StringBuffer JavaDoc(96);
848         result.append("<tr>\n");
849         result.append("\t<td style=\"white-space: nowrap;\" unselectable=\"on\">");
850         result.append(propertyName);
851         result.append("</td>\n");
852         result.append("\t<td class=\"maxwidth\" colspan=\"");
853         result.append(String.valueOf(colspan));
854         result.append("\">");
855
856         return result;
857     }
858
859     /**
860      * Returns the layout configuration files for the specified list type.<p>
861      *
862      * @param listType the type of the layout list, "center" or "right"
863      * @return the layout configuration files for the specified list type
864      */

865     private List JavaDoc getConfigurationFiles(String JavaDoc listType) {
866
867         List JavaDoc result = new ArrayList JavaDoc();
868         String JavaDoc configFolder;
869         if (listType.equals(CmsTemplateContentListItem.DISPLAYAREA_CENTER)) {
870             configFolder = VFS_PATH_CONFIGFILES_CENTER;
871         } else {
872             configFolder = VFS_PATH_CONFIGFILES_RIGHT;
873         }
874         try {
875             // first get the default layout files for the list type
876
result = getCms().readResources(configFolder, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
877
878             // add eventual individual layout files for the list type in the microsite
879
String JavaDoc configPath = getCms().readPropertyObject(
880                 getParamResource(),
881                 CmsTemplateBean.PROPERTY_CONFIGPATH,
882                 true).getValue();
883             if (CmsStringUtil.isNotEmpty(configPath)) {
884                 int type = OpenCms.getResourceManager().getResourceType(CmsLayoutXmlContentHandler.CONFIG_RESTYPE_NAME).getTypeId();
885                 CmsResourceFilter filter = CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(type);
886                 Iterator JavaDoc i = getCms().readResources(configPath, filter, false).iterator();
887                 while (i.hasNext()) {
888                     CmsResource res = (CmsResource)i.next();
889                     // read column property
890
String JavaDoc column = getCms().readPropertyObject(
891                         getCms().getSitePath(res),
892                         CmsLayoutXmlContentHandler.PROPERTY_LAYOUT_COLUMN,
893                         false).getValue();
894                     if (listType.equals(column)) {
895                         // add resource to list
896
result.add(res);
897                     }
898                 }
899             }
900         } catch (CmsException e) {
901             // error reading resources
902
if (LOG.isErrorEnabled()) {
903                 LOG.error(e);
904             }
905         }
906         return result;
907     }
908 }
Popular Tags