![JAR search and dependency download from the Maven repository](/logo.png)
cz.vutbr.web.domassign.BaseNodeDataImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jstyleparser Show documentation
Show all versions of jstyleparser Show documentation
jStyleParser is a CSS parser written in Java. It has its own application interface that is designed to allow an efficient CSS processing in Java and mapping the values to the Java data types. It parses CSS 2.1 style sheets into structures that can be efficiently assigned to DOM elements. It is intended be the primary CSS parser for the CSSBox library. While handling errors, it is user agent conforming according to the CSS specification.
The newest version!
/**
* BaseNodeDataImpl.java
* Created on 29.12.2016 22:39 by Radek Burget
*/
package cz.vutbr.web.domassign;
import cz.vutbr.web.css.CSSFactory;
import cz.vutbr.web.css.CSSProperty;
import cz.vutbr.web.css.NodeData;
import cz.vutbr.web.css.SupportedCSS;
import cz.vutbr.web.css.Term;
import cz.vutbr.web.css.TermColor;
import cz.vutbr.web.css.TermColor.Keyword;
import cz.vutbr.web.css.TermFactory;
import cz.vutbr.web.css.TermList;
import cz.vutbr.web.css.TermPropertyValue;
import cz.vutbr.web.csskit.DeclarationTransformer;
/**
* A common base for all the NodeData implementations.
* @author burgetr
*/
public abstract class BaseNodeDataImpl implements NodeData {
protected static DeclarationTransformer transformer = CSSFactory.getDeclarationTransformer();
protected static SupportedCSS css = CSSFactory.getSupportedCSS();
@Override
public T getSpecifiedProperty(String name) {
T prop = getProperty(name, true);
if (prop == null) {
@SuppressWarnings("unchecked")
T def = (T) css.getDefaultProperty(name);
return def;
} else {
return prop;
}
}
@Override
public Term> getSpecifiedValue(String name) {
Term> ret = getValue(name, true);
if (ret == null)
ret = css.getDefaultValue(name);
if (ret != null) {
if (ret instanceof TermColor && ((TermColor) ret).getKeyword() == Keyword.CURRENT_COLOR) {
//clone the value fot setting the current color
final TermFactory tf = CSSFactory.getTermFactory();
ret = tf.createColor(tf.createIdent("currentColor"));
//set the current color value
TermColor cvalue = getValue(TermColor.class, "color", true);
if (cvalue == null)
cvalue = (TermColor) css.getDefaultValue("color");
((TermColor) ret).setValue(cvalue.getValue());
}
}
return ret;
}
@Override
public > T getSpecifiedValue(Class clazz, String name) {
return clazz.cast(getSpecifiedValue(name));
}
@Override
public T getProperty(String name, int index) {
return getProperty(name, index, true);
}
@Override
public T getProperty(String name, int index, boolean includeInherited) {
final TermList list = getValue(TermList.class, name, includeInherited);
if (list != null && index < list.size()) {
final TermPropertyValue pair = (TermPropertyValue) list.get(index);
@SuppressWarnings("unchecked")
T ret = (T) pair.getKey();
return ret;
} else {
return null;
}
}
@Override
public Term> getValue(String name, int index, boolean includeInherited) {
final TermList list = getValue(TermList.class, name, includeInherited);
if (list != null && index < list.size()) {
final TermPropertyValue pair = (TermPropertyValue) list.get(index);
return pair.getValue();
} else {
return null;
}
}
@Override
public > T getValue(Class clazz, String name, int index) {
return getValue(clazz, name, index, true);
}
@Override
public > T getValue(Class clazz, String name, int index,
boolean includeInherited) {
final TermList list = getValue(TermList.class, name, includeInherited);
if (list != null && index < list.size()) {
final TermPropertyValue pair = (TermPropertyValue) list.get(index);
return clazz.cast(pair.getValue());
} else {
return null;
}
}
@Override
public int getListSize(String name, boolean includeInherited) {
final TermList list = getValue(TermList.class, name, includeInherited);
if (list != null)
return list.size();
else
return 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy