Search in sources :

Example 1 with EventListener

use of org.w3c.dom.events.EventListener in project intellij-community by JetBrains.

the class IpnbJfxUtils method initHyperlinkListener.

private static void initHyperlinkListener(@NotNull final WebEngine engine) {
    engine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
        if (newState == Worker.State.SUCCEEDED) {
            final EventListener listener = new HyperlinkListener(engine);
            addListenerToAllHyperlinkItems(engine, listener);
        }
    });
}
Also used : EventListener(org.w3c.dom.events.EventListener)

Example 2 with EventListener

use of org.w3c.dom.events.EventListener in project intellij-community by JetBrains.

the class StudyBrowserWindow method makeHyperLinkListener.

@NotNull
private EventListener makeHyperLinkListener() {
    return new EventListener() {

        @Override
        public void handleEvent(Event ev) {
            String domEventType = ev.getType();
            if (domEventType.equals(EVENT_TYPE_CLICK)) {
                Element target = (Element) ev.getTarget();
                String hrefAttribute = target.getAttribute("href");
                if (hrefAttribute != null) {
                    final Matcher matcher = IN_COURSE_LINK.matcher(hrefAttribute);
                    if (matcher.matches()) {
                        final String lessonName = matcher.group(1);
                        final String taskName = matcher.group(2);
                        StudyNavigator.navigateToTask(myProject, lessonName, taskName);
                    } else {
                        myEngine.setJavaScriptEnabled(true);
                        myEngine.getLoadWorker().cancel();
                        ev.preventDefault();
                        final String href = getLink(target);
                        if (href == null)
                            return;
                        BrowserUtil.browse(href);
                    }
                }
            }
        }

        @Nullable
        private String getLink(@NotNull Element element) {
            final String href = element.getAttribute("href");
            return href == null ? getLinkFromNodeWithCodeTag(element) : href;
        }

        @Nullable
        private String getLinkFromNodeWithCodeTag(@NotNull Element element) {
            Node parentNode = element.getParentNode();
            NamedNodeMap attributes = parentNode.getAttributes();
            while (attributes.getLength() > 0 && attributes.getNamedItem("class") != null) {
                parentNode = parentNode.getParentNode();
                attributes = parentNode.getAttributes();
            }
            return attributes.getNamedItem("href").getNodeValue();
        }
    };
}
Also used : Matcher(java.util.regex.Matcher) MouseEvent(java.awt.event.MouseEvent) Event(org.w3c.dom.events.Event) EventListener(org.w3c.dom.events.EventListener) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with EventListener

use of org.w3c.dom.events.EventListener in project intellij-community by JetBrains.

the class StudyBrowserWindow method initHyperlinkListener.

private void initHyperlinkListener() {
    myEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
        if (newState == Worker.State.SUCCEEDED) {
            final EventListener listener = makeHyperLinkListener();
            addListenerToAllHyperlinkItems(listener);
        }
    });
}
Also used : EventListener(org.w3c.dom.events.EventListener)

Example 4 with EventListener

use of org.w3c.dom.events.EventListener in project poi by apache.

the class SignatureInfo method preSign.

/**
     * Helper method for adding informations before the signing.
     * Normally {@link #confirmSignature()} is sufficient to be used.
     */
@SuppressWarnings("unchecked")
public DigestInfo preSign(Document document, List<DigestInfo> digestInfos) throws XMLSignatureException, MarshalException {
    signatureConfig.init(false);
    // it's necessary to explicitly set the mdssi namespace, but the sign() method has no
    // normal way to interfere with, so we need to add the namespace under the hand ...
    EventTarget target = (EventTarget) document;
    EventListener creationListener = signatureConfig.getSignatureMarshalListener();
    if (creationListener != null) {
        if (creationListener instanceof SignatureMarshalListener) {
            ((SignatureMarshalListener) creationListener).setEventTarget(target);
        }
        SignatureMarshalListener.setListener(target, creationListener, true);
    }
    /*
         * Signature context construction.
         */
    XMLSignContext xmlSignContext = new DOMSignContext(signatureConfig.getKey(), document);
    URIDereferencer uriDereferencer = signatureConfig.getUriDereferencer();
    if (null != uriDereferencer) {
        xmlSignContext.setURIDereferencer(uriDereferencer);
    }
    for (Map.Entry<String, String> me : signatureConfig.getNamespacePrefixes().entrySet()) {
        xmlSignContext.putNamespacePrefix(me.getKey(), me.getValue());
    }
    xmlSignContext.setDefaultNamespacePrefix("");
    // signatureConfig.getNamespacePrefixes().get(XML_DIGSIG_NS));
    brokenJvmWorkaround(xmlSignContext);
    XMLSignatureFactory signatureFactory = signatureConfig.getSignatureFactory();
    /*
         * Add ds:References that come from signing client local files.
         */
    List<Reference> references = new ArrayList<Reference>();
    for (DigestInfo digestInfo : safe(digestInfos)) {
        byte[] documentDigestValue = digestInfo.digestValue;
        String uri = new File(digestInfo.description).getName();
        Reference reference = SignatureFacet.newReference(uri, null, null, null, documentDigestValue, signatureConfig);
        references.add(reference);
    }
    /*
         * Invoke the signature facets.
         */
    List<XMLObject> objects = new ArrayList<XMLObject>();
    for (SignatureFacet signatureFacet : signatureConfig.getSignatureFacets()) {
        LOG.log(POILogger.DEBUG, "invoking signature facet: " + signatureFacet.getClass().getSimpleName());
        signatureFacet.preSign(document, references, objects);
    }
    /*
         * ds:SignedInfo
         */
    SignedInfo signedInfo;
    try {
        SignatureMethod signatureMethod = signatureFactory.newSignatureMethod(signatureConfig.getSignatureMethodUri(), null);
        CanonicalizationMethod canonicalizationMethod = signatureFactory.newCanonicalizationMethod(signatureConfig.getCanonicalizationMethod(), (C14NMethodParameterSpec) null);
        signedInfo = signatureFactory.newSignedInfo(canonicalizationMethod, signatureMethod, references);
    } catch (GeneralSecurityException e) {
        throw new XMLSignatureException(e);
    }
    /*
         * JSR105 ds:Signature creation
         */
    String signatureValueId = signatureConfig.getPackageSignatureId() + "-signature-value";
    javax.xml.crypto.dsig.XMLSignature xmlSignature = signatureFactory.newXMLSignature(signedInfo, null, objects, signatureConfig.getPackageSignatureId(), signatureValueId);
    /*
         * ds:Signature Marshalling.
         */
    xmlSignature.sign(xmlSignContext);
    /*
         * Completion of undigested ds:References in the ds:Manifests.
         */
    for (XMLObject object : objects) {
        LOG.log(POILogger.DEBUG, "object java type: " + object.getClass().getName());
        List<XMLStructure> objectContentList = object.getContent();
        for (XMLStructure objectContent : objectContentList) {
            LOG.log(POILogger.DEBUG, "object content java type: " + objectContent.getClass().getName());
            if (!(objectContent instanceof Manifest))
                continue;
            Manifest manifest = (Manifest) objectContent;
            List<Reference> manifestReferences = manifest.getReferences();
            for (Reference manifestReference : manifestReferences) {
                if (manifestReference.getDigestValue() != null)
                    continue;
                DOMReference manifestDOMReference = (DOMReference) manifestReference;
                manifestDOMReference.digest(xmlSignContext);
            }
        }
    }
    /*
         * Completion of undigested ds:References.
         */
    List<Reference> signedInfoReferences = signedInfo.getReferences();
    for (Reference signedInfoReference : signedInfoReferences) {
        DOMReference domReference = (DOMReference) signedInfoReference;
        // ds:Reference with external digest value
        if (domReference.getDigestValue() != null)
            continue;
        domReference.digest(xmlSignContext);
    }
    /*
         * Calculation of XML signature digest value.
         */
    DOMSignedInfo domSignedInfo = (DOMSignedInfo) signedInfo;
    ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    domSignedInfo.canonicalize(xmlSignContext, dataStream);
    byte[] octets = dataStream.toByteArray();
    /*
         * TODO: we could be using DigestOutputStream here to optimize memory
         * usage.
         */
    MessageDigest md = CryptoFunctions.getMessageDigest(signatureConfig.getDigestAlgo());
    byte[] digestValue = md.digest(octets);
    String description = signatureConfig.getSignatureDescription();
    return new DigestInfo(digestValue, signatureConfig.getDigestAlgo(), description);
}
Also used : ArrayList(java.util.ArrayList) XMLStructure(javax.xml.crypto.XMLStructure) URIDereferencer(javax.xml.crypto.URIDereferencer) XMLSignContext(javax.xml.crypto.dsig.XMLSignContext) EventListener(org.w3c.dom.events.EventListener) MessageDigest(java.security.MessageDigest) EventTarget(org.w3c.dom.events.EventTarget) XMLSignatureFactory(javax.xml.crypto.dsig.XMLSignatureFactory) DOMSignedInfo(org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo) DOMReference(org.apache.jcp.xml.dsig.internal.dom.DOMReference) Reference(javax.xml.crypto.dsig.Reference) GeneralSecurityException(java.security.GeneralSecurityException) CanonicalizationMethod(javax.xml.crypto.dsig.CanonicalizationMethod) XMLObject(javax.xml.crypto.dsig.XMLObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(javax.xml.crypto.dsig.Manifest) DOMReference(org.apache.jcp.xml.dsig.internal.dom.DOMReference) DOMSignedInfo(org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo) SignedInfo(javax.xml.crypto.dsig.SignedInfo) SignatureFacet(org.apache.poi.poifs.crypt.dsig.facets.SignatureFacet) DOMSignContext(javax.xml.crypto.dsig.dom.DOMSignContext) SignatureMethod(javax.xml.crypto.dsig.SignatureMethod) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File) XMLSignatureException(javax.xml.crypto.dsig.XMLSignatureException) XMLSignature(javax.xml.crypto.dsig.XMLSignature)

Example 5 with EventListener

use of org.w3c.dom.events.EventListener in project elki by elki-project.

the class SVGCheckbox method renderCheckBox.

/**
 * Render the SVG checkbox to a plot
 *
 * @param svgp Plot to draw to
 * @param x X offset
 * @param y Y offset
 * @param size Size factor
 * @return Container element
 */
public Element renderCheckBox(SVGPlot svgp, double x, double y, double size) {
    // create check
    final Element checkmark = SVGEffects.makeCheckmark(svgp);
    checkmark.setAttribute(SVGConstants.SVG_TRANSFORM_ATTRIBUTE, "scale(" + (size / 11) + ") translate(" + x + " " + y + ")");
    if (!checked) {
        checkmark.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, SVGConstants.CSS_DISPLAY_PROPERTY + ":" + SVGConstants.CSS_NONE_VALUE);
    }
    // create box
    Element checkbox_box = SVGUtil.svgRect(svgp.getDocument(), x, y, size, size);
    checkbox_box.setAttribute(SVGConstants.SVG_FILL_ATTRIBUTE, "#d4e4f1");
    checkbox_box.setAttribute(SVGConstants.SVG_STROKE_ATTRIBUTE, "#a0a0a0");
    checkbox_box.setAttribute(SVGConstants.SVG_STROKE_WIDTH_ATTRIBUTE, "0.5");
    // create checkbox
    final Element checkbox = svgp.svgElement(SVGConstants.SVG_G_TAG);
    checkbox.appendChild(checkbox_box);
    checkbox.appendChild(checkmark);
    // create Label
    if (label != null) {
        Element labele = svgp.svgText(x + 2 * size, y + size, label);
        // TODO: font size!
        checkbox.appendChild(labele);
    }
    // add click event listener
    EventTarget targ = (EventTarget) checkbox;
    targ.addEventListener(SVGConstants.SVG_CLICK_EVENT_TYPE, new EventListener() {

        /**
         * Set the checkmark, and fire the event.
         */
        protected void check() {
            checkmark.removeAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE);
            checked = true;
            fireSwitchEvent(new ChangeEvent(SVGCheckbox.this));
        }

        /**
         * Remove the checkmark and fire the event.
         */
        protected void uncheck() {
            checkmark.setAttribute(SVGConstants.SVG_STYLE_ATTRIBUTE, SVGConstants.CSS_DISPLAY_PROPERTY + ":" + SVGConstants.CSS_NONE_VALUE);
            checked = false;
            fireSwitchEvent(new ChangeEvent(SVGCheckbox.this));
        }

        @Override
        public void handleEvent(Event evt) {
            if (checked) {
                uncheck();
            } else {
                check();
            }
        }
    }, false);
    return checkbox;
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) Element(org.w3c.dom.Element) ChangeEvent(javax.swing.event.ChangeEvent) Event(org.w3c.dom.events.Event) EventListener(org.w3c.dom.events.EventListener) EventTarget(org.w3c.dom.events.EventTarget)

Aggregations

EventListener (org.w3c.dom.events.EventListener)7 EventTarget (org.w3c.dom.events.EventTarget)4 Event (org.w3c.dom.events.Event)3 MouseEvent (java.awt.event.MouseEvent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 GeneralSecurityException (java.security.GeneralSecurityException)1 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 ChangeEvent (javax.swing.event.ChangeEvent)1 URIDereferencer (javax.xml.crypto.URIDereferencer)1 XMLStructure (javax.xml.crypto.XMLStructure)1 CanonicalizationMethod (javax.xml.crypto.dsig.CanonicalizationMethod)1 Manifest (javax.xml.crypto.dsig.Manifest)1 Reference (javax.xml.crypto.dsig.Reference)1 SignatureMethod (javax.xml.crypto.dsig.SignatureMethod)1 SignedInfo (javax.xml.crypto.dsig.SignedInfo)1