/* $$ Clover has instrumented this file $$ */// Copyright 2004 The Apache Software Foundation
//
// Licensed 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.tapestry;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import javax.servlet.ServletContext;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
import org.apache.tapestry.event.ChangeObserver;
import org.apache.tapestry.event.ObservedChangeEvent;
import org.apache.tapestry.request.RequestContext;
import org.apache.tapestry.resource.ContextResource;
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.util.AdaptorRegistry;
import org.apache.tapestry.util.StringSplitter;
/**
* A placeholder for a number of (static) methods that don't belong elsewhere, as well as a global
* location for static constants.
*
* @since 1.0.1
* @author Howard Lewis Ship
*/
public final class Tapestry
{public static com.cortexeb.tools.clover.d __CLOVER_33_0 = com.cortexeb.tools.clover.aq.getRecorder(new char[] {67,58,92,119,111,114,107,115,112,97,99,101,92,106,97,107,97,114,116,97,45,116,97,112,101,115,116,114,121,92,102,114,97,109,101,119,111,114,107,92,116,97,114,103,101,116,92,99,108,111,118,101,114,45,100,98},1097439627296L);
/**
* Name of a request attribute used with the {@link #TAGSUPPORT_SERVICE}service. The attribute
* defines the underlying service to for which a URL will be generated.
*
* @since 3.0
*/
public final static String TAG_SUPPORT_SERVICE_ATTRIBUTE = "org.apache.tapestry.tagsupport.service";
/**
* Name of a request attribute used with the {@link #TAGSUPPORT_SERVICE}service. The attribute
* defines the correct servlet path for the Tapestry application (which, for the odd-man-out
* TAGSUPPORT_SERVICE may not match HttpServletRequest.getServletPath() because of the use of an
* include.
*
* @since 3.0
*/
public final static String TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE = "org.apache.tapestry.tagsupport.servlet-path";
/**
* Name of a request attribute used with the {@link #TAGSUPPORT_SERVICE}service. The attribute
* defines an array of objects to be converted into service parameters (i.e., for use with the
* {@link #EXTERNAL_SERVICE}).
*
* @since 3.0
*/
public final static String TAG_SUPPORT_PARAMETERS_ATTRIBUTE = "org.apache.tapestry.tagsupport.parameters";
/**
* Service used to support rendering of JSP tags. tagsupport is provided with a service and
* service parameters via request attributes and creates a URI from the result, which is output
* to the response.
*
* @since 3.0
*/
public static final String TAGSUPPORT_SERVICE = "tagsupport";
/**
* The name ("action") of a service that allows behavior to be associated with an
* {@link IAction}component, such as {@link org.apache.tapestry.link.ActionLink}or
* {@link org.apache.tapestry.form.Form}.
* <p>
* This service is used with actions that are tied to the dynamic state of the page, and which
* require a rewind of the page.
*/
public final static String ACTION_SERVICE = "action";
/**
* The name ("direct") of a service that allows stateless behavior for an {@link
* org.apache.tapestry.link.DirectLink} component.
* <p>
* This service rolls back the state of the page but doesn't rewind the the dynamic state of the
* page the was the action service does, which is more efficient but less powerful.
* <p>
* An array of String parameters may be included with the service URL; these will be made
* available to the {@link org.apache.tapestry.link.DirectLink}component's listener.
*/
public final static String DIRECT_SERVICE = "direct";
/**
* The name ("external") of a service that a allows {@link IExternalPage}to be selected.
* Associated with a {@link org.apache.tapestry.link.ExternalLink}component.
* <p>
* This service enables {@link IExternalPage}s to be accessed via a URL. External pages may be
* booked marked using their URL for future reference.
* <p>
* An array of Object parameters may be included with the service URL; these will be passed to
* the {@link IExternalPage#activateExternalPage(Object[], IRequestCycle)}method.
*/
public final static String EXTERNAL_SERVICE = "external";
/**
* The name ("page") of a service that allows a new page to be selected. Associated with a
* {@link org.apache.tapestry.link.PageLink}component.
* <p>
* The service requires a single parameter: the name of the target page.
*/
public final static String PAGE_SERVICE = "page";
/**
* The name ("home") of a service that jumps to the home page. A stand-in for when no service is
* provided, which is typically the entrypoint to the application.
*/
public final static String HOME_SERVICE = "home";
/**
* The name ("restart") of a service that invalidates the session and restarts the application.
* Typically used just to recover from an exception.
*/
public static final String RESTART_SERVICE = "restart";
/**
* The name ("asset") of a service used to access internal assets.
*/
public static final String ASSET_SERVICE = "asset";
/**
* The name ("reset") of a service used to clear cached template and specification data and
* remove all pooled pages. This is only used when debugging as a quick way to clear the out
* cached data, to allow updated versions of specifications and templates to be loaded (without
* stopping and restarting the servlet container).
* <p>
* This service is only available if the Java system property
* <code>org.apache.tapestry.enable-reset-service</code> is set to <code>true</code>.
*/
public static final String RESET_SERVICE = "reset";
/**
* Query parameter that identfies the service for the request.
*
* @since 1.0.3
*/
public static final String SERVICE_QUERY_PARAMETER_NAME = "service";
/**
* The query parameter for application specific parameters to the service (this is used with the
* direct service). Each of these values is encoded with
* {@link java.net.URLEncoder#encode(String)}before being added to the URL. Multiple values are
* handle by repeatedly establishing key/value pairs (this is a change from behavior in 2.1 and
* earlier).
*
* @since 1.0.3
*/
public static final String PARAMETERS_QUERY_PARAMETER_NAME = "sp";
/**
* Property name used to get the extension used for templates. This may be set in the page or
* component specification, or in the page (or component's) immediate container (library or
* application specification). Unlike most properties, value isn't inherited all the way up the
* chain. The default template extension is "html".
*
* @since 3.0
*/
public static final String TEMPLATE_EXTENSION_PROPERTY = "org.apache.tapestry.template-extension";
/**
* The default extension for templates, "html".
*
* @since 3.0
*/
public static final String DEFAULT_TEMPLATE_EXTENSION = "html";
/**
* The name of an {@link org.apache.tapestry.IRequestCycle}attribute in which the currently
* rendering {@link org.apache.tapestry.components.ILinkComponent}is stored. Link components do
* not nest.
*/
public static final String LINK_COMPONENT_ATTRIBUTE_NAME = "org.apache.tapestry.active-link-component";
/**
* Suffix appended to a parameter name to form the name of a property that stores the binding
* for the parameter.
*
* @since 3.0
*/
public static final String PARAMETER_PROPERTY_NAME_SUFFIX = "Binding";
/**
* Key used to obtain an extension from the application specification. The extension, if it
* exists, implements {@link org.apache.tapestry.request.IRequestDecoder}.
*
* @since 2.2
*/
public static final String REQUEST_DECODER_EXTENSION_NAME = "org.apache.tapestry.request-decoder";
/**
* Name of optional application extension for the multipart decoder used by the application. The
* extension must implement {@link org.apache.tapestry.multipart.IMultipartDecoder}(and is
* generally a configured instance of
* {@link org.apache.tapestry.multipart.DefaultMultipartDecoder}).
*
* @since 3.0
*/
public static final String MULTIPART_DECODER_EXTENSION_NAME = "org.apache.tapestry.multipart-decoder";
/**
* Method id used to check that {@link IPage#validate(IRequestCycle)}is invoked.
*
* @see #checkMethodInvocation(Object, String, Object)
* @since 3.0
*/
public static final String ABSTRACTPAGE_VALIDATE_METHOD_ID = "AbstractPage.validate()";
/**
* Method id used to check that {@link IPage#detach()}is invoked.
*
* @see #checkMethodInvocation(Object, String, Object)
* @since 3.0
*/
public static final String ABSTRACTPAGE_DETACH_METHOD_ID = "AbstractPage.detach()";
/**
* Regular expression defining a simple property name. Used by several different parsers. Simple
* property names match Java variable names; a leading letter (or underscore), followed by
* letters, numbers and underscores.
*
* @since 3.0
*/
public static final String SIMPLE_PROPERTY_NAME_PATTERN = "^_?[a-zA-Z]\\w*$";
/**
* Name of an application extension used as a factory for
* {@link org.apache.tapestry.engine.IMonitor}instances. The extension must implement
* {@link org.apache.tapestry.engine.IMonitorFactory}.
*
* @since 3.0
*/
public static final String MONITOR_FACTORY_EXTENSION_NAME = "org.apache.tapestry.monitor-factory";
/**
* Class name of an {@link ognl.TypeConverter}implementing class to use as a type converter for
* {@link org.apache.tapestry.binding.ExpressionBinding}
*/
public static final String OGNL_TYPE_CONVERTER = "org.apache.tapestry.ognl-type-converter";
/**
* Prevent instantiation.
*/
private Tapestry()
{try { __CLOVER_33_0.M[2894]++;
} finally { }}
/**
* The version of the framework; this is updated for major releases.
*/
public static final String VERSION = readVersion();
/**
* Contains strings loaded from TapestryStrings.properties.
*
* @since 1.0.8
*/
private static ResourceBundle _strings;
/**
* A {@link Map}that links Locale names (as in {@link Locale#toString()}to {@link Locale}
* instances. This prevents needless duplication of Locales.
*/
private static final Map _localeMap = new HashMap();
static
{
__CLOVER_33_0.S[11852]++;Locale[] locales = Locale.getAvailableLocales();
__CLOVER_33_0.S[11853]++;for (int i = 0; (((i < locales.length) && (++__CLOVER_33_0.CT[2034] != 0)) || (++__CLOVER_33_0.CF[2034] == 0)); i++){
{
__CLOVER_33_0.S[11854]++;_localeMap.put(locales[i].toString(), locales[i]);
}}
}
/**
* Used for tracking if a particular super-class method has been invoked.
*/
private static final ThreadLocal _invokedMethodIds = new ThreadLocal();
/**
* A {@link org.apache.tapestry.util.AdaptorRegistry}used to coerce arbitrary objects to
* boolean values.
*
* @see #evaluateBoolean(Object)
*/
private static final AdaptorRegistry _booleanAdaptors = new AdaptorRegistry();
private static abstract class BoolAdaptor
{
/**
* Implemented by subclasses to coerce an object to a boolean.
*/
public abstract boolean coerce(Object value);
}
private static class BooleanAdaptor extends BoolAdaptor
{
public boolean coerce(Object value)
{try { __CLOVER_33_0.M[2895]++;
__CLOVER_33_0.S[11855]++;Boolean b = (Boolean) value;
__CLOVER_33_0.S[11856]++;return b.booleanValue();
} finally { }}
}
private static class NumberAdaptor extends BoolAdaptor
{
public boolean coerce(Object value)
{try { __CLOVER_33_0.M[2896]++;
__CLOVER_33_0.S[11857]++;Number n = (Number) value;
__CLOVER_33_0.S[11858]++;return n.intValue() > 0;
} finally { }}
}
private static class CollectionAdaptor extends BoolAdaptor
{
public boolean coerce(Object value)
{try { __CLOVER_33_0.M[2897]++;
__CLOVER_33_0.S[11859]++;Collection c = (Collection) value;
__CLOVER_33_0.S[11860]++;return c.size() > 0;
} finally { }}
}
private static class StringAdaptor extends BoolAdaptor
{
public boolean coerce(Object value)
{try { __CLOVER_33_0.M[2898]++;
__CLOVER_33_0.S[11861]++;String s = (String) value;
__CLOVER_33_0.S[11862]++;if ((((s.length() == 0) && (++__CLOVER_33_0.CT[2035] != 0)) || (++__CLOVER_33_0.CF[2035] == 0))){
__CLOVER_33_0.S[11863]++;return false;}
__CLOVER_33_0.S[11864]++;String ts = s.trim();
__CLOVER_33_0.S[11865]++;if ((((ts.length() == 0) && (++__CLOVER_33_0.CT[2036] != 0)) || (++__CLOVER_33_0.CF[2036] == 0))){
__CLOVER_33_0.S[11866]++;return false;}
// Here probably Boolean.getBoolean(s) should be used,
// but we need the opposite check
__CLOVER_33_0.S[11867]++;if ((((ts.equalsIgnoreCase("false")) && (++__CLOVER_33_0.CT[2037] != 0)) || (++__CLOVER_33_0.CF[2037] == 0))){
__CLOVER_33_0.S[11868]++;return false;}
__CLOVER_33_0.S[11869]++;return true;
} finally { }}
}
static
{
__CLOVER_33_0.S[11870]++;_booleanAdaptors.register(Boolean.class, new BooleanAdaptor());
__CLOVER_33_0.S[11871]++;_booleanAdaptors.register(Number.class, new NumberAdaptor());
__CLOVER_33_0.S[11872]++;_booleanAdaptors.register(Collection.class, new CollectionAdaptor());
__CLOVER_33_0.S[11873]++;_booleanAdaptors.register(String.class, new StringAdaptor());
// Register a default, catch-all adaptor.
__CLOVER_33_0.S[11875]++;_booleanAdaptors.register(Object.class, new BoolAdaptor()
{
public boolean coerce(Object value)
{try { __CLOVER_33_0.M[2899]++;
__CLOVER_33_0.S[11874]++;return true;
} finally { }}
});
}
/**
* {@link AdaptorRegistry}used to extract an {@link Iterator}from an arbitrary object.
*/
private static AdaptorRegistry _iteratorAdaptors = new AdaptorRegistry();
private abstract static class IteratorAdaptor
{
/**
* Coeerces the object into an {@link Iterator}.
*/
abstract public Iterator coerce(Object value);
}
private static class DefaultIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2900]++;
__CLOVER_33_0.S[11876]++;return (Iterator) value;
} finally { }}
}
private static class CollectionIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2901]++;
__CLOVER_33_0.S[11877]++;Collection c = (Collection) value;
__CLOVER_33_0.S[11878]++;if ((((c.size() == 0) && (++__CLOVER_33_0.CT[2038] != 0)) || (++__CLOVER_33_0.CF[2038] == 0))){
__CLOVER_33_0.S[11879]++;return null;}
__CLOVER_33_0.S[11880]++;return c.iterator();
} finally { }}
}
private static class ObjectIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2902]++;
__CLOVER_33_0.S[11881]++;return Collections.singleton(value).iterator();
} finally { }}
}
private static class ObjectArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2903]++;
__CLOVER_33_0.S[11882]++;Object[] array = (Object[]) value;
__CLOVER_33_0.S[11883]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2039] != 0)) || (++__CLOVER_33_0.CF[2039] == 0))){
__CLOVER_33_0.S[11884]++;return null;}
__CLOVER_33_0.S[11885]++;return Arrays.asList(array).iterator();
} finally { }}
}
private static class BooleanArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2904]++;
__CLOVER_33_0.S[11886]++;boolean[] array = (boolean[]) value;
__CLOVER_33_0.S[11887]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2040] != 0)) || (++__CLOVER_33_0.CF[2040] == 0))){
__CLOVER_33_0.S[11888]++;return null;}
__CLOVER_33_0.S[11889]++;List l = new ArrayList(array.length);
__CLOVER_33_0.S[11890]++;for (int i = 0; (((i < array.length) && (++__CLOVER_33_0.CT[2041] != 0)) || (++__CLOVER_33_0.CF[2041] == 0)); i++){
__CLOVER_33_0.S[11891]++;l.add((((array[i] ) && (++__CLOVER_33_0.CT[2042] != 0)) || (++__CLOVER_33_0.CF[2042] == 0))? Boolean.TRUE : Boolean.FALSE);}
__CLOVER_33_0.S[11892]++;return l.iterator();
} finally { }}
}
private static class ByteArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2905]++;
__CLOVER_33_0.S[11893]++;byte[] array = (byte[]) value;
__CLOVER_33_0.S[11894]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2043] != 0)) || (++__CLOVER_33_0.CF[2043] == 0))){
__CLOVER_33_0.S[11895]++;return null;}
__CLOVER_33_0.S[11896]++;List l = new ArrayList(array.length);
__CLOVER_33_0.S[11897]++;for (int i = 0; (((i < array.length) && (++__CLOVER_33_0.CT[2044] != 0)) || (++__CLOVER_33_0.CF[2044] == 0)); i++){
__CLOVER_33_0.S[11898]++;l.add(new Byte(array[i]));}
__CLOVER_33_0.S[11899]++;return l.iterator();
} finally { }}
}
private static class CharArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2906]++;
__CLOVER_33_0.S[11900]++;char[] array = (char[]) value;
__CLOVER_33_0.S[11901]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2045] != 0)) || (++__CLOVER_33_0.CF[2045] == 0))){
__CLOVER_33_0.S[11902]++;return null;}
__CLOVER_33_0.S[11903]++;List l = new ArrayList(array.length);
__CLOVER_33_0.S[11904]++;for (int i = 0; (((i < array.length) && (++__CLOVER_33_0.CT[2046] != 0)) || (++__CLOVER_33_0.CF[2046] == 0)); i++){
__CLOVER_33_0.S[11905]++;l.add(new Character(array[i]));}
__CLOVER_33_0.S[11906]++;return l.iterator();
} finally { }}
}
private static class ShortArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2907]++;
__CLOVER_33_0.S[11907]++;short[] array = (short[]) value;
__CLOVER_33_0.S[11908]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2047] != 0)) || (++__CLOVER_33_0.CF[2047] == 0))){
__CLOVER_33_0.S[11909]++;return null;}
__CLOVER_33_0.S[11910]++;List l = new ArrayList(array.length);
__CLOVER_33_0.S[11911]++;for (int i = 0; (((i < array.length) && (++__CLOVER_33_0.CT[2048] != 0)) || (++__CLOVER_33_0.CF[2048] == 0)); i++){
__CLOVER_33_0.S[11912]++;l.add(new Short(array[i]));}
__CLOVER_33_0.S[11913]++;return l.iterator();
} finally { }}
}
private static class IntArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2908]++;
__CLOVER_33_0.S[11914]++;int[] array = (int[]) value;
__CLOVER_33_0.S[11915]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2049] != 0)) || (++__CLOVER_33_0.CF[2049] == 0))){
__CLOVER_33_0.S[11916]++;return null;}
__CLOVER_33_0.S[11917]++;List l = new ArrayList(array.length);
__CLOVER_33_0.S[11918]++;for (int i = 0; (((i < array.length) && (++__CLOVER_33_0.CT[2050] != 0)) || (++__CLOVER_33_0.CF[2050] == 0)); i++){
__CLOVER_33_0.S[11919]++;l.add(new Integer(array[i]));}
__CLOVER_33_0.S[11920]++;return l.iterator();
} finally { }}
}
private static class LongArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2909]++;
__CLOVER_33_0.S[11921]++;long[] array = (long[]) value;
__CLOVER_33_0.S[11922]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2051] != 0)) || (++__CLOVER_33_0.CF[2051] == 0))){
__CLOVER_33_0.S[11923]++;return null;}
__CLOVER_33_0.S[11924]++;List l = new ArrayList(array.length);
__CLOVER_33_0.S[11925]++;for (int i = 0; (((i < array.length) && (++__CLOVER_33_0.CT[2052] != 0)) || (++__CLOVER_33_0.CF[2052] == 0)); i++){
__CLOVER_33_0.S[11926]++;l.add(new Long(array[i]));}
__CLOVER_33_0.S[11927]++;return l.iterator();
} finally { }}
}
private static class FloatArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2910]++;
__CLOVER_33_0.S[11928]++;float[] array = (float[]) value;
__CLOVER_33_0.S[11929]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2053] != 0)) || (++__CLOVER_33_0.CF[2053] == 0))){
__CLOVER_33_0.S[11930]++;return null;}
__CLOVER_33_0.S[11931]++;List l = new ArrayList(array.length);
__CLOVER_33_0.S[11932]++;for (int i = 0; (((i < array.length) && (++__CLOVER_33_0.CT[2054] != 0)) || (++__CLOVER_33_0.CF[2054] == 0)); i++){
__CLOVER_33_0.S[11933]++;l.add(new Float(array[i]));}
__CLOVER_33_0.S[11934]++;return l.iterator();
} finally { }}
}
private static class DoubleArrayIteratorAdaptor extends IteratorAdaptor
{
public Iterator coerce(Object value)
{try { __CLOVER_33_0.M[2911]++;
__CLOVER_33_0.S[11935]++;double[] array = (double[]) value;
__CLOVER_33_0.S[11936]++;if ((((array.length == 0) && (++__CLOVER_33_0.CT[2055] != 0)) || (++__CLOVER_33_0.CF[2055] == 0))){
__CLOVER_33_0.S[11937]++;return null;}
__CLOVER_33_0.S[11938]++;List l = new ArrayList(array.length);
__CLOVER_33_0.S[11939]++;for (int i = 0; (((i < array.length) && (++__CLOVER_33_0.CT[2056] != 0)) || (++__CLOVER_33_0.CF[2056] == 0)); i++){
__CLOVER_33_0.S[11940]++;l.add(new Double(array[i]));}
__CLOVER_33_0.S[11941]++;return l.iterator();
} finally { }}
}
static
{
__CLOVER_33_0.S[11942]++;_iteratorAdaptors.register(Iterator.class, new DefaultIteratorAdaptor());
__CLOVER_33_0.S[11943]++;_iteratorAdaptors.register(Collection.class, new CollectionIteratorAdaptor());
__CLOVER_33_0.S[11944]++;_iteratorAdaptors.register(Object.class, new ObjectIteratorAdaptor());
__CLOVER_33_0.S[11945]++;_iteratorAdaptors.register(Object[].class, new ObjectArrayIteratorAdaptor());
__CLOVER_33_0.S[11946]++;_iteratorAdaptors.register(boolean[].class, new BooleanArrayIteratorAdaptor());
__CLOVER_33_0.S[11947]++;_iteratorAdaptors.register(byte[].class, new ByteArrayIteratorAdaptor());
__CLOVER_33_0.S[11948]++;_iteratorAdaptors.register(char[].class, new CharArrayIteratorAdaptor());
__CLOVER_33_0.S[11949]++;_iteratorAdaptors.register(short[].class, new ShortArrayIteratorAdaptor());
__CLOVER_33_0.S[11950]++;_iteratorAdaptors.register(int[].class, new IntArrayIteratorAdaptor());
__CLOVER_33_0.S[11951]++;_iteratorAdaptors.register(long[].class, new LongArrayIteratorAdaptor());
__CLOVER_33_0.S[11952]++;_iteratorAdaptors.register(float[].class, new FloatArrayIteratorAdaptor());
__CLOVER_33_0.S[11953]++;_iteratorAdaptors.register(double[].class, new DoubleArrayIteratorAdaptor());
}
/**
* Copys all informal {@link IBinding bindings}from a source component to the destination
* component. Informal bindings are bindings for informal parameters. This will overwrite
* parameters (formal or informal) in the destination component if there is a naming conflict.
*/
public static void copyInformalBindings(IComponent source, IComponent destination)
{try { __CLOVER_33_0.M[2912]++;
__CLOVER_33_0.S[11954]++;Collection names = source.getBindingNames();
__CLOVER_33_0.S[11955]++;if ((((names == null) && (++__CLOVER_33_0.CT[2057] != 0)) || (++__CLOVER_33_0.CF[2057] == 0))){
__CLOVER_33_0.S[11956]++;return;}
__CLOVER_33_0.S[11957]++;IComponentSpecification specification = source.getSpecification();
__CLOVER_33_0.S[11958]++;Iterator i = names.iterator();
__CLOVER_33_0.S[11959]++;while ((((i.hasNext()) && (++__CLOVER_33_0.CT[2058] != 0)) || (++__CLOVER_33_0.CF[2058] == 0))){
{
__CLOVER_33_0.S[11960]++;String name = (String) i.next();
// If not a formal parameter, then copy it over.
__CLOVER_33_0.S[11961]++;if ((((specification.getParameter(name) == null) && (++__CLOVER_33_0.CT[2059] != 0)) || (++__CLOVER_33_0.CF[2059] == 0))){
{
__CLOVER_33_0.S[11962]++;IBinding binding = source.getBinding(name);
__CLOVER_33_0.S[11963]++;destination.setBinding(name, binding);
}}
}}
} finally { }}
/**
* Evaluates an object to determine its boolean value. <table border=1>
* <tr>
* <th>Class</th>
* <th>Test</th>
* </tr>
* <tr>
* <td>{@link Boolean}</td>
* <td>Self explanatory.</td>
* </tr>
* <tr>
* <td>{@link Number}</td>
* <td>True if non-zero, false otherwise.</td>
* </tr>
* <tr>
* <td>{@link Collection}</td>
* <td>True if contains any elements (non-zero size), false otherwise.</td>
* </tr>
* <tr>
* <td>{@link String}</td>
* <td>True if contains any non-whitespace characters, false otherwise.</td>
* </tr>
* <tr>
* <td>Any Object array type</td>
* <td>True if contains any elements (non-zero length), false otherwise.</td>
* <tr></table>
* <p>
* Any other non-null object evaluates to true.
*/
public static boolean evaluateBoolean(Object value)
{try { __CLOVER_33_0.M[2913]++;
__CLOVER_33_0.S[11964]++;if ((((value == null) && (++__CLOVER_33_0.CT[2060] != 0)) || (++__CLOVER_33_0.CF[2060] == 0))){
__CLOVER_33_0.S[11965]++;return false;}
__CLOVER_33_0.S[11966]++;Class valueClass = value.getClass();
__CLOVER_33_0.S[11967]++;if ((((valueClass.isArray()) && (++__CLOVER_33_0.CT[2061] != 0)) || (++__CLOVER_33_0.CF[2061] == 0))){
{
__CLOVER_33_0.S[11968]++;Object[] array = (Object[]) value;
__CLOVER_33_0.S[11969]++;return array.length > 0;
}}
__CLOVER_33_0.S[11970]++;BoolAdaptor adaptor = (BoolAdaptor) _booleanAdaptors.getAdaptor(valueClass);
__CLOVER_33_0.S[11971]++;return adaptor.coerce(value);
} finally { }}
/**
* Converts an Object into an {@link Iterator}, following some basic rules. <table border=1>
* <tr>
* <th>Input Class</th>
* <th>Result</th>
* </tr>
* <tr>
* <td>array</td>
* <td>Converted to a {@link List}and iterator returned. null returned if the array is empty.
* This works with both object arrays and arrays of scalars.</td>
* </tr>
* <tr>
* <td>{@link Iterator}</td>
* <td>Returned as-is.</td>
* <tr>
* <td>{@link Collection}</td>
* <td>Iterator returned, or null if the Collection is empty</td>
* </tr>
* <tr>
* <td>Any other</td>
* <td>{@link Iterator}for singleton collection returned</td>
* </tr>
* <tr>
* <td>null</td>
* <td>null returned</td>
* </tr>
* </table>
*/
public static Iterator coerceToIterator(Object value)
{try { __CLOVER_33_0.M[2914]++;
__CLOVER_33_0.S[11972]++;if ((((value == null) && (++__CLOVER_33_0.CT[2062] != 0)) || (++__CLOVER_33_0.CF[2062] == 0))){
__CLOVER_33_0.S[11973]++;return null;}
__CLOVER_33_0.S[11974]++;IteratorAdaptor adaptor = (IteratorAdaptor) _iteratorAdaptors.getAdaptor(value.getClass());
__CLOVER_33_0.S[11975]++;return adaptor.coerce(value);
} finally { }}
/**
* Gets the {@link Locale}for the given string, which is the result of
* {@link Locale#toString()}. If no such locale is already registered, a new instance is
* created, registered and returned.
*/
public static Locale getLocale(String s)
{try { __CLOVER_33_0.M[2915]++;
__CLOVER_33_0.S[11976]++;Locale result = null;
__CLOVER_33_0.S[11977]++;synchronized (_localeMap)
{
__CLOVER_33_0.S[11978]++;result = (Locale) _localeMap.get(s);
}
__CLOVER_33_0.S[11979]++;if ((((result == null) && (++__CLOVER_33_0.CT[2063] != 0)) || (++__CLOVER_33_0.CF[2063] == 0))){
{
__CLOVER_33_0.S[11980]++;StringSplitter splitter = new StringSplitter('_');
__CLOVER_33_0.S[11981]++;String[] terms = splitter.splitToArray(s);
__CLOVER_33_0.S[11982]++;switch (terms.length)
{
case 1:
__CLOVER_33_0.S[11983]++;result = new Locale(terms[0], "");
__CLOVER_33_0.S[11984]++;break;
case 2:
__CLOVER_33_0.S[11985]++;result = new Locale(terms[0], terms[1]);
__CLOVER_33_0.S[11986]++;break;
case 3:
__CLOVER_33_0.S[11987]++;result = new Locale(terms[0], terms[1], terms[2]);
__CLOVER_33_0.S[11988]++;break;
default:
__CLOVER_33_0.S[11989]++;throw new IllegalArgumentException("Unable to convert '" + s + "' to a Locale.");
}
__CLOVER_33_0.S[11990]++;synchronized (_localeMap)
{
__CLOVER_33_0.S[11991]++;_localeMap.put(s, result);
}
}}
__CLOVER_33_0.S[11992]++;return result;
} finally { }}
/**
* Closes the stream (if not null), ignoring any {@link IOException}thrown.
*
* @since 1.0.2
*/
public static void close(InputStream stream)
{try { __CLOVER_33_0.M[2916]++;
__CLOVER_33_0.S[11993]++;if ((((stream != null) && (++__CLOVER_33_0.CT[2064] != 0)) || (++__CLOVER_33_0.CF[2064] == 0))){
{
__CLOVER_33_0.S[11994]++;try
{
__CLOVER_33_0.S[11995]++;stream.close();
}
catch (IOException ex)
{
// Ignore.
}
}}
} finally { }}
/**
* Gets a string from the TapestryStrings resource bundle. The string in the bundle is treated
* as a pattern for {@link MessageFormat#format(java.lang.String, java.lang.Object[])}.
*
* @since 1.0.8
*/
public static String format(String key, Object[] args)
{try { __CLOVER_33_0.M[2917]++;
__CLOVER_33_0.S[11996]++;if ((((_strings == null) && (++__CLOVER_33_0.CT[2065] != 0)) || (++__CLOVER_33_0.CF[2065] == 0))){
__CLOVER_33_0.S[11997]++;_strings = ResourceBundle.getBundle("org.apache.tapestry.TapestryStrings");}
__CLOVER_33_0.S[11998]++;String pattern = _strings.getString(key);
__CLOVER_33_0.S[11999]++;if ((((args == null) && (++__CLOVER_33_0.CT[2066] != 0)) || (++__CLOVER_33_0.CF[2066] == 0))){
__CLOVER_33_0.S[12000]++;return pattern;}
__CLOVER_33_0.S[12001]++;return MessageFormat.format(pattern, args);
} finally { }}
/**
* Convienience method for invoking {@link #format(String, Object[])}.
*
* @since 3.0
*/
public static String getMessage(String key)
{try { __CLOVER_33_0.M[2918]++;
__CLOVER_33_0.S[12002]++;return format(key, null);
} finally { }}
/**
* Convienience method for invoking {@link #format(String, Object[])}.
*
* @since 3.0
*/
public static String format(String key, Object arg)
{try { __CLOVER_33_0.M[2919]++;
__CLOVER_33_0.S[12003]++;return format(key, new Object[]
{ arg });
} finally { }}
/**
* Convienience method for invoking {@link #format(String, Object[])}.
*
* @since 3.0
*/
public static String format(String key, Object arg1, Object arg2)
{try { __CLOVER_33_0.M[2920]++;
__CLOVER_33_0.S[12004]++;return format(key, new Object[]
{ arg1, arg2 });
} finally { }}
/**
* Convienience method for invoking {@link #format(String, Object[])}.
*
* @since 3.0
*/
public static String format(String key, Object arg1, Object arg2, Object arg3)
{try { __CLOVER_33_0.M[2921]++;
__CLOVER_33_0.S[12005]++;return format(key, new Object[]
{ arg1, arg2, arg3 });
} finally { }}
private static final String UNKNOWN_VERSION = "Unknown";
/**
* Invoked when the class is initialized to read the current version file.
*/
private static final String readVersion()
{try { __CLOVER_33_0.M[2922]++;
__CLOVER_33_0.S[12006]++;Properties props = new Properties();
__CLOVER_33_0.S[12007]++;try
{
__CLOVER_33_0.S[12008]++;InputStream in = Tapestry.class.getResourceAsStream("version.properties");
__CLOVER_33_0.S[12009]++;if ((((in == null) && (++__CLOVER_33_0.CT[2067] != 0)) || (++__CLOVER_33_0.CF[2067] == 0))){
__CLOVER_33_0.S[12010]++;return UNKNOWN_VERSION;}
__CLOVER_33_0.S[12011]++;props.load(in);
__CLOVER_33_0.S[12012]++;in.close();
__CLOVER_33_0.S[12013]++;return props.getProperty("project.version", UNKNOWN_VERSION);
}
catch (IOException ex)
{
__CLOVER_33_0.S[12014]++;return UNKNOWN_VERSION;
}
} finally { }}
/**
* Returns the size of a collection, or zero if the collection is null.
*
* @since 2.2
*/
public static int size(Collection c)
{try { __CLOVER_33_0.M[2923]++;
__CLOVER_33_0.S[12015]++;if ((((c == null) && (++__CLOVER_33_0.CT[2068] != 0)) || (++__CLOVER_33_0.CF[2068] == 0))){
__CLOVER_33_0.S[12016]++;return 0;}
__CLOVER_33_0.S[12017]++;return c.size();
} finally { }}
/**
* Returns the length of the array, or 0 if the array is null.
*
* @since 2.2
*/
public static int size(Object[] array)
{try { __CLOVER_33_0.M[2924]++;
__CLOVER_33_0.S[12018]++;if ((((array == null) && (++__CLOVER_33_0.CT[2069] != 0)) || (++__CLOVER_33_0.CF[2069] == 0))){
__CLOVER_33_0.S[12019]++;return 0;}
__CLOVER_33_0.S[12020]++;return array.length;
} finally { }}
/**
* Returns true if the Map is null or empty.
*
* @since 3.0
*/
public static boolean isEmpty(Map map)
{try { __CLOVER_33_0.M[2925]++;
__CLOVER_33_0.S[12021]++;return map == null || map.isEmpty();
} finally { }}
/**
* Returns true if the Collection is null or empty.
*
* @since 3.0
*/
public static boolean isEmpty(Collection c)
{try { __CLOVER_33_0.M[2926]++;
__CLOVER_33_0.S[12022]++;return c == null || c.isEmpty();
} finally { }}
/**
* Converts a {@link Map}to an even-sized array of key/value pairs. This may be useful when
* using a Map as service parameters (with {@link org.apache.tapestry.link.DirectLink}.
* Assuming the keys and values are simple objects (String, Boolean, Integer, etc.), then the
* representation as an array will encode more efficiently (via
* {@link org.apache.tapestry.util.io.DataSqueezerImpl}than serializing the Map and its
* contents.
*
* @return the array of keys and values, or null if the input Map is null or empty
* @since 2.2
*/
public static Object[] convertMapToArray(Map map)
{try { __CLOVER_33_0.M[2927]++;
__CLOVER_33_0.S[12023]++;if ((((isEmpty(map)) && (++__CLOVER_33_0.CT[2070] != 0)) || (++__CLOVER_33_0.CF[2070] == 0))){
__CLOVER_33_0.S[12024]++;return null;}
__CLOVER_33_0.S[12025]++;Set entries = map.entrySet();
__CLOVER_33_0.S[12026]++;Object[] result = new Object[2 * entries.size()];
__CLOVER_33_0.S[12027]++;int x = 0;
__CLOVER_33_0.S[12028]++;Iterator i = entries.iterator();
__CLOVER_33_0.S[12029]++;while ((((i.hasNext()) && (++__CLOVER_33_0.CT[2071] != 0)) || (++__CLOVER_33_0.CF[2071] == 0))){
{
__CLOVER_33_0.S[12030]++;Map.Entry entry = (Map.Entry) i.next();
__CLOVER_33_0.S[12031]++;result[x++] = entry.getKey();
__CLOVER_33_0.S[12032]++;result[x++] = entry.getValue();
}}
__CLOVER_33_0.S[12033]++;return result;
} finally { }}
/**
* Converts an even-sized array of objects back into a {@link Map}.
*
* @see #convertMapToArray(Map)
* @return a Map, or null if the array is null or empty
* @since 2.2
*/
public static Map convertArrayToMap(Object[] array)
{try { __CLOVER_33_0.M[2928]++;
__CLOVER_33_0.S[12034]++;if ((((array == null || array.length == 0) && (++__CLOVER_33_0.CT[2072] != 0)) || (++__CLOVER_33_0.CF[2072] == 0))){
__CLOVER_33_0.S[12035]++;return null;}
__CLOVER_33_0.S[12036]++;if ((((array.length % 2 != 0) && (++__CLOVER_33_0.CT[2073] != 0)) || (++__CLOVER_33_0.CF[2073] == 0))){
__CLOVER_33_0.S[12037]++;throw new IllegalArgumentException(getMessage("Tapestry.even-sized-array"));}
__CLOVER_33_0.S[12038]++;Map result = new HashMap();
__CLOVER_33_0.S[12039]++;int x = 0;
__CLOVER_33_0.S[12040]++;while ((((x < array.length) && (++__CLOVER_33_0.CT[2074] != 0)) || (++__CLOVER_33_0.CF[2074] == 0))){
{
__CLOVER_33_0.S[12041]++;Object key = array[x++];
__CLOVER_33_0.S[12042]++;Object value = array[x++];
__CLOVER_33_0.S[12043]++;result.put(key, value);
}}
__CLOVER_33_0.S[12044]++;return result;
} finally { }}
/**
* Returns the application root location, which is in the {@link javax.servlet.ServletContext},
* based on the {@link javax.servlet.http.HttpServletRequest#getServletPath() servlet path}.
*
* @since 3.0
*/
public static Resource getApplicationRootLocation(IRequestCycle cycle)
{try { __CLOVER_33_0.M[2929]++;
__CLOVER_33_0.S[12045]++;RequestContext context = cycle.getRequestContext();
__CLOVER_33_0.S[12046]++;ServletContext servletContext = context.getServlet().getServletContext();
__CLOVER_33_0.S[12047]++;String servletPath = context.getRequest().getServletPath();
// Could strip off the servlet name (i.e., "app" in "/app") but
// there's no need.
__CLOVER_33_0.S[12048]++;return new ContextResource(servletContext, servletPath);
} finally { }}
/**
* Given a Class, creates a presentable name for the class, even if the class is a scalar type
* or Array type.
*
* @since 3.0
*/
public static String getClassName(Class subject)
{try { __CLOVER_33_0.M[2930]++;
__CLOVER_33_0.S[12049]++;if ((((subject.isArray()) && (++__CLOVER_33_0.CT[2075] != 0)) || (++__CLOVER_33_0.CF[2075] == 0))){
__CLOVER_33_0.S[12050]++;return getClassName(subject.getComponentType()) + "[]";}
__CLOVER_33_0.S[12051]++;return subject.getName();
} finally { }}
/**
* Creates an exception indicating the binding value is null.
*
* @since 3.0
*/
public static BindingException createNullBindingException(IBinding binding)
{try { __CLOVER_33_0.M[2931]++;
__CLOVER_33_0.S[12052]++;return new BindingException(getMessage("null-value-for-binding"), binding);
} finally { }}
/** @since 3.0 * */
public static ApplicationRuntimeException createNoSuchComponentException(IComponent component,
String id, Location location)
{try { __CLOVER_33_0.M[2932]++;
__CLOVER_33_0.S[12053]++;return new ApplicationRuntimeException(format("no-such-component", component
.getExtendedId(), id), component, location, null);
} finally { }}
/** @since 3.0 * */
public static BindingException createRequiredParameterException(IComponent component,
String parameterName)
{try { __CLOVER_33_0.M[2933]++;
__CLOVER_33_0.S[12054]++;return new BindingException(format("required-parameter", parameterName, component
.getExtendedId()), component, null, component.getBinding(parameterName), null);
} finally { }}
/** @since 3.0 * */
public static ApplicationRuntimeException createRenderOnlyPropertyException(
IComponent component, String propertyName)
{try { __CLOVER_33_0.M[2934]++;
__CLOVER_33_0.S[12055]++;return new ApplicationRuntimeException(format(
"render-only-property",
propertyName,
component.getExtendedId()), component, null, null);
} finally { }}
/**
* Clears the list of method invocations.
*
* @see #checkMethodInvocation(Object, String, Object)
* @since 3.0
*/
public static void clearMethodInvocations()
{try { __CLOVER_33_0.M[2935]++;
__CLOVER_33_0.S[12056]++;_invokedMethodIds.set(null);
} finally { }}
/**
* Adds a method invocation to the list of invocations. This is done in a super-class
* implementations.
*
* @see #checkMethodInvocation(Object, String, Object)
* @since 3.0
*/
public static void addMethodInvocation(Object methodId)
{try { __CLOVER_33_0.M[2936]++;
__CLOVER_33_0.S[12057]++;List methodIds = (List) _invokedMethodIds.get();
__CLOVER_33_0.S[12058]++;if ((((methodIds == null) && (++__CLOVER_33_0.CT[2076] != 0)) || (++__CLOVER_33_0.CF[2076] == 0))){
{
__CLOVER_33_0.S[12059]++;methodIds = new ArrayList();
__CLOVER_33_0.S[12060]++;_invokedMethodIds.set(methodIds);
}}
__CLOVER_33_0.S[12061]++;methodIds.add(methodId);
} finally { }}
/**
* Checks to see if a particular method has been invoked. The method is identified by a methodId
* (usually a String). The methodName and object are used to create an error message.
* <p>
* The caller should invoke {@link #clearMethodInvocations()}, then invoke a method on the
* object. The super-class implementation should invoke {@link #addMethodInvocation(Object)}to
* indicate that it was, in fact, invoked. The caller then invokes this method to vlaidate that
* the super-class implementation was invoked.
* <p>
* The list of method invocations is stored in a {@link ThreadLocal}variable.
*
* @since 3.0
*/
public static void checkMethodInvocation(Object methodId, String methodName, Object object)
{try { __CLOVER_33_0.M[2937]++;
__CLOVER_33_0.S[12062]++;List methodIds = (List) _invokedMethodIds.get();
__CLOVER_33_0.S[12063]++;if ((((methodIds != null && methodIds.contains(methodId)) && (++__CLOVER_33_0.CT[2077] != 0)) || (++__CLOVER_33_0.CF[2077] == 0))){
__CLOVER_33_0.S[12064]++;return;}
__CLOVER_33_0.S[12065]++;throw new ApplicationRuntimeException(Tapestry.format(
"Tapestry.missing-method-invocation",
object.getClass().getName(),
methodName));
} finally { }}
/**
* Method used by pages and components to send notifications about property changes.
*
* @param component
* the component containing the property
* @param propertyName
* the name of the property which changed
* @param newValue
* the new value for the property
* @since 3.0
*/
public static void fireObservedChange(IComponent component, String propertyName, Object newValue)
{try { __CLOVER_33_0.M[2938]++;
__CLOVER_33_0.S[12066]++;ChangeObserver observer = component.getPage().getChangeObserver();
__CLOVER_33_0.S[12067]++;if ((((observer == null) && (++__CLOVER_33_0.CT[2078] != 0)) || (++__CLOVER_33_0.CF[2078] == 0))){
__CLOVER_33_0.S[12068]++;return;}
__CLOVER_33_0.S[12069]++;ObservedChangeEvent event = new ObservedChangeEvent(component, propertyName, newValue);
__CLOVER_33_0.S[12070]++;observer.observeChange(event);
} finally { }}
/**
* Returns true if the input is null or contains only whitespace.
* <p>
* Note: Yes, you'd think we'd use <code>StringUtils</code>, but with the change in names and
* behavior between releases, it is smarter to just implement our own little method!
*
* @since 3.0
*/
public static boolean isBlank(String input)
{try { __CLOVER_33_0.M[2939]++;
__CLOVER_33_0.S[12071]++;if ((((input == null || input.length() == 0) && (++__CLOVER_33_0.CT[2079] != 0)) || (++__CLOVER_33_0.CF[2079] == 0))){
__CLOVER_33_0.S[12072]++;return true;}
__CLOVER_33_0.S[12073]++;return input.trim().length() == 0;
} finally { }}
/**
* Returns true if the input is not null and not empty (or only whitespace).
*
* @since 3.0
*/
public static boolean isNonBlank(String input)
{try { __CLOVER_33_0.M[2940]++;
__CLOVER_33_0.S[12074]++;return !isBlank(input);
} finally { }}
}