Example usage for com.google.gwt.dom.client AnchorElement getRel

List of usage examples for com.google.gwt.dom.client AnchorElement getRel

Introduction

In this page you can find the example usage for com.google.gwt.dom.client AnchorElement getRel.

Prototype

public String getRel() 

Source Link

Document

Forward link type.

Usage

From source file:org.xwiki.gwt.wysiwyg.client.plugin.link.LinkConfigDOMReader.java

License:Open Source License

/**
 * {@inheritDoc}//www  .jav  a2s  .  c  o  m
 * 
 * @see ConfigDOMReader#read(com.google.gwt.dom.client.Element)
 */
public LinkConfig read(AnchorElement anchor) {
    LinkConfig linkConfig = new LinkConfig();

    // Get link meta data.
    DocumentFragment linkMetadata = Element.as(anchor).getMetaData();
    if (linkMetadata != null) {
        // Process the meta data.
        String startComment = linkMetadata.getChildNodes().getItem(0).getNodeValue();
        Element wrappingSpan = (Element) linkMetadata.getChildNodes().getItem(1);
        linkConfig
                .setReference(EscapeUtils.unescapeBackslash(startComment.substring("startwikilink:".length())));
        linkConfig.setType(readLinkType(wrappingSpan, linkConfig.getReference()));
    } else {
        // It's an external link.
        linkConfig.setType(LinkType.EXTERNAL);
    }

    // NOTE: We use getAttribute and not getHref to access the URL because we want the exact value of the attribute
    // and not the resolved (absolute) URL.
    linkConfig.setUrl(anchor.getAttribute("href"));
    linkConfig.setLabel(anchor.getInnerHTML());
    if (anchor.getChildNodes().getLength() == 1
            && "img".equalsIgnoreCase(anchor.getFirstChild().getNodeName())) {
        // The anchor wraps an image.
        ImageElement image = (ImageElement) anchor.getFirstChild();
        linkConfig.setLabelText(imageConfigHTMLParser.read(image).getReference());
        linkConfig.setReadOnlyLabel(true);
    } else {
        linkConfig.setLabelText(anchor.getInnerText());
    }
    linkConfig.setTooltip(anchor.getTitle());
    linkConfig.setOpenInNewWindow("__blank".equals(anchor.getRel()));

    return linkConfig;
}

From source file:org.xwiki.gwt.wysiwyg.client.plugin.link.LinkConfigDOMWriter.java

License:Open Source License

/**
 * {@inheritDoc}//from   ww  w  .j  ava  2s. c  o  m
 * 
 * @see ConfigDOMWriter#write(Object, com.google.gwt.dom.client.Element)
 */
public void write(LinkConfig config, AnchorElement anchor) {
    // Required attributes.
    updateMetaData(anchor, config.getReference(), config.getType());
    anchor.setHref(config.getUrl());
    // Optional attributes.
    updateAttribute(anchor, "title", config.getTooltip());
    if (config.isOpenInNewWindow()) {
        anchor.setRel(TARGET_BLANK);
    } else if (TARGET_BLANK.equalsIgnoreCase(anchor.getRel())) {
        anchor.removeAttribute("rel");
    }
    // Update the content.
    if (!anchor.getInnerHTML().equals(config.getLabel())) {
        // Inner HTML listeners have to be notified in order to extract the meta data.
        Element.as(anchor).xSetInnerHTML(config.getLabel());
    }
}