This is an automated email from the ASF dual-hosted git repository. dashorst pushed a commit to branch archive/wicket-1.1.x in repository https://gitbox.apache.org/repos/asf/wicket.git
commit 2c8fe42ba20867d14754228ebd7ea9afcfe424eb Author: Igor Vaynberg <[email protected]> AuthorDate: Wed Jan 25 21:02:55 2006 +0000 wicket:message backport git-svn-id: https://svn.apache.org/repos/asf/incubator/wicket/branches/WICKET_1_1@458821 13f79535-47bb-0310-9956-ffa450edef68 --- wicket/src/java/wicket/Application.java | 3 +- wicket/src/java/wicket/WicketMessageResolver.java | 135 +++++++++++++++++++++ wicket/src/java/wicket/markup/WicketTag.java | 8 ++ wicket/src/test/log4j.properties | 2 +- .../html/basic/SimplePageExpectedResult_7.html | 6 +- .../wicket/markup/html/basic/SimplePageTest.java | 10 ++ .../wicket/markup/html/basic/SimplePage_7.html | 6 +- .../wicket/markup/html/basic/SimplePage_7.java | 41 +++++++ wicket/xdocs/changes.xml | 1 + 9 files changed, 200 insertions(+), 12 deletions(-) diff --git a/wicket/src/java/wicket/Application.java b/wicket/src/java/wicket/Application.java index d4ff0bb88c..fcb220bd42 100644 --- a/wicket/src/java/wicket/Application.java +++ b/wicket/src/java/wicket/Application.java @@ -209,7 +209,8 @@ public abstract class Application componentResolvers.add(new HtmlHeaderResolver()); componentResolvers.add(new BodyOnLoadResolver()); componentResolvers.add(new WicketLinkResolver()); - + componentResolvers.add(new WicketMessageResolver()); + // Install button image resource factory addResourceFactory("buttonFactory", new DefaultButtonImageResourceFactory()); } diff --git a/wicket/src/java/wicket/WicketMessageResolver.java b/wicket/src/java/wicket/WicketMessageResolver.java new file mode 100644 index 0000000000..e04d764427 --- /dev/null +++ b/wicket/src/java/wicket/WicketMessageResolver.java @@ -0,0 +1,135 @@ +/* + * $Id: WicketTagComponentResolver.java,v 1.4 2005/01/18 08:04:29 jonathanlocke + * Exp $ $Revision$ $Date$ + * + * ============================================================================== + * 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 wicket; + +import wicket.Component; +import wicket.MarkupContainer; +import wicket.markup.ComponentTag; +import wicket.markup.MarkupException; +import wicket.markup.MarkupStream; +import wicket.markup.WicketTag; +import wicket.markup.html.WebMarkupContainer; +import wicket.markup.html.basic.Label; +import wicket.markup.parser.XmlTag; + +/** + * This is a tag resolver which handles <wicket:message + * attr="myKey">Default Text</wicket:message>. The resolver will + * replace the whole tag with the message found in the properties file + * associated with the Page. If no message is found, the default body text will + * remain. + * + * @author Juergen Donnerstag + */ +public class WicketMessageResolver implements IComponentResolver +{ + private static final long serialVersionUID = 1L; + + /** + * Try to resolve the tag, then create a component, add it to the container + * and render it. + * + * @see wicket.IComponentResolver#resolve(MarkupContainer, MarkupStream, + * ComponentTag) + * + * @param container + * The container parsing its markup + * @param markupStream + * The current markupStream + * @param tag + * The current component tag while parsing the markup + * @return true, if componentId was handle by the resolver. False, otherwise + */ + public boolean resolve(final MarkupContainer container, final MarkupStream markupStream, + final ComponentTag tag) + { + // It must be <body onload> + if (tag instanceof WicketTag) + { + WicketTag wtag = (WicketTag)tag; + if (wtag.isMessageTag() && (wtag.getNamespace() != null)) + { + String messageKey = wtag.getAttributes().getString("key"); + if ((messageKey == null) || (messageKey.trim().length() == 0)) + { + throw new MarkupException( + "Wrong format of <wicket:message key='xxx'>: attribute 'key' is missing"); + } + + final String value = container.getApplication().getLocalizer().getString( + messageKey, container, ""); + + final String id = "_message_" + container.getPage().getAutoIndex(); + Component component = null; + if ((value != null) && (value.trim().length() > 0)) + { + component = new MyLabel(id, value); + } + else + { + component = new WebMarkupContainer(id); + } + + component.setRenderBodyOnly(container.getApplication().getSettings() + .getStripWicketTags()); + + container.autoAdd(component); + + // Yes, we handled the tag + return true; + } + } + + // We were not able to handle the tag + return false; + } + + /** + * A Label with expands open-close tags to open-body-close if required + */ + public static class MyLabel extends Label + { + private static final long serialVersionUID = 1L; + + /** + * Construct. + * + * @param id + * @param value + */ + public MyLabel(final String id, final String value) + { + super(id, value); + } + + /** + * + * @see wicket.Component#onComponentTag(wicket.markup.ComponentTag) + */ + protected void onComponentTag(ComponentTag tag) + { + // Convert <wicket:message /> into + // <wicket:message>...</wicket:message> + if (tag.isOpenClose()) + { + tag.setType(XmlTag.OPEN); + } + super.onComponentTag(tag); + } + } +} \ No newline at end of file diff --git a/wicket/src/java/wicket/markup/WicketTag.java b/wicket/src/java/wicket/markup/WicketTag.java index 295c0ab7b7..a4365c87e5 100644 --- a/wicket/src/java/wicket/markup/WicketTag.java +++ b/wicket/src/java/wicket/markup/WicketTag.java @@ -118,6 +118,14 @@ public class WicketTag extends ComponentTag return "head".equalsIgnoreCase(getName()); } + /** + * @return True, if tag name equals 'wicket:message' + */ + public final boolean isMessageTag() + { + return "message".equalsIgnoreCase(getName()); + } + /** * Gets this tag if it is already mutable, or a mutable copy of this tag if * it is immutable. diff --git a/wicket/src/test/log4j.properties b/wicket/src/test/log4j.properties index 2dc2699f52..e8dc3ba16f 100644 --- a/wicket/src/test/log4j.properties +++ b/wicket/src/test/log4j.properties @@ -6,7 +6,7 @@ log4j.logger.com=INFO log4j.logger.net=INFO log4j.logger.nl=INFO -log4j.logger.wicket=WARN +log4j.logger.wicket=FATAL log4j.appender.Stdout=org.apache.log4j.ConsoleAppender log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout diff --git a/wicket/src/test/wicket/markup/html/basic/SimplePageExpectedResult_7.html b/wicket/src/test/wicket/markup/html/basic/SimplePageExpectedResult_7.html index 65dba54d49..a0f1851e2d 100644 --- a/wicket/src/test/wicket/markup/html/basic/SimplePageExpectedResult_7.html +++ b/wicket/src/test/wicket/markup/html/basic/SimplePageExpectedResult_7.html @@ -1,12 +1,8 @@ <html xmlns:wicket> <body> - <span attr="" wicket:message="attr=myKeyNotExist">Some text</span> - <span attr="default" wicket:message="attr=myKeyNotExist">Some text</span> - <span attr="myValue" wicket:message="attr=myKey">Some text</span> - <span attr="myValue" wicket:message="attr=myKey">Some text</span> <wicket:message key="myKeyNotExsts">Default Text</wicket:message> <wicket:message key="myKey">myValue</wicket:message> <wicket:message key="myKeyNotExsts"/> - <wicket:message key="myKey">myValue</message> + <wicket:message key="myKey">myValue</wicket:message> </body> </html> diff --git a/wicket/src/test/wicket/markup/html/basic/SimplePageTest.java b/wicket/src/test/wicket/markup/html/basic/SimplePageTest.java index 91e5a3f100..6a9e07ddd4 100644 --- a/wicket/src/test/wicket/markup/html/basic/SimplePageTest.java +++ b/wicket/src/test/wicket/markup/html/basic/SimplePageTest.java @@ -115,4 +115,14 @@ public class SimplePageTest extends WicketTestCase } assertTrue("Did expect a MarkupNotFoundException", hit); } + + + /** + * @throws Exception + */ + public void testRenderHomePage_7() throws Exception + { + executeTest(SimplePage_7.class, "SimplePageExpectedResult_7.html"); + } + } diff --git a/wicket/src/test/wicket/markup/html/basic/SimplePage_7.html b/wicket/src/test/wicket/markup/html/basic/SimplePage_7.html index a4d213c36e..a61530970c 100644 --- a/wicket/src/test/wicket/markup/html/basic/SimplePage_7.html +++ b/wicket/src/test/wicket/markup/html/basic/SimplePage_7.html @@ -1,12 +1,8 @@ <html xmlns:wicket> <body> - <span wicket:message="attr=myKeyNotExist">Some text</span> - <span attr="default" wicket:message="attr=myKeyNotExist">Some text</span> - <span wicket:message="attr=myKey">Some text</span> - <span attr="default" wicket:message="attr=myKey">Some text</span> <wicket:message key="myKeyNotExsts">Default Text</wicket:message> <wicket:message key="myKey">Default Text</wicket:message> <wicket:message key="myKeyNotExsts"/> - <wicket:message key="myKey"/> + <wicket:message key="myKey"></wicket:message> </body> </html> diff --git a/wicket/src/test/wicket/markup/html/basic/SimplePage_7.java b/wicket/src/test/wicket/markup/html/basic/SimplePage_7.java new file mode 100644 index 0000000000..2a0d17ea6b --- /dev/null +++ b/wicket/src/test/wicket/markup/html/basic/SimplePage_7.java @@ -0,0 +1,41 @@ +/* + * $Id$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * 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 wicket.markup.html.basic; + +import wicket.PageParameters; +import wicket.markup.html.WebPage; + + +/** + * Mock page for testing. + * + * @author Chris Turner + */ +public class SimplePage_7 extends WebPage +{ + private static final long serialVersionUID = 1L; + + /** + * Construct. + * @param params page params + */ + public SimplePage_7(PageParameters params) + { + } +} diff --git a/wicket/xdocs/changes.xml b/wicket/xdocs/changes.xml index 6f9974395c..cb075413d1 100644 --- a/wicket/xdocs/changes.xml +++ b/wicket/xdocs/changes.xml @@ -11,6 +11,7 @@ <release version="1.2-alpha1" date="tbd" description="Wicket CVS HEAD development"> </release> <release version="1.1.1" date="tbd" description="Wicket 1.1.1"> + <action type="add" dev="Igor Vaynberg" >back ported wicket:message tag functionality from 1.2</action> <action type="update" dev="Igor Vaynberg" due-to="Frank Silbermann">clarified PropertyModel javadoc</action> <action type="update" dev="Igor Vaynberg">Added check and better exception when servlet's init param is missing</action> <action type="update" dev="Igor Vaynberg" issue="1345198">Added label tags for generated input tags in CheckBoxMultipleChoice and RadioChoice</action>
