use of org.w3c.dom.svg.SVGAElement in project scout.rt by eclipse.
the class SVGUtility method removeHyperlink.
/**
* A link is enclosed to the main element
* <p>
* Moves move all inner elements out of the link element and removes the link element
*/
public static void removeHyperlink(SVGAElement e) {
if (SVGConstants.SVG_A_TAG.equals(e.getTagName())) {
NodeList nodes = e.getChildNodes();
for (int i = 0, n = nodes.getLength(); i < n; i++) {
Node node = nodes.item(i);
if (node instanceof Element) {
e.getParentNode().insertBefore(nodes.item(i), e);
}
}
e.getParentNode().removeChild(e);
}
}
use of org.w3c.dom.svg.SVGAElement in project scout.rt by eclipse.
the class SVGUtility method addHyperlink.
/**
* Enclose the element with a link to an url
* <p>
* Bug fix: batik sometimes creates a new namespace for xlink even though the namespace is already defined. This
* utility method fixes that behaviour.
* <p>
* Bug:
* <xmp><a xlink:actuate="onRequest" xlink:type="simple" xlink:show="replace" xmlns:ns3="http://www.w3.org/1999/xlink"
* ns3:href="http://local/info-prev">....</a></xmp>
* <p>
* Fixed:
* <xmp><a xlink:actuate="onRequest" xlink:type="simple" xlink:show="replace" xlink:href="http://local/info-prev">....
* </a></xmp>
*/
public static void addHyperlink(Element e, String url) {
SVGAElement aElem = (SVGAElement) e.getOwnerDocument().createElementNS(SVG_NS, "a");
e.getParentNode().insertBefore(aElem, e);
e.getParentNode().removeChild(e);
aElem.appendChild(e);
aElem.getHref().setBaseVal(url);
// bug fix: remove xmlns:xlink=... attributes, change attributes of ns xlink to have name prefixed with 'xlink'
NamedNodeMap nnmap = aElem.getAttributes();
for (int i = 0, n = nnmap.getLength(); i < n; i++) {
Node node = nnmap.item(i);
if (node instanceof Attr) {
Attr a = (Attr) node;
if (XLINK_NS.equals(a.getNamespaceURI()) && !"xlink".equals(a.getPrefix())) {
nnmap.removeNamedItemNS(a.getNamespaceURI(), a.getLocalName());
a.setPrefix("xlink");
nnmap.setNamedItemNS(a);
}
}
}
for (int i = 0, n = nnmap.getLength(); i < n; i++) {
Node node = nnmap.item(i);
if (node instanceof Attr) {
Attr a = (Attr) node;
if (javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(a.getNamespaceURI())) {
nnmap.removeNamedItemNS(a.getNamespaceURI(), a.getLocalName());
}
}
}
}
use of org.w3c.dom.svg.SVGAElement in project scout.rt by eclipse.
the class SVGUtilityTest method assertHyperlinkAdded.
private void assertHyperlinkAdded(Element e, String url) {
if (!(e.getParentNode() instanceof SVGAElement)) {
Assert.fail("parent is not an 'a-tag'");
}
SVGAElement parent = (SVGAElement) e.getParentNode();
Assert.assertEquals(parent.getHref().getBaseVal(), url);
}
Aggregations