Package org.apache.wicket.settings

Examples of org.apache.wicket.settings.IResourceSettings


   * @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 4 default loaders", 4, loaders.size());
    Assert.assertTrue("First loader one should be the component one",
      loaders.get(0) instanceof ComponentStringResourceLoader);
    Assert.assertTrue("Second loader should be the application 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

   *             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();

    boolean addedToPage = (component != null && null != component.findParent(Page.class));
    if (!addedToPage)
    {
      logger
          .warn(
              "Tried to retrieve a localized string for a component that has not yet been added to the page. "
                  + "This can sometimes lead to an invalid or no localized resource returned. "
                  + "Make sure you are not calling Component#getString() inside your Component's constructor. "
                  + "Offending component: {}", component);
    }

    String cacheKey = null;
    String string = null;

    // If this component is not yet added to page we do not want to check
    // cache as we can generate an invalid cache key
    if (addedToPage)
    {
      cacheKey = getCacheKey(key, component);
    }

    // Value not found are cached as well (value = null)
    if (cacheKey != null && cache.containsKey(cacheKey))
    {
      string = getFromCache(cacheKey);
    }
    else
    {
      // Iterate over all registered string resource loaders until the
      // property has been found

      Iterator iter = resourceSettings.getStringResourceLoaders().iterator();
      while (iter.hasNext())
      {
        IStringResourceLoader loader = (IStringResourceLoader)iter.next();
        string = loader.loadStringResource(component, key);
        if (string != null)
        {
          break;
        }
      }

      // Cache the result incl null if not found
      if (cacheKey != null)
      {
        putIntoCache(cacheKey, string);
      }
    }

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

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

    if (resourceSettings.getThrowExceptionOnMissingResource())
    {
      AppendingStringBuffer message = new AppendingStringBuffer("Unable to find resource: " +
          key);
      if (component != null)
      {
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();

    boolean addedToPage = false;
    if (component != null)
    {
      if ((component instanceof Page) || null != component.findParent(Page.class))
      {
        addedToPage = true;
      }

      if (!addedToPage)
      {
        logger.warn(
          "Tried to retrieve a localized string for a component that has not yet been added to the page. "
            + "This can sometimes lead to an invalid or no localized resource returned. "
            + "Make sure you are not calling Component#getString() inside your Component's constructor. "
            + "Offending component: {}", component);
      }
    }


    String cacheKey = null;
    String string = null;

    // If this component is not yet added to page we do not want to check
    // cache as we can generate an invalid cache key
    if ((cache != null) && addedToPage)
    {
      cacheKey = getCacheKey(key, component);
    }

    // Value not found are cached as well (value = null)
    if ((cacheKey != null) && cache.containsKey(cacheKey))
    {
      string = getFromCache(cacheKey);
    }
    else
    {
      // Iterate over all registered string resource loaders until the
      // property has been found

      Iterator<IStringResourceLoader> iter = resourceSettings.getStringResourceLoaders()
        .iterator();
      while (iter.hasNext())
      {
        IStringResourceLoader loader = iter.next();
        string = loader.loadStringResource(component, key);
        if (string != null)
        {
          break;
        }
      }

      // Cache the result incl null if not found
      if (cacheKey != null)
      {
        putIntoCache(cacheKey, string);
      }
    }

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

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

    if (resourceSettings.getThrowExceptionOnMissingResource())
    {
      AppendingStringBuffer message = new AppendingStringBuffer("Unable to find property: '" +
        key + "'");
      if (component != null)
      {
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();

    boolean addedToPage = false;
    if (component != null)
    {
      if ((component instanceof Page) || null != component.findParent(Page.class))
      {
        addedToPage = true;
      }

      if (!addedToPage)
      {
        logger.warn(
          "Tried to retrieve a localized string for a component that has not yet been added to the page. "
            + "This can sometimes lead to an invalid or no localized resource returned. "
            + "Make sure you are not calling Component#getString() inside your Component's constructor. "
            + "Offending component: {}", component);
      }
    }


    String cacheKey = null;
    String string = null;

    // If this component is not yet added to page we do not want to check
    // cache as we can generate an invalid cache key
    if ((cache != null) && addedToPage)
    {
      cacheKey = getCacheKey(key, component);
    }

    // Value not found are cached as well (value = null)
    if ((cacheKey != null) && cache.containsKey(cacheKey))
    {
      string = getFromCache(cacheKey);
    }
    else
    {
      // Iterate over all registered string resource loaders until the
      // property has been found

      Iterator iter = resourceSettings.getStringResourceLoaders().iterator();
      while (iter.hasNext())
      {
        IStringResourceLoader loader = (IStringResourceLoader)iter.next();
        string = loader.loadStringResource(component, key);
        if (string != null)
        {
          break;
        }
      }

      // Cache the result incl null if not found
      if (cacheKey != null)
      {
        putIntoCache(cacheKey, string);
      }
    }

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

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

    if (resourceSettings.getThrowExceptionOnMissingResource())
    {
      AppendingStringBuffer message = new AppendingStringBuffer("Unable to find resource: " +
        key);
      if (component != null)
      {
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();

    boolean addedToPage = false;
    if (component != null)
    {
      if ((component instanceof Page) || null != component.findParent(Page.class))
      {
        addedToPage = true;
      }

      if (!addedToPage)
      {
        logger.warn(
          "Tried to retrieve a localized string for a component that has not yet been added to the page. "
            + "This can sometimes lead to an invalid or no localized resource returned. "
            + "Make sure you are not calling Component#getString() inside your Component's constructor. "
            + "Offending component: {}", component);
      }
    }


    String cacheKey = null;
    String string = null;

    // If this component is not yet added to page we do not want to check
    // cache as we can generate an invalid cache key
    if ((cache != null) && addedToPage)
    {
      cacheKey = getCacheKey(key, component);
    }

    // Value not found are cached as well (value = null)
    if ((cacheKey != null) && cache.containsKey(cacheKey))
    {
      string = getFromCache(cacheKey);
    }
    else
    {
      // Iterate over all registered string resource loaders until the
      // property has been found

      Iterator<IStringResourceLoader> iter = resourceSettings.getStringResourceLoaders()
        .iterator();
      while (iter.hasNext())
      {
        IStringResourceLoader loader = iter.next();
        string = loader.loadStringResource(component, key);
        if (string != null)
        {
          break;
        }
      }

      // Cache the result incl null if not found
      if (cacheKey != null)
      {
        putIntoCache(cacheKey, string);
      }
    }

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

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

    if (resourceSettings.getThrowExceptionOnMissingResource())
    {
      AppendingStringBuffer message = new AppendingStringBuffer("Unable to find resource: " +
        key);
      if (component != null)
      {
View Full Code Here

  {
    // Iterate over all registered string resource loaders until the
    // property has been found
    String string = null;

    final IResourceSettings resourceSettings = Application.get().getResourceSettings();
    Iterator iter = resourceSettings.getStringResourceLoaders().iterator();
    while (iter.hasNext())
    {
      IStringResourceLoader loader = (IStringResourceLoader)iter.next();
      string = loader.loadStringResource(component, key);
      if (string != null)
      {
        break;
      }
    }

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

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

    if (resourceSettings.getThrowExceptionOnMissingResource())
    {
      AppendingStringBuffer message = new AppendingStringBuffer("Unable to find resource: " +
          key);
      if (component != null)
      {
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.