init
This commit is contained in:
59
java/org/apache/el/util/ConcurrentCache.java
Normal file
59
java/org/apache/el/util/ConcurrentCache.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 org.apache.el.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public final class ConcurrentCache<K,V> {
|
||||
|
||||
private final int size;
|
||||
|
||||
private final Map<K,V> eden;
|
||||
|
||||
private final Map<K,V> longterm;
|
||||
|
||||
public ConcurrentCache(int size) {
|
||||
this.size = size;
|
||||
this.eden = new ConcurrentHashMap<>(size);
|
||||
this.longterm = new WeakHashMap<>(size);
|
||||
}
|
||||
|
||||
public V get(K k) {
|
||||
V v = this.eden.get(k);
|
||||
if (v == null) {
|
||||
synchronized (longterm) {
|
||||
v = this.longterm.get(k);
|
||||
}
|
||||
if (v != null) {
|
||||
this.eden.put(k, v);
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
public void put(K k, V v) {
|
||||
if (this.eden.size() >= size) {
|
||||
synchronized (longterm) {
|
||||
this.longterm.putAll(this.eden);
|
||||
}
|
||||
this.eden.clear();
|
||||
}
|
||||
this.eden.put(k, v);
|
||||
}
|
||||
}
|
||||
58
java/org/apache/el/util/Jre9Compat.java
Normal file
58
java/org/apache/el/util/Jre9Compat.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 org.apache.el.util;
|
||||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/*
|
||||
* This is a cut down version of org.apache.tomcat.util.Jre9Compat that provides
|
||||
* only the methods required by the EL implementation.
|
||||
*
|
||||
* This class is duplicated in javax.el
|
||||
* When making changes keep the two in sync.
|
||||
*/
|
||||
class Jre9Compat extends JreCompat {
|
||||
|
||||
private static final Method canAccessMethod;
|
||||
|
||||
|
||||
static {
|
||||
Method m1 = null;
|
||||
try {
|
||||
m1 = AccessibleObject.class.getMethod("canAccess", new Class<?>[] { Object.class });
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Expected for Java 8
|
||||
}
|
||||
canAccessMethod = m1;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSupported() {
|
||||
return canAccessMethod != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canAcccess(Object base, AccessibleObject accessibleObject) {
|
||||
try {
|
||||
return ((Boolean) canAccessMethod.invoke(accessibleObject, base)).booleanValue();
|
||||
} catch (ReflectiveOperationException | IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
60
java/org/apache/el/util/JreCompat.java
Normal file
60
java/org/apache/el/util/JreCompat.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 org.apache.el.util;
|
||||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
|
||||
/*
|
||||
* This is a cut down version of org.apache.tomcat.util.JreCompat that provides
|
||||
* only the methods required by the EL implementation.
|
||||
*
|
||||
* This class is duplicated in javax.el
|
||||
* When making changes keep the two in sync.
|
||||
*/
|
||||
public class JreCompat {
|
||||
|
||||
private static final JreCompat instance;
|
||||
|
||||
static {
|
||||
if (Jre9Compat.isSupported()) {
|
||||
instance = new Jre9Compat();
|
||||
} else {
|
||||
instance = new JreCompat();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static JreCompat getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is the accessibleObject accessible (as a result of appropriate module
|
||||
* exports) on the provided instance?
|
||||
*
|
||||
* @param base The specific instance to be tested.
|
||||
* @param accessibleObject The method/field/constructor to be tested.
|
||||
*
|
||||
* @return {code true} if the AccessibleObject can be accessed otherwise
|
||||
* {code false}
|
||||
*/
|
||||
public boolean canAcccess(Object base, AccessibleObject accessibleObject) {
|
||||
// Java 8 doesn't support modules so default to true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
49
java/org/apache/el/util/MessageFactory.java
Normal file
49
java/org/apache/el/util/MessageFactory.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 org.apache.el.util;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* @author Jacob Hookom [jacob@hookom.net]
|
||||
*/
|
||||
public final class MessageFactory {
|
||||
|
||||
static final ResourceBundle bundle =
|
||||
ResourceBundle.getBundle("org.apache.el.Messages");
|
||||
|
||||
public MessageFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static String get(final String key) {
|
||||
try {
|
||||
return bundle.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public static String get(final String key, final Object... args) {
|
||||
String value = get(key);
|
||||
|
||||
MessageFormat mf = new MessageFormat(value);
|
||||
return mf.format(args, new StringBuffer(), null).toString();
|
||||
}
|
||||
}
|
||||
585
java/org/apache/el/util/ReflectionUtil.java
Normal file
585
java/org/apache/el/util/ReflectionUtil.java
Normal file
File diff suppressed because it is too large
Load Diff
117
java/org/apache/el/util/Validation.java
Normal file
117
java/org/apache/el/util/Validation.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 org.apache.el.util;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
public class Validation {
|
||||
|
||||
// Java keywords, boolean literals & the null literal in alphabetical order
|
||||
private static final String invalidIdentifiers[] = { "abstract", "assert",
|
||||
"boolean", "break", "byte", "case", "catch", "char", "class", "const",
|
||||
"continue", "default", "do", "double", "else", "enum", "extends",
|
||||
"false", "final", "finally", "float", "for", "goto", "if", "implements",
|
||||
"import", "instanceof", "int", "interface", "long", "native", "new",
|
||||
"null", "package", "private", "protected", "public", "return", "short",
|
||||
"static", "strictfp", "super", "switch", "synchronized", "this",
|
||||
"throw", "throws", "transient", "true", "try", "void", "volatile",
|
||||
"while" };
|
||||
|
||||
private static final boolean IS_SECURITY_ENABLED =
|
||||
(System.getSecurityManager() != null);
|
||||
|
||||
private static final boolean SKIP_IDENTIFIER_CHECK;
|
||||
|
||||
static {
|
||||
String skipIdentifierCheckStr;
|
||||
if (IS_SECURITY_ENABLED) {
|
||||
skipIdentifierCheckStr = AccessController.doPrivileged(
|
||||
new PrivilegedAction<String>(){
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getProperty(
|
||||
"org.apache.el.parser.SKIP_IDENTIFIER_CHECK",
|
||||
"false");
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
skipIdentifierCheckStr = System.getProperty(
|
||||
"org.apache.el.parser.SKIP_IDENTIFIER_CHECK", "false");
|
||||
}
|
||||
SKIP_IDENTIFIER_CHECK = Boolean.parseBoolean(skipIdentifierCheckStr);
|
||||
}
|
||||
|
||||
|
||||
private Validation() {
|
||||
// Utility class. Hide default constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether a string is a Java identifier. Note that the behaviour of
|
||||
* this method depend on the system property
|
||||
* {@code org.apache.el.parser.SKIP_IDENTIFIER_CHECK}
|
||||
*
|
||||
* @param key The string to test
|
||||
*
|
||||
* @return {@code true} if the provided String should be treated as a Java
|
||||
* identifier, otherwise false
|
||||
*/
|
||||
public static boolean isIdentifier(String key) {
|
||||
|
||||
if (SKIP_IDENTIFIER_CHECK) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Should not be the case but check to be sure
|
||||
if (key == null || key.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the list of known invalid values
|
||||
int i = 0;
|
||||
int j = invalidIdentifiers.length;
|
||||
while (i < j) {
|
||||
int k = (i + j) >>> 1; // Avoid overflow
|
||||
int result = invalidIdentifiers[k].compareTo(key);
|
||||
if (result == 0) {
|
||||
return false;
|
||||
}
|
||||
if (result < 0) {
|
||||
i = k + 1;
|
||||
} else {
|
||||
j = k;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the start character that has more restrictions
|
||||
if (!Character.isJavaIdentifierStart(key.charAt(0))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check each remaining character used is permitted
|
||||
for (int idx = 1; idx < key.length(); idx++) {
|
||||
if (!Character.isJavaIdentifierPart(key.charAt(idx))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user