KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > commons > CmsPropertyCustom


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsPropertyCustom.java,v $
3  * Date : $Date: 2006/03/27 14:52:18 $
4  * Version: $Revision: 1.22 $
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.workplace.commons;
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.i18n.CmsEncoder;
39 import org.opencms.jsp.CmsJspActionElement;
40 import org.opencms.main.CmsException;
41 import org.opencms.main.CmsLog;
42 import org.opencms.main.OpenCms;
43 import org.opencms.util.CmsStringUtil;
44 import org.opencms.workplace.CmsWorkplace;
45 import org.opencms.workplace.CmsWorkplaceSettings;
46 import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
47
48 import java.util.HashMap JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.Map JavaDoc;
51
52 import javax.servlet.http.HttpServletRequest JavaDoc;
53 import javax.servlet.http.HttpServletResponse JavaDoc;
54 import javax.servlet.jsp.JspException JavaDoc;
55 import javax.servlet.jsp.PageContext JavaDoc;
56
57 import org.apache.commons.logging.Log;
58
59 /**
60  * Provides methods for the customized property dialog.<p>
61  *
62  * This is a special dialog that is used for the different resource types in the workplace.<p>
63  * For the xmlpage resource type, this class is extended in the editor subpackage.<p>
64  *
65  * The following files use this class:
66  * <ul>
67  * <li>/commons/property_custom.jsp
68  * </ul>
69  * <p>
70  *
71  * @author Andreas Zahner
72  *
73  * @version $Revision: 1.22 $
74  *
75  * @since 6.0.0
76  */

