📄 cmsjspactionelement.java
字号:
try {
if (file == null) file = CmsJspTagProperty.USE_URI;
switch (CmsJspTagProperty.m_actionValue.indexOf(file)) {
case 0: // USE_URI
case 1: // USE_PARENT
value = getCmsObject().readProperties(getRequestContext().getUri(), false);
break;
case 2: // USE_SEARCH
case 3: // USE_SEARCH_URI
case 4: // USE_SEARCH_PARENT
value = getCmsObject().readProperties(getRequestContext().getUri(), true);
break;
case 5: // USE_ELEMENT_URI
case 6: // USE_THIS
// Read properties of this file
value = getCmsObject().readProperties(m_controller.getCurrentRequest().getElementUri(), false);
break;
case 7: // USE_SEARCH_ELEMENT_URI
case 8: // USE_SEARCH_THIS
// Try to find property on this file and all parent folders
value = getCmsObject().readProperties(m_controller.getCurrentRequest().getElementUri(), true);
break;
default:
// Read properties of the file named in the attribute
value = getCmsObject().readProperties(toAbsolute(file), false);
}
} catch (Throwable t) {
handleException(t);
}
return value;
}
/**
* Returns an OpenCms or JVM system info property value, same as using
* the <code><cms:info property="..." /></code> tag.<p>
*
* See the description of the class {@link CmsJspTagInfo} for a detailed list
* of available options for the property value.<p>
*
* @param property the property to look up
* @return String the value of the system property
* @see com.opencms.flex.jsp.CmsJspTagInfo
*/
public String info(String property) {
try {
return CmsJspTagInfo.infoTagAction(property, m_request);
} catch (Throwable t) {
handleException(t);
}
return "+++ error reading info property '" + property + "' +++";
}
/**
* Returns an OpenCms workplace label.<p>
*
* You should consider using a standard
* {@link java.util.ResourceBundle java.util.ResourceBundle} instead of the
* OpenCms workplace language files.
*
* @param label the label to look up
* @return label the value of the label
*
* @see com.opencms.flex.jsp.CmsJspTagLabel
*/
public String label(String label) {
if (m_notInitialized) return C_NOT_INITIALIZED;
try {
return CmsJspTagLabel.wpLabelTagAction(label, m_request);
} catch (Throwable t) {
handleException(t);
}
return "+++ error reading workplace label '" + label + "' +++";
}
/**
* Checks if a template part should be used or not, same as using
* the <code><cms:template element="..." /></code> tag.<p>
*
* @param part the template element to check
* @return <code>true</code> if the element is active, <code>false</code> otherwise
*
* @see com.opencms.flex.jsp.CmsJspTagUser
*/
public boolean template(String element) {
if (m_notInitialized) return true;
try {
return CmsJspTagTemplate.templateTagAction(element, m_request);
} catch (Throwable t) {
handleException(t);
}
return true;
}
/**
* Returns the current request context from the internal CmsObject.
*
* @return the current request context from the internal CmsObject
*/
public CmsRequestContext getRequestContext() {
if (m_notInitialized) return null;
try {
return m_controller.getCmsObject().getRequestContext();
} catch (Throwable t) {
handleException(t);
}
return null;
}
/**
* Returns an initialized {@link CmsJspNavBuilder} instance.<p>
*
* @return CmsJspNavBuilder an initialized <code>CmsJspNavBuilder</code>
*
* @see com.opencms.flex.jsp.CmsJspNavBuilder
*/
public CmsJspNavBuilder getNavigation() {
if (m_notInitialized) return null;
try {
if (m_navigation == null) {
m_navigation = new CmsJspNavBuilder(m_controller.getCmsObject());
}
return m_navigation;
} catch (Throwable t) {
handleException(t);
}
return null;
}
/**
* Generates an initialized instance of {@link com.opencms.flex.util.CmsMessages} for
* convenient access to localized resource bundles.<p>
*
* @param bundleName the name of the ResourceBundle to use
* @param language language indentificator for the locale of the bundle
* @return CmsMessages a message bundle initialized with the provided values
*/
public CmsMessages getMessages(String bundleName, String language) {
return getMessages(bundleName, language, "", "", null);
}
/**
* Generates an initialized instance of {@link com.opencms.flex.util.CmsMessages} for
* convenient access to localized resource bundles.<p>
*
* @param bundleName the name of the ResourceBundle to use
* @param language language indentificator for the locale of the bundle
* @param defaultLanguage default for the language, will be used
* if language is null or empty String "", and defaultLanguage is not null
* @return CmsMessages a message bundle initialized with the provided values
*/
public CmsMessages getMessages(String bundleName, String language, String defaultLanguage) {
return getMessages(bundleName, language, "", "", defaultLanguage);
}
/**
* Generates an initialized instance of {@link com.opencms.flex.util.CmsMessages} for
* convenient access to localized resource bundles.<p>
*
* @param bundleName the name of the ResourceBundle to use
* @param language language indentificator for the locale of the bundle
* @param country 2 letter country code for the locale of the bundle
* @param variant a vendor or browser-specific variant code
* @param defaultLanguage default for the language, will be used
* if language is null or empty String "", and defaultLanguage is not null
* @return CmsMessages a message bundle initialized with the provided values
*
* @see java.util.ResourceBundle
* @see com.opencms.flex.util.CmsMessages
*/
public CmsMessages getMessages(String bundleName, String language, String country, String variant, String defaultLanguage) {
try {
if ((defaultLanguage != null) && ((language == null) || ("".equals(language)))) {
language = defaultLanguage;
}
if (language == null) language = "";
if (country == null) country = "";
if (variant == null) variant = "";
return new CmsMessages(bundleName, language, country, variant);
} catch (Throwable t) {
handleException(t);
}
return null;
}
/**
* Returns the processed output of an OpenCms resource in a String.<p>
*
* @param target the target to process
* @return the processed output of an OpenCms resource in a String
*/
public String getContent(String target) {
try {
I_CmsLauncher launcher = null;
target = toAbsolute(target);
try {
CmsResource resource = getCmsObject().readFileHeader(target);
launcher = getCmsObject().getLauncherManager().getLauncher(resource.getLauncherType());
} catch (java.lang.ClassCastException e) {
// no loader omplementation found
return "??? " + e.getMessage() + " ???";
} catch (com.opencms.core.CmsException e) {
// file might not exist or no read permissions
return "??? " + e.getMessage() + " ???";
}
try {
if (launcher instanceof CmsJspLoader) {
// jsp page
CmsJspTemplate template = new CmsJspTemplate();
byte[] res = template.getContent(getCmsObject(), target, null, null);
return new String(res, getRequestContext().getEncoding());
} else if (launcher instanceof CmsXmlLauncher) {
// XmlTemplate page (will not work if file does not use the standard XmlTemplate class)
CmsXmlTemplate template = new CmsXmlTemplate();
byte[] res = template.getContent(getCmsObject(), target, null, null);
return new String(res, getRequestContext().getEncoding());
} else if (launcher instanceof CmsDumpLauncher) {
// static page
CmsFile file = getCmsObject().readFile(target);
return new String(file.getContents(), getRequestContext().getEncoding());
} else if (launcher instanceof CmsLinkLauncher) {
// link
CmsFile file = getCmsObject().readFile(target);
return new String(file.getContents());
}
} catch (CmsException ce) {
return "??? " + ce.getMessage() + " ???";
} catch (UnsupportedEncodingException uee) {
return "??? " + uee.getMessage() + " ???";
}
} catch (Throwable t) {
handleException(t);
return "??? " + t.getMessage() + " ???";
}
return "";
}
/**
* Handles any exception that might occur in the context of this element to
* ensure that templates are not disturbed.<p>
*
* @param e the exception that was catched
*/
private void handleException(Throwable t) {
if (I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging(I_CmsLogChannels.C_FLEX_LOADER)) {
A_OpenCms.log(I_CmsLogChannels.C_FLEX_LOADER, Utils.getStackTrace(t));
}
if (! (m_handleExceptions || getRequestContext().currentProject().isOnlineProject())) {
if (DEBUG > 0) {
System.err.println("Exception in " + this.getClass().getName() + ":");
if (DEBUG > 1) t.printStackTrace(System.err);
}
throw new RuntimeException("Exception in " + this.getClass().getName(), t);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -