Ejemplo n.º 1
0
    /** Runs the script. */
    public void handleEvent(Event evt) {
      Element elt = (Element) evt.getCurrentTarget();
      // Evaluate the script
      String script = handlerElement.getTextContent();
      if (script.length() == 0) return;

      DocumentLoader dl = bridgeContext.getDocumentLoader();
      AbstractDocument d = (AbstractDocument) handlerElement.getOwnerDocument();
      int line = dl.getLineNumber(handlerElement);
      final String desc =
          Messages.formatMessage(
              HANDLER_SCRIPT_DESCRIPTION,
              new Object[] {d.getDocumentURI(), eventNamespaceURI, eventType, new Integer(line)});

      // Find the scripting language
      String lang =
          handlerElement.getAttributeNS(null, SVGConstants.SVG_CONTENT_SCRIPT_TYPE_ATTRIBUTE);
      if (lang.length() == 0) {
        Element e = elt;
        while (e != null
            && (!SVGConstants.SVG_NAMESPACE_URI.equals(e.getNamespaceURI())
                || !SVGConstants.SVG_SVG_TAG.equals(e.getLocalName()))) {
          e = SVGUtilities.getParentElement(e);
        }
        if (e == null) return;

        lang = e.getAttributeNS(null, SVGConstants.SVG_CONTENT_SCRIPT_TYPE_ATTRIBUTE);
      }

      runEventHandler(script, evt, lang, desc);
    }
Ejemplo n.º 2
0
 /** Tells whether the given SVG document is dynamic. */
 public static boolean isDynamicDocument(BridgeContext ctx, Document doc) {
   Element elt = doc.getDocumentElement();
   if ((elt != null) && SVGConstants.SVG_NAMESPACE_URI.equals(elt.getNamespaceURI())) {
     if (elt.getAttributeNS(null, SVGConstants.SVG_ONABORT_ATTRIBUTE).length() > 0) {
       return true;
     }
     if (elt.getAttributeNS(null, SVGConstants.SVG_ONERROR_ATTRIBUTE).length() > 0) {
       return true;
     }
     if (elt.getAttributeNS(null, SVGConstants.SVG_ONRESIZE_ATTRIBUTE).length() > 0) {
       return true;
     }
     if (elt.getAttributeNS(null, SVGConstants.SVG_ONUNLOAD_ATTRIBUTE).length() > 0) {
       return true;
     }
     if (elt.getAttributeNS(null, SVGConstants.SVG_ONSCROLL_ATTRIBUTE).length() > 0) {
       return true;
     }
     if (elt.getAttributeNS(null, SVGConstants.SVG_ONZOOM_ATTRIBUTE).length() > 0) {
       return true;
     }
     return isDynamicElement(ctx, doc.getDocumentElement());
   }
   return false;
 }
Ejemplo n.º 3
0
  /** Removes the scripting listeners from the given element. */
  protected void removeScriptingListenersOn(Element elt) {
    String eltNS = elt.getNamespaceURI();
    String eltLN = elt.getLocalName();
    if (SVGConstants.SVG_NAMESPACE_URI.equals(eltNS)
        && SVG12Constants.SVG_HANDLER_TAG.equals(eltLN)) {
      // For this 'handler' element, remove the handler for the given
      // event type.
      AbstractElement tgt = (AbstractElement) elt.getParentNode();
      String eventType =
          elt.getAttributeNS(
              XMLConstants.XML_EVENTS_NAMESPACE_URI, XMLConstants.XML_EVENTS_EVENT_ATTRIBUTE);
      String eventNamespaceURI = XMLConstants.XML_EVENTS_NAMESPACE_URI;
      if (eventType.indexOf(':') != -1) {
        String prefix = DOMUtilities.getPrefix(eventType);
        eventType = DOMUtilities.getLocalName(eventType);
        eventNamespaceURI = ((AbstractElement) elt).lookupNamespaceURI(prefix);
      }

      EventListener listener =
          (EventListener) handlerScriptingListeners.put(eventNamespaceURI, eventType, elt, null);
      tgt.removeEventListenerNS(eventNamespaceURI, eventType, listener, false);
    }

    super.removeScriptingListenersOn(elt);
  }
Ejemplo n.º 4
0
  /** Tells whether the given SVG element is dynamic. */
  public static boolean isDynamicElement(Element elt, BridgeContext ctx, List bridgeExtensions) {
    Iterator i = bridgeExtensions.iterator();
    while (i.hasNext()) {
      BridgeExtension bridgeExtension = (BridgeExtension) i.next();
      if (bridgeExtension.isDynamicElement(elt)) {
        return true;
      }
    }
    if (SVGConstants.SVG_NAMESPACE_URI.equals(elt.getNamespaceURI())) {
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONKEYUP_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONKEYDOWN_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONKEYPRESS_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONLOAD_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONERROR_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONACTIVATE_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONCLICK_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONFOCUSIN_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONFOCUSOUT_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONMOUSEDOWN_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONMOUSEMOVE_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONMOUSEOUT_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONMOUSEOVER_ATTRIBUTE).length() > 0) {
        return true;
      }
      if (elt.getAttributeNS(null, SVGConstants.SVG_ONMOUSEUP_ATTRIBUTE).length() > 0) {
        return true;
      }
    }

    for (Node n = elt.getFirstChild(); n != null; n = n.getNextSibling()) {
      if (n.getNodeType() == Node.ELEMENT_NODE) {
        if (isDynamicElement(ctx, (Element) n)) {
          return true;
        }
      }
    }
    return false;
  }