Package org.apache.wicket.settings

Examples of org.apache.wicket.settings.IResourceSettings


   */
  public String getString(final String key, final Component component, final IModel<?> model,
    final Locale locale, final String style, final String defaultValue)
    throws MissingResourceException
  {
    final IResourceSettings resourceSettings = Application.get().getResourceSettings();

    String value = getStringIgnoreSettings(key, component, model, locale, style, null);
    if ((value == null) && (defaultValue != null))
    {
      // Resource not found, so handle missing resources based on
      // application configuration and try the default value
      if (resourceSettings.getUseDefaultOnMissingResource())
      {
        value = defaultValue;

        // If a property value has been found, or a default value was given,
        // than replace the placeholder and we are done
        if (value != null)
        {
          return substitutePropertyExpressions(component, value, model);
        }
      }
    }

    // If a property value has been found, or a default value was given,
    // than replace the placeholder and we are done
    if (value != null)
    {
      return value;
    }

    if (resourceSettings.getThrowExceptionOnMissingResource())
    {
      AppendingStringBuffer message = new AppendingStringBuffer("Unable to find property: '");
      message.append(key);
      message.append("'");

View Full Code Here


   * @throws Exception
   */
  @Test
  public void testExceptionOnMissingResourceDefaultValue() throws Exception
  {
    IResourceSettings settings = new ResourceSettings(new MockApplication());
    Assert.assertTrue("exceptionOnMissingResource should default to true",
      settings.getThrowExceptionOnMissingResource());
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testExceptionOnMissingResourceSetsCorrectly() throws Exception
  {
    IResourceSettings settings = new ResourceSettings(new MockApplication());
    settings.setThrowExceptionOnMissingResource(false);
    Assert.assertFalse("exceptionOnMissingResource should have been set to false",
      settings.getThrowExceptionOnMissingResource());
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testUseDefaultOnMissingResourceDefaultValue() throws Exception
  {
    IResourceSettings settings = new ResourceSettings(new MockApplication());
    Assert.assertTrue("useDefaultOnMissingResource should default to true",
      settings.getUseDefaultOnMissingResource());
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testUseDefaultOnMissingResourceSetsCorrectly() throws Exception
  {
    IResourceSettings settings = new ResourceSettings(new MockApplication());
    settings.setUseDefaultOnMissingResource(false);
    Assert.assertFalse("useDefaultOnMissingResource should have been set to false",
      settings.getUseDefaultOnMissingResource());
  }
View Full Code Here

   *
   */
  @Test
  public void testDefaultStringResourceLoaderSetup()
  {
    IResourceSettings settings = new ResourceSettings(new MockApplication());
    List<IStringResourceLoader> loaders = settings.getStringResourceLoaders();
    Assert.assertEquals("There should be 5 default loaders", 5, loaders.size());
    Assert.assertTrue("First loader one should be the component one",
      loaders.get(0) instanceof ComponentStringResourceLoader);
    Assert.assertTrue("Second loader should be the package one",
      loaders.get(1) instanceof PackageStringResourceLoader);
View Full Code Here

   *
   */
  @Test
  public void testOverrideStringResourceLoaderSetup()
  {
    IResourceSettings settings = new ResourceSettings(new MockApplication());
    settings.getStringResourceLoaders().clear();
    settings.getStringResourceLoaders().add(
      new BundleStringResourceLoader("org.apache.wicket.resource.DummyResources"));
    settings.getStringResourceLoaders().add(new ComponentStringResourceLoader());
    List<IStringResourceLoader> loaders = settings.getStringResourceLoaders();
    Assert.assertEquals("There should be 2 overridden loaders", 2, loaders.size());
    Assert.assertTrue("First loader one should be the bundle one",
      loaders.get(0) instanceof BundleStringResourceLoader);
    Assert.assertTrue("Second loader should be the component one",
      loaders.get(1) instanceof ComponentStringResourceLoader);
View Full Code Here

   *             If resource not found and configuration dictates that exception should be thrown
   */
  public String getString(final String key, final Component component, final IModel<?> model,
    final String defaultValue) throws MissingResourceException
  {
    final IResourceSettings resourceSettings = Application.get().getResourceSettings();

    String value = getStringIgnoreSettings(key, component, model, null);
    if ((value == null) && (defaultValue != null))
    {
      // Resource not found, so handle missing resources based on
      // application configuration and try the default value
      if (resourceSettings.getUseDefaultOnMissingResource())
      {
        value = defaultValue;
      }
    }

    // If a property value has been found, or a default value was given,
    // than replace the placeholder and we are done
    if (value != null)
    {
      return substitutePropertyExpressions(component, value, model);
    }

    if (resourceSettings.getThrowExceptionOnMissingResource())
    {
      AppendingStringBuffer message = new AppendingStringBuffer("Unable to find property: '");
      message.append(key);
      message.append("'");

View Full Code Here

   * @throws Exception
   */
  @Test
  public void testExceptionOnMissingResourceDefaultValue() throws Exception
  {
    IResourceSettings settings = new ResourceSettings(new MockApplication());
    Assert.assertTrue("exceptionOnMissingResource should default to true",
      settings.getThrowExceptionOnMissingResource());
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testExceptionOnMissingResourceSetsCorrectly() throws Exception
  {
    IResourceSettings settings = new ResourceSettings(new MockApplication());
    settings.setThrowExceptionOnMissingResource(false);
    Assert.assertFalse("exceptionOnMissingResource should have been set to false",
      settings.getThrowExceptionOnMissingResource());
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.settings.IResourceSettings

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.