77 public class CmsPropertyCustom extends CmsPropertyAdvanced {
78
79     /** Value for the action: edit the properties. */
80     public static final int ACTION_EDIT = 500;
81
82     /** The log object for this class. */
83     private static final Log LOG = CmsLog.getLog(CmsPropertyCustom.class);
84
85     /** Holds all active properties for the current resource. */
86     private Map JavaDoc m_activeProperties;
87
88     /** Helper object holding the information about the customized properties. */
89     private CmsExplorerTypeSettings m_explorerTypeSettings;
90
91     /** Flag to determine if navigation properties are shown. */
92     private boolean m_showNavigation;
93
94     /**
95      * Public constructor with JSP action element.<p>
96      *
97      * @param jsp an initialized JSP action element
98      */

99     public CmsPropertyCustom(CmsJspActionElement jsp) {
100
101         super(jsp);
102     }
103
104     /**
105      * Public constructor with JSP variables.<p>
106      *
107      * @param context the JSP page context
108      * @param req the JSP request
109      * @param res the JSP response
110      */

111     public CmsPropertyCustom(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
112
113         this(new CmsJspActionElement(context, req, res));
114     }
115
116     /**
117      * Performs the edit properties action, will be called by the JSP page.<p>
118      *
119      * @param request the HttpServletRequest
120      * @throws JspException if problems including sub-elements occur
121      */

122     public void actionEdit(HttpServletRequest JavaDoc request) throws JspException JavaDoc {
123
124         // save initialized instance of this class in request attribute for included sub-elements
125
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
126         try {
127             // save the changes only if resource is properly locked
128
if (isEditable()) {
129                 performEditOperation(request);
130             }
131         } catch (Throwable JavaDoc e) {
132             // Cms error defining property, show error dialog
133
includeErrorpage(this, e);
134         }
135     }
136
137     /**
138      * Creates the HTML String for the edit properties form.<p>
139      *
140      * @return the HTML output String for the edit properties form
141      */

142     public String JavaDoc buildEditForm() {
143
144         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
145
146         // check if the properties are editable
147
boolean editable = isEditable();
148
149         // create the column heads
150
result.append("<table border=\"0\">\n");
151         result.append("<tr>\n");
152         result.append("\t<td class=\"textbold\">");
153         result.append(key(Messages.GUI_PROPERTY_0));
154         result.append("</td>\n");
155         result.append("\t<td class=\"textbold\">");
156         result.append(key(Messages.GUI_PROPERTY_VALUE_0));
157         result.append("</td>\n");
158         result.append("\t<td class=\"textbold\" style=\"white-space: nowrap;\">");
159         result.append(key(Messages.GUI_PROPERTY_USED_0));
160         result.append("</td>\n");
161         result.append("</tr>\n");
162         result.append("<tr><td><span style=\"height: 6px;\"></span></td></tr>\n");
163
164         // create the text property input rows from explorer type settings
165
result.append(buildTextInput(editable));
166
167         // show navigation properties if enabled in explorer type settings
168
if (showNavigation()) {
169             result.append(buildNavigationProperties(editable));
170         }
171         result.append("</table>");
172
173         return result.toString();
174     }
175
176     /**
177      * Builds the JavaScript to set the property form values delayed.<p>
178      *
179      * The values of the properties are not inserted directly in the &lt;input&gt; tag,
180      * because there is a display issue when the property values are very long.
181      * This method creates JavaScript to set the property input field values delayed.
182      * On the JSP, the code which is created from this method has to be executed delayed after
183      * the creation of the html form, e.g. in the &lt;body&gt; tag with the attribute
184      * onload="window.setTimeout('doSet()',50);".<p>
185      *
186      * @return the JavaScript to set the property form values delayed
187      */

188     public String JavaDoc buildSetFormValues() {
189
190         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
191         Iterator JavaDoc i = getExplorerTypeSettings().getProperties().iterator();
192         // iterate over the customized properties
193
while (i.hasNext()) {
194             String JavaDoc curProperty = (String JavaDoc)i.next();
195             if (getActiveProperties().containsKey(curProperty)) {
196                 CmsProperty property = (CmsProperty)getActiveProperties().get(curProperty);
197                 String JavaDoc propValue = property.getValue();
198                 if (propValue != null) {
199                     propValue = propValue.trim();
200                     propValue = CmsStringUtil.escapeJavaScript(propValue);
201                     // create the JS output for a single property
202
result.append("\tdocument.getElementById(\"");
203                     result.append(PREFIX_VALUE);
204                     result.append(curProperty);
205                     result.append("\").value = \"");
206                     result.append(propValue);
207                     result.append("\";\n");
208                 }
209             }
210         }
211         // check if the navigation text property value has to be added
212
if (showNavigation() && getActiveProperties().containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT)) {
213             CmsProperty property = (CmsProperty)getActiveProperties().get(CmsPropertyDefinition.PROPERTY_NAVTEXT);
214             String JavaDoc propValue = property.getValue();
215             if (propValue != null) {
216                 propValue = propValue.trim();
217                 propValue = CmsStringUtil.escapeJavaScript(propValue);
218                 // create the JS output for a single property
219
result.append("\tdocument.getElementById(\"");
220                 result.append(PREFIX_VALUE);
221                 result.append(CmsPropertyDefinition.PROPERTY_NAVTEXT);
222                 result.append("\").value = \"");
223                 result.append(propValue);
224                 result.append("\";\n");
225             }
226         }
227         return result.toString();
228     }
229
230     /**
231      * Builds a button row with an "ok", a "cancel" and an "advanced" button.<p>
232      *
233      * @param okAttributes additional attributes for the "ok" button
234      * @param cancelAttributes additional attributes for the "cancel" button
235      * @param advancedAttributes additional attributes for the "advanced" button
236      * @return the button row
237      */

238     public String JavaDoc dialogButtonsOkCancelAdvanced(String JavaDoc okAttributes, String JavaDoc cancelAttributes, String JavaDoc advancedAttributes) {
239
240         if (isEditable()) {
241             int okButton = BUTTON_OK;
242             if (getParamDialogmode() != null && getParamDialogmode().startsWith(MODE_WIZARD)) {
243                 // in wizard mode, display finish button instead of ok button
244
okButton = BUTTON_FINISH;
245             }
246             return dialogButtons(new int[] {okButton, BUTTON_CANCEL, BUTTON_ADVANCED}, new String JavaDoc[] {
247                 okAttributes,
248                 cancelAttributes,
249                 advancedAttributes});
250         } else {
251             return dialogButtons(new int[] {BUTTON_CLOSE, BUTTON_ADVANCED}, new String JavaDoc[] {
252                 cancelAttributes,
253                 advancedAttributes});
254         }
255     }
256
257     /**
258      * Returns the explorer type settings for the current resource type.<p>
259      *
260      * @return the explorer type settings for the current resource type
261      */

262     public CmsExplorerTypeSettings getExplorerTypeSettings() {
263
264         return m_explorerTypeSettings;
265     }
266
267     /**
268      * Sets the explorer type settings for the current resource type.<p>
269      *
270      * @param typeSettings the explorer type settings for the current resource type
271      */

