¿Cómo acceder a una hoja de estilo externa a través de la interfaz de Documento en Java?

I have an interface reference (en vez de Document) pointing to a valid object. The problem is that I want to view the papa attribute associated with a particular element in DOM, but it will only expose en línea attributes (while papa has been set through an externo stylesheet). The end goal is to acquire a reference to ViewCSS, as I want to view the associated computed style - how would I do this? I'm presuming, that acquiring a DocumentView object might be needed (if so, how, as I did not find any method that will return the aforementioned object)?


Document document = ...;

document.getImplementation().hasFeature("Views", "2.0"));

esto vuelve verdadero.

Object obj = document.getImplementation().getFeature("Views", "2.0");

this throws an java.lang.UnsupportedOperationException: Not supported yet.


What am I doing wrong, how to fix it and what is the best way to go about this (I want to view/cambiar the associated computed style for this document)? Thank you.

Editar:

I think this is an important part of details that should have been provided initially:

java.lang.UnsupportedOperationException: Not supported yet.
    at com.sun.webpane.webkit.dom.NodeImpl.getFeature(Unknown Source)

el Documento object returned was from a javafx package triggered on motor web.

preguntado el 31 de julio de 12 a las 10:07

I believe you met a bug. I've filed it as javafx-jira.kenai.com/browse/RT-23857 -

3 Respuestas

May be this fragment solves your problem:

Document doc = ???;
HTMLDocument htmlDoc = (HTMLDocument)doc;
final HTMLBodyElement body = (HTMLBodyElement)htmlDoc.getBody();

//JS [window] access
DOMWindowImpl wnd =
        (DOMWindowImpl)((DocumentView)htmlDoc).getDefaultView();

//Style access
CSSStyleDeclaration style = wnd.getComputedStyle(body, "");
assertEquals("Style extraction", "blue", style.getPropertyValue("background-color"));

Respondido 03 ago 12, 17:08

hmm, sorry, what am I missing - is DOMWindowImpl a part of JFX2.2? otherwise what is the proper package path for it in 2.1? Same goes for assertEquals. - XXL

[DOMWindowImpl] is a part of JFX2.2 (very last moment), but it is undocumented and subject for changes. That part of project was essentially changed and is not accessible in JFX2.1. The [assertEquals] is a unit test validation procedure (CSS "background-color" has a "blue" value). - uta

The problem is that [Source/WebCore/dom/Node.idl] in Webkit does not support [getFeature] method:

#if 0
        DOMObject          getFeature(in DOMString feature, 
                                      in DOMString version);
        DOMUserData        setUserData(in DOMString key, 
                                       in DOMUserData data, 
                                       in UserDataHandler handler);
        DOMUserData        getUserData(in DOMString key);
#endif /* 0 */

So, the only thing I could do - make a stub for it in [com.sun.webpane.webkit.dom.DOMImplementationImpl.java], [com.sun.webpane.webkit.dom.NodeImpl.java]

public Object getFeature(String feature, String version) {
    throw new UnsupportedOperationException("Not supported yet.");
}

Eso es un característica. Regards, -uta

Respondido 09 ago 12, 15:08

Can you check what class is being returned by document.getImplementation() (try to print its .getClass())

My best guess is .getFeature() is an enhancement in Java 5 and it looks like there is a half baked implementation of DOMImplementation in your class path. Get the real class being loaded and check its doc so see if they have an implementation for getFeatures() method or not.

Respondido 31 Jul 12, 10:07

I've deleted my previous wall of comments, heh. com.sun.webpane.webkit.dom.DOMImplementationImpl por getImplementation() y com.sun.webpane.webkit.dom.HTMLDocumentImpl por javafx.​scene.​web.​WebEngine / obtenerDocumento(). It seems this might be indeed the case of a half-baked implementation.. - XXL

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.