    001    // Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    // http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5.internal.services;
    016
    017    import org.apache.tapestry5.internal.structure.ComponentPageElement;
    018    import org.apache.tapestry5.internal.structure.Page;
    019    import org.apache.tapestry5.ioc.Location;
    020    import org.apache.tapestry5.ioc.Messages;
    021    import org.apache.tapestry5.ioc.Resource;
    022    import org.apache.tapestry5.ioc.internal.util.InternalUtils;
    023    import org.apache.tapestry5.ioc.internal.util.MessagesImpl;
    024    import org.apache.tapestry5.ioc.services.ClassFabUtils;
    025    import org.apache.tapestry5.runtime.Component;
    026    import org.apache.tapestry5.runtime.RenderCommand;
    027
    028    import java.util.Arrays;
    029    import java.util.Collection;
    030    import java.util.List;
    031
    032    public class ServicesMessages
    033    {
    034        private static final Messages MESSAGES = MessagesImpl.forClass(ServicesMessages.class);
    035
    036        public static String markupWriterNoCurrentElement()
    037        {
    038            return MESSAGES.get("markup-writer-no-current-element");
    039        }
    040
    041        public static String missingTemplateResource(Resource resource)
    042        {
    043            return MESSAGES.format("missing-template-resource", resource);
    044        }
    045
    046        public static String contentInsideBodyNotAllowed(Location location)
    047        {
    048            return MESSAGES.format("content-inside-body-not-allowed", location);
    049        }
    050
    051        public static String renderQueueError(RenderCommand command, Throwable cause)
    052        {
    053            return MESSAGES.format("render-queue-error", command, cause);
    054        }
    055
    056        public static String contextIndexOutOfRange(String methodDescription)
    057        {
    058            return MESSAGES.format("context-index-out-of-range", methodDescription);
    059        }
    060
    061        public static String pageNameUnresolved(String pageClassName)
    062        {
    063            return MESSAGES.format("page-name-unresolved", pageClassName);
    064        }
    065
    066        public static String exceptionInMethodParameter(String methodDescription, int index, Throwable cause)
    067        {
    068            return MESSAGES.format("exception-in-method-parameter", methodDescription, index + 1, cause);
    069        }
    070
    071        public static String componentEventIsAborted(String methodDescription)
    072        {
    073            return MESSAGES.format("component-event-is-aborted", methodDescription);
    074        }
    075
    076        public static String componentInstanceIsNotAPage(Component result)
    077        {
    078            return MESSAGES.format("component-instance-is-not-a-page", result.getComponentResources().getCompleteId());
    079        }
    080
    081        public static String failureReadingMessages(Resource url, Throwable cause)
    082        {
    083            return MESSAGES.format("failure-reading-messages", url, cause);
    084        }
    085
    086        public static String unknownAssetPrefix(String path)
    087        {
    088            return MESSAGES.format("unknown-asset-prefix", path);
    089        }
    090
    091        public static String assetDoesNotExist(Resource resource)
    092        {
    093            return MESSAGES.format("asset-does-not-exist", resource);
    094        }
    095
    096        public static String wrongAssetDigest(Resource resource)
    097        {
    098            return MESSAGES.format("wrong-asset-digest", resource.getPath());
    099        }
    100
    101        public static String unknownValidatorType(String validatorType, List<String> knownValidatorTypes)
    102        {
    103            return MESSAGES.format("unknown-validator-type", validatorType, InternalUtils.join(knownValidatorTypes));
    104        }
    105
    106        public static String validatorSpecificationParseError(int cursor, String specification)
    107        {
    108            return MESSAGES.format("validator-specification-parse-error", specification.charAt(cursor), cursor + 1,
    109                    specification);
    110        }
    111
    112        public static String mixinsInvalidWithoutIdOrType(String elementName)
    113        {
    114            return MESSAGES.format("mixins-invalid-without-id-or-type", elementName);
    115        }
    116
    117        public static String undefinedTapestryAttribute(String elementName, String attributeName,
    118                                                        String allowedAttributeName)
    119        {
    120            return MESSAGES.format("undefined-tapestry-attribute", elementName, attributeName, allowedAttributeName);
    121        }
    122
    123        public static String parameterElementNameRequired()
    124        {
    125            return MESSAGES.get("parameter-element-name-required");
    126        }
    127
    128        public static String missingApplicationStatePersistenceStrategy(String name, Collection<String> availableNames)
    129        {
    130            return MESSAGES.format("missing-application-state-persistence-strategy", name, InternalUtils
    131                    .joinSorted(availableNames));
    132        }
    133
    134        public static String requestException(Throwable cause)
    135        {
    136            return MESSAGES.format("request-exception", cause);
    137        }
    138
    139        public static String clientStateMustBeSerializable(Object newValue)
    140        {
    141            return MESSAGES.format("client-state-must-be-serializable", newValue);
    142        }
    143
    144        public static String corruptClientState()
    145        {
    146            return MESSAGES.get("corrupt-client-state");
    147        }
    148
    149        public static String unclosedAttributeExpression(String expression)
    150        {
    151            return MESSAGES.format("unclosed-attribute-expression", expression);
    152        }
    153
    154        public static String noDisplayForDataType(String datatype)
    155        {
    156            return MESSAGES.format("no-display-for-data-type", datatype);
    157        }
    158
    159        public static String noEditForDataType(String datatype)
    160        {
    161            return MESSAGES.format("no-edit-for-data-type", datatype);
    162        }
    163
    164        public static String missingValidatorConstraint(String validatorType, Class type, String perFormMessageKey,
    165                                                        String generalMessageKey)
    166        {
    167            return MESSAGES.format("missing-validator-constraint", validatorType, type.getName(), perFormMessageKey,
    168                    generalMessageKey);
    169        }
    170
    171        public static String resourcesAccessForbidden(String URI)
    172        {
    173            return MESSAGES.format("resource-access-forbidden", URI);
    174        }
    175
    176        public static String noMarkupFromPageRender(Page page)
    177        {
    178            return MESSAGES.format("no-markup-from-page-render", page.getName());
    179        }
    180
    181        public static String baseClassInWrongPackage(String parentClassName, String className, String suggestedPackage)
    182        {
    183            return MESSAGES.format("base-class-in-wrong-package", parentClassName, className, suggestedPackage);
    184        }
    185
    186        public static String invalidId(String messageKey, String idValue)
    187        {
    188            return MESSAGES.format(messageKey, idValue);
    189        }
    190
    191        public static String noTranslatorForType(Class valueType, Collection<String> typeNames)
    192        {
    193            return MESSAGES.format("no-translator-for-type", ClassFabUtils.toJavaClassName(valueType), InternalUtils
    194                    .joinSorted(typeNames));
    195        }
    196
    197        public static String eventNotHandled(ComponentPageElement element, String eventName)
    198        {
    199            return MESSAGES.format("event-not-handled", eventName, element.getCompleteId());
    200        }
    201
    202        public static String documentMissingHTMLRoot(String rootElementName)
    203        {
    204            return MESSAGES.format("document-missing-html-root", rootElementName);
    205        }
    206
    207        public static String parameterElementDoesNotAllowAttributes()
    208        {
    209            return MESSAGES.get("parameter-element-does-not-allow-attributes");
    210        }
    211
    212        public static String invalidPathForLibraryNamespace(String URI)
    213        {
    214            return MESSAGES.format("invalid-path-for-library-namespace", URI);
    215        }
    216
    217        public static String literalConduitNotUpdateable()
    218        {
    219            return MESSAGES.get("literal-conduit-not-updateable");
    220        }
    221
    222        public static String markupWriterAttributeNameOrValueOmitted(String element, Object[] namesAndValues)
    223        {
    224            return MESSAGES.format("markup-writer-attribute-name-or-value-omitted", element, InternalUtils.join(Arrays
    225                    .asList(namesAndValues)));
    226        }
    227    }