You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Apache Wiki <wi...@apache.org> on 2006/02/13 19:53:07 UTC

[Jakarta-tapestry Wiki] Update of "UsingCustomResourceSourceForLibs" by SvenHomburg

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-tapestry Wiki" for change notification.

The following page has been changed by SvenHomburg:
http://wiki.apache.org/jakarta-tapestry/UsingCustomResourceSourceForLibs

New page:
overwrite tapestry's ComponentMessagesSourceImpl like this ...

== the new ComponentMessagesSource implementation ==
{{{
public class Core4ComponentMessagesSourceImpl extends ComponentMessagesSourceImpl
{
    /**
     * Returns an instance of {@link java.util.Properties}containing the properly localized messages for the
     * component, in the {@link java.util.Locale}identified by the component's containing page.
     */
    protected synchronized Properties getLocalizedProperties(IComponent component)
    {
        Properties tapestryProperties = super.getLocalizedProperties(component);

        INamespace iNamespace = component.getNamespace();
        while (iNamespace != null && !iNamespace.isApplicationNamespace())
            iNamespace = iNamespace.getParentNamespace();

        if (iNamespace != null)
        {
            iNamespace.getSpecificationLocation().getPath();
            String globalMessagefile = iNamespace.getSpecification().getProperty("global.message.file");
            if (globalMessagefile == null)
                throw new ApplicationRuntimeException("application property 'global.message.file' not set!");

            globalMessagefile =
                    component.getPage().getRequestCycle().getInfrastructure().getContextRoot().getRelativeResource(globalMessagefile).
                            getResourceURL().getFile();

            try
            {
                tapestryProperties.load(new FileInputStream(globalMessagefile));
            }
            catch (IOException e)
            {
                throw new ApplicationRuntimeException(e);
            }
        }

        return tapestryProperties;
    }
}
}}}

== your application hivemind.xml ==
{{{
    <implementation service-id="tapestry.ComponentMessagesSource">

        <invoke-factory>
            <construct class="de.hsofttec.core4.service.impl.Core4ComponentMessagesSourceImpl">
                <event-listener service-id="tapestry.ResetEventHub"/>
                <set-object property="componentPropertySource" value="infrastructure:componentPropertySource"/>
            </construct>
        </invoke-factory>

    </implementation>
}}}

== put this in your application properties ==
{{{
<meta key="global.message.file" value="WEB-INF/conf/global.messages.properties"/>
}}}

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org