1 31 32 package org.opencms.jsp; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.file.CmsProperty; 36 import org.opencms.flex.CmsFlexController; 37 import org.opencms.i18n.CmsMessageContainer; 38 import org.opencms.i18n.CmsMessages; 39 import org.opencms.loader.CmsImageScaler; 40 import org.opencms.loader.I_CmsResourceLoader; 41 import org.opencms.main.CmsException; 42 import org.opencms.main.OpenCms; 43 import org.opencms.security.CmsSecurityException; 44 import org.opencms.staticexport.CmsLinkManager; 45 import org.opencms.util.CmsStringUtil; 46 import org.opencms.workplace.editors.directedit.CmsDirectEditJspIncludeProvider; 47 import org.opencms.workplace.editors.directedit.CmsDirectEditMode; 48 import org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider; 49 50 import java.io.UnsupportedEncodingException ; 51 import java.util.HashMap ; 52 import java.util.Iterator ; 53 import java.util.Locale ; 54 import java.util.Map ; 55 56 import javax.servlet.http.HttpServletRequest ; 57 import javax.servlet.http.HttpServletResponse ; 58 import javax.servlet.jsp.JspException ; 59 import javax.servlet.jsp.PageContext ; 60 61 89 public class CmsJspActionElement extends CmsJspBean { 90 91 92 public static final CmsMessageContainer NOT_INITIALIZED = Messages.get().container( 95 Messages.GUI_ERR_ACTIONELEM_NOT_INIT_0); 96 97 98 private CmsJspNavBuilder m_navigation; 99 100 103 public CmsJspActionElement() { 104 105 super(); 106 } 107 108 115 public CmsJspActionElement(PageContext context, HttpServletRequest req, HttpServletResponse res) { 116 117 super(); 118 init(context, req, res); 119 } 120 121 131 public void editable(boolean isEditable) throws JspException { 132 133 if (isEditable) { 134 CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.AUTO, null); 135 } 136 } 137 138 149 public void editable(boolean isEditable, String filename) throws JspException { 150 151 if (isEditable) { 152 CmsJspTagEditable.editableTagAction( 153 getJspContext(), 154 CmsDirectEditJspIncludeProvider.class.getName(), 155 CmsDirectEditMode.AUTO, 156 filename); 157 } 158 } 159 160 170 public void editable(String provider, String mode, String filename) throws JspException { 171 172 CmsJspTagEditable.editableTagAction(getJspContext(), provider, CmsDirectEditMode.valueOf(mode), filename); 173 } 174 175 184 public void editableManualClose(boolean needsClose) throws JspException { 185 186 if (needsClose) { 187 CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.MANUAL, null); 188 } 189 } 190 191 200 public boolean editableManualOpen() throws JspException { 201 202 boolean result = false; 203 if (!CmsFlexController.isCmsOnlineRequest(getJspContext().getRequest())) { 204 I_CmsDirectEditProvider eb = CmsJspTagEditable.getDirectEditProvider(getJspContext()); 206 if ((eb != null)) { 207 if (eb.isManual(CmsDirectEditMode.MANUAL)) { 209 result = true; 211 CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.MANUAL, null); 212 } 213 } 214 } 215 return result; 216 } 217 218 224 public String getContent(String target) { 225 226 return getContent(target, null, null); 227 } 228 229 237 public String getContent(String target, String element, Locale locale) { 238 239 I_CmsResourceLoader loader; 240 CmsFile file; 241 target = toAbsolute(target); 242 243 try { 244 file = getCmsObject().readFile(target); 245 loader = OpenCms.getResourceManager().getLoader(file); 246 } catch (ClassCastException e) { 247 return CmsMessages.formatUnknownKey(e.getMessage()); 249 } catch (CmsException e) { 250 return CmsMessages.formatUnknownKey(e.getMessage()); 252 } 253 254 try { 255 byte[] result = loader.dump(getCmsObject(), file, element, locale, getRequest(), getResponse()); 256 return new String (result, getRequestContext().getEncoding()); 257 } catch (UnsupportedEncodingException uee) { 258 return CmsMessages.formatUnknownKey(uee.getMessage()); 260 } catch (Throwable t) { 261 Throwable cause = CmsFlexController.getThrowable(getRequest()); 263 if (cause == null) { 264 cause = t; 265 } 266 handleException(cause); 267 return CmsMessages.formatUnknownKey(cause.getMessage()); 268 } 269 } 270 271 280 public CmsMessages getMessages(String bundleName, Locale locale) { 281 282 return new CmsMessages(bundleName, locale); 283 } 284 285 293 public CmsMessages getMessages(String bundleName, String language) { 294 295 return getMessages(bundleName, language, "", "", null); 296 } 297 298 308 public CmsMessages getMessages(String bundleName, String language, String defaultLanguage) { 309 310 return getMessages(bundleName, language, "", "", defaultLanguage); 311 } 312 313 328 public CmsMessages getMessages( 329 String bundleName, 330 String language, 331 String country, 332 String variant, 333 String defaultLanguage) { 334 335 try { 336 if ((defaultLanguage != null) && CmsStringUtil.isEmpty(language)) { 337 language = defaultLanguage; 338 } 339 if (language == null) { 340 language = ""; 341 } 342 if (country == null) { 343 country = ""; 344 } 345 if (variant == null) { 346 variant = ""; 347 } 348 return getMessages(bundleName, new Locale (language, country, variant)); 349 } catch (Throwable t) { 350 handleException(t); 351 } 352 return null; 353 } 354 355 362 public CmsJspNavBuilder getNavigation() { 363 364 if (isNotInitialized()) { 365 return null; 366 } 367 if (m_navigation == null) { 368 m_navigation = new CmsJspNavBuilder(getController().getCmsObject()); 369 } 370 return m_navigation; 371 } 372 373 382 public String img(String target, CmsImageScaler scaler, Map attributes) { 383 384 return img(target, scaler, attributes, false); 385 } 386 387 397 public String img(String target, CmsImageScaler scaler, Map attributes, boolean partialTag) { 398 399 try { 400 return CmsJspTagImage.imageTagAction(target, scaler, attributes, partialTag, getRequest()); 401 } catch (Throwable t) { 402 handleException(t); 403 } 404 CmsMessageContainer msgContainer = Messages.get().container( 405 Messages.GUI_ERR_IMG_SCALE_2, 406 target, 407 scaler == null ? "null" : scaler.toString()); 408 return getMessage(msgContainer); 409 } 410 411 420 public void include(String target) throws JspException { 421 422 include(target, null, null); 423 } 424 425 435 public void include(String target, String element) throws JspException { 436 437 include(target, element, null); 438 } 439 440 451 public void include(String target, String element, boolean editable) throws JspException { 452 453 include(target, element, editable, null); 454 } 455 456 481 public void include(String target, String element, boolean editable, Map parameterMap) throws JspException { 482 483 if (isNotInitialized()) { 484 return; 485 } 486 if (parameterMap != null) { 487 try { 488 HashMap modParameterMap = new HashMap (parameterMap.size()); 489 Iterator i = parameterMap.entrySet().iterator(); 491 while (i.hasNext()) { 492 Map.Entry entry = (Map.Entry )i.next(); 493 String key = (String )entry.getKey(); 494 Object value = entry.getValue(); 495 if (value instanceof String []) { 496 modParameterMap.put(key, value); 497 } else { 498 if (value == null) { 499 value = "null"; 500 } 501 String [] newValue = new String [] {value.toString()}; 502 modParameterMap.put(key, newValue); 503 } 504 } 505 parameterMap = modParameterMap; 506 } catch (UnsupportedOperationException e) { 507 } 509 } 510 CmsJspTagInclude.includeTagAction( 511 getJspContext(), 512 target, 513 element, 514 editable, 515 parameterMap, 516 getRequest(), 517 getResponse()); 518 } 519 520 532 public void include(String target, String element, Map parameterMap) throws JspException { 533 534 include(target, element, false, parameterMap); 535 } 536 537 548 public void includeSilent(String target, String element) { 549 550 try { 551 include(target, element, null); 552 } catch (Throwable t) { 553 } 555 } 556 557 569 public void includeSilent(String target, String element, boolean editable) { 570 571 try { 572 include(target, element, editable, null); 573 } catch (Throwable t) { 574 } 576 } 577 578 591 public void includeSilent(String target, String element, boolean editable, Map parameterMap) { 592 593 try { 594 include(target, element, editable, parameterMap); 595 } catch (Throwable t) { 596 } 598 } 599 600 612 public void includeSilent(String target, String element, Map parameterMap) { 613 614 try { 615 include(target, element, parameterMap); 616 } catch (Throwable t) { 617 } 619 } 620 621 632 public String info(String property) { 633 634 try { 635 return CmsJspTagInfo.infoTagAction(property, getRequest()); 636 } catch (Throwable t) { 637 handleException(t); 638 } 639 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_INFO_PROP_READ_1, property); 640 return getMessage(msgContainer); 641 } 642 643 655 public String label(String label) { 656 657 if (isNotInitialized()) { 658 return getMessage(NOT_INITIALIZED); 659 } 660 try { 661 return CmsJspTagLabel.wpLabelTagAction(label, getRequest()); 662 } catch (Throwable t) { 663 handleException(t); 664 } 665 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_WORKPL_LABEL_READ_1, label); 666 return getMessage(msgContainer); 667 } 668 669 681 public String link(String link) { 682 683 if (isNotInitialized()) { 684 return getMessage(NOT_INITIALIZED); 685 } 686 try { 687 return CmsJspTagLink.linkTagAction(link, getRequest()); 688 } catch (Throwable t) { 689 handleException(t); 690 } 691 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_GEN_LINK_1, link); 692 return getMessage(msgContainer); 693 } 694 695 700 public Map properties() { 701 702 return properties(null); 703 } 704 705 717 public Map properties(String file) { 718 719 if (isNotInitialized()) { 720 return new HashMap (); 721 } 722 Map value = new HashMap (); 723 try { 724 if (file == null) { 725 file = CmsJspTagProperty.USE_URI; 726 } 727 switch (CmsJspTagProperty.ACTION_VALUES_LIST.indexOf(file)) { 728 case 0: case 1: value = CmsProperty.toMap(getCmsObject().readPropertyObjects(getRequestContext().getUri(), false)); 731 break; 732 case 2: case 3: case 4: value = CmsProperty.toMap(getCmsObject().readPropertyObjects(getRequestContext().getUri(), true)); 736 break; 737 case 5: case 6: value = CmsProperty.toMap(getCmsObject().readPropertyObjects( 741 getController().getCurrentRequest().getElementUri(), 742 false)); 743 break; 744 case 7: case 8: value = CmsProperty.toMap(getCmsObject().readPropertyObjects( 748 getController().getCurrentRequest().getElementUri(), 749 true)); 750 break; 751 default: 752 value = CmsProperty.toMap(getCmsObject().readPropertyObjects(toAbsolute(file), false)); 754 } 755 } catch (Throwable t) { 756 handleException(t); 757 } 758 return value; 759 } 760 761 772 public String property(String name) { 773 774 return property(name, null, null, false); 775 } 776 777 789 public String property(String name, String file) { 790 791 return property(name, file, null, false); 792 } 793 794 808 public String property(String name, String file, String defaultValue) { 809 810 return property(name, file, defaultValue, false); 811 } 812 813 830 public String property(String name, String file, String defaultValue, boolean escapeHtml) { 831 832 if (isNotInitialized()) { 833 return getMessage(NOT_INITIALIZED); 834 } 835 try { 836 if (file == null) { 837 file = getController().getCmsObject().getRequestContext().getUri(); 838 } 839 return CmsJspTagProperty.propertyTagAction(name, file, defaultValue, escapeHtml, getRequest()); 840 } catch (CmsSecurityException e) { 841 if (defaultValue == null) { 842 handleException(e); 843 } 844 } catch (Throwable t) { 845 handleException(t); 846 } 847 if (defaultValue == null) { 848 CmsMessageContainer msgContainer = Messages.get().container( 849 Messages.GUI_ERR_FILE_PROP_MISSING_2, 850 name, 851 file); 852 return getMessage(msgContainer); 853 } else { 854 return defaultValue; 855 } 856 } 857 858 867 public boolean template(String element) { 868 869 return template(element, null, false); 870 } 871 872 882 public boolean template(String elementlist, boolean checkall) { 883 884 return template(null, elementlist, checkall); 885 } 886 887 898 public boolean template(String element, String elementlist, boolean checkall) { 899 900 if (isNotInitialized()) { 901 return true; 902 } 903 try { 904 return CmsJspTagTemplate.templateTagAction(element, elementlist, checkall, false, getRequest()); 905 } catch (Throwable t) { 906 handleException(t); 907 } 908 return true; 909 } 910 911 918 public String toAbsolute(String target) { 919 920 if (isNotInitialized()) { 921 return getMessage(NOT_INITIALIZED); 922 } 923 return CmsLinkManager.getAbsoluteUri(target, getController().getCurrentRequest().getElementUri()); 924 } 925 926 936 public String user(String property) { 937 938 if (isNotInitialized()) { 939 return getMessage(NOT_INITIALIZED); 940 } 941 try { 942 return CmsJspTagUser.userTagAction(property, getRequest()); 943 } catch (Throwable t) { 944 handleException(t); 945 } 946 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_USER_PROP_READ_1, property); 947 return getMessage(msgContainer); 948 } 949 } | Popular Tags |