You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/02/16 23:08:43 UTC
[18/54] [partial] incubator-freemarker git commit: Top level package
name change to org.apache.freemarker,
and some of of the internal package structure changes. Other smaller cleanup.
To be continued...
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java b/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java
deleted file mode 100644
index 3780bf5..0000000
--- a/src/main/java/freemarker/ext/jsp/TaglibMethodUtil.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.ext.jsp;
-
-import java.lang.reflect.Method;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import freemarker.template.utility.ClassUtil;
-import freemarker.template.utility.StringUtil;
-
-final class TaglibMethodUtil {
-
- private TaglibMethodUtil() {
- // Not meant to be instantiated
- }
-
- private static final Pattern FUNCTION_SIGNATURE_PATTERN =
- Pattern.compile("^([\\w\\.]+(\\s*\\[\\s*\\])?)\\s+([\\w]+)\\s*\\((.*)\\)$");
- private static final Pattern FUNCTION_PARAMETER_PATTERN =
- Pattern.compile("^([\\w\\.]+)(\\s*\\[\\s*\\])?$");
-
- /**
- * Finds method by function signature string which is compliant with
- * Tag Library function signature in Java Server Page (TM) Specification.
- * A function signature example is as follows: {@code java.lang.String nickName( java.lang.String, int)}
- *
- * @param clazz Class having the method.
- * @param signature Java Server Page (TM) Specification compliant function signature string.
- * @return method if found.
- */
- public static Method getMethodByFunctionSignature(Class clazz, String signature)
- throws SecurityException, NoSuchMethodException, ClassNotFoundException {
- Matcher m1 = FUNCTION_SIGNATURE_PATTERN.matcher(signature);
-
- if (!m1.matches()) {
- throw new IllegalArgumentException("Invalid function signature.");
- }
-
- String methodName = m1.group(3);
- String params = m1.group(4).trim();
- Class [] paramTypes = null;
-
- if ("".equals(params)) {
- paramTypes = new Class[0];
- } else {
- String [] paramsArray = StringUtil.split(params, ',');
- paramTypes = new Class[paramsArray.length];
- String token = null;
- String paramType = null;
- boolean isPrimitive = false;
- boolean isArrayType = false;
- Matcher m2 = null;
-
- for (int i = 0; i < paramsArray.length; i++) {
- token = paramsArray[i].trim();
- m2 = FUNCTION_PARAMETER_PATTERN.matcher(token);
-
- if (!m2.matches()) {
- throw new IllegalArgumentException("Invalid argument signature: '" + token + "'.");
- }
-
- paramType = m2.group(1);
- isPrimitive = (paramType.indexOf('.') == -1);
- isArrayType = (m2.group(2) != null);
-
- if (isPrimitive) {
- if ("byte".equals(paramType)) {
- paramTypes[i] = (isArrayType ? byte[].class : byte.class);
- } else if ("short".equals(paramType)) {
- paramTypes[i] = (isArrayType ? short[].class : short.class);
- } else if ("int".equals(paramType)) {
- paramTypes[i] = (isArrayType ? int[].class : int.class);
- } else if ("long".equals(paramType)) {
- paramTypes[i] = (isArrayType ? long[].class : long.class);
- } else if ("float".equals(paramType)) {
- paramTypes[i] = (isArrayType ? float[].class : float.class);
- } else if ("double".equals(paramType)) {
- paramTypes[i] = (isArrayType ? double[].class : double.class);
- } else if ("boolean".equals(paramType)) {
- paramTypes[i] = (isArrayType ? boolean[].class : boolean.class);
- } else if ("char".equals(paramType)) {
- paramTypes[i] = (isArrayType ? char[].class : char.class);
- } else {
- throw new IllegalArgumentException("Invalid primitive type: '" + paramType + "'.");
- }
- } else {
- if (isArrayType) {
- paramTypes[i] = ClassUtil.forName("[L" + paramType + ";");
- } else {
- paramTypes[i] = ClassUtil.forName(paramType);
- }
- }
- }
- }
-
- return clazz.getMethod(methodName, paramTypes);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/ext/jsp/_FreeMarkerPageContext21.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/jsp/_FreeMarkerPageContext21.java b/src/main/java/freemarker/ext/jsp/_FreeMarkerPageContext21.java
deleted file mode 100644
index 172f8c5..0000000
--- a/src/main/java/freemarker/ext/jsp/_FreeMarkerPageContext21.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.ext.jsp;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import javax.el.ELContext;
-import javax.servlet.jsp.JspApplicationContext;
-import javax.servlet.jsp.JspContext;
-import javax.servlet.jsp.JspFactory;
-import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.el.ELException;
-import javax.servlet.jsp.el.ExpressionEvaluator;
-import javax.servlet.jsp.el.VariableResolver;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import freemarker.template.TemplateModelException;
-import freemarker.template.utility.ClassUtil;
-
-/**
- * Don't use this class; it's only public to work around Google App Engine Java
- * compliance issues. FreeMarker developers only: treat this class as package-visible.
- *
- * Implementation of PageContext that contains all JSP 2.1 methods.
- */
-public class _FreeMarkerPageContext21 extends FreeMarkerPageContext {
- private static final Logger LOG = LoggerFactory.getLogger("freemarker.jsp");
-
- static {
- if (JspFactory.getDefaultFactory() == null) {
- JspFactory.setDefaultFactory(new FreeMarkerJspFactory21());
- }
- LOG.debug("Using JspFactory implementation class {}",
- JspFactory.getDefaultFactory().getClass().getName());
- }
-
- public _FreeMarkerPageContext21() throws TemplateModelException {
- super();
- }
-
- /**
- * Attempts to locate and manufacture an expression evaulator instance. For this
- * to work you <b>must</b> have the Apache Commons-EL package in the classpath. If
- * Commons-EL is not available, this method will throw an UnsupportedOperationException.
- */
- @Override
- public ExpressionEvaluator getExpressionEvaluator() {
- try {
- Class type = ((ClassLoader) AccessController.doPrivileged(
- new PrivilegedAction() {
- @Override
- public Object run() {
- return Thread.currentThread().getContextClassLoader();
- }
- })).loadClass
- ("org.apache.commons.el.ExpressionEvaluatorImpl");
- return (ExpressionEvaluator) type.newInstance();
- } catch (Exception e) {
- throw new UnsupportedOperationException("In order for the getExpressionEvaluator() " +
- "method to work, you must have downloaded the apache commons-el jar and " +
- "made it available in the classpath.");
- }
- }
-
- /**
- * Returns a variable resolver that will resolve variables by searching through
- * the page scope, request scope, session scope and application scope for an
- * attribute with a matching name.
- */
- @Override
- public VariableResolver getVariableResolver() {
- final PageContext ctx = this;
-
- return new VariableResolver() {
- @Override
- public Object resolveVariable(String name) throws ELException {
- return ctx.findAttribute(name);
- }
- };
- }
-
- private ELContext elContext;
-
- @Override
- public ELContext getELContext() {
- if (elContext == null) {
- JspApplicationContext jspctx = JspFactory.getDefaultFactory().getJspApplicationContext(getServletContext());
- if (jspctx instanceof FreeMarkerJspApplicationContext) {
- elContext = ((FreeMarkerJspApplicationContext) jspctx).createNewELContext(this);
- elContext.putContext(JspContext.class, this);
- } else {
- throw new UnsupportedOperationException(
- "Can not create an ELContext using a foreign JspApplicationContext (of class "
- + ClassUtil.getShortClassNameOfObject(jspctx) + ").\n" +
- "Hint: The cause of this is often that you are trying to use JSTL tags/functions in FTL. "
- + "In that case, know that that's not really suppored, and you are supposed to use FTL "
- + "constrcuts instead, like #list instead of JSTL's forEach, etc.");
- }
- }
- return elContext;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/ext/jsp/package.html
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/jsp/package.html b/src/main/java/freemarker/ext/jsp/package.html
deleted file mode 100644
index 23a891b..0000000
--- a/src/main/java/freemarker/ext/jsp/package.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<html>
-<head>
-</head>
-<body>
-<p>
-Classes for two-way FreeMarker-JSP integration. It contains both a JSP
-custom tag that allows embedding of FreeMarker templates inside JSP
-pages, as well as the infrastructure that allows JSP custom tags to be
-used inside FreeMarker templates.
-</body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/ext/package.html
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/package.html b/src/main/java/freemarker/ext/package.html
deleted file mode 100644
index 0f45e3f..0000000
--- a/src/main/java/freemarker/ext/package.html
+++ /dev/null
@@ -1,25 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
-<p>Extensions to FreeMarker's core functionality.</p>
-</body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ecb4e230/src/main/java/freemarker/ext/servlet/AllHttpScopesHashModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/servlet/AllHttpScopesHashModel.java b/src/main/java/freemarker/ext/servlet/AllHttpScopesHashModel.java
deleted file mode 100644
index 8273521..0000000
--- a/src/main/java/freemarker/ext/servlet/AllHttpScopesHashModel.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.ext.servlet;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import freemarker.template.ObjectWrapper;
-import freemarker.template.SimpleHash;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-
-/**
- * An extension of SimpleHash that looks up keys in the hash, then in the
- * request, session, and servlet context scopes. Makes "Application", "Session"
- * and "Request" keys largely obsolete, however we keep them for backward
- * compatibility (also, "Request" is required for proper operation of JSP
- * taglibs).
- * It is on purpose that we didn't override <tt>keys</tt> and <tt>values</tt>
- * methods. That way, only those variables assigned into the hash directly by a
- * subclass of <tt>FreemarkerServlet</tt> that overrides
- * <tt>preTemplateProcess</tt>) are discovered as "page" variables by the FM
- * JSP PageContext implementation.
- */
-public class AllHttpScopesHashModel extends SimpleHash {
- private final ServletContext context;
- private final HttpServletRequest request;
- private final Map unlistedModels = new HashMap();
-
- /**
- * Creates a new instance of AllHttpScopesHashModel for handling a single
- * HTTP servlet request.
- * @param wrapper the object wrapper to use
- * @param context the servlet context of the web application
- * @param request the HTTP servlet request being processed
- */
- public AllHttpScopesHashModel(ObjectWrapper wrapper,
- ServletContext context, HttpServletRequest request) {
- setObjectWrapper(wrapper);
- this.context = context;
- this.request = request;
- }
-
- /**
- * Stores a model in the hash so that it doesn't show up in <tt>keys()</tt>
- * and <tt>values()</tt> methods. Used to put the Application, Session,
- * Request, RequestParameters and JspTaglibs objects.
- * @param key the key under which the model is stored
- * @param model the stored model
- */
- public void putUnlistedModel(String key, TemplateModel model) {
- unlistedModels.put(key, model);
- }
-
- @Override
- public TemplateModel get(String key) throws TemplateModelException {
- // Lookup in page scope
- TemplateModel model = super.get(key);
- if (model != null) {
- return model;
- }
-
- // Look in unlisted models
- model = (TemplateModel) unlistedModels.get(key);
- if (model != null) {
- return model;
- }
-
- // Lookup in request scope
- Object obj = request.getAttribute(key);
- if (obj != null) {
- return wrap(obj);
- }
-
- // Lookup in session scope
- HttpSession session = request.getSession(false);
- if (session != null) {
- obj = session.getAttribute(key);
- if (obj != null) {
- return wrap(obj);
- }
- }
-
- // Lookup in application scope
- obj = context.getAttribute(key);
- if (obj != null) {
- return wrap(obj);
- }
-
- // return wrapper's null object (probably null).
- return wrap(null);
- }
-}