272     public void setExplorerTypeSettings(CmsExplorerTypeSettings typeSettings) {
273
274         m_explorerTypeSettings = typeSettings;
275     }
276
277     /**
278      * Sets if navigation properties are shown.<p>
279      *
280      * @param showNav true, if navigation properties are shown, otherwise false
281      */

282     public void setShowNavigation(boolean showNav) {
283
284         m_showNavigation = showNav;
285     }
286
287     /**
288      * Returns if navigation properties are shown.<p>
289      *
290      * @return true, if navigation properties are shown, otherwise false
291      */

292     public boolean showNavigation() {
293
294         return m_showNavigation;
295     }
296
297     /**
298      * Builds the HTML code for the special properties of an xmlpage resource.<p>
299      *
300      * @param editable indicates if the properties are editable
301      * @return the HTML code for the special properties of a file resource
302      */

303     protected StringBuffer JavaDoc buildNavigationProperties(boolean editable) {
304
305         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
306
307         // create "disabled" attribute if properties are not editable
308
String JavaDoc disabled = "";
309         if (!editable) {
310             disabled = " disabled=\"disabled\"";
311         }
312
313         // create "add to navigation" checkbox
314
result.append(buildTableRowStart(key(Messages.GUI_PROPERTY_ADD_TO_NAV_0)));
315         result.append("<input type=\"checkbox\" name=\"enablenav\" id=\"enablenav\" value=\"true\" onClick=\"toggleNav();\"");
316         if (getActiveProperties().containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT)
317             || getActiveProperties().containsKey(CmsPropertyDefinition.PROPERTY_NAVPOS)) {
318             result.append(" checked=\"checked\"");
319         }
320         result.append(disabled);
321         result.append(">");
322         result.append("</td>\n");
323         result.append("\t<td class=\"textcenter\">");
324         result.append("&nbsp;");
325         result.append(buildTableRowEnd());
326
327         // create NavText input row
328
result.append(buildPropertyEntry(CmsPropertyDefinition.PROPERTY_NAVTEXT, key(Messages.GUI_LABEL_NAVTEXT_0), editable));
329
330         // create NavPos select box row
331
result.append(buildTableRowStart(key(Messages.GUI_CHNAV_INSERT_AFTER_0)));
332         result.append(CmsChnav.buildNavPosSelector(getCms(), getParamResource(), disabled
333             + " id=\"navpos\" class=\"maxwidth noborder\"", getMessages()));
334         // get the old NavPos value and store it in hidden field
335
String JavaDoc navPos = null;
336         try {
337             navPos = getCms().readPropertyObject(getParamResource(), CmsPropertyDefinition.PROPERTY_NAVPOS, false).getValue();
338         } catch (CmsException e) {
339             // should usually never happen
340
if (LOG.isInfoEnabled()) {
341                 LOG.info(e.getLocalizedMessage());
342             }
343         }
344         if (navPos == null) {
345             navPos = "";
346         }
347         result.append("<input type=\"hidden\" name=\"");
348         result.append(PREFIX_HIDDEN);
349         result.append(CmsPropertyDefinition.PROPERTY_NAVPOS);
350         result.append("\" value=\"");
351         result.append(navPos);
352         result.append("\">");
353         result.append("</td>\n");
354         result.append("\t<td class=\"textcenter\">");
355         result.append("&nbsp;");
356         result.append(buildTableRowEnd());
357
358         return result;
359     }
360
361     /**
362      * Builds the html for a single text input property row.<p>
363      *
364      * The html does not include the value of the created property,
365      * the values are set delayed (see buildSetFormValues() for details).<p>
366      *
367      * @param propertyName the name of the property
368      * @param propertyTitle the nice name of the property
369      * @param editable indicates if the properties are editable
370      * @return the html for a single text input property row
371      */

372     protected StringBuffer JavaDoc buildPropertyEntry(String JavaDoc propertyName, String JavaDoc propertyTitle, boolean editable) {
373
374         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
375         // create "disabled" attribute if properties are not editable
376
String JavaDoc disabled = "";
377         if (!editable) {
378             disabled = " disabled=\"disabled\"";
379         }
380         result.append(buildTableRowStart(propertyTitle));
381         if (getActiveProperties().containsKey(propertyName)) {
382             // the property is used, so create text field with checkbox and hidden field
383
CmsProperty currentProperty = (CmsProperty)getActiveProperties().get(propertyName);
384             String JavaDoc propValue = currentProperty.getValue();
385             if (propValue != null) {
386                 propValue = propValue.trim();
387             }
388             propValue = CmsEncoder.escapeXml(propValue);
389             
390             // create text input field
391
result.append("<input type=\"text\" class=\"maxwidth\"");
392             result.append(" name=\"");
393             result.append(PREFIX_VALUE);
394             result.append(propertyName);
395             result.append("\" id=\"");
396             result.append(PREFIX_VALUE);
397             result.append(propertyName);
398             result.append("\"");
399             if (editable) {
400                 result.append(" onKeyup=\"checkValue('");
401                 result.append(propertyName);
402                 result.append("');\"");
403             }
404             result.append(disabled);
405             result.append(">");
406             
407             // create hidden field for value
408
result.append("<input type=\"hidden\" name=\"");
409             result.append(PREFIX_HIDDEN);
410             result.append(propertyName);
411             result.append("\" id=\"");
412             result.append(PREFIX_HIDDEN);
413             result.append(propertyName);
414             result.append("\" value=\"");
415             result.append(propValue);
416             result.append("\">");
417             result.append("</td>\n");
418             result.append("\t<td class=\"textcenter\">");
419             
420             // create activate/deactivate checkbox
421
result.append("<input type=\"checkbox\" name=\"");
422             result.append(PREFIX_USEPROPERTY);
423             result.append(propertyName);
424             result.append("\" id=\"");
425             result.append(PREFIX_USEPROPERTY);
426             result.append(propertyName);
427             result.append("\" value=\"true\"");
428             result.append(" checked=\"checked\"");
429             if (editable) {
430                 result.append(" onClick=\"toggleDelete('");
431                 result.append(propertyName);
432                 result.append("');\"");
433             }
434             result.append(disabled + ">");
435         } else {
436             // property is not used, create an empty text input field
437
result.append("<input type=\"text\" class=\"maxwidth\" ");
438             result.append("name=\"");
439             result.append(PREFIX_VALUE);
440             result.append(propertyName);
441             result.append("\" id=\"");
442             result.append(PREFIX_VALUE);
443             result.append(propertyName);
444             result.append("\"");
445             result.append(disabled);
446             result.append("></td>\n");
447             result.append("\t<td class=\"textcenter\">&nbsp;");
448         }
449         result.append(buildTableRowEnd());
450         return result;
451     }
452
453     /**
454      * Builds the HTML for the end of a table row for a single property.<p>
455      *
456      * @return the HTML code for a table row end
457      */

458     protected String JavaDoc buildTableRowEnd() {
459
460         return "</td>\n</tr>\n";
461     }
462
463     /**
464      * Builds the HTML for the start of a table row for a single property.<p>
465      *
466      * @param propertyName the name of the current property
467      * @return the HTML code for the start of a table row
468      */

469     protected StringBuffer JavaDoc buildTableRowStart(String JavaDoc propertyName) {
470
471         StringBuffer JavaDoc result = new StringBuffer JavaDoc(96);
472         result.append("<tr>\n");
473         result.append("\t<td style=\"white-space: nowrap;\" unselectable=\"on\">");
474         result.append(propertyName);
475         result.append("</td>\n");
476         result.append("\t<td class=\"maxwidth\">");
477         return result;
478     }
479
480     /**
481      * Builds the HTML for the common text input property values stored in the String array "PROPERTIES".<p>
482      *
483      * @param editable indicates if the properties are editable
484      * @return the HTML code for the common text input fields
485      */

486     protected StringBuffer JavaDoc buildTextInput(boolean editable) {
487
488         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
489         Iterator JavaDoc i = getExplorerTypeSettings().getProperties().iterator();
490         // iterate over the properties
491
while (i.hasNext()) {
492             String JavaDoc curProperty = (String JavaDoc)i.next();
493             result.append(buildPropertyEntry(curProperty, curProperty, editable));
494         }
495         return result;
496     }
497
498     /**
499      * Returns a map with CmsProperty object values keyed by property keys.<p>
500      *
501      * @return a map with CmsProperty object values
502      */

