public void testNoDefaultLocaleForChangeAndRefresh() throws Throwable {
    VpeController controller =
        openInVpe(JsfAllTests.IMPORT_JSF_LOCALES_PROJECT_NAME, NO_DEFLOC_CHANGE_REFRESH_PAGE);
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();

    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT_ID);
    String localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'de' locale",
        HELLO2_DE.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
    /*
     * Change the locale
     */
    Element fViewElement =
        controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
    int offset = controller.getSourceBuilder().getPosition(fViewElement, 0, false);
    assertTrue(
        "Previous locale should be 'de'",
        "de"
            .equalsIgnoreCase(
                fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    IRegion reg =
        new FindReplaceDocumentAdapter(
                controller.getSourceBuilder().getStructuredTextViewer().getDocument())
            .find(offset, "de", true, true, false, false);
    controller
        .getSourceBuilder()
        .getStructuredTextViewer()
        .getDocument()
        .replace(reg.getOffset(), reg.getLength(), "en_GB");
    /*
     * Wait until new value is applied and children are refreshed.
     * Wait while all deferred events are processed
     */
    while (Display.getCurrent().readAndDispatch()) ;
    /*
     * Wait while all jobs including started through deferred events are ended
     */
    JobUtils.delay(VpeController.DEFAULT_UPDATE_DELAY_TIME * 4);
    TestUtil.waitForIdle();
    fViewElement = controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
    assertTrue(
        "Current locale should be 'en_GB'",
        "en_GB"
            .equalsIgnoreCase(
                fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    doc = controller.getXulRunnerEditor().getDOMDocument();
    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);

    /*
     * Check the new localized message.
     */
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_GB' locale",
        HELLO_EN_GB.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
    closeEditors();
  }
Пример #2
0
 /** @see com.aptana.ide.editors.unified.ContributedBrowser#execute(java.lang.String) */
 public boolean execute(String script) {
   nsIDOMDocument document = internalGetDocument();
   if (document != null) {
     nsIDOMElement se = document.createElement("script"); // $NON-NLS-1$
     nsIDOMHTMLScriptElement scriptBlock =
         (nsIDOMHTMLScriptElement)
             se.queryInterface(nsIDOMHTMLScriptElement.NS_IDOMHTMLSCRIPTELEMENT_IID);
     String s2 =
         "if("
             + script
             + "){"
             + "document.getElementById('execute').setAttribute('text','success');}"; //$NON-NLS-1$
                                                                                      // //$NON-NLS-2$ //$NON-NLS-3$
     scriptBlock.setText(s2);
     nsIDOMElement executeBlock = document.getElementById("execute"); // $NON-NLS-1$
     if (executeBlock == null) {
       executeBlock = document.createElement("div"); // $NON-NLS-1$
       executeBlock.setAttribute("id", "execute"); // $NON-NLS-1$ //$NON-NLS-2$
       nsIDOMNode body = document.getElementsByTagName("body").item(0); // $NON-NLS-1$
       body.appendChild(executeBlock);
     }
     executeBlock.setAttribute("text", ""); // $NON-NLS-1$ //$NON-NLS-2$
     nsIDOMNode head = document.getElementsByTagName("head").item(0); // $NON-NLS-1$
     head.appendChild(scriptBlock);
     executeBlock = document.getElementById("execute"); // $NON-NLS-1$
     return "success".equals(executeBlock.getAttribute("text")); // $NON-NLS-1$ //$NON-NLS-2$
   } else {
     return false;
   }
 }
 /**
  * Tests that the dafault locale is applied by default, f:view has no locale attribute in this
  * case.
  *
  * @throws Throwable
  */
 public void testDefaultLocale() throws Throwable {
   VpeController controller = openInVpe(JsfAllTests.IMPORT_I18N_PROJECT_NAME, DEFAULT_LOCALE_PAGE);
   nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
   nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT_ID);
   String localizedText = getLocalizedText(localeText);
   assertTrue(
       "Text is '" + localizedText + "', but should be in 'de' locale",
       HELLO_DE.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
   closeEditors();
 }
  /**
   * If there are several f:views on the page. Only the last f:view one should be applied on server,
   * but each f:view should have its own locale.
   *
   * @throws Throwable
   */
  public void testSeveralFViewsWithLocales() throws Throwable {

    IFile file =
        (IFile)
            TestUtil.getComponentPath(SEVERAL_FVIEWS_PAGE, JsfAllTests.IMPORT_JSF_20_PROJECT_NAME);
    assertNotNull(
        "Could not open specified file." //$NON-NLS-1$
            + " componentPage = "
            + SEVERAL_FVIEWS_PAGE //$NON-NLS-1$
            + ";projectName = "
            + JsfAllTests.IMPORT_JSF_20_PROJECT_NAME,
        file); //$NON-NLS-1$
    IEditorInput input = new FileEditorInput(file);
    assertNotNull("Editor input is null", input); // $NON-NLS-1$
    /*
     * open and get the editor
     */
    JSPMultiPageEditor part = openEditor(input);
    VpeController controller = TestUtil.getVpeController(part);

    javaSources = EclipseResourceUtil.getJavaProjectSrcLocations(file.getProject());
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT0_ID);
    String localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "en", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT1_ID);
    localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "de", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT2_ID);
    localizedText = getLocalizedText(localeText);
    /*
     * f:view will use default locale if nothing is specified.
     */
    checkLocaleStrings(file, "en_US", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "en_GB", localizedText); // $NON-NLS-1$

    closeEditors();
  }
 /**
  * After the locale attribute value has been changed and Refresh button is clicked - the correct
  * locale should be applied, bundle messages should be updated and showed in the correct locale.
  *
  * @throws Throwable
  */
 public void testChangeLocaleAndRefresh() throws Throwable {
   VpeController controller =
       openInVpe(JsfAllTests.IMPORT_JSF_20_PROJECT_NAME, CHANGE_LOCALE_AND_REFRESH_PAGE);
   nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
   nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT_ID);
   String localizedText = getLocalizedText(localeText);
   assertTrue(
       "Text is '" + localizedText + "', but should be in 'de' locale",
       HELLO2_DE.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
   /*
    * Change the locale
    */
   Element fViewElement =
       controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
   assertTrue(
       "Previous locale should be 'de'",
       "de"
           .equalsIgnoreCase(
               fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   fViewElement.setAttribute("locale", "en_GB"); // $NON-NLS-1$ //$NON-NLS-2$
   /*
    * Wait until new value is applied and children are refreshed.
    */
   TestUtil.delay(500);
   TestUtil.waitForIdle();
   assertTrue(
       "Current locale should be 'en_GB'",
       "en_GB"
           .equalsIgnoreCase(
               fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   doc = controller.getXulRunnerEditor().getDOMDocument();
   localeText = doc.getElementById(LOCALE_TEXT_ID);
   localizedText = getLocalizedText(localeText);
   /*
    * Check the new localized message.
    */
   assertTrue(
       "Text is '" + localizedText + "', but should be in 'en_GB' locale",
       HELLO_EN_GB.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
   closeEditors();
 }
  public void testNoDefaultLocaleForSingleFLoadBundle() throws Throwable {
    VpeController controller =
        openInVpe(JsfAllTests.IMPORT_JSF_LOCALES_PROJECT_NAME, NO_DEFLOC_ONE_LOAD_BUNDLE_PAGE);
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();

    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT0_ID);
    String localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    localeText = doc.getElementById(LOCALE_TEXT1_ID);
    localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    localeText = doc.getElementById(LOCALE_TEXT2_ID);
    localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    localeText = doc.getElementById(LOCALE_TEXT3_ID);
    localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    closeEditors();
  }