Java Code Examples for cz.vutbr.web.css.Declaration#size()
The following examples show how to use
cz.vutbr.web.css.Declaration#size() .
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 |
@SuppressWarnings("unused") private boolean processAnimationDuration(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (Decoder.genericTime(AnimationDuration.class, AnimationDuration.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(), AnimationDuration.list_values); values.put(d.getProperty(), list); return true; }
Example 2
Source File: Decoder.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
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 3
Source File: Variator.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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 4
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@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: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unused") private boolean processUnicodeRange(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.size() > 0) { TermList list = tf.createList(); for (int i = 0; i < d.size(); i++) { Term<?> term = d.get(i); if (term instanceof TermUnicodeRange && ((i == 0 && term.getOperator() == null) || (i != 0 && term.getOperator() == Operator.COMMA))) { list.add(term); } else { return false; } } properties.put("unicode-range", UnicodeRange.list_values); values.put("unicode-range", list); return true; } else return false; }
Example 6
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unused") private boolean processOverflow(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.size() == 1) { Term<?> term = d.get(0); if (term instanceof TermIdent) { return Decoder.genericProperty(Overflow.class, (TermIdent) term, Decoder.ALLOW_INH, properties, "overflow-x") && Decoder.genericProperty(Overflow.class, (TermIdent) term, Decoder.ALLOW_INH, properties, "overflow-y"); } else return false; } else return false; }
Example 7
Source File: Decoder.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
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 8
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@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 9
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@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 10
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unused") private boolean processAnimationDirection(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if(Decoder.genericOneIdent(AnimationDirection.class, d, properties)) { 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 TermIdent) { CSSProperty property = Decoder.genericPropertyRaw(AnimationDirection.class, null, (TermIdent) t); if (property == null) { return false; } } else { return false; } list.add(t); } properties.put(d.getProperty(), AnimationDirection.list_values); values.put(d.getProperty(), list); return true; }
Example 11
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") private boolean processCursor(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.size() == 1 && Decoder.genericOneIdent(Cursor.class, d, properties)) { return true; } else { final Set<Cursor> allowedCursors = EnumSet.complementOf(EnumSet .of(Cursor.INHERIT)); TermList list = tf.createList(); Cursor cur = null; for (Term<?> term : d.asList()) { if (term instanceof TermURI) { list.add(term); } else if (term instanceof TermIdent && (cur = Decoder.genericPropertyRaw(Cursor.class, allowedCursors, (TermIdent) term)) != null) { // this have to be the last cursor in sequence // and only one Decoder.generic cursor is allowed if (d.indexOf(term) != d.size() - 1) return false; // passed as last cursor, insert into properties and values properties.put("cursor", cur); if (!list.isEmpty()) values.put("cursor", list); return true; } else return false; } return false; } }
Example 12
Source File: Decoder.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
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 13
Source File: Variator.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
/** * Tries a single variant that may consist of space-separated terms or a comma-separated list * of space-separated lists. * * @param variant the variant to be tried * @param d the declaration to be processed * @param properties target property map * @param values target value map * @param listValue the list_values value to be used for the property value * @return {@code true} when parsed successfully */ public boolean tryListOfMultiTermVariant(int variant, Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values, CSSProperty listValue) { // try inherit variant if (d.size() == 1 && checkInherit(variant, d.get(0), properties)) return true; // for all sub-declarations TermList list = tf.createList(); final Map<String, CSSProperty> p = new HashMap<>(); final Map<String, Term<?>> v = new HashMap<>(); boolean first = true; List<Declaration> subs = splitDeclarations(d, Operator.COMMA); for (Declaration sub : subs) { p.clear(); v.clear(); assignTermsFromDeclaration(sub); if (!variant(variant, new IntegerRef(0), p, v)) return false; final CSSProperty prop = p.values().iterator().next(); final Term<?> val = (v.values().isEmpty()) ? null : v.values().iterator().next(); final TermPropertyValue pval = tf.createPropertyValue(prop, val); if (!first) pval.setOperator(Operator.COMMA); list.add(pval); first = false; } //store the result properties.put(names.get(variant), listValue); values.put(names.get(variant), list); return true; }
Example 14
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") private boolean processTransitionTimingFunction(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if(Decoder.genericOneIdent(TransitionTimingFunction.class, d, properties)) { 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) { return false; } if (t instanceof TermIdent) { CSSProperty property = Decoder.genericPropertyRaw(TransitionTimingFunction.class, null, (TermIdent) t); if (property == null) { return false; } } else if (!(t instanceof TermFunction.TimingFunction)) { return false; } list.add(t); } if(list.size() == 1) { properties.put(d.getProperty(), TransitionTimingFunction.timing_function); values.put(d.getProperty(), list.get(0)); } else { properties.put(d.getProperty(), TransitionTimingFunction.list_values); values.put(d.getProperty(), list); } return true; }
Example 15
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@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 16
Source File: Variator.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
/** * Tries a single variant that may consist of a term or a list of comma-separated terms. * * @param variant the variant to be tried * @param d the declaration to be processed * @param properties target property map * @param values target value map * @param listValue the list_values value to be used for the property value * @return {@code true} when parsed successfully */ public boolean tryListOfOneTermVariant(int variant, Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values, CSSProperty listValue) { // try inherit variant if (d.size() == 1 && checkInherit(variant, d.get(0), properties)) return true; //scan the list TermList list = tf.createList(); final Map<String, CSSProperty> p = new HashMap<>(); final Map<String, Term<?>> v = new HashMap<>(); boolean first = true; for (Term<?> t : d.asList()) { //terms must be separated by commas if ((first && t.getOperator() != null) || (!first && t.getOperator() != Operator.COMMA)) return false; //process the variant for a single term p.clear(); v.clear(); this.terms = new ArrayList<Term<?>>(); this.terms.add(t); if (!variant(variant, new IntegerRef(0), p, v)) return false; //collect the resulting term final CSSProperty prop = p.values().iterator().next(); final Term<?> val = (v.values().isEmpty()) ? null : v.values().iterator().next(); final TermPropertyValue pval = tf.createPropertyValue(prop, val); if (!first) pval.setOperator(Operator.COMMA); list.add(pval); first = false; } //store the result properties.put(names.get(variant), listValue); values.put(names.get(variant), list); return true; }
Example 17
Source File: RuleFontFaceImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Override public List<String> getUnicodeRanges() { Declaration decl = getDeclaration(PROPERTY_UNICODE_RANGE); if (decl != null) { List<String> ret = new ArrayList<>(decl.size()); for (Term<?> term : decl) { ret.add(term.getValue().toString()); } return ret; } else return null; }
Example 18
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@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 19
Source File: Repeater.java From jStyleParser with GNU Lesser General Public License v3.0 | 4 votes |
/** * Construct terms array to be used by repeated object from available terms * (in size 1 to 4) according to CSS rules. * * Example: * <p> * <code>margin: 2px 5px;</code> creates virtual terms array with terms * <code>2px 5px 2px 5px</code> so top and bottom; left and right contains * the same margin * </p> * * @param d * Declaration with terms * @param properties * Properties map where to store properties types * @param values * Value map where to store properties values * @return <code>true</code> in case of success, <code>false</code> * elsewhere * @throws IllegalArgumentException * In case when number of terms passed does not correspond to * iteration times */ public boolean repeatOverFourTermDeclaration(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) throws IllegalArgumentException { switch (d.size()) { case 1: // one term for all value Term<?> term = d.get(0); // check inherit if(term instanceof TermIdent && CSSProperty.INHERIT_KEYWORD.equalsIgnoreCase(((TermIdent) term).getValue())) { CSSProperty property = CSSProperty.Translator.createInherit(type); for(int i = 0; i < times; i++) { properties.put(names.get(i), property); } return true; } assignTerms(term, term, term, term); return repeat(properties, values); case 2: // one term for bottom-top and left-right Term<?> term1 = d.get(0); Term<?> term2 = d.get(1); assignTerms(term1, term2, term1, term2); return repeat(properties, values); case 3: // terms for bottom, top, left-right Term<?> term31 = d.get(0); Term<?> term32 = d.get(1); Term<?> term33 = d.get(2); assignTerms(term31, term32, term33, term32); return repeat(properties, values); case 4: // four individual terms (or more - omitted) //if (d.size() > 4) // LoggerFactory.getLogger(Repeater.class).warn("Omitting additional terms in four-term declaration"); Term<?> term41 = d.get(0); Term<?> term42 = d.get(1); Term<?> term43 = d.get(2); Term<?> term44 = d.get(3); assignTerms(term41, term42, term43, term44); return repeat(properties, values); default: throw new IllegalArgumentException( "Invalid length of terms in Repeater."); } }
Example 20
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 4 votes |
private boolean processPropertiesInList(String[] propertyList, Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { Declaration subDeclaration = (Declaration) rf.createDeclaration().unlock(); TermList[] termLists = new TermList[propertyList.length]; for (int i = 0; i < termLists.length; i++) termLists[i] = tf.createList(); boolean[] propertySet = new boolean[propertyList.length]; Arrays.fill(propertySet, false); for (int i = 0; i < d.size(); i++) { Term<?> t = d.get(i); subDeclaration.add(t); if (t.getOperator() == Operator.COMMA) { Arrays.fill(propertySet, false); } for (int propertyIndex = 0; propertyIndex <= propertyList.length; propertyIndex++) { if (propertyIndex == propertyList.length) { return false; } if (propertySet[propertyIndex]) { continue; } subDeclaration.setProperty(propertyList[propertyIndex]); if (parseDeclaration(subDeclaration, properties, values)) { propertySet[propertyIndex] = true; t.setOperator(termLists[propertyIndex].isEmpty() ? null : Operator.COMMA); termLists[propertyIndex].add(t); break; } } subDeclaration.clear(); } for (int propertyIndex = 0; propertyIndex < propertyList.length; propertyIndex++) { subDeclaration.setProperty(propertyList[propertyIndex]); subDeclaration.addAll(termLists[propertyIndex]); if (!subDeclaration.isEmpty() && !parseDeclaration(subDeclaration, properties, values)) { return false; } subDeclaration.clear(); } return true; }