503     protected Map JavaDoc getActiveProperties() {
504
505         // get all used properties for the resource
506
if (m_activeProperties == null) {
507             try {
508                 m_activeProperties = CmsPropertyAdvanced.getPropertyMap(getCms().readPropertyObjects(
509                     getParamResource(),
510                     false));
511             } catch (CmsException e) {
512                 // create an empty list
513
if (LOG.isInfoEnabled()) {
514                     LOG.info(e.getLocalizedMessage());
515                 }
516                 m_activeProperties = new HashMap JavaDoc();
517             }
518         }
519         return m_activeProperties;
520     }
521
522     /**
523      * Initializes the explorer type settings for the current resource type.<p>
524      */

525     protected void initExplorerTypeSettings() {
526
527         try {
528             CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
529             String JavaDoc resTypeName = OpenCms.getResourceManager().getResourceType(res.getTypeId()).getTypeName();
530             // get settings for resource type
531
setExplorerTypeSettings(getSettingsForType(resTypeName));
532             setShowNavigation(getExplorerTypeSettings().isShowNavigation());
533         } catch (Throwable JavaDoc e) {
534             // error reading file, show error dialog
535
try {
536                 includeErrorpage(this, e);
537             } catch (JspException JavaDoc exc) {
538                 LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_INCLUDE_FAILED_1, FILE_DIALOG_SCREEN_ERRORPAGE));
539             }
540         }
541     }
542
543     /**
544      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
545      */

546     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
547
548         // fill the parameter values in the get/set methods
549
fillParamValues(request);
550         // get the explorer type settings for the current resource
551
initExplorerTypeSettings();
552         // set the dialog type
553
setParamDialogtype(DIALOG_TYPE);
554         boolean isPopup = Boolean.valueOf(getParamIsPopup()).booleanValue();
555         // set the action for the JSP switch
556
if (DIALOG_SHOW_DEFAULT.equals(getParamAction())) {
557             // save changed properties and redirect to the default OpenCms dialog
558
setAction(ACTION_DEFAULT);
559             try {
560                 actionEdit(request);
561                 sendForward(CmsPropertyAdvanced.URI_PROPERTY_DIALOG, paramsAsParameterMap());
562             } catch (Exception JavaDoc e) {
563                 // should usually never happen
564
if (LOG.isInfoEnabled()) {
565                     LOG.info(e.getLocalizedMessage());
566                 }
567             }
568         } else if (DIALOG_SAVE_EDIT.equals(getParamAction())) {
569             // save the edited properties
570
if (isPopup) {
571                 setAction(ACTION_CLOSEPOPUP_SAVE);
572             } else {
573                 setAction(ACTION_SAVE_EDIT);
574             }
575         } else if (DIALOG_CANCEL.equals(getParamAction())) {
576             // save the edited properties
577
if (isPopup) {
578                 setAction(ACTION_CLOSEPOPUP);
579             } else {
580                 setAction(ACTION_CANCEL);
581             }
582         } else {
583             setAction(ACTION_EDIT);
584             String JavaDoc resName = CmsResource.getName(getParamResource());
585             if (resName.startsWith(CmsWorkplace.TEMP_FILE_PREFIX)) {
586                 resName = resName.substring(1);
587             }
588             setParamTitle(key(Messages.GUI_PROPERTIES_1, new Object JavaDoc[] {resName}));
589         }
590     }
591
592     /**
593      * Performs the editing of the resources properties.<p>
594      *
595      * @param request the HttpServletRequest
596      * @return true, if the properties were successfully changed, otherwise false
597      * @throws CmsException if editing is not successful
598      */

599     protected boolean performEditOperation(HttpServletRequest JavaDoc request) throws CmsException {
600
601         boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue();
602         try {
603             if (useTempfileProject) {
604                 switchToTempProject();
605             }
606             // write the common properties defined in the explorer type settings
607
Iterator JavaDoc i = getExplorerTypeSettings().getProperties().iterator();
608             // iterate over the properties
609
while (i.hasNext()) {
610                 String JavaDoc curProperty = (String JavaDoc)i.next();
611                 String JavaDoc paramValue = request.getParameter(PREFIX_VALUE + curProperty);
612                 String JavaDoc oldValue = request.getParameter(PREFIX_HIDDEN + curProperty);
613                 writeProperty(curProperty, paramValue, oldValue);
614             }
615
616             // write the navigation properties if enabled
617
if (showNavigation()) {
618                 // get the navigation enabled parameter
619
String JavaDoc paramValue = request.getParameter("enablenav");
620                 String JavaDoc oldValue = null;
621                 if (Boolean.valueOf(paramValue).booleanValue()) {
622                     // navigation enabled, update params
623
paramValue = request.getParameter("navpos");
624                     if (!"-1".equals(paramValue) && !String.valueOf(Float.MAX_VALUE).equals(paramValue)) {
625                         // update the property only when it is different from "-1" (meaning no change)
626
oldValue = request.getParameter(PREFIX_HIDDEN + CmsPropertyDefinition.PROPERTY_NAVPOS);
627                         writeProperty(CmsPropertyDefinition.PROPERTY_NAVPOS, paramValue, oldValue);
628                     }
629                     paramValue = request.getParameter(PREFIX_VALUE + CmsPropertyDefinition.PROPERTY_NAVTEXT);
630                     oldValue = request.getParameter(PREFIX_HIDDEN + CmsPropertyDefinition.PROPERTY_NAVTEXT);
631                     writeProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT, paramValue, oldValue);
632                 } else {
633                     // navigation disabled, delete property values
634
writeProperty(CmsPropertyDefinition.PROPERTY_NAVPOS, null, null);
635                     writeProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT, null, null);
636                 }
637             }
638         } finally {
639             if (useTempfileProject) {
640                 switchToCurrentProject();
641             }
642         }
643         return true;
644     }
645
646     /**
647      * Writes a property value for a resource, if the value was changed.<p>
648      *
649      * If a property definition for the resource does not exist,
650      * it is automatically created by this method.<p>
651      *
652      * @param propName the name of the property
653      * @param propValue the new value of the property
654      * @param oldValue the old value of the property
655      * @throws CmsException if something goes wrong
656      */

657     protected void writeProperty(String JavaDoc propName, String JavaDoc propValue, String JavaDoc oldValue) throws CmsException {
658
659         // get the current property object
660
CmsProperty currentProperty = (CmsProperty)getActiveProperties().get(propName);
661         if (currentProperty == null) {
662             // new property, create new property object
663
currentProperty = new CmsProperty();
664             currentProperty.setName(propName);
665         } else {
666             // clone the property, because the original property is frozen
667
currentProperty = currentProperty.cloneAsProperty();
668         }
669
670         // check if there is a parameter value for the current property
671
boolean emptyParam = true;
672         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(propValue)) {
673             emptyParam = false;
674         }
675
676         if (emptyParam) {
677             // parameter is empty, check if the property has to be deleted
678
if (getActiveProperties().containsKey(propName)) {
679                 // lock resource if autolock is enabled
680
checkLock(getParamResource());
681                 // determine the value to delete
682
if (currentProperty.getStructureValue() != null) {
683                     currentProperty.setStructureValue(CmsProperty.DELETE_VALUE);
684                     currentProperty.setResourceValue(null);
685                 } else {
686                     currentProperty.setResourceValue(CmsProperty.DELETE_VALUE);
687                     currentProperty.setStructureValue(null);
688                 }
689                 // write the updated property object
690
getCms().writePropertyObject(getParamResource(), currentProperty);
691             }
692         } else {
693             // parameter is not empty, check if the value has changed
694
if (!propValue.equals(oldValue)) {
695                 // lock resource if autolock is enabled
696
checkLock(getParamResource());
697                 if (currentProperty.getStructureValue() == null && currentProperty.getResourceValue() == null) {
698                     // new property, determine setting from OpenCms workplace configuration
699
if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
700                         currentProperty.setStructureValue(propValue);
701                         currentProperty.setResourceValue(null);
702                     } else {
703                         currentProperty.setResourceValue(propValue);
704                         currentProperty.setStructureValue(null);
705                     }
706                 } else if (currentProperty.getStructureValue() != null) {
707                     // structure value has to be updated
708
currentProperty.setStructureValue(propValue);
709                     currentProperty.setResourceValue(null);
710                 } else {
711                     // resource value has to be updated
712
currentProperty.setResourceValue(propValue);
713                     currentProperty.setStructureValue(null);
714                 }
715                 // set auto-creation of the property to true
716
currentProperty.setAutoCreatePropertyDefinition(true);
717                 // write the updated property object
718
getCms().writePropertyObject(getParamResource(), currentProperty);
719             }
720         }
721     }
722
723 }
724
Popular Tags