Skip to content

Commit

Permalink
#340 change parameter type from Object to Node
Browse files Browse the repository at this point in the history
I don't know what was the initial idea, and was it intended to pass any other parameters, but currently only `org.w3c.dom.Node` is passed there.
  • Loading branch information
asolntsev committed Jul 19, 2024
1 parent f8b331c commit fc6312f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.xhtmlrenderer.context;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xhtmlrenderer.css.extend.AttributeResolver;
import org.xhtmlrenderer.extend.NamespaceHandler;
import org.xhtmlrenderer.extend.UserAgentCallback;
Expand Down Expand Up @@ -49,89 +50,89 @@ public StandardAttributeResolver(NamespaceHandler nsh, UserAgentCallback uac, Us
* Gets the attributeValue attribute of the StandardAttributeResolver object
*/
@Override
public String getAttributeValue(Object e, String attrName) {
public String getAttributeValue(Node e, String attrName) {
return nsh.getAttributeValue((Element) e, attrName);
}

@Override
public String getAttributeValue(Object e, String namespaceURI, String attrName) {
public String getAttributeValue(Node e, String namespaceURI, String attrName) {
return nsh.getAttributeValue((Element)e, namespaceURI, attrName);
}

/**
* Gets the class attribute of the StandardAttributeResolver object
*/
@Override
public String getClass(Object e) {
public String getClass(Node e) {
return nsh.getClass((Element) e);
}

/**
* Gets the iD attribute of the StandardAttributeResolver object
*/
@Override
public String getID(Object e) {
public String getID(Node e) {
return nsh.getID((Element) e);
}

@Override
public String getNonCssStyling(Object e) {
public String getNonCssStyling(Node e) {
return nsh.getNonCssStyling((Element) e);
}

/**
* Gets the elementStyling attribute of the StandardAttributeResolver object
*/
@Override
public String getElementStyling(Object e) {
public String getElementStyling(Node e) {
return nsh.getElementStyling((Element) e);
}

/**
* Gets the lang attribute of the StandardAttributeResolver object
*/
@Override
public String getLang(Object e) {
public String getLang(Node e) {
return nsh.getLang((Element) e);
}

/**
* Gets the link attribute of the StandardAttributeResolver object
*/
@Override
public boolean isLink(Object e) {
public boolean isLink(Node e) {
return nsh.getLinkUri((Element) e) != null;
}

/**
* Gets the visited attribute of the StandardAttributeResolver object
*/
@Override
public boolean isVisited(Object e) {
public boolean isVisited(Node e) {
return isLink(e) && uac.isVisited(nsh.getLinkUri((Element) e));
}

/**
* Gets the hover attribute of the StandardAttributeResolver object
*/
@Override
public boolean isHover(Object e) {
public boolean isHover(Node e) {
return ui.isHover((Element) e);
}

/**
* Gets the active attribute of the StandardAttributeResolver object
*/
@Override
public boolean isActive(Object e) {
public boolean isActive(Node e) {
return ui.isActive((Element) e);
}

/**
* Gets the focus attribute of the StandardAttributeResolver object
*/
@Override
public boolean isFocus(Object e) {
public boolean isFocus(Node e) {
return ui.isFocus((Element) e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.xhtmlrenderer.css.extend;

import org.w3c.dom.Node;

import javax.annotation.Nullable;

/**
Expand All @@ -42,61 +44,61 @@ public interface AttributeResolver {
* not null if attribute exists.
*/
@Nullable
String getAttributeValue(Object e, String attrName);
String getAttributeValue(Node e, String attrName);

/**
* Required to return null if attribute does not exist and
* not null if attribute exists.
*/
@Nullable
String getAttributeValue(Object e, String namespaceURI, String attrName);
String getAttributeValue(Node e, String namespaceURI, String attrName);

@Nullable
String getClass(Object e);
String getClass(Node e);

@Nullable
String getID(Object e);
String getID(Node e);

/**
* @return The non css styling (specificity 0,0,0,0 on author styles, according to css 2.1)
*/
@Nullable
String getNonCssStyling(Object e);
String getNonCssStyling(Node e);

/**
* @return The elementStyling value
* (corresponding to xhtml style attribute, specificity 1,0,0,0 according to css 2.1)
*/
@Nullable
String getElementStyling(Object e);
String getElementStyling(Node e);

@Nullable
String getLang(Object e);
String getLang(Node e);

/**
* Gets the link attribute of the AttributeResolver object
*/
boolean isLink(Object e);
boolean isLink(Node e);

/**
* Gets the visited attribute of the AttributeResolver object
*/
boolean isVisited(Object e);
boolean isVisited(Node e);

/**
* Gets the hover attribute of the AttributeResolver object
*/
boolean isHover(Object e);
boolean isHover(Node e);

/**
* Gets the active attribute of the AttributeResolver object
*/
boolean isActive(Object e);
boolean isActive(Node e);

/**
* Gets the focus attribute of the AttributeResolver object
*/
boolean isFocus(Object e);
boolean isFocus(Node e);

}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xhtmlrenderer.css.extend.AttributeResolver;
import org.xhtmlrenderer.css.extend.TreeResolver;

Expand All @@ -32,12 +33,12 @@
*/
public class DOMStaticXhtmlAttributeResolver implements AttributeResolver {
@Override
public String getAttributeValue(Object e, String attrName) {
public String getAttributeValue(Node e, String attrName) {
return ((Element) e).getAttribute(attrName);
}

@Override
public String getAttributeValue(Object o, String namespaceURI, String attrName) {
public String getAttributeValue(Node o, String namespaceURI, String attrName) {
Element e = (Element)o;
if (namespaceURI == TreeResolver.NO_NAMESPACE) {
return e.getAttribute(attrName);
Expand All @@ -62,27 +63,27 @@ public String getAttributeValue(Object o, String namespaceURI, String attrName)
}

@Override
public String getClass(Object e) {
public String getClass(Node e) {
return ((Element) e).getAttribute("class");
}

@Override
public String getID(Object e) {
public String getID(Node e) {
return ((Element) e).getAttribute("id");
}

@Override
public String getNonCssStyling(Object e) {
public String getNonCssStyling(Node e) {
return null;
}

@Override
public String getLang(Object e) {
public String getLang(Node e) {
return ((Element) e).getAttribute("lang");
}

@Override
public String getElementStyling(Object el) {
public String getElementStyling(Node el) {
Element e = ((Element) el);
StringBuilder style = new StringBuilder();
if (e.getNodeName().equals("td")) {
Expand All @@ -103,28 +104,28 @@ public String getElementStyling(Object el) {
}

@Override
public boolean isActive(Object e) {
public boolean isActive(Node e) {
return false;
}

@Override
public boolean isFocus(Object e) {
public boolean isFocus(Node e) {
return false;
}

@Override
public boolean isHover(Object e) {
public boolean isHover(Node e) {
return false;
}

@Override
public boolean isLink(Object el) {
public boolean isLink(Node el) {
Element e = ((Element) el);
return e.getNodeName().equalsIgnoreCase("a") && !e.getAttribute("href").isEmpty();
}

@Override
public boolean isVisited(Object e) {
public boolean isVisited(Node e) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public boolean isFocusStyled(Node e) {
return _focusElements.contains(e);
}

protected Mapper matchElement(Node e) {
private Mapper matchElement(Node e) {
synchronized (e) {
Node parent = _treeRes.getParentElement(e);
Mapper child;
Expand All @@ -150,7 +150,7 @@ protected Mapper matchElement(Node e) {
}
}

Mapper createDocumentMapper(List<Stylesheet> stylesheets, String medium) {
private Mapper createDocumentMapper(List<Stylesheet> stylesheets, String medium) {
Map<String, Selector> sorter = new TreeMap<>();
addAllStylesheets(stylesheets, sorter, medium);
XRLog.match("Matcher created with " + sorter.size() + " selectors");
Expand Down

0 comments on commit fc6312f

Please sign in to comment.