cz.vutbr.web.css.Declaration Java Examples

The following examples show how to use cz.vutbr.web.css.Declaration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unused")
private boolean processTransform(Declaration d,
        Map<String, CSSProperty> properties, Map<String, Term<?>> values) {

    // just a simple value (e.g. "none")
    if (d.size() == 1 && Decoder.genericOneIdent(Transform.class, d, properties)) {
        return true;
    } else {

        TermList list = tf.createList();

        for (Term<?> t : d.asList()) {
            if (t instanceof TermFunction.TransformFunction)
                list.add(t);
            else
                return false;
        }
        // there is nothing in list after parsing
        if (list.isEmpty())
            return false;

        properties.put("transform", Transform.list_values);
        values.put("transform", list);
        return true;
    }
}
 
Example #2
Source File: Variator.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Uses variator functionality to test selected variant on term
 * 
 * @param variant
 *            Which variant will be tested
 * @param d
 *            The declaration on which variant will be tested
 * @param properties
 *            Properties map where to store property type
 * @param values
 *            Values map where to store property value
 * @return <code>true</code> in case of success, <code>false</code>
 *         otherwise
 */
public boolean tryOneTermVariant(int variant, Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {

	// only one term is allowed
	if (d.size() != 1)
		return false;

	// try inherit variant
	if (checkInherit(variant, d.get(0), properties))
		return true;

	this.terms = new ArrayList<Term<?>>();
	this.terms.add(d.get(0));

	return variant(variant, new IntegerRef(0), properties, values);
}
 
Example #3
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unused")
private boolean processCounterIncrement(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {

	if (d.size() == 1
			&& Decoder.genericOneIdent(CounterIncrement.class, d, properties)) {
		return true;
	}
	// counter with increments
	else {
		List<Term<?>> termList = decodeCounterList(d.asList(), 1);
		if (termList != null && !termList.isEmpty()) {
			TermList list = tf.createList(termList.size());
			list.addAll(termList);
			properties.put("counter-increment",	CounterIncrement.list_values);
			values.put("counter-increment", list);
			return true;
		}
		return false;
	}
}
 
Example #4
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unused")
private boolean processAnimationDelay(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
    if (Decoder.genericTime(AnimationDelay.class, AnimationDelay.time, ValueRange.DISALLOW_NEGATIVE, d, properties, values)) {
        return true;
    }
    TermList list = tf.createList();
    for (int i = 0; i < d.size(); i++) {
        Term<?> t = d.get(i);
        if ((i == 0 || t.getOperator() == Operator.COMMA) && t instanceof TermTime) {
            if (!isPositive(t)) {
                return false;
            }
        } else {
            return false;
        }
        list.add(t);
    }
    properties.put(d.getProperty(), AnimationDelay.list_values);
    values.put(d.getProperty(), list);
    return true;
}
 
Example #5
Source File: Decoder.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static <T extends CSSProperty> boolean genericTime(
        Class<T> type, T integerIdentification, ValueRange range,
        Declaration d, Map<String, CSSProperty> properties,
        Map<String, Term<?>> values) {
    if (d.size() != 1)
        return false;
    
    Term<?> term = d.get(0);
    if (term instanceof TermIdent) {
        T property = genericPropertyRaw(type, null, (TermIdent) term);
        if (!property.equalsInherit())
            return false;
        else
        {
            properties.put(d.getProperty(), property);
            return true;
        }
    }
    return genericTerm(TermTime.class, term, d.getProperty(), integerIdentification, range, properties, values);
}
 
Example #6
Source File: Decoder.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static <T extends CSSProperty> boolean genericInteger(
        Class<T> type, T integerIdentification, ValueRange range,
        Declaration d, Map<String, CSSProperty> properties,
        Map<String, Term<?>> values) {

    if (d.size() != 1)
        return false;
    
    Term<?> term = d.get(0);
    if (term instanceof TermIdent)
    {
        T property = genericPropertyRaw(type, null, (TermIdent) term);
        if (!property.equalsInherit())
            return false;
        else
        {
            properties.put(d.getProperty(), property);
            return true;
        }
    }
    else
    {
        return genericTerm(TermInteger.class, term, d.getProperty(), integerIdentification, range, properties, values);
    }
}
 
Example #7
Source File: SimpleTest.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testBracketedIdent() throws IOException, CSSException   {
    
    StyleSheet ss = CSSFactory.parseString(TEST_BRACKETED_IDENT, null);
    assertEquals("There is one rule", 1, ss.size());
    
    Declaration dec = (Declaration) ss.get(0).get(0);
    assertEquals("There is one declaration", 1, ss.get(0).size());
    assertEquals("Four terms", 4, dec.size());
    
    assertTrue("Term[0] type is BracketedIdents", dec.get(0) instanceof TermBracketedIdents);
    assertEquals("Term[0] : There is one ident", 1, ((TermBracketedIdents) dec.get(0)).size());
    assertEquals("Term[0] : Identifier value is correct", "-linename1", ((TermBracketedIdents) dec.get(0)).get(0).getValue());
    assertTrue("Term[3] type is BracketedIdents", dec.get(3) instanceof TermBracketedIdents);
    assertEquals("Term[3] : There is one ident", 1, ((TermBracketedIdents) dec.get(3)).size());
    assertEquals("Term[3] : Identifier value is correct", "linename2", ((TermBracketedIdents) dec.get(3)).get(0).getValue());
}
 
Example #8
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unused")
private boolean processTransitionDuration(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
    if (Decoder.genericTime(TransitionDuration.class, TransitionDuration.time, ValueRange.DISALLOW_NEGATIVE, d, properties, values)) {
        return true;
    }
    TermList list = tf.createList();
    for (int i = 0; i < d.size(); i++) {
        Term<?> t = d.get(i);
        if ((i == 0 || t.getOperator() == Operator.COMMA) && t instanceof TermTime) {
            if(!isPositive(t)) {
                return false;
            }
        } else {
            return false;
        }
        list.add(t);
    }
    properties.put(d.getProperty(), TransitionDuration.list_values);
    values.put(d.getProperty(), list);
    return true;
}
 
Example #9
Source File: BoxFactory.java    From CSSBox with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates the style definition for an anonymous box. It contains only the class name set to "Xanonymous"
 * and the display: property set according to the parametres.
 * @param display <code>display:</code> property value of the resulting style.
 * @return Resulting style definition
 */
public NodeData createAnonymousStyle(String display)
{
    NodeData ret = CSSFactory.createNodeData();
    
    Declaration cls = CSSFactory.getRuleFactory().createDeclaration();
    cls.unlock();
    cls.setProperty("class");
    cls.add(CSSFactory.getTermFactory().createString("Xanonymous"));
    ret.push(cls);
    
    Declaration disp = CSSFactory.getRuleFactory().createDeclaration();
    disp.unlock();
    disp.setProperty("display");
    disp.add(CSSFactory.getTermFactory().createIdent(display));
    ret.push(disp);
    
    return ret;
}
 
Example #10
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processTransition(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
    return processPropertiesInList(new String[]{
        "transition-duration",
        "transition-delay",
        "transition-timing-function",
        "transition-property"
    }, d, properties, values);
}
 
Example #11
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processBorderBottom(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	Variator borderSide = new BorderSideVariator("bottom");
	borderSide.assignTermsFromDeclaration(d);
       borderSide.assignDefaults(properties, values);
	return borderSide.vary(properties, values);
}
 
Example #12
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processBorderRight(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	Variator borderSide = new BorderSideVariator("right");
	borderSide.assignTermsFromDeclaration(d);
       borderSide.assignDefaults(properties, values);
	return borderSide.vary(properties, values);
}
 
Example #13
Source File: AssignedDeclaration.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(Declaration other) {
	
	if( !(other instanceof AssignedDeclaration))
		return super.compareTo(other);
	
	AssignedDeclaration o = (AssignedDeclaration) other;

	int res = getOriginOrder() - o.getOriginOrder();
	if (res == 0)
		return this.spec.compareTo(o.spec);
	else
		return res;
}
 
Example #14
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processOutlineColor(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	final Variator outline = new OutlineVariator();
	return outline.tryOneTermVariant(OutlineVariator.COLOR, d, properties,
			values);
}
 
Example #15
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processMinWidth(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	return Decoder.genericOneIdentOrLengthOrPercent(MinWidth.class,
			MinWidth.length, MinWidth.percentage, ValueRange.DISALLOW_NEGATIVE, d, properties,
			values);
}
 
Example #16
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processFontVariant(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	final Variator font = new FontVariator();
	return font.tryOneTermVariant(FontVariator.VARIANT, d, properties,
			values);
}
 
Example #17
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processFont(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	Variator font = new FontVariator();
	font.assignTermsFromDeclaration(d);
	font.assignDefaults(properties, values);
	return font.vary(properties, values);
}
 
Example #18
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processLineHeight(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	final Variator font = new FontVariator();
	return font.tryOneTermVariant(FontVariator.LINE_HEIGHT, d, properties,
			values);
}
 
Example #19
Source File: SimpleTest.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testPositiveNumber1() throws IOException, CSSException   {
	
	StyleSheet ss = CSSFactory.parseString(TEST_POSITIVE_NUMBER1, null);
	assertEquals("There is one rule", 1, ss.size());
	
	Declaration dec = (Declaration) ss.get(0).get(0);
	assertEquals("There is one declaration", 1, ss.get(0).size());
	
	Object term = dec.get(0);
	assertTrue("Term value is Numeric", term instanceof TermLength);
	
	TermLength length = (TermLength) term;
	assertThat(length, is(tf.createLength(10.0f, Unit.px)));
}
 
Example #20
Source File: FunctionsTest.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void negativeArgument() throws IOException, CSSException 
{
	StyleSheet ss = CSSFactory.parseString(TEST_DECL3A, null);
	assertEquals("One properties is accepted", 1, ss.get(0).size());
	Declaration d = (Declaration) ss.get(0).get(0);
	TermFunction f = (TermFunction) d.get(0);
	assertEquals("The argument is -0.1em", tf.createLength(-0.1f, Unit.em), f.get(0));
}
 
Example #21
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processFlex(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
    Variator variator = new FlexVariator();
    variator.assignTermsFromDeclaration(d);
    variator.assignDefaults(properties, values);
    return variator.vary(properties, values);
}
 
Example #22
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processBorderRightColor(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	final Variator borderSide = new BorderSideVariator("right");
	return borderSide.tryOneTermVariant(BorderSideVariator.COLOR, d,
			properties, values);
}
 
Example #23
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processBackgroundRepeat(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	final Variator background = new BackgroundVariator();
	return background.tryListOfOneTermVariant(BackgroundVariator.REPEAT, d,
			properties, values, BackgroundRepeat.nested_list);
}
 
Example #24
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processBorderTopWidth(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	final Variator borderSide = new BorderSideVariator("top");
	return borderSide.tryOneTermVariant(BorderSideVariator.WIDTH, d,
			properties, values);
}
 
Example #25
Source File: Decoder.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static <T extends Enum<T> & CSSProperty> boolean genericOneIdentOrLengthOrPercent(
        Class<T> type, T lengthIdentification, T percentIdentification,
        ValueRange range, Declaration d, Map<String, CSSProperty> properties,
        Map<String, Term<?>> values) {

    if (d.size() != 1)
        return false;

    return genericTermIdent(type, d.get(0), ALLOW_INH, d.getProperty(),
            properties)
            || genericTermLength(d.get(0), d.getProperty(),
                    lengthIdentification, range, properties, values)
            || genericTerm(TermPercent.class, d.get(0), d.getProperty(),
                    percentIdentification, range, properties, values);
}
 
Example #26
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processBorderBottomStyle(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	final Variator borderSide = new BorderSideVariator("bottom");
	return borderSide.tryOneTermVariant(BorderSideVariator.STYLE, d,
			properties, values);
}
 
Example #27
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processBorder(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	Variator border = new BorderVariator();
	border.assignTermsFromDeclaration(d);
	border.assignDefaults(properties, values);
	return border.vary(properties, values);
}
 
Example #28
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processFilter(Declaration d,
        Map<String, CSSProperty> properties, Map<String, Term<?>> values) {

    // single ident: none, or global ones
    if (d.size() == 1 && Decoder.genericOneIdent(Filter.class, d, properties)) {
        return true;
    } else {
        //list of uri() or <filter-function> expected
        TermList list = tf.createList();

        for (Term<?> t : d.asList()) {
            if (t instanceof TermFunction.FilterFunction)
                list.add(t);
            else if (t instanceof TermURI)
                list.add(t);
            else
                return false;
        }
        // there is nothing in list after parsing
        if (list.isEmpty())
            return false;

        properties.put("filter", Filter.list_values);
        values.put("filter", list);
        return true;
    }
}
 
Example #29
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processGridTemplateAreas(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
    if (Decoder.genericOneIdent(GridTemplateAreas.class, d, properties)) {
        return true;
    }
    TermList list = tf.createList();
    int areasInRow = 0;
    String[][] map = new String[d.size()][];
    for (int i = 0; i < d.size(); i++) {
        Term<?> t = d.get(i);
        if (t instanceof TermString) {
            map[i] = ValidationUtils.getAreas(((TermString) t).getValue());
            if (map[i].length == 0 || (i > 0 && map[i].length != areasInRow)) {
                return false;
            }
            areasInRow = map[i].length;
        } else {
            return false;
        }
        list.add(t);
    }
    if (!ValidationUtils.containsRectangles(map)) {
        return false;
    }
    properties.put(d.getProperty(), GridTemplateAreas.list_values);
    values.put(d.getProperty(), list);
    return true;
}
 
Example #30
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unused")
private boolean processOutlineWidth(Declaration d,
		Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
	final Variator outline = new OutlineVariator();
	return outline.tryOneTermVariant(OutlineVariator.WIDTH, d, properties,
			values);
}