/**
  * Gets the text value from the container. Container should be a simple tag like div or span. The
  * text node in the VPE is initially wrapped in a span element, thus to get its value two child
  * elements should be skipped.
  *
  * @param textContainer - the tag with text
  * @return localized by VPE string
  */
 private String getLocalizedText(nsIDOMElement textContainer) {
   String text = ""; // $NON-NLS-1$
   if ((textContainer != null)
       && (textContainer.getFirstChild() != null)
       && (textContainer.getFirstChild().getFirstChild() != null)
       && HTML.TAG_SPAN.equalsIgnoreCase(textContainer.getFirstChild().getNodeName())) {
     text = textContainer.getFirstChild().getFirstChild().getNodeValue().trim();
   }
   return text;
 }
Ejemplo n.º 2
0
  /**
   * Checks if the first element in the test file is selected in the VPE when the VPE is just
   * loaded.
   *
   * @throws Throwable
   */
  public void testJBIDE4037Test() throws Throwable {
    setException(null);
    IFile ifile = (IFile) TestUtil.getComponentPath(FILE_PATH, JsfAllTests.IMPORT_PROJECT_NAME);
    IEditorInput input = new FileEditorInput(ifile);
    JSPMultiPageEditor part = openEditor(input);

    TestUtil.waitForJobs();
    nsIDOMElement rootElement =
        TestUtil.getVpeController(part).getXulRunnerEditor().getSelectedElement();

    // check if something selected
    assertNotNull(rootElement);
    // check if the selected element is the first element on the page (we know its ID)
    assertEquals(ROOT_ELEMENT_ID, rootElement.getAttribute(HTML.ATTR_ID));

    if (getException() != null) {
      throw getException();
    }
  }
  /* (non-Javadoc)
   * @see org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools.vpe.editor.context.VpePageContext, org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMDocument)
   */
  public VpeCreationData create(
      VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) {
    Element sourceElement = (Element) sourceNode;
    nsIDOMElement select = visualDocument.createElement(HTML.TAG_SELECT);

    VisualDomUtil.copyAttributes(sourceElement, select, COMMON_SPRING_FORM_ATTRIBUTES_MAP);

    if (SpringConstant.VALUE_TRUE.equals(
        sourceElement.getAttribute(SpringConstant.ATTR_DISABLED))) {
      select.setAttribute(HTML.ATTR_DISABLED, HTML.ATTR_DISABLED);
    }

    if (!SpringConstant.VALUE_FALSE.equals(
        sourceElement.getAttribute(SpringConstant.ATTR_MULTIPLE))) {
      select.setAttribute(HTML.ATTR_MULTIPLE, HTML.ATTR_MULTIPLE);
    }

    if (sourceElement.hasAttribute(SpringConstant.ATTR_ITEMS)) {
      // an inner 'option' tag has to be generated
      String optionBody = sourceElement.getAttribute(SpringConstant.ATTR_ITEMS);
      if (sourceElement.hasAttribute(SpringConstant.ATTR_ITEM_LABEL)) {
        optionBody += '.' + sourceElement.getAttribute(SpringConstant.ATTR_ITEM_LABEL);
      }

      nsIDOMElement option = visualDocument.createElement(HTML.TAG_OPTION);
      option.appendChild(visualDocument.createTextNode(optionBody));
      select.appendChild(option);
    }

    return new VpeCreationData(select);
  }
Ejemplo n.º 4
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;
   }
 }
  /**
   * Creates a node of the visual tree on the node of the source tree. This visual node should not
   * have the parent node This visual node can have child nodes.
   *
   * @param pageContext Contains the information on edited page.
   * @param sourceNode The current node of the source tree.
   * @param visualDocument The document of the visual tree.
   * @return The information on the created node of the visual tree.
   */
  public VpeCreationData create(
      VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) {
    ComponentUtil.setCSSLink(pageContext, SPACER_CSS_FILE, "spacer"); // $NON-NLS-1$
    // convert to Element
    Element sourceElement = (Element) sourceNode;

    nsIDOMElement img = visualDocument.createElement(HTML.TAG_IMG);
    ComponentUtil.setImg(img, IMAGE_NAME);

    // set STYLE attributes
    String attrValue = ComponentUtil.getAttribute(sourceElement, RichFaces.ATTR_STYLE);
    if (attrValue.length() != 0) {
      img.setAttribute(HTML.ATTR_STYLE, attrValue);
    }
    // set CLASS attribute
    attrValue = ComponentUtil.getAttribute(sourceElement, RichFaces.ATTR_STYLE_CLASS);
    String styleClass = RICH_SPACER_STYLE;
    if (attrValue.length() != 0) {
      styleClass += Constants.WHITE_SPACE + attrValue;
    }
    img.setAttribute(HTML.ATTR_CLASS, styleClass);
    // set WIDTH attribute
    String width = ComponentUtil.getAttribute(sourceElement, HTML.ATTR_WIDTH, DEFAULT_SIZE);
    img.setAttribute(HTML.ATTR_WIDTH, width);
    // set HEIGHT attribute
    String height = ComponentUtil.getAttribute(sourceElement, HTML.ATTR_HEIGHT, DEFAULT_SIZE);
    img.setAttribute(HTML.ATTR_HEIGHT, height);

    /*
     * https://jira.jboss.org/jira/browse/JBIDE-3225
     * Component should render its children.
     */
    VpeCreationData creationData =
        VisualDomUtil.createTemplateWithTextContainer(
            sourceElement, img, HTML.TAG_SPAN, visualDocument);

    return creationData;
  }