下面列出了javax.servlet.jsp.tagext.JspTag#org.apache.jasper.Constants 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void init(ServletConfig config) {
int maxSize = -1;
String maxSizeS = getOption(config, OPTION_MAXSIZE, null);
if (maxSizeS != null) {
try {
maxSize = Integer.parseInt(maxSizeS);
} catch (Exception ex) {
maxSize = -1;
}
}
if (maxSize < 0) {
maxSize = Constants.MAX_POOL_SIZE;
}
this.handlers = new Tag[maxSize];
this.current = -1;
instanceManager = InstanceManagerFactory.getInstanceManager(config);
}
/**
* Convert a binary class name into a canonical one that can be used
* when generating Java source code.
*
* @param className Binary class name
* @return Canonical equivalent
*/
private String getCanonicalName(String className) throws JasperException {
Class<?> clazz;
ClassLoader tccl;
if (Constants.IS_SECURITY_ENABLED) {
PrivilegedAction<ClassLoader> pa = new PrivilegedGetTccl();
tccl = AccessController.doPrivileged(pa);
} else {
tccl = Thread.currentThread().getContextClassLoader();
}
try {
clazz = Class.forName(className, false, tccl);
} catch (ClassNotFoundException e) {
throw new JasperException(e);
}
return clazz.getCanonicalName();
}
public TldCache(ServletContext servletContext,
Map<String, TldResourcePath> uriTldResourcePathMap,
Map<TldResourcePath, TaglibXml> tldResourcePathTaglibXmlMap) {
this.servletContext = servletContext;
this.uriTldResourcePathMap.putAll(uriTldResourcePathMap);
for (Entry<TldResourcePath, TaglibXml> entry : tldResourcePathTaglibXmlMap.entrySet()) {
TldResourcePath tldResourcePath = entry.getKey();
long lastModified[] = getLastModified(tldResourcePath);
TaglibXmlCacheEntry cacheEntry = new TaglibXmlCacheEntry(
entry.getValue(), lastModified[0], lastModified[1]);
this.tldResourcePathTaglibXmlMap.put(tldResourcePath, cacheEntry);
}
boolean validate = Boolean.parseBoolean(
servletContext.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM));
String blockExternalString = servletContext.getInitParameter(
Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
boolean blockExternal;
if (blockExternalString == null) {
blockExternal = true;
} else {
blockExternal = Boolean.parseBoolean(blockExternalString);
}
tldParser = new TldParser(true, validate, blockExternal);
}
private void writeNewInstance(String tagHandlerVar, String tagHandlerClassName) {
out.printin(tagHandlerClassName);
out.print(" ");
out.print(tagHandlerVar);
out.print(" = ");
if (Constants.USE_INSTANCE_MANAGER_FOR_TAGS) {
out.print("(");
out.print(tagHandlerClassName);
out.print(")");
out.print("_jsp_getInstanceManager().newInstance(\"");
out.print(tagHandlerClassName);
out.println("\", this.getClass().getClassLoader());");
} else {
out.print("new ");
out.print(tagHandlerClassName);
out.println("();");
out.printin("_jsp_getInstanceManager().newInstance(");
out.print(tagHandlerVar);
out.println(");");
}
}
PageInfo(BeanRepository beanRepository, String jspFile, boolean isTagFile) {
this.isTagFile = isTagFile;
this.jspFile = jspFile;
this.beanRepository = beanRepository;
this.varInfoNames = new HashSet<>();
this.taglibsMap = new HashMap<>();
this.jspPrefixMapper = new HashMap<>();
this.xmlPrefixMapper = new HashMap<>();
this.nonCustomTagPrefixMap = new HashMap<>();
this.imports = new Vector<>();
this.dependants = new HashMap<>();
this.includePrelude = new Vector<>();
this.includeCoda = new Vector<>();
this.pluginDcls = new Vector<>();
this.prefixes = new HashSet<>();
// Enter standard imports
imports.addAll(Constants.STANDARD_IMPORTS);
}
@Override
protected void init(ServletConfig config) {
maxSize = Constants.MAX_POOL_SIZE;
String maxSizeS = getOption(config, OPTION_MAXSIZE, null);
if (maxSizeS != null) {
maxSize = Integer.parseInt(maxSizeS);
if (maxSize < 0) {
maxSize = Constants.MAX_POOL_SIZE;
}
}
perThread = new ThreadLocal<PerThreadData>() {
@Override
protected PerThreadData initialValue() {
PerThreadData ptd = new PerThreadData();
ptd.handlers = new Tag[maxSize];
ptd.current = -1;
perThreadDataVector.addElement(ptd);
return ptd;
}
};
}
public static void introspecthelper(Object bean, String prop,
String value, ServletRequest request,
String param, boolean ignoreMethodNF)
throws JasperException
{
if( Constants.IS_SECURITY_ENABLED ) {
try {
PrivilegedIntrospectHelper dp =
new PrivilegedIntrospectHelper(
bean,prop,value,request,param,ignoreMethodNF);
AccessController.doPrivileged(dp);
} catch( PrivilegedActionException pe) {
Exception e = pe.getException();
throw (JasperException)e;
}
} else {
internalIntrospecthelper(
bean,prop,value,request,param,ignoreMethodNF);
}
}
/**
* Convert a binary class name into a canonical one that can be used
* when generating Java source code.
*
* @param className Binary class name
* @return Canonical equivalent
*/
private String getCanonicalName(String className) throws JasperException {
Class<?> clazz;
ClassLoader tccl;
if (Constants.IS_SECURITY_ENABLED) {
PrivilegedAction<ClassLoader> pa = new PrivilegedGetTccl();
tccl = AccessController.doPrivileged(pa);
} else {
tccl = Thread.currentThread().getContextClassLoader();
}
try {
clazz = Class.forName(className, false, tccl);
} catch (ClassNotFoundException e) {
throw new JasperException(e);
}
return clazz.getCanonicalName();
}
protected void init( ServletConfig config ) {
int maxSize=-1;
String maxSizeS=getOption(config, OPTION_MAXSIZE, null);
if( maxSizeS != null ) {
try {
maxSize=Integer.parseInt(maxSizeS);
} catch( Exception ex) {
maxSize=-1;
}
}
if( maxSize <0 ) {
maxSize=Constants.MAX_POOL_SIZE;
}
this.handlers = new JspTag[maxSize];
this.current = -1;
this.resourceInjector = (ResourceInjector)
config.getServletContext().getAttribute(
Constants.JSP_RESOURCE_INJECTOR_CONTEXT_ATTRIBUTE);
}
private void writeNewInstance(String tagHandlerVar, String tagHandlerClassName) {
if (Constants.USE_INSTANCE_MANAGER_FOR_TAGS) {
out.printin(tagHandlerClassName);
out.print(" ");
out.print(tagHandlerVar);
out.print(" = (");
out.print(tagHandlerClassName);
out.print(")");
out.print("_jsp_getInstanceManager().newInstance(\"");
out.print(tagHandlerClassName);
out.println("\", this.getClass().getClassLoader());");
} else {
out.printin(tagHandlerClassName);
out.print(" ");
out.print(tagHandlerVar);
out.print(" = (");
out.print("new ");
out.print(tagHandlerClassName);
out.println("());");
out.printin("_jsp_getInstanceManager().newInstance(");
out.print(tagHandlerVar);
out.println(");");
}
}
PageInfo(BeanRepository beanRepository, String jspFile, boolean isTagFile) {
this.isTagFile = isTagFile;
this.jspFile = jspFile;
this.beanRepository = beanRepository;
this.varInfoNames = new HashSet<String>();
this.taglibsMap = new HashMap<String, TagLibraryInfo>();
this.jspPrefixMapper = new HashMap<String, String>();
this.xmlPrefixMapper = new HashMap<String, LinkedList<String>>();
this.nonCustomTagPrefixMap = new HashMap<String, Mark>();
this.imports = new Vector<String>();
this.dependants = new HashMap<String,Long>();
this.includePrelude = new Vector<String>();
this.includeCoda = new Vector<String>();
this.pluginDcls = new Vector<String>();
this.prefixes = new HashSet<String>();
// Enter standard imports
imports.addAll(Constants.STANDARD_IMPORTS);
}
@Override
protected void init(ServletConfig config) {
maxSize = Constants.MAX_POOL_SIZE;
String maxSizeS = getOption(config, OPTION_MAXSIZE, null);
if (maxSizeS != null) {
maxSize = Integer.parseInt(maxSizeS);
if (maxSize < 0) {
maxSize = Constants.MAX_POOL_SIZE;
}
}
perThread = new ThreadLocal<PerThreadData>() {
@Override
protected PerThreadData initialValue() {
PerThreadData ptd = new PerThreadData();
ptd.handlers = new Tag[maxSize];
ptd.current = -1;
perThreadDataVector.addElement(ptd);
return ptd;
}
};
}
protected void init(ServletConfig config) {
int maxSize = -1;
String maxSizeS = getOption(config, OPTION_MAXSIZE, null);
if (maxSizeS != null) {
try {
maxSize = Integer.parseInt(maxSizeS);
} catch (Exception ex) {
maxSize = -1;
}
}
if (maxSize < 0) {
maxSize = Constants.MAX_POOL_SIZE;
}
this.handlers = new Tag[maxSize];
this.current = -1;
instanceManager = InstanceManagerFactory.getInstanceManager(config);
}
PageInfo(BeanRepository beanRepository, String jspFile, boolean isTagFile) {
this.isTagFile = isTagFile;
this.jspFile = jspFile;
this.beanRepository = beanRepository;
this.varInfoNames = new HashSet<String>();
this.taglibsMap = new HashMap<String, TagLibraryInfo>();
this.jspPrefixMapper = new HashMap<String, String>();
this.xmlPrefixMapper = new HashMap<String, LinkedList<String>>();
this.nonCustomTagPrefixMap = new HashMap<String, Mark>();
this.imports = new Vector<String>();
this.dependants = new HashMap<String,Long>();
this.includePrelude = new Vector<String>();
this.includeCoda = new Vector<String>();
this.pluginDcls = new Vector<String>();
this.prefixes = new HashSet<String>();
// Enter standard imports
imports.addAll(Constants.STANDARD_IMPORTS);
}
@Override
public PageContext getPageContext(Servlet servlet, ServletRequest request,
ServletResponse response, String errorPageURL, boolean needsSession,
int bufferSize, boolean autoflush) {
if( Constants.IS_SECURITY_ENABLED ) {
PrivilegedGetPageContext dp = new PrivilegedGetPageContext(
this, servlet, request, response, errorPageURL,
needsSession, bufferSize, autoflush);
return AccessController.doPrivileged(dp);
} else {
return internalGetPageContext(servlet, request, response,
errorPageURL, needsSession,
bufferSize, autoflush);
}
}
/**
* Return the <code>SecurityManager</code> only if Security is enabled AND
* package protection mechanism is enabled.
* @return <code>true</code> if package protection is enabled
*/
public static boolean isPackageProtectionEnabled(){
if (packageDefinitionEnabled && Constants.IS_SECURITY_ENABLED){
return true;
}
return false;
}
@Override
public void onStartup(Set<Class<?>> types, ServletContext context) throws ServletException {
if (log.isDebugEnabled()) {
log.debug(Localizer.getMessage(MSG + ".onStartup", context.getServletContextName()));
}
// Setup a simple default Instance Manager
if (context.getAttribute(InstanceManager.class.getName())==null) {
context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
}
boolean validate = Boolean.parseBoolean(
context.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM));
String blockExternalString = context.getInitParameter(
Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
boolean blockExternal;
if (blockExternalString == null) {
blockExternal = true;
} else {
blockExternal = Boolean.parseBoolean(blockExternalString);
}
// scan the application for TLDs
TldScanner scanner = newTldScanner(context, true, validate, blockExternal);
try {
scanner.scan();
} catch (IOException | SAXException e) {
throw new ServletException(e);
}
// add any listeners defined in TLDs
for (String listener : scanner.getListeners()) {
context.addListener(listener);
}
context.setAttribute(TldCache.SERVLET_CONTEXT_ATTRIBUTE_NAME,
new TldCache(context, scanner.getUriTldResourcePathMap(),
scanner.getTldResourcePathTaglibXmlMap()));
}
/**
* Create a new instance of this ServletContext implementation.
*
* @param aLogWriter PrintWriter which is used for <code>log()</code> calls
* @param aResourceBaseURL Resource base URL
* @param classLoader Class loader for this {@link ServletContext}
* @param validate Should a validating parser be used to parse web.xml?
* @param blockExternal Should external entities be blocked when parsing
* web.xml?
* @throws JasperException An error occurred building the merged web.xml
*/
public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL,
ClassLoader classLoader, boolean validate, boolean blockExternal)
throws JasperException {
myAttributes = new HashMap<>();
myParameters.put(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM,
String.valueOf(blockExternal));
myLogWriter = aLogWriter;
myResourceBaseURL = aResourceBaseURL;
this.loader = classLoader;
this.webXml = buildMergedWebXml(validate, blockExternal);
jspConfigDescriptor = webXml.getJspConfigDescriptor();
}
/**
* Gets the next available tag handler from this tag handler pool,
* instantiating one if this tag handler pool is empty.
*
* @param handlerClass
* Tag handler class
* @return Reused or newly instantiated tag handler
* @throws JspException
* if a tag handler cannot be instantiated
*/
public Tag get(Class<? extends Tag> handlerClass) throws JspException {
Tag handler;
synchronized (this) {
if (current >= 0) {
handler = handlers[current--];
return handler;
}
}
// Out of sync block - there is no need for other threads to
// wait for us to construct a tag for this thread.
try {
if (Constants.USE_INSTANCE_MANAGER_FOR_TAGS) {
return (Tag) instanceManager.newInstance(
handlerClass.getName(), handlerClass.getClassLoader());
} else {
Tag instance = handlerClass.getConstructor().newInstance();
instanceManager.newInstance(instance);
return instance;
}
} catch (Exception e) {
Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(t);
throw new JspException(e.getMessage(), t);
}
}
@Override
public void releasePageContext(PageContext pc) {
if( pc == null )
return;
if( Constants.IS_SECURITY_ENABLED ) {
PrivilegedReleasePageContext dp = new PrivilegedReleasePageContext(
this,pc);
AccessController.doPrivileged(dp);
} else {
internalReleasePageContext(pc);
}
}
@Override
public JspApplicationContext getJspApplicationContext(
final ServletContext context) {
if (Constants.IS_SECURITY_ENABLED) {
return AccessController.doPrivileged(
new PrivilegedAction<JspApplicationContext>() {
@Override
public JspApplicationContext run() {
return JspApplicationContextImpl.getInstance(context);
}
});
} else {
return JspApplicationContextImpl.getInstance(context);
}
}
public static ELResolver getDefaultResolver(ExpressionFactory factory) {
if (Constants.IS_SECURITY_ENABLED) {
CompositeELResolver defaultResolver = new CompositeELResolver();
defaultResolver.add(factory.getStreamELResolver());
defaultResolver.add(new StaticFieldELResolver());
defaultResolver.add(new MapELResolver());
defaultResolver.add(new ResourceBundleELResolver());
defaultResolver.add(new ListELResolver());
defaultResolver.add(new ArrayELResolver());
defaultResolver.add(new BeanELResolver());
return defaultResolver;
} else {
return DefaultResolver;
}
}
public JspDocumentParser(
ParserController pc,
String path,
boolean isTagFile,
boolean directivesOnly) {
this.parserController = pc;
this.ctxt = pc.getJspCompilationContext();
this.pageInfo = pc.getCompiler().getPageInfo();
this.err = pc.getCompiler().getErrorDispatcher();
this.path = path;
this.isTagFile = isTagFile;
this.directivesOnly = directivesOnly;
this.isTop = true;
String blockExternalString = ctxt.getServletContext().getInitParameter(
Constants.XML_BLOCK_EXTERNAL_INIT_PARAM);
boolean blockExternal;
if (blockExternalString == null) {
blockExternal = true;
} else {
blockExternal = Boolean.parseBoolean(blockExternalString);
}
this.entityResolver = new LocalResolver(
DigesterFactory.SERVLET_API_PUBLIC_IDS,
DigesterFactory.SERVLET_API_SYSTEM_IDS,
blockExternal);
}
private static String getClassNameBase(String urn) {
StringBuilder base =
new StringBuilder(Constants.TAG_FILE_PACKAGE_NAME + ".meta.");
if (urn != null) {
base.append(makeJavaPackage(urn));
base.append('.');
}
return base.toString();
}
/**
* Generates a new temporary variable name.
*
* @return The name to use for the temporary variable
*/
public String nextTemporaryVariableName() {
if (parentRoot == null) {
return Constants.TEMP_VARIABLE_NAME_PREFIX + (tempSequenceNumber++);
} else {
return parentRoot.nextTemporaryVariableName();
}
}
/**
* Method used to initialize classpath for compiles.
* @return the compilation classpath
*/
private String initClassPath() {
StringBuilder cpath = new StringBuilder();
if (parentClassLoader instanceof URLClassLoader) {
URL [] urls = ((URLClassLoader)parentClassLoader).getURLs();
for (int i = 0; i < urls.length; i++) {
// Tomcat can use URLs other than file URLs. However, a protocol
// other than file: will generate a bad file system path, so
// only add file: protocol URLs to the classpath.
if (urls[i].getProtocol().equals("file") ) {
try {
// Need to decode the URL, primarily to convert %20
// sequences back to spaces
String decoded = urls[i].toURI().getPath();
cpath.append(decoded + File.pathSeparator);
} catch (URISyntaxException e) {
log.warn(Localizer.getMessage("jsp.warning.classpathUrl"), e);
}
}
}
}
cpath.append(options.getScratchDir() + File.pathSeparator);
String cp = (String) context.getAttribute(Constants.SERVLET_CLASSPATH);
if (cp == null || cp.equals("")) {
cp = options.getClassPath();
}
String path = cpath.toString() + cp;
if(log.isDebugEnabled()) {
log.debug("Compilation classpath initialized: " + path);
}
return path;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(
this, req, resp, null, false, JspWriter.DEFAULT_BUFFER, true);
JspWriter out = pageContext.getOut();
if (Constants.DEFAULT_BUFFER_SIZE == out.getBufferSize()) {
resp.getWriter().println("OK");
} else {
resp.getWriter().println("FAIL");
}
}
/**
* Return the <code>SecurityManager</code> only if Security is enabled AND
* package protection mechanism is enabled.
*/
public static boolean isPackageProtectionEnabled(){
if (packageDefinitionEnabled && Constants.IS_SECURITY_ENABLED){
return true;
}
return false;
}
/**
* Strips a servlet session ID from <tt>url</tt>. The session ID
* is encoded as a URL "path parameter" beginning with "jsessionid=".
* We thus remove anything we find between ";jsessionid=" (inclusive)
* and either EOS or a subsequent ';' (exclusive).
*
* taken from org.apache.taglibs.standard.tag.common.core.ImportSupport
*/
public static String stripSession(String url) {
StringBuilder u = new StringBuilder(url);
int sessionStart;
while ((sessionStart = u.toString().indexOf(";" + Constants.SESSION_PARAMETER_NAME + "=")) != -1) {
int sessionEnd = u.toString().indexOf(';', sessionStart + 1);
if (sessionEnd == -1)
sessionEnd = u.toString().indexOf('?', sessionStart + 1);
if (sessionEnd == -1) // still
sessionEnd = u.length();
u.delete(sessionStart, sessionEnd);
}
return u.toString();
}
/**
* Method used to initialize classpath for compiles.
*/
private void initClassPath() {
/* Classpath can be specified in one of two ways, depending on
whether the compilation is embedded or invoked from Jspc.
1. Calculated by the web container, and passed to Jasper in the
context attribute.
2. Jspc directly invoke JspCompilationContext.setClassPath, in
case the classPath initialzed here is ignored.
*/
StringBuilder cpath = new StringBuilder();
String sep = System.getProperty("path.separator");
cpath.append(options.getScratchDir() + sep);
String cp = (String) context.getAttribute(Constants.SERVLET_CLASSPATH);
if (cp == null || cp.equals("")) {
cp = options.getClassPath();
}
if (cp != null) {
classpath = cpath.toString() + cp;
}
// START GlassFish Issue 845
if (classpath != null) {
try {
classpath = URLDecoder.decode(classpath, "UTF-8");
} catch (UnsupportedEncodingException e) {
if (log.isLoggable(Level.FINE))
log.log(Level.FINE,
"Exception decoding classpath : " + classpath, e);
}
}
// END GlassFish Issue 845
}