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);
}
});
}
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();
}
};
}
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);
}
});
}
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);
}
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;
}
Aggregations