001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.jsp; 029 030import org.opencms.file.CmsFile; 031import org.opencms.flex.CmsFlexController; 032import org.opencms.i18n.CmsMessageContainer; 033import org.opencms.i18n.CmsMessages; 034import org.opencms.loader.CmsImageScaler; 035import org.opencms.loader.I_CmsResourceLoader; 036import org.opencms.main.CmsException; 037import org.opencms.main.OpenCms; 038import org.opencms.security.CmsSecurityException; 039import org.opencms.staticexport.CmsLinkManager; 040import org.opencms.util.CmsRequestUtil; 041import org.opencms.util.CmsStringUtil; 042import org.opencms.workplace.editors.directedit.CmsDirectEditJspIncludeProvider; 043import org.opencms.workplace.editors.directedit.CmsDirectEditMode; 044import org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider; 045 046import java.io.UnsupportedEncodingException; 047import java.util.HashMap; 048import java.util.Iterator; 049import java.util.Locale; 050import java.util.Map; 051import java.util.Map.Entry; 052 053import javax.servlet.http.HttpServletRequest; 054import javax.servlet.http.HttpServletResponse; 055import javax.servlet.jsp.JspException; 056import javax.servlet.jsp.PageContext; 057 058/** 059 * Bean to be used in JSP scriptlet code that provides direct 060 * access to the functionality offered by the OpenCms taglib.<p> 061 * 062 * By instantiating a bean of this type and accessing the methods provided by 063 * the instance, all functionality of the OpenCms JSP taglib can be easily 064 * used from within JSP scriptlet code.<p> 065 * 066 * Initialize this bean at the beginning of your JSP like this: 067 * <pre> 068 * <jsp:useBean id="cms" class="org.opencms.jsp.CmsJspActionElement"> 069 * <% cms.init(pageContext, request, response); %> 070 * </jsp:useBean> 071 * </pre> 072 * 073 * You can also access the current users <code>{@link org.opencms.file.CmsObject}</code> 074 * by using <code>{@link org.opencms.jsp.CmsJspBean#getCmsObject()}</code>.<p> 075 * 076 * All exceptions that occur when calling any method of this class are caught 077 * and written to the log output only, so that a template still has a chance of 078 * working at least in some elements.<p> 079 * 080 * @since 6.0.0 081 */ 082public class CmsJspActionElement extends CmsJspBean { 083 084 /** Error message in case bean was not properly initialized. */ 085 // cannot use a string: At class-loading time the 086 // user request context for localization is not at hand. 087 public static final CmsMessageContainer NOT_INITIALIZED = Messages.get().container( 088 Messages.GUI_ERR_ACTIONELEM_NOT_INIT_0); 089 090 /** JSP navigation builder. */ 091 private CmsJspNavBuilder m_vfsNav; 092 093 /** 094 * Empty constructor, required for every JavaBean. 095 */ 096 public CmsJspActionElement() { 097 098 super(); 099 } 100 101 /** 102 * Constructor, with parameters. 103 * 104 * @param context the JSP page context object 105 * @param req the JSP request 106 * @param res the JSP response 107 */ 108 public CmsJspActionElement(PageContext context, HttpServletRequest req, HttpServletResponse res) { 109 110 super(); 111 init(context, req, res); 112 } 113 114 /** 115 * Includes the direct edit scriptlet, same as 116 * using the <code><cms:editable /></code> tag.<p> 117 * 118 * The configured default direct edit provider is used.<p> 119 * 120 * @param isEditable include scriptlet only if true 121 * 122 * @throws JspException if something goes wrong 123 */ 124 public void editable(boolean isEditable) throws JspException { 125 126 if (isEditable) { 127 CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.AUTO, null); 128 } 129 } 130 131 /** 132 * Includes the direct edit scriptlet, same as 133 * using the <code><cms:editable file="..." /></code>tag.<p> 134 * 135 * For backward compatibility, this always uses the JSP include based direct edit provider<p>. 136 * 137 * @param isEditable include scriptlet only if true 138 * @param filename file with scriptlet code 139 * 140 * @throws JspException if something goes wrong 141 */ 142 public void editable(boolean isEditable, String filename) throws JspException { 143 144 if (isEditable) { 145 CmsJspTagEditable.editableTagAction( 146 getJspContext(), 147 CmsDirectEditJspIncludeProvider.class.getName(), 148 CmsDirectEditMode.AUTO, 149 filename); 150 } 151 } 152 153 /** 154 * Includes the direct edit scriptlet, same as 155 * using the <code><cms:editable provider="..." mode="..." file="..." /></code>tag.<p> 156 * 157 * @param provider the direct edit provider class name 158 * @param mode the direct edit mode to use 159 * @param filename file with scriptlet code (may be <code>null</code>) 160 * 161 * @throws JspException if something goes wrong 162 */ 163 public void editable(String provider, String mode, String filename) throws JspException { 164 165 CmsJspTagEditable.editableTagAction(getJspContext(), provider, CmsDirectEditMode.valueOf(mode), filename); 166 } 167 168 /** 169 * Insert the end HTML for the direct edit buttons in manual mode (if required).<p> 170 * 171 * Same as closing the <code></cms:editable</code> tag after opening one in manual mode.<p> 172 * 173 * @param needsClose result of {@link #editableManualOpen()} should be the value for this parameter 174 * 175 * @throws JspException if something goes wrong 176 */ 177 public void editableManualClose(boolean needsClose) throws JspException { 178 179 if (needsClose) { 180 CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.MANUAL, null); 181 } 182 } 183 184 /** 185 * Insert the start HTML for the direct edit buttons in manual mode.<p> 186 * 187 * Same as opening the <code><cms:editable mode="manual"></code> tag.<p> 188 * 189 * @return <code>true</code> if HTML was inserted that needs to be closed 190 * 191 * @throws JspException if something goes wrong 192 */ 193 public boolean editableManualOpen() throws JspException { 194 195 boolean result = false; 196 if (!CmsFlexController.isCmsOnlineRequest(getJspContext().getRequest())) { 197 // all this does NOT apply to the "online" project 198 I_CmsDirectEditProvider eb = CmsJspTagEditable.getDirectEditProvider(getJspContext()); 199 if ((eb != null)) { 200 // check if the provider support manual placement of buttons 201 if (eb.isManual(CmsDirectEditMode.MANUAL)) { 202 // the provider supports manual placement of buttons 203 result = true; 204 CmsJspTagEditable.editableTagAction(getJspContext(), null, CmsDirectEditMode.MANUAL, null); 205 } 206 } 207 } 208 return result; 209 } 210 211 /** 212 * Returns the processed output of an OpenCms resource in a String.<p> 213 * 214 * @param target the target to process 215 * @return the processed output of an OpenCms resource in a String 216 */ 217 public String getContent(String target) { 218 219 return getContent(target, null, null); 220 } 221 222 /** 223 * Returns the processed output of an element within an OpenCms resource.<p> 224 * 225 * @param target the target to process 226 * @param element name of the element 227 * @param locale locale of the element 228 * @return the processed output 229 */ 230 public String getContent(String target, String element, Locale locale) { 231 232 I_CmsResourceLoader loader; 233 CmsFile file; 234 target = toAbsolute(target); 235 236 try { 237 file = getCmsObject().readFile(target); 238 loader = OpenCms.getResourceManager().getLoader(file); 239 } catch (ClassCastException e) { 240 // no loader implementation found 241 return CmsMessages.formatUnknownKey(e.getMessage()); 242 } catch (CmsException e) { 243 // file might not exist or no read permissions 244 return CmsMessages.formatUnknownKey(e.getMessage()); 245 } 246 247 try { 248 byte[] result = loader.dump(getCmsObject(), file, element, locale, getRequest(), getResponse()); 249 return new String(result, getRequestContext().getEncoding()); 250 } catch (UnsupportedEncodingException uee) { 251 // encoding unsupported 252 return CmsMessages.formatUnknownKey(uee.getMessage()); 253 } catch (Throwable t) { 254 // any other exception, check for hidden root cause first 255 Throwable cause = CmsFlexController.getThrowable(getRequest()); 256 if (cause == null) { 257 cause = t; 258 } 259 handleException(cause); 260 return CmsMessages.formatUnknownKey(cause.getMessage()); 261 } 262 } 263 264 /** 265 * Generates an initialized instance of {@link CmsMessages} for 266 * convenient access to localized resource bundles.<p> 267 * 268 * @param bundleName the name of the ResourceBundle to use 269 * @param locale the locale to use for localization 270 * 271 * @return CmsMessages a message bundle initialized with the provided values 272 */ 273 public CmsMessages getMessages(String bundleName, Locale locale) { 274 275 return new CmsMessages(bundleName, locale); 276 } 277 278 /** 279 * Generates an initialized instance of {@link CmsMessages} for 280 * convenient access to localized resource bundles.<p> 281 * 282 * @param bundleName the name of the ResourceBundle to use 283 * @param language language identifier for the locale of the bundle 284 * @return CmsMessages a message bundle initialized with the provided values 285 */ 286 public CmsMessages getMessages(String bundleName, String language) { 287 288 return getMessages(bundleName, language, "", "", null); 289 } 290 291 /** 292 * Generates an initialized instance of {@link CmsMessages} for 293 * convenient access to localized resource bundles.<p> 294 * 295 * @param bundleName the name of the ResourceBundle to use 296 * @param language language identifier for the locale of the bundle 297 * @param defaultLanguage default for the language, will be used 298 * if language is null or empty String "", and defaultLanguage is not null 299 * @return CmsMessages a message bundle initialized with the provided values 300 */ 301 public CmsMessages getMessages(String bundleName, String language, String defaultLanguage) { 302 303 return getMessages(bundleName, language, "", "", defaultLanguage); 304 } 305 306 /** 307 * Generates an initialized instance of {@link CmsMessages} for 308 * convenient access to localized resource bundles.<p> 309 * 310 * @param bundleName the name of the ResourceBundle to use 311 * @param language language identifier for the locale of the bundle 312 * @param country 2 letter country code for the locale of the bundle 313 * @param variant a vendor or browser-specific variant code 314 * @param defaultLanguage default for the language, will be used 315 * if language is null or empty String "", and defaultLanguage is not null 316 * @return CmsMessages a message bundle initialized with the provided values 317 * 318 * @see java.util.ResourceBundle 319 * @see org.opencms.i18n.CmsMessages 320 */ 321 public CmsMessages getMessages( 322 String bundleName, 323 String language, 324 String country, 325 String variant, 326 String defaultLanguage) { 327 328 try { 329 if ((defaultLanguage != null) && CmsStringUtil.isEmpty(language)) { 330 language = defaultLanguage; 331 } 332 if (language == null) { 333 language = ""; 334 } 335 if (country == null) { 336 country = ""; 337 } 338 if (variant == null) { 339 variant = ""; 340 } 341 return getMessages(bundleName, new Locale(language, country, variant)); 342 } catch (Throwable t) { 343 handleException(t); 344 } 345 return null; 346 } 347 348 /** 349 * Returns an initialized {@link CmsJspNavBuilder} instance.<p> 350 * 351 * @return an initialized navigation builder instance 352 * 353 * @see org.opencms.jsp.CmsJspNavBuilder 354 */ 355 public CmsJspNavBuilder getNavigation() { 356 357 if (isNotInitialized()) { 358 return null; 359 } 360 if (m_vfsNav == null) { 361 m_vfsNav = new CmsJspNavBuilder(getCmsObject()); 362 } 363 return m_vfsNav; 364 } 365 366 /** 367 * Returns the current uri for the navigation.<p> 368 * 369 * @return the current uri for the navigation 370 */ 371 public String getNavigationUri() { 372 373 return getCmsObject().getRequestContext().getUri(); 374 } 375 376 /** 377 * Returns the HTML for an <code><img src="..." /></code> tag that includes the given image scaling parameters.<p> 378 * 379 * @param target the target URI of the file in the OpenCms VFS 380 * @param scaler the image scaler to use for scaling the image 381 * @param attributes a map of additional HTML attributes that are added to the output 382 * 383 * @return the HTML for an <code><img src></code> tag that includes the given image scaling parameters 384 */ 385 public String img(String target, CmsImageScaler scaler, Map<String, String> attributes) { 386 387 return img(target, scaler, attributes, false); 388 } 389 390 /** 391 * Returns the HTML for an <code><img src="..." /></code> tag that includes the given image scaling parameters.<p> 392 * 393 * @param target the target URI of the file in the OpenCms VFS 394 * @param scaler the image scaler to use for scaling the image 395 * @param attributes a map of additional HTML attributes that are added to the output 396 * @param partialTag if <code>true</code>, the opening <code><img</code> and closing <code> /></code> is omitted 397 * 398 * @return the HTML for an <code><img src></code> tag that includes the given image scaling parameters 399 */ 400 public String img(String target, CmsImageScaler scaler, Map<String, String> attributes, boolean partialTag) { 401 402 try { 403 return CmsJspTagImage.imageTagAction(target, scaler, attributes, partialTag, getRequest()); 404 } catch (Throwable t) { 405 handleException(t); 406 } 407 CmsMessageContainer msgContainer = Messages.get().container( 408 Messages.GUI_ERR_IMG_SCALE_2, 409 target, 410 scaler == null ? "null" : scaler.toString()); 411 return getMessage(msgContainer); 412 } 413 414 /** 415 * Include a sub-element without parameters from the OpenCms VFS, same as 416 * using the <code><cms:include file="***" /></code> tag.<p> 417 * 418 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 419 * @throws JspException in case there were problems including the target 420 * 421 * @see org.opencms.jsp.CmsJspTagInclude 422 */ 423 public void include(String target) throws JspException { 424 425 include(target, null, null); 426 } 427 428 /** 429 * Include a named sub-element without parameters from the OpenCms VFS, same as 430 * using the <code><cms:include file="***" element="***" /></code> tag.<p> 431 * 432 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 433 * @param element the element (template selector) to display from the target 434 * @throws JspException in case there were problems including the target 435 * 436 * @see org.opencms.jsp.CmsJspTagInclude 437 */ 438 public void include(String target, String element) throws JspException { 439 440 include(target, element, null); 441 } 442 443 /** 444 * Include a named sub-element without parameters from the OpenCms VFS, same as 445 * using the <code><cms:include file="***" element="***" /></code> tag.<p> 446 * 447 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 448 * @param element the element (template selector) to display from the target 449 * @param editable flag to indicate if direct edit should be enabled for the element 450 * @throws JspException in case there were problems including the target 451 * 452 * @see org.opencms.jsp.CmsJspTagInclude 453 */ 454 public void include(String target, String element, boolean editable) throws JspException { 455 456 include(target, element, editable, null); 457 } 458 459 /** 460 * Include a named sub-element with parameters from the OpenCms VFS, same as 461 * using the <code><cms:include file="***" element="***" /></code> tag 462 * with parameters in the tag body.<p> 463 * 464 * The parameter map should be a map where the keys are Strings 465 * (the parameter names) and the values are of type String[]. 466 * However, as a convenience feature, 467 * in case you provide just a String for the parameter value, 468 * it will automatically be translated to a String[1].<p> 469 * 470 * The handling of the <code>element</code> parameter depends on the 471 * included file type. Most often it is used as template selector.<p> 472 * 473 * <b>Important:</b> Exceptions that occur in the include process are NOT 474 * handled even if {@link #setSupressingExceptions(boolean)} was set to <code>true</code>. 475 * 476 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 477 * @param element the element (template selector) to display from the target 478 * @param editable flag to indicate if direct edit should be enabled for the element 479 * @param cacheable flag to indicate if the target should be cacheable in the Flex cache 480 * @param parameterMap a map of the request parameters 481 * @throws JspException in case there were problems including the target 482 * 483 * @see org.opencms.jsp.CmsJspTagInclude 484 */ 485 public void include(String target, String element, boolean editable, boolean cacheable, Map<String, ?> parameterMap) 486 throws JspException { 487 488 if (isNotInitialized()) { 489 return; 490 } 491 Map<String, String[]> modParameterMap = null; 492 if (parameterMap != null) { 493 try { 494 modParameterMap = new HashMap<String, String[]>(parameterMap.size()); 495 // ensure parameters are always of type String[] not just String 496 Iterator<?> i = parameterMap.entrySet().iterator(); 497 while (i.hasNext()) { 498 Map.Entry<String, ?> entry = (Entry<String, ?>)i.next(); 499 String key = entry.getKey(); 500 Object value = entry.getValue(); 501 if (value instanceof String[]) { 502 modParameterMap.put(key, (String[])value); 503 } else { 504 if (value == null) { 505 value = "null"; 506 } 507 String[] newValue = new String[] {value.toString()}; 508 modParameterMap.put(key, newValue); 509 } 510 } 511 } catch (UnsupportedOperationException e) { 512 // parameter map is immutable, just use it "as is" 513 } 514 } 515 CmsJspTagInclude.includeTagAction( 516 getJspContext(), 517 target, 518 element, 519 null, 520 editable, 521 cacheable, 522 modParameterMap, 523 CmsRequestUtil.getAtrributeMap(getRequest()), 524 getRequest(), 525 getResponse()); 526 } 527 528 /** 529 * Include a named sub-element with parameters from the OpenCms VFS, same as 530 * using the <code><cms:include file="***" element="***" /></code> tag 531 * with parameters in the tag body.<p> 532 * 533 * The parameter map should be a map where the keys are Strings 534 * (the parameter names) and the values are of type String[]. 535 * However, as a convenience feature, 536 * in case you provide just a String for the parameter value, 537 * it will automatically be translated to a String[1].<p> 538 * 539 * The handling of the <code>element</code> parameter depends on the 540 * included file type. Most often it is used as template selector.<p> 541 * 542 * <b>Important:</b> Exceptions that occur in the include process are NOT 543 * handled even if {@link #setSupressingExceptions(boolean)} was set to <code>true</code>. 544 * 545 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 546 * @param element the element (template selector) to display from the target 547 * @param editable flag to indicate if direct edit should be enabled for the element 548 * @param parameterMap a map of the request parameters 549 * @throws JspException in case there were problems including the target 550 * 551 * @see org.opencms.jsp.CmsJspTagInclude 552 */ 553 public void include(String target, String element, boolean editable, Map<String, ?> parameterMap) 554 throws JspException { 555 556 include(target, element, editable, true, parameterMap); 557 } 558 559 /** 560 * Include a named sub-element with parameters from the OpenCms VFS, same as 561 * using the <code><cms:include file="***" element="***" /></code> tag 562 * with parameters in the tag body.<p> 563 * 564 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 565 * @param element the element (template selector) to display from the target 566 * @param parameterMap a map of the request parameters 567 * @throws JspException in case there were problems including the target 568 * 569 * @see org.opencms.jsp.CmsJspTagInclude 570 */ 571 public void include(String target, String element, Map<String, ?> parameterMap) throws JspException { 572 573 include(target, element, false, parameterMap); 574 } 575 576 /** 577 * Includes a named sub-element suppressing all Exceptions that occur during the include, 578 * otherwise the same as using {@link #include(String, String, Map)}.<p> 579 * 580 * This is a convenience method that allows to include elements on a page without checking 581 * if they exist or not. If the target element does not exist, nothing is printed to 582 * the JSP output.<p> 583 * 584 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 585 * @param element the element (template selector) to display from the target 586 */ 587 public void includeSilent(String target, String element) { 588 589 try { 590 include(target, element, null); 591 } catch (Throwable t) { 592 // ignore 593 } 594 } 595 596 /** 597 * Includes a named sub-element suppressing all Exceptions that occur during the include, 598 * otherwise the same as using {@link #include(String, String, Map)}.<p> 599 * 600 * This is a convenience method that allows to include elements on a page without checking 601 * if they exist or not. If the target element does not exist, nothing is printed to 602 * the JSP output.<p> 603 * 604 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 605 * @param element the element (template selector) to display from the target 606 * @param editable flag to indicate if direct edit should be enabled for the element 607 */ 608 public void includeSilent(String target, String element, boolean editable) { 609 610 try { 611 include(target, element, editable, null); 612 } catch (Throwable t) { 613 // ignore 614 } 615 } 616 617 /** 618 * Includes a named sub-element suppressing all Exceptions that occur during the include, 619 * otherwise the same as using {@link #include(String, String, Map)}.<p> 620 * 621 * This is a convenience method that allows to include elements on a page without checking 622 * if they exist or not. If the target element does not exist, nothing is printed to 623 * the JSP output.<p> 624 * 625 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 626 * @param element the element (template selector) to display from the target 627 * @param editable flag to indicate if direct edit should be enabled for the element 628 * @param parameterMap a map of the request parameters 629 */ 630 public void includeSilent(String target, String element, boolean editable, Map<String, Object> parameterMap) { 631 632 try { 633 include(target, element, editable, parameterMap); 634 } catch (Throwable t) { 635 // ignore 636 } 637 } 638 639 /** 640 * Includes a named sub-element suppressing all Exceptions that occur during the include, 641 * otherwise the same as using {@link #include(String, String, Map)}.<p> 642 * 643 * This is a convenience method that allows to include elements on a page without checking 644 * if they exist or not. If the target element does not exist, nothing is printed to 645 * the JSP output.<p> 646 * 647 * @param target the target URI of the file in the OpenCms VFS (can be relative or absolute) 648 * @param element the element (template selector) to display from the target 649 * @param parameterMap a map of the request parameters 650 */ 651 public void includeSilent(String target, String element, Map<String, Object> parameterMap) { 652 653 try { 654 include(target, element, parameterMap); 655 } catch (Throwable t) { 656 // ignore 657 } 658 } 659 660 /** 661 * Returns an OpenCms or JVM system info property value, same as using 662 * the <code><cms:info property="***" /></code> tag.<p> 663 * 664 * See the description of the class {@link CmsJspTagInfo} for a detailed list 665 * of available options for the property value.<p> 666 * 667 * @param property the property to look up 668 * @return String the value of the system property 669 * @see org.opencms.jsp.CmsJspTagInfo 670 */ 671 public String info(String property) { 672 673 try { 674 return CmsJspTagInfo.infoTagAction(property, getRequest()); 675 } catch (Throwable t) { 676 handleException(t); 677 } 678 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_INFO_PROP_READ_1, property); 679 return getMessage(msgContainer); 680 } 681 682 /** 683 * Returns an OpenCms workplace label.<p> 684 * 685 * You should consider using a standard 686 * {@link java.util.ResourceBundle java.util.ResourceBundle} instead of the 687 * OpenCms workplace language files.<p> 688 * 689 * @param label the label to look up 690 * @return label the value of the label 691 * 692 * @see org.opencms.jsp.CmsJspTagLabel 693 */ 694 public String label(String label) { 695 696 if (isNotInitialized()) { 697 return getMessage(NOT_INITIALIZED); 698 } 699 try { 700 return CmsJspTagLabel.wpLabelTagAction(label, getRequest()); 701 } catch (Throwable t) { 702 handleException(t); 703 } 704 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_WORKPL_LABEL_READ_1, label); 705 return getMessage(msgContainer); 706 } 707 708 /** 709 * Returns a link to a file in the OpenCms VFS 710 * that has been adjusted according to the web application path and the 711 * OpenCms static export rules.<p> 712 * 713 * Please note that the target is always assumed to be in the OpenCms VFS, so you can't use 714 * this method for links external to OpenCms.<p> 715 * 716 * Relative links are converted to absolute links, using the current element URI as base.<p> 717 * 718 * This is the same as using the <code><cms:link>***</cms:link></code> tag.<p> 719 * 720 * @param target the URI in the OpenCms VFS to link to 721 * 722 * @return the translated link 723 * 724 * @see org.opencms.jsp.CmsJspTagLink 725 * @see #link(String, String) 726 */ 727 public String link(String target) { 728 729 return link(target, null); 730 } 731 732 /** 733 * Returns a link to a file in the OpenCms VFS 734 * that has been adjusted according to the web application path and the 735 * OpenCms static export rules.<p> 736 * 737 * Please note that the target is always assumed to be in the OpenCms VFS, so you can't use 738 * this method for links external to OpenCms.<p> 739 * 740 * Relative links are converted to absolute links, using the current element URI as base.<p> 741 * 742 * This is the same as using the <code><cms:link baseUri="..." >***</cms:link></code> tag.<p> 743 * 744 * @param target the URI in the OpenCms VFS to link to 745 * @param baseUri the optional alternative base URI 746 * 747 * @return the translated link 748 * 749 * @see org.opencms.jsp.CmsJspTagLink 750 * @see #link(String) 751 */ 752 public String link(String target, String baseUri) { 753 754 if (isNotInitialized()) { 755 return getMessage(NOT_INITIALIZED); 756 } 757 try { 758 return CmsJspTagLink.linkTagAction(target, getRequest(), baseUri); 759 } catch (Throwable t) { 760 handleException(t); 761 } 762 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_GEN_LINK_1, target); 763 return getMessage(msgContainer); 764 } 765 766 /** 767 * Returns all properties of the current file.<p> 768 * 769 * @return Map all properties of the current file 770 */ 771 public Map<String, String> properties() { 772 773 return properties(null); 774 } 775 776 /** 777 * Returns all properties of the selected file.<p> 778 * 779 * Please see the description of the class {@link org.opencms.jsp.CmsJspTagProperty} for 780 * valid options of the <code>file</code> parameter.<p> 781 * 782 * @param file the file (or folder) to look at for the properties 783 * @return Map all properties of the current file 784 * (and optional of the folders containing the file) 785 * 786 * @see org.opencms.jsp.CmsJspTagProperty 787 */ 788 public Map<String, String> properties(String file) { 789 790 Map<String, String> props = new HashMap<String, String>(); 791 if (isNotInitialized()) { 792 return props; 793 } 794 try { 795 props = CmsJspTagProperty.propertiesTagAction(file, getRequest()); 796 } catch (Throwable t) { 797 handleException(t); 798 } 799 return props; 800 } 801 802 /** 803 * Returns a selected file property value, same as using 804 * the <code><cms:property name="***" /></code> tag or 805 * calling {@link #property(String, String, String, boolean)}.<p> 806 * 807 * @param name the name of the property to look for 808 * @return the value of the property found, or null if the property could not be found 809 * 810 * @see #property(String, String, String, boolean) 811 * @see org.opencms.jsp.CmsJspTagProperty 812 */ 813 public String property(String name) { 814 815 return property(name, null, null, false); 816 } 817 818 /** 819 * Returns a selected file property value, same as using 820 * the <code><cms:property name="***" file="***" /></code> tag or 821 * calling {@link #property(String, String, String, boolean)}.<p> 822 * 823 * @param name the name of the property to look for 824 * @param file the file (or folder) to look at for the property 825 * @return the value of the property found, or null if the property could not be found 826 * 827 * @see #property(String, String, String, boolean) 828 * @see org.opencms.jsp.CmsJspTagProperty 829 */ 830 public String property(String name, String file) { 831 832 return property(name, file, null, false); 833 } 834 835 /** 836 * Returns a selected file property value, same as using 837 * the <code><cms:property name="***" file="***" default="***" /></code> tag or 838 * calling {@link #property(String, String, String, boolean)}.<p> 839 * 840 * @param name the name of the property to look for 841 * @param file the file (or folder) to look at for the property 842 * @param defaultValue a default value in case the property was not found 843 * @return the value of the property found, or the value of defaultValue 844 * if the property could not be found 845 * 846 * @see #property(String, String, String, boolean) 847 * @see org.opencms.jsp.CmsJspTagProperty 848 */ 849 public String property(String name, String file, String defaultValue) { 850 851 return property(name, file, defaultValue, false); 852 } 853 854 /** 855 * Returns a selected file property value with optional HTML escaping, same as using 856 * the <code><cms:property name="***" file="***" default="***" /></code> tag.<p> 857 * 858 * Please see the description of the class {@link org.opencms.jsp.CmsJspTagProperty} for 859 * valid options of the <code>file</code> parameter.<p> 860 * 861 * @param name the name of the property to look for 862 * @param file the file (or folder) to look at for the property 863 * @param defaultValue a default value in case the property was not found 864 * @param escapeHtml if <code>true</code>, special HTML characters in the return value 865 * are escaped with their number representations (e.g. & becomes &#38;) 866 * @return the value of the property found, or the value of defaultValue 867 * if the property could not be found 868 * 869 * @see org.opencms.jsp.CmsJspTagProperty 870 */ 871 public String property(String name, String file, String defaultValue, boolean escapeHtml) { 872 873 if (isNotInitialized()) { 874 return getMessage(NOT_INITIALIZED); 875 } 876 try { 877 if (file == null) { 878 file = getController().getCmsObject().getRequestContext().getUri(); 879 } 880 return CmsJspTagProperty.propertyTagAction(name, file, defaultValue, escapeHtml, getRequest()); 881 } catch (CmsSecurityException e) { 882 if (defaultValue == null) { 883 handleException(e); 884 } 885 } catch (Throwable t) { 886 handleException(t); 887 } 888 if (defaultValue == null) { 889 CmsMessageContainer msgContainer = Messages.get().container( 890 Messages.GUI_ERR_FILE_PROP_MISSING_2, 891 name, 892 file); 893 return getMessage(msgContainer); 894 } else { 895 return defaultValue; 896 } 897 } 898 899 /** 900 * Checks if a template part should be used or not, same as using 901 * the <code><cms:template element="***" /></code> tag.<p> 902 * 903 * @param element the template element to check 904 * @return <code>true</code> if the element is active, <code>false</code> otherwise 905 * 906 * @see org.opencms.jsp.CmsJspTagUser 907 */ 908 public boolean template(String element) { 909 910 return template(element, null, false); 911 } 912 913 /** 914 * Checks if a template part should be used or not, same as using 915 * the <code><cms:template ifexists="***" /></code> tag.<p> 916 * 917 * @param elementlist the list of elements to check 918 * @param checkall <code>true</code> if all elements in the list should be checked 919 * @return <code>true</code> if the elements available, <code>false</code> otherwise 920 * 921 * @see org.opencms.jsp.CmsJspTagUser 922 */ 923 public boolean template(String elementlist, boolean checkall) { 924 925 return template(null, elementlist, checkall); 926 } 927 928 /** 929 * Checks if a template part should be used or not, same as using 930 * the <code><cms:template element="***" ifexists="***" /></code> tag.<p> 931 * 932 * @param element the template element to check 933 * @param elementlist the list of elements to check 934 * @param checkall <code>true</code> if all elements in the list should be checked 935 * @return <code>true</code> if the element is active, <code>false</code> otherwise 936 * 937 * @see org.opencms.jsp.CmsJspTagUser 938 */ 939 public boolean template(String element, String elementlist, boolean checkall) { 940 941 if (isNotInitialized()) { 942 return true; 943 } 944 try { 945 return CmsJspTagTemplate.templateTagAction(element, elementlist, checkall, false, getRequest()); 946 } catch (Throwable t) { 947 handleException(t); 948 } 949 return true; 950 } 951 952 /** 953 * Converts a relative URI in the OpenCms VFS to an absolute one based on 954 * the location of the currently processed OpenCms URI.<p> 955 * 956 * @param target the relative URI to convert 957 * @return the target URI converted to an absolute one 958 */ 959 public String toAbsolute(String target) { 960 961 if (isNotInitialized()) { 962 return getMessage(NOT_INITIALIZED); 963 } 964 return CmsLinkManager.getAbsoluteUri(target, getController().getCurrentRequest().getElementUri()); 965 } 966 967 /** 968 * Returns a selected user property, i.e. information about the currently 969 * logged in user, same as using 970 * the <code><cms:user property="***" /></code> tag.<p> 971 * 972 * @param property the user property to display, please see the tag documentation for valid options 973 * @return the value of the selected user property 974 * 975 * @see org.opencms.jsp.CmsJspTagUser 976 */ 977 public String user(String property) { 978 979 if (isNotInitialized()) { 980 return getMessage(NOT_INITIALIZED); 981 } 982 try { 983 return CmsJspTagUser.userTagAction(property, getRequest()); 984 } catch (Throwable t) { 985 handleException(t); 986 } 987 CmsMessageContainer msgContainer = Messages.get().container(Messages.GUI_ERR_USER_PROP_READ_1, property); 988 return getMessage(msgContainer); 989 } 990}