📄 cmsxmllauncher.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/launcher/Attic/CmsXmlLauncher.java,v $
* Date : $Date: 2003/02/26 10:30:36 $
* Version: $Revision: 1.44 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.launcher;
import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.I_CmsRequest;
import com.opencms.file.CmsFile;
import com.opencms.file.CmsObject;
import com.opencms.template.CmsXmlControlFile;
import com.opencms.template.I_CmsTemplate;
import com.opencms.template.I_CmsXmlTemplate;
import com.opencms.template.cache.CmsElementCache;
import com.opencms.template.cache.CmsElementDefinition;
import com.opencms.template.cache.CmsElementDefinitionCollection;
import com.opencms.template.cache.CmsElementDescriptor;
import com.opencms.template.cache.CmsUri;
import com.opencms.template.cache.CmsUriDescriptor;
import com.opencms.template.cache.CmsUriLocator;
import com.opencms.util.Utils;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.http.HttpServletRequest;
/**
* OpenCms launcher class for XML templates.<p>
*
* This can be used generating output for XML body files using XML template and
* subtemplate technology.<p>
*
* The selected body should define a start template class using <BR> <CODE>
* <PAGE><BR>
* <CLASS>...</CLASS><BR>
* </PAGE></CODE><p>
*
* If no start template is defined, the class given by the parameters
* will be used.
* If even this is not defined, CmsXmlTemplate will
* be used to create output.<p>
*
* @author Alexander Lucas
* @version $Revision: 1.44 $ $Date: 2003/02/26 10:30:36 $
*/
public class CmsXmlLauncher extends A_CmsLauncher implements I_CmsLogChannels, I_CmsConstants {
/** Magic elemet replace name */
public static final String C_ELEMENT_REPLACE = "_CMS_ELEMENTREPLACE";
/**
* Starts generating the output.
* Calls the canonical root with the appropriate template class.
*
* @param cms CmsObject Object for accessing system resources
* @param file CmsFile Object with the selected resource to be shown
* @param startTemplateClass Name of the template class to start with.
* @throws CmsException
*/
protected byte[] generateOutput(CmsObject cms, CmsFile file, String startTemplateClass, I_CmsRequest req) throws CmsException {
byte[] output = null;
// Hashtable for collecting all parameters.
Hashtable newParameters = new Hashtable();
// Parameters used for element cache
boolean elementCacheEnabled = cms.getRequestContext().isElementCacheEnabled();
CmsElementCache elementCache = null;
String uri = cms.getRequestContext().getUri();
CmsUriDescriptor uriDesc = null;
CmsUriLocator uriLoc = null;
CmsUri cmsUri = null;
String templateClass = null;
String templateName = null;
CmsXmlControlFile doc = null;
if(elementCacheEnabled) {
// Get the global element cache object
elementCache = cms.getRequestContext().getElementCache();
// Prepare URI Locator
uriDesc = new CmsUriDescriptor(uri);
uriLoc = elementCache.getUriLocator();
cmsUri = uriLoc.get(uriDesc);
}
// check if printversion is requested
String replace = req.getParameter(C_ELEMENT_REPLACE);
boolean elementreplace = false;
CmsElementDefinition replaceDef = null;
if(replace != null){
int index = replace.indexOf(":");
if(index != -1){
elementreplace = true;
cmsUri = null;
replaceDef = new CmsElementDefinition(replace.substring(0,index),
"com.opencms.template.CmsXmlTemplate",
replace.substring(index+1), null, new Hashtable());
}
}
if(cmsUri == null || !elementCacheEnabled) {
// Entry point to page file analysis.
// For performance reasons this should only be done if the element
// cache is not activated or if it's activated but no URI object could be found.
// Parse the page file
try {
doc = new CmsXmlControlFile(cms, file);
}
catch(Exception e) {
// there was an error while parsing the document.
// No chance to go on here.
handleException(cms, e, "There was an error while parsing XML page file " + file.getAbsolutePath());
return "".getBytes();
}
if (! elementCacheEnabled && (replaceDef != null)) {
// Required to enable element replacement if element cache is disabled
doc.setElementClass(replaceDef.getName(), replaceDef.getClassName());
doc.setElementTemplate(replaceDef.getName(), replaceDef.getTemplateName());
}
// Get the names of the master template and the template class from
// the parsed page file. Fall back to default value, if template class
// is not defined
templateClass = doc.getTemplateClass();
if(templateClass == null || "".equals(templateClass)) {
templateClass = startTemplateClass;
}
if(templateClass == null || "".equals(templateClass)) {
templateClass = "com.opencms.template.CmsXmlTemplate";
}
templateName = doc.getMasterTemplate();
if(templateName != null && !"".equals(templateName)){
templateName = Utils.mergeAbsolutePath(file.getAbsolutePath(), templateName);
}
// Previously, the template class was loaded here.
// We avoid doing this so early, since in element cache mode the template
// class is not needed here.
// Now look for parameters in the page file...
// ... first the params of the master template...
Enumeration masterTemplateParams = doc.getParameterNames();
while(masterTemplateParams.hasMoreElements()) {
String paramName = (String)masterTemplateParams.nextElement();
String paramValue = doc.getParameter(paramName);
newParameters.put(C_ROOT_TEMPLATE_NAME + "." + paramName, paramValue);
}
// ... and now the params of all subtemplates
Enumeration elementDefinitions = doc.getElementDefinitions();
while(elementDefinitions.hasMoreElements()) {
String elementName = (String)elementDefinitions.nextElement();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -