Ejemplo n.º 1
0
  /**
   * This method has been overridden to load a WComponent from parameters.
   *
   * @param httpServletRequest the servlet request being handled.
   * @return the top-level WComponent for this servlet.
   */
  @Override
  public synchronized WComponent getUI(final Object httpServletRequest) {
    String configuredUIClassName = Config.getInstance().getString(COMPONENT_TO_LAUNCH_PARAM_KEY);

    if (sharedUI == null || !Util.equals(configuredUIClassName, uiClassName)) {
      uiClassName = configuredUIClassName;
      WComponent ui = createUI();

      if (ui instanceof WApplication) {
        sharedUI = (WApplication) ui;
      } else {
        LOG.warn(
            "Top-level component should be a WApplication." + " Creating WApplication wrapper...");

        sharedUI = new WApplication();
        ui.setLocked(false);
        sharedUI.add(ui);
        sharedUI.setLocked(true);
      }

      if (Config.getInstance().getBoolean(SHOW_MEMORY_PROFILE_PARAM_KEY, false)) {
        ProfileContainer profiler = new ProfileContainer();

        sharedUI.setLocked(false);
        sharedUI.add(profiler);
        sharedUI.setLocked(true);
      }
    }

    return sharedUI;
  }
 /** Ensure that the interceptor does nothing as long as the controlling property is disabled. */
 @Test
 public void testPaintWhileDisabled() {
   MyComponent testUI = new MyComponent(TEST_XML);
   Config.getInstance().setProperty(Environment.THEME_CONTENT_PATH, "");
   Config.getInstance().setProperty(TransformXMLInterceptor.PARAMETERS_KEY, "false");
   TestResult actual = generateOutput(testUI);
   Assert.assertEquals(
       "XML should not be transformed when interceptor disabled", TEST_XML, actual.result);
 }
 /** Ensure that the interceptor does nothing as long as the controlling property is disabled. */
 @Test
 public void testPaintWhileEnabledWithThemeContentPathSet() {
   MyComponent testUI = new MyComponent(TEST_XML);
   Config.getInstance().setProperty(Environment.THEME_CONTENT_PATH, "set");
   Config.getInstance().setProperty(TransformXMLInterceptor.PARAMETERS_KEY, "true");
   TestResult actual = generateOutput(testUI);
   Assert.assertEquals(
       "XML should not be transformed when interceptor enabled but theme content path set",
       TEST_XML,
       actual.result);
 }
 /** Test that the interceptor transforms our XML when it is enabled. */
 @Test
 public void testPaintWhileEnabled() {
   final String expected = "<omg><wtf>is good for you</wtf></omg>";
   MyComponent testUI = new MyComponent(TEST_XML);
   Config.getInstance().setProperty(Environment.THEME_CONTENT_PATH, "");
   Config.getInstance().setProperty(TransformXMLInterceptor.PARAMETERS_KEY, "true");
   TestResult actual = generateOutput(testUI);
   Assert.assertEquals(
       "XML should be transformed when interceptor enabled", expected, actual.result);
   Assert.assertEquals(
       "The content type should be correctly set",
       WebUtilities.CONTENT_TYPE_HTML,
       actual.contentType);
 }
Ejemplo n.º 5
0
  /**
   * Creates the UI which the launcher displays. If there is misconfiguration or error, a UI
   * containing an error message is returned.
   *
   * @return the UI which the launcher displays.
   */
  protected WComponent createUI() {
    // Check if the parameter COMPONENT_TO_LAUNCH_PARAM_KEY has been
    // configured with the name of a component to launch.

    WComponent sharedApp = null;

    Configuration config = Config.getInstance();
    uiClassName = config.getString(COMPONENT_TO_LAUNCH_PARAM_KEY);

    if (uiClassName == null) {
      sharedApp =
          new WText(
              "You need to set the class name of the WComponent you want to run.<br />"
                  + "Do this by setting the parameter \""
                  + COMPONENT_TO_LAUNCH_PARAM_KEY
                  + "\" in your \"local_app.properties\" file.<br />"
                  + "Eg.  <code>"
                  + COMPONENT_TO_LAUNCH_PARAM_KEY
                  + "=com.github.bordertech.wcomponents.examples.picker.ExamplePicker</code>");

      ((WText) sharedApp).setEncodeText(false);
    } else {
      UIRegistry registry = UIRegistry.getInstance();
      sharedApp = registry.getUI(uiClassName);

      if (sharedApp == null) {
        sharedApp =
            new WText(
                "Unable to load the component \""
                    + uiClassName
                    + "\".<br />"
                    + "Either the component does not exist as a resource in the classpath,"
                    + " or is not a WComponent.<br />"
                    + "Check that the parameter \""
                    + COMPONENT_TO_LAUNCH_PARAM_KEY
                    + "\" is set correctly.");

        ((WText) sharedApp).setEncodeText(false);
      }
    }

    return sharedApp;
  }
 /** When these tests are done put things back as they were. */
 @AfterClass
 public static void tearDownClass() {
   Config.reset();
 }