1 31 32 package org.opencms.workplace.commons; 33 34 import org.opencms.file.CmsProject; 35 import org.opencms.file.CmsProperty; 36 import org.opencms.file.CmsPropertyDefinition; 37 import org.opencms.file.CmsResource; 38 import org.opencms.file.CmsResourceFilter; 39 import org.opencms.file.types.CmsResourceTypeXmlPage; 40 import org.opencms.i18n.CmsEncoder; 41 import org.opencms.jsp.CmsJspActionElement; 42 import org.opencms.lock.CmsLock; 43 import org.opencms.main.CmsException; 44 import org.opencms.main.CmsLog; 45 import org.opencms.main.OpenCms; 46 import org.opencms.security.CmsPermissionSet; 47 import org.opencms.util.CmsRequestUtil; 48 import org.opencms.util.CmsStringUtil; 49 import org.opencms.util.CmsUriSplitter; 50 import org.opencms.workplace.CmsDialogSelector; 51 import org.opencms.workplace.CmsTabDialog; 52 import org.opencms.workplace.CmsWorkplace; 53 import org.opencms.workplace.CmsWorkplaceSettings; 54 import org.opencms.workplace.I_CmsDialogHandler; 55 import org.opencms.workplace.explorer.CmsExplorerTypeSettings; 56 57 import java.io.IOException ; 58 import java.util.ArrayList ; 59 import java.util.Collections ; 60 import java.util.HashMap ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 import java.util.Map ; 64 import java.util.RandomAccess ; 65 66 import javax.servlet.ServletException ; 67 import javax.servlet.http.HttpServletRequest ; 68 import javax.servlet.http.HttpServletResponse ; 69 import javax.servlet.jsp.JspException ; 70 import javax.servlet.jsp.PageContext ; 71 72 import org.apache.commons.logging.Log; 73 74 89 public class CmsPropertyAdvanced extends CmsTabDialog implements I_CmsDialogHandler { 90 91 92 public static final int ACTION_SAVE_DEFINE = 400; 93 94 public static final int ACTION_SAVE_EDIT = 300; 95 96 public static final int ACTION_SHOW_DEFINE = 200; 97 98 public static final int ACTION_SHOW_EDIT = 100; 99 100 101 public static final int BUTTON_DEFINE = 201; 102 103 public static final int BUTTON_FINISH = 202; 104 105 106 public static final String DIALOG_SAVE_DEFINE = "savedefine"; 107 108 public static final String DIALOG_SAVE_EDIT = "saveedit"; 109 110 public static final String DIALOG_SHOW_DEFAULT = "default"; 111 112 public static final String DIALOG_SHOW_DEFINE = "define"; 113 114 public static final String DIALOG_SHOW_EDIT = "edit"; 115 116 117 public static final String DIALOG_TYPE = "property"; 118 119 120 public static final String MODE_WIZARD = "wizard"; 121 122 public static final String MODE_WIZARD_CREATEINDEX = "wizardcreateindex"; 123 124 public static final String MODE_WIZARD_INDEXCREATED = "wizardindexcreated"; 125 126 127 public static final String PANEL_RESOURCE = "panel.properties.resource"; 128 129 public static final String PANEL_STRUCTURE = "panel.properties.structure"; 130 131 132 public static final String PARAM_DIALOGMODE = "dialogmode"; 133 134 public static final String PARAM_NEWPROPERTY = "newproperty"; 135 136 137 public static final String PREFIX_HIDDEN = "valhidden"; 138 139 public static final String PREFIX_RESOURCE = "valresource"; 140 141 public static final String PREFIX_STRUCTURE = "valstructure"; 142 143 public static final String PREFIX_USEPROPERTY = "useprop"; 144 145 public static final String PREFIX_VALUE = "valprop"; 146 147 148 public static final String TAB_RESOURCE = "tabres"; 149 150 public static final String TAB_STRUCTURE = "tabstr"; 151 152 153 public static final String URI_PROPERTY_CUSTOM_DIALOG = PATH_DIALOGS + "property_custom.jsp"; 154 155 156 public static final String URI_PROPERTY_DIALOG = PATH_DIALOGS + "property_advanced.jsp"; 157 158 159 public static final String URI_PROPERTY_DIALOG_HANDLER = PATH_DIALOGS + "property.jsp"; 160 161 162 private static final Log LOG = CmsLog.getLog(CmsPropertyAdvanced.class); 163 164 165 private Boolean m_isEditable; 166 167 168 private boolean m_isFolder; 169 170 171 private String m_paramDialogMode; 172 173 174 private String m_paramNewproperty; 175 private String m_paramUseTempfileProject; 176 177 178 private List m_propertyValues; 179 180 181 private boolean m_tabSwitched; 182 183 188 public CmsPropertyAdvanced() { 189 190 super(null); 191 } 192 193 198 public CmsPropertyAdvanced(CmsJspActionElement jsp) { 199 200 super(jsp); 201 } 202 203 210 public CmsPropertyAdvanced(PageContext context, HttpServletRequest req, HttpServletResponse res) { 211 212 this(new CmsJspActionElement(context, req, res)); 213 } 214 215 222 public static Map getPropertyMap(List list) { 223 224 Map result = null; 225 String key = null; 226 CmsProperty property = null; 227 228 if (list == null || list.size() == 0) { 229 return Collections.EMPTY_MAP; 230 } 231 232 result = new HashMap (); 233 234 if (list instanceof RandomAccess ) { 236 for (int i = 0, n = list.size(); i < n; i++) { 237 property = (CmsProperty)list.get(i); 238 key = property.getName(); 239 result.put(key, property); 240 } 241 } else { 242 Iterator i = list.iterator(); 243 while (i.hasNext()) { 244 property = (CmsProperty)i.next(); 245 key = property.getName(); 246 result.put(key, property); 247 } 248 } 249 250 return result; 251 } 252 253 265 public void actionCloseDialog() throws JspException { 266 267 if (getAction() == ACTION_SAVE_EDIT && MODE_WIZARD_CREATEINDEX.equals(getParamDialogmode())) { 268 String newFolder = getParamResource(); 270 if (!newFolder.endsWith("/")) { 271 newFolder += "/"; 272 } 273 getSettings().setExplorerResource(newFolder); 275 String newUri = PATH_DIALOGS 276 + OpenCms.getWorkplaceManager().getExplorerTypeSetting(CmsResourceTypeXmlPage.getStaticTypeName()).getNewResourceUri(); 277 try { 278 CmsUriSplitter splitter = new CmsUriSplitter(newUri); 280 Map params = CmsRequestUtil.createParameterMap(splitter.getQuery()); 281 params.put(PARAM_DIALOGMODE, MODE_WIZARD_CREATEINDEX); 282 sendForward(splitter.getPrefix(), params); 283 return; 284 } catch (IOException e) { 285 LOG.error(Messages.get().getBundle().key(Messages.ERR_REDIRECT_XMLPAGE_DIALOG_1, PATH_DIALOGS + newUri)); 286 } catch (ServletException e) { 287 LOG.error(Messages.get().getBundle().key(Messages.ERR_REDIRECT_XMLPAGE_DIALOG_1, PATH_DIALOGS + newUri)); 288 } 289 } else if (getAction() == ACTION_SAVE_EDIT && MODE_WIZARD.equals(getParamDialogmode())) { 290 try { 292 CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 293 if (res.isFolder()) { 294 List folderList = new ArrayList (1); 295 folderList.add(CmsResource.getParentFolder(getParamResource())); 296 getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList); 297 } 298 } catch (CmsException e) { 299 if (LOG.isInfoEnabled()) { 301 LOG.info(e.getLocalizedMessage()); 302 } 303 } 304 } else if (MODE_WIZARD_INDEXCREATED.equals(getParamDialogmode())) { 305 getSettings().setExplorerResource( 307 CmsResource.getParentFolder(CmsResource.getParentFolder(getParamResource()))); 308 List folderList = new ArrayList (1); 309 folderList.add(CmsResource.getParentFolder(CmsResource.getParentFolder(getParamResource()))); 310 getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList); 311 } 312 super.actionCloseDialog(); 313 } 314 315 320 public void actionDefine() throws JspException { 321 322 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 324 try { 325 performDefineOperation(); 326 setParamAction(DIALOG_SHOW_DEFAULT); 328 setParamNewproperty(null); 329 sendForward(CmsWorkplace.VFS_PATH_COMMONS + "property_advanced.jsp", paramsAsParameterMap()); 330 } catch (Throwable e) { 331 includeErrorpage(this, e); 333 } 334 } 335 336 343 public void actionDeleteResource() throws JspException { 344 345 if (getParamDialogmode() != null && getParamDialogmode().startsWith(MODE_WIZARD)) { 346 try { 348 getCms().deleteResource(getParamResource(), CmsResource.DELETE_PRESERVE_SIBLINGS); 349 } catch (Throwable e) { 350 includeErrorpage(this, e); 352 } 353 } 354 } 355 356 362 public void actionEdit(HttpServletRequest request) throws JspException { 363 364 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 366 try { 367 if (isEditable()) { 368 performDialogOperation(request); 369 } 370 } catch (Throwable e) { 371 includeErrorpage(this, e); 373 } 374 } 375 376 381 public String buildActivePropertiesList() { 382 383 StringBuffer retValue = new StringBuffer (256); 384 List propertyDef = new ArrayList (); 385 try { 386 propertyDef = getCms().readAllPropertyDefinitions(); 388 } catch (CmsException e) { 389 if (LOG.isInfoEnabled()) { 391 LOG.info(e.getLocalizedMessage()); 392 } 393 } 394 395 Iterator j = propertyDef.iterator(); 396 int i = 0; 397 while (j.hasNext()) { 398 CmsPropertyDefinition curProperty = (CmsPropertyDefinition)j.next(); 399 retValue.append(CmsEncoder.escapeXml(curProperty.getName())); 400 if ((i + 1) < propertyDef.size()) { 401 retValue.append("<br>"); 402 } 403 i++; 404 } 405 406 return retValue.toString(); 407 } 408 409 417 public String buildEditForm() { 418 419 StringBuffer result = new StringBuffer (4096); 420 421 String activeTab = getActiveTabName(); 423 424 String disabled = ""; 426 if (!isEditable()) { 427 disabled = " disabled=\"disabled\""; 428 } 429 430 List properties = getPropertyValues(); 432 433 if (properties.size() > 0) { 435 result.append("<table border=\"0\">\n"); 437 result.append("<tr>\n"); 438 result.append("\t<td class=\"textbold\">"); 439 result.append(key(Messages.GUI_PROPERTY_0)); 440 result.append("</td>\n"); 441 result.append("\t<td class=\"textbold\">"); 442 result.append(key(Messages.GUI_PROPERTY_VALUE_0)); 443 result.append("</td>\n"); 444 result.append("\t<td class=\"textbold\" style=\"white-space: nowrap;\">"); 445 result.append(key(Messages.GUI_PROPERTY_USED_0)); 446 result.append("</td>\n"); 447 result.append("</tr>\n"); 448 result.append("<tr><td colspan=\"3\"><span style=\"height: 6px;\"></span></td></tr>\n"); 449 450 Iterator i = properties.iterator(); 452 while (i.hasNext()) { 453 String [] curProp = (String [])i.next(); 454 result.append(buildPropertyRow(curProp[0], curProp[1], curProp[2], curProp[3], disabled, activeTab)); 456 } 457 result.append("</table>"); 458 } else { 459 result.append(key(Messages.GUI_PROPERTY_ADVANCED_NO_PROPDEFS_0)); 461 } 462 return result.toString(); 463 } 464 465 477 public String buildSetFormValues() { 478 479 StringBuffer result = new StringBuffer (1024); 480 String activeTab = getActiveTabName(); 482 String structurePanelName = key(Messages.GUI_PROPERTIES_INDIVIDUAL_0); 484 Iterator i = getPropertyValues().iterator(); 485 while (i.hasNext()) { 486 String [] curProp = (String [])i.next(); 487 String shownValue = curProp[1]; 489 if (structurePanelName.equals(activeTab) && "".equals(curProp[2]) && !"".equals(curProp[3])) { 491 shownValue = curProp[3]; 492 } 493 if (!"".equals(shownValue)) { 494 result.append("\tdocument.getElementById(\""); 496 result.append(PREFIX_VALUE); 497 result.append(curProp[0]); 498 result.append("\").value = \""); 499 result.append(CmsStringUtil.escapeJavaScript(shownValue)); 500 result.append("\";\n"); 501 } 502 503 } 504 return result.toString(); 505 } 506 507 512 public String dialogButtonsOkCancelDefine() { 513 514 if (isEditable()) { 515 int okButton = BUTTON_OK; 516 if (getParamDialogmode() != null && getParamDialogmode().startsWith(MODE_WIZARD)) { 517 okButton = BUTTON_FINISH; 519 } 520 return dialogButtons(new int[] {okButton, BUTTON_CANCEL, BUTTON_DEFINE}, new String [] { 521 null, 522 null, 523 "onclick=\"definePropertyForm();\""}); 524 } else { 525 return dialogButtons(new int[] {BUTTON_CLOSE}, new String [] {null}); 526 527 } 528 } 529 530 533 public String getDialogHandler() { 534 535 return CmsDialogSelector.DIALOG_PROPERTY; 536 } 537 538 541 public String getDialogUri(String resource, CmsJspActionElement jsp) { 542 543 try { 544 CmsResource res = jsp.getCmsObject().readResource(resource, CmsResourceFilter.ALL); 545 if (res.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) { 546 return PATH_WORKPLACE + "editors/dialogs/property.jsp"; 548 } 549 String resTypeName = OpenCms.getResourceManager().getResourceType(res.getTypeId()).getTypeName(); 550 CmsExplorerTypeSettings settings = getSettingsForType(resTypeName); 552 if (settings.isPropertiesEnabled()) { 553 return URI_PROPERTY_CUSTOM_DIALOG; 555 } 556 } catch (CmsException e) { 557 if (LOG.isInfoEnabled()) { 559 LOG.info(e.getLocalizedMessage()); 560 } 561 } 562 return URI_PROPERTY_DIALOG; 563 } 564 565 574 public String getParamDialogmode() { 575 576 return m_paramDialogMode; 577 } 578 579 588 public String getParamNewproperty() { 589 590 return m_paramNewproperty; 591 } 592 593 602 public String getParamUsetempfileproject() { 603 604 return m_paramUseTempfileProject; 605 } 606 607 610 public List getTabParameterOrder() { 611 612 ArrayList orderList = new ArrayList (2); 613 orderList.add(TAB_STRUCTURE); 614 orderList.add(TAB_RESOURCE); 615 return orderList; 616 } 617 618 621 public List getTabs() { 622 623 ArrayList tabList = new ArrayList (2); 624 if (OpenCms.getWorkplaceManager().isEnableAdvancedPropertyTabs()) { 625 if (m_isFolder) { 627 tabList.add(key(Messages.GUI_PROPERTIES_INDIVIDUAL_0)); 629 } else { 630 tabList.add(key(Messages.GUI_PROPERTIES_INDIVIDUAL_0)); 632 tabList.add(key(Messages.GUI_PROPERTIES_SHARED_0)); 633 } 634 } else { 635 if (m_isFolder || OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) { 637 tabList.add(key(Messages.GUI_PROPERTIES_INDIVIDUAL_0)); 638 } else { 639 tabList.add(key(Messages.GUI_PROPERTIES_SHARED_0)); 640 } 641 } 642 return tabList; 643 } 644 645 650 public void setParamDialogmode(String value) { 651 652 m_paramDialogMode = value; 653 } 654 655 660 public void setParamNewproperty(String value) { 661 662 m_paramNewproperty = value; 663 } 664 665 670 public void setParamUsetempfileproject(String value) { 671 672 m_paramUseTempfileProject = value; 673 } 674 675 678 protected void dialogButtonsHtml(StringBuffer result, int button, String attribute) { 679 680 attribute = appendDelimiter(attribute); 681 682 switch (button) { 683 case BUTTON_DEFINE: 684 result.append("<input name=\"define\" type=\"button\" value=\""); 685 result.append(key(Messages.GUI_PROPERTY_DEFINE_0)); 686 result.append("\" class=\"dialogbutton\""); 687 result.append(attribute); 688 result.append(">\n"); 689 break; 690 case BUTTON_FINISH: 691 result.append("<input name=\"finish\" type=\"submit\" value=\""); 692 result.append(key(Messages.GUI_PROPERTY_FINISH_0)); 693 result.append("\" class=\"dialogbutton\""); 694 result.append(attribute); 695 result.append(">\n"); 696 break; 697 default: 698 super.dialogButtonsHtml(result, button, attribute); 699 } 700 } 701 702 708 protected CmsExplorerTypeSettings getSettingsForType(String resTypeName) { 709 710 CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(resTypeName); 712 if (CmsStringUtil.isNotEmpty(settings.getReference())) { 713 settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(settings.getReference()); 715 } 716 return settings; 717 } 718 719 722 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 723 724 fillParamValues(request); 726 727 getActiveTab(); 729 730 m_isFolder = false; 732 try { 733 CmsResource resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 734 if (resource.isFolder()) { 735 m_isFolder = true; 736 if (!getParamResource().endsWith("/")) { 737 setParamResource(getParamResource() + "/"); 739 } 740 } 741 } catch (CmsException e) { 742 LOG.error(e.getLocalizedMessage()); 744 } 745 746 setParamDialogtype(DIALOG_TYPE); 748 boolean isPopup = Boolean.valueOf(getParamIsPopup()).booleanValue(); 749 if (DIALOG_SHOW_DEFINE.equals(getParamAction())) { 751 setAction(ACTION_SHOW_DEFINE); 752 setParamTitle(key(Messages.GUI_PROPERTY_NEW_DEF_1, new Object [] {CmsResource.getName(getParamResource())})); 753 } else if (DIALOG_SAVE_EDIT.equals(getParamAction())) { 754 if (isPopup) { 755 setAction(ACTION_CLOSEPOPUP_SAVE); 756 } else { 757 setAction(ACTION_SAVE_EDIT); 758 } 759 } else if (DIALOG_SAVE_DEFINE.equals(getParamAction())) { 760 setAction(ACTION_SAVE_DEFINE); 761 } else if (DIALOG_CANCEL.equals(getParamAction())) { 762 if (isPopup) { 763 setAction(ACTION_CLOSEPOPUP); 764 } else { 765 setAction(ACTION_CANCEL); 766 } 767 } else { 768 setAction(ACTION_DEFAULT); 770 if (!isEditable()) { 771 setParamTitle(key(Messages.GUI_PROPERTIES_OF_1, 772 new Object [] {CmsResource.getName(getParamResource())})); 773 } else { 774 setParamTitle(key(Messages.GUI_PROPERTIES_EDIT_1, 775 new Object [] {CmsResource.getName(getParamResource())})); 776 } 777 m_tabSwitched = false; 779 if (DIALOG_SWITCHTAB.equals(getParamAction())) { 780 m_tabSwitched = true; 781 } 782 } 783 } 784 785 790 protected boolean isEditable() { 791 792 if (m_isEditable == null) { 793 794 if (getCms().getRequestContext().currentProject().getId() == CmsProject.ONLINE_PROJECT_ID 795 || !getCms().isInsideCurrentProject(getParamResource())) { 796 m_isEditable = new Boolean (false); 798 799 } else { 800 802 if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) { 804 getSettings().setErrorMessage(null); 805 m_isEditable = new Boolean (false); 806 return m_isEditable.booleanValue(); 807 } 808 809 String resourceName = getParamResource(); 811 CmsResource file = null; 812 CmsLock lock = null; 813 try { 814 file = getCms().readResource(resourceName, CmsResourceFilter.ALL); 815 if (file.isFolder() && !resourceName.endsWith("/")) { 817 resourceName += "/"; 818 } 819 } catch (CmsException e) { 820 if (LOG.isInfoEnabled()) { 822 LOG.info(e.getLocalizedMessage()); 823 } 824 } 825 826 try { 827 lock = getCms().getLock(resourceName); 829 } catch (CmsException e) { 830 lock = CmsLock.getNullLock(); 831 832 if (LOG.isErrorEnabled()) { 833 LOG.error(e.getLocalizedMessage(), e); 834 } 835 } 836 837 if (!lock.isNullLock()) { 838 if (lock.getType() != CmsLock.TYPE_SHARED_EXCLUSIVE 840 && lock.getType() != CmsLock.TYPE_SHARED_INHERITED 841 && lock.getUserId().equals(getCms().getRequestContext().currentUser().getId())) { 842 if (getCms().getRequestContext().currentProject().getId() == lock.getProjectId() 844 || Boolean.valueOf(getParamUsetempfileproject()).booleanValue()) { 845 m_isEditable = new Boolean (true); 847 return m_isEditable.booleanValue(); 848 } 849 } 850 } else if (OpenCms.getWorkplaceManager().autoLockResources()) { 851 m_isEditable = new Boolean (true); 852 return m_isEditable.booleanValue(); 853 } 854 m_isEditable = new Boolean (false); 856 } 857 } 858 return m_isEditable.booleanValue(); 859 } 860 861 879 private StringBuffer buildPropertyRow( 880 String propName, 881 String propValue, 882 String valueStructure, 883 String valueResource, 884 String disabled, 885 String activeTab) { 886 887 StringBuffer result = new StringBuffer (256); 888 String structurePanelName = key(Messages.GUI_PROPERTIES_INDIVIDUAL_0); 889 String inputAttrs = "class=\"maxwidth\""; 890 if (structurePanelName.equals(activeTab)) { 891 if ("".equals(valueStructure) && !"".equals(valueResource)) { 893 inputAttrs = "class=\"dialogmarkedfield\""; 894 } 895 } 896 result.append("<tr>\n"); 897 result.append("\t<td style=\"white-space: nowrap;\">" + propName); 898 result.append("</td>\n"); 899 result.append("\t<td class=\"maxwidth\">"); 900 901 result.append("<input type=\"text\" "); 903 result.append(inputAttrs); 904 result.append(" name=\""); 905 result.append(PREFIX_VALUE); 906 result.append(propName); 907 result.append("\" id=\""); 908 result.append(PREFIX_VALUE); 909 result.append(propName); 910 result.append("\""); 911 result.append(" onFocus=\"deleteResEntry('"); 912 result.append(propName); 913 result.append("', '"); 914 result.append(activeTab); 915 result.append("');\""); 916 result.append(" onBlur=\"checkResEntry('"); 917 result.append(propName); 918 result.append("', '"); 919 result.append(activeTab); 920 result.append("');\" onKeyup=\"checkValue('"); 921 result.append(propName); 922 result.append("', '"); 923 result.append(activeTab); 924 result.append("');\""); 925 result.append(disabled); 926 result.append(">"); 927 928 result.append("<input type=\"hidden\" name=\""); 930 result.append(PREFIX_STRUCTURE); 931 result.append(propName); 932 result.append("\" id=\""); 933 result.append(PREFIX_STRUCTURE); 934 result.append(propName); 935 result.append("\" value=\""); 936 result.append(CmsEncoder.escapeXml(valueStructure)); 937 result.append("\">"); 938 939 result.append("<input type=\"hidden\" name=\""); 941 result.append(PREFIX_RESOURCE); 942 result.append(propName); 943 result.append("\" id=\""); 944 result.append(PREFIX_RESOURCE); 945 result.append(propName); 946 result.append("\" value=\""); 947 result.append(CmsEncoder.escapeXml(valueResource)); 948 result.append("\"></td>\n"); 949 result.append("\t<td class=\"textcenter\">"); 950 if (!"".equals(propValue)) { 951 String prefix = PREFIX_RESOURCE; 953 if (structurePanelName.equals(activeTab)) { 954 prefix = PREFIX_STRUCTURE; 955 } 956 result.append("<input type=\"checkbox\" name=\""); 957 result.append(PREFIX_USEPROPERTY); 958 result.append(propName); 959 result.append("\" id=\""); 960 result.append(PREFIX_USEPROPERTY); 961 result.append(propName); 962 result.append("\" value=\"true\""); 963 result.append(disabled); 964 result.append(" checked=\"checked\" onClick=\"toggleDelete('"); 965 result.append(propName); 966 result.append("', '"); 967 result.append(prefix); 968 result.append("', '"); 969 result.append(activeTab); 970 result.append("');\">"); 971 } else { 972 result.append(" "); 973 } 974 result.append("</td>\n"); 975 result.append("</tr>\n"); 976 return result; 977 } 978 979 992 private List getPropertyValues() { 993 994 if (m_propertyValues == null) { 996 997 String activeTab = getActiveTabName(); 999 String structurePanelName = key(Messages.GUI_PROPERTIES_INDIVIDUAL_0); 1000 1001 List propertyDef = new ArrayList (); 1003 try { 1004 propertyDef = getCms().readAllPropertyDefinitions(); 1005 } catch (CmsException e) { 1006 if (LOG.isInfoEnabled()) { 1008 LOG.info(e.getLocalizedMessage()); 1009 } 1010 } 1011 m_propertyValues = new ArrayList (propertyDef.size()); 1012 1013 Map activeProperties = null; 1015 if (!m_tabSwitched) { 1016 try { 1017 activeProperties = CmsPropertyAdvanced.getPropertyMap(getCms().readPropertyObjects( 1018 getParamResource(), 1019 false)); 1020 } catch (CmsException e) { 1021 if (LOG.isInfoEnabled()) { 1023 LOG.info(e.getLocalizedMessage()); 1024 } 1025 activeProperties = new HashMap (); 1026 } 1027 } 1028 1029 Iterator i = propertyDef.iterator(); 1031 while (i.hasNext()) { 1032 CmsPropertyDefinition currentPropertyDef = (CmsPropertyDefinition)i.next(); 1033 String propName = CmsEncoder.escapeXml(currentPropertyDef.getName()); 1034 String propValue = ""; 1035 String valueStructure = ""; 1036 String valueResource = ""; 1037 if (m_tabSwitched) { 1038 if (structurePanelName.equals(activeTab)) { 1040 propValue = getJsp().getRequest().getParameter(PREFIX_STRUCTURE + propName); 1042 valueStructure = getJsp().getRequest().getParameter(PREFIX_STRUCTURE + propName); 1043 if (!isEditable()) { 1044 valueResource = getJsp().getRequest().getParameter(PREFIX_RESOURCE + propName); 1046 } else { 1047 valueResource = getJsp().getRequest().getParameter(PREFIX_VALUE + propName); 1048 } 1049 } else { 1050 propValue = getJsp().getRequest().getParameter(PREFIX_RESOURCE + propName); 1052 if (!isEditable()) { 1053 valueStructure = getJsp().getRequest().getParameter(PREFIX_STRUCTURE + propName); 1055 } else { 1056 valueStructure = getJsp().getRequest().getParameter(PREFIX_VALUE + propName); 1057 } 1058 valueResource = getJsp().getRequest().getParameter(PREFIX_RESOURCE + propName); 1059 if (valueStructure != null 1060 && !"".equals(valueStructure.trim()) 1061 && valueStructure.equals(valueResource)) { 1062 valueStructure = ""; 1064 } 1065 } 1066 } else { 1067 CmsProperty currentProperty = (CmsProperty)activeProperties.get(propName); 1069 if (currentProperty == null) { 1070 currentProperty = new CmsProperty(); 1071 } 1072 if (structurePanelName.equals(activeTab)) { 1073 propValue = currentProperty.getStructureValue(); 1075 } else { 1076 propValue = currentProperty.getResourceValue(); 1078 } 1079 valueStructure = currentProperty.getStructureValue(); 1080 valueResource = currentProperty.getResourceValue(); 1081 if (propValue == null) { 1083 propValue = ""; 1084 } 1085 if (valueStructure == null) { 1086 valueStructure = ""; 1087 } 1088 if (valueResource == null) { 1089 valueResource = ""; 1090 } 1091 } 1092 propValue = propValue.trim(); 1094 valueStructure = valueStructure.trim(); 1095 valueResource = valueResource.trim(); 1096 String [] property = new String [] {propName, propValue, valueStructure, valueResource}; 1097 m_propertyValues.add(property); 1098 } 1099 } 1100 return m_propertyValues; 1102 } 1103 1104 1110 private boolean performDefineOperation() throws CmsException { 1111 1112 boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue(); 1113 try { 1114 if (useTempfileProject) { 1115 switchToTempProject(); 1116 } 1117 String newProperty = getParamNewproperty(); 1118 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(newProperty)) { 1119 getCms().createPropertyDefinition(newProperty); 1120 return true; 1121 } else { 1122 throw new CmsException(Messages.get().container(Messages.ERR_INVALID_PROP_0)); 1123 } 1124 } finally { 1125 if (useTempfileProject) { 1126 switchToCurrentProject(); 1127 } 1128 } 1129 } 1130 1131 1138 private boolean performDialogOperation(HttpServletRequest request) throws CmsException { 1139 1140 List propertyDef = getCms().readAllPropertyDefinitions(); 1141 boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue(); 1142 try { 1143 if (useTempfileProject) { 1144 switchToTempProject(); 1145 } 1146 Map activeProperties = getPropertyMap(getCms().readPropertyObjects(getParamResource(), false)); 1147 String activeTab = getActiveTabName(); 1148 List propertiesToWrite = new ArrayList (); 1149 1150 Iterator i = propertyDef.iterator(); 1152 while (i.hasNext()) { 1153 CmsPropertyDefinition curPropDef = (CmsPropertyDefinition)i.next(); 1154 String propName = CmsEncoder.escapeXml(curPropDef.getName()); 1155 String valueStructure = null; 1156 String valueResource = null; 1157 1158 if (key(Messages.GUI_PROPERTIES_INDIVIDUAL_0).equals(activeTab)) { 1159 valueStructure = request.getParameter(PREFIX_VALUE + propName); 1161 valueResource = request.getParameter(PREFIX_RESOURCE + propName); 1162 if (valueStructure != null 1163 && !"".equals(valueStructure.trim()) 1164 && valueStructure.equals(valueResource)) { 1165 valueStructure = ""; 1167 } 1168 } else { 1169 valueStructure = request.getParameter(PREFIX_STRUCTURE + propName); 1171 valueResource = request.getParameter(PREFIX_VALUE + propName); 1172 } 1173 1174 if (valueStructure != null) { 1176 valueStructure = valueStructure.trim(); 1177 } 1178 1179 if (valueResource != null) { 1180 valueResource = valueResource.trim(); 1181 } 1182 1183 CmsProperty newProperty = new CmsProperty(); 1185 newProperty.setName(curPropDef.getName()); 1186 newProperty.setStructureValue(valueStructure); 1187 newProperty.setResourceValue(valueResource); 1188 1189 CmsProperty oldProperty = (CmsProperty)activeProperties.get(curPropDef.getName()); 1191 if (oldProperty == null) { 1192 oldProperty = new CmsProperty(); 1194 oldProperty.setName(curPropDef.getName()); 1195 } 1196 1197 boolean writeStructureValue = false; 1198 boolean writeResourceValue = false; 1199 String oldValue = oldProperty.getStructureValue(); 1200 String newValue = newProperty.getStructureValue(); 1201 1202 writeStructureValue = (oldValue != null && newProperty.isDeleteStructureValue()); 1204 writeStructureValue |= !newValue.equals(oldValue) 1206 && !"".equalsIgnoreCase(newValue) 1207 && !CmsProperty.DELETE_VALUE.equalsIgnoreCase(newValue); 1208 if (!writeStructureValue) { 1210 newProperty.setStructureValue(null); 1211 } 1212 1213 oldValue = oldProperty.getResourceValue(); 1214 newValue = newProperty.getResourceValue(); 1215 1216 writeResourceValue = (oldValue != null && newProperty.isDeleteResourceValue()); 1218 writeResourceValue |= !newValue.equals(oldValue) 1220 && !"".equalsIgnoreCase(newValue) 1221 && !CmsProperty.DELETE_VALUE.equalsIgnoreCase(newValue); 1222 if (!writeResourceValue) { 1224 newProperty.setResourceValue(null); 1225 } 1226 1227 if (writeStructureValue || writeResourceValue) { 1228 propertiesToWrite.add(newProperty); 1230 } 1231 } 1232 if (propertiesToWrite.size() > 0) { 1233 checkLock(getParamResource()); 1235 getCms().writePropertyObjects(getParamResource(), propertiesToWrite); 1237 } 1238 } finally { 1239 if (useTempfileProject) { 1240 switchToCurrentProject(); 1241 } 1242 } 1243 return true; 1244 } 1245 1246} 1247 | Popular Tags |