cz.vutbr.web.css.Term Java Examples
The following examples show how to use
cz.vutbr.web.css.Term.
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: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testAttributePresence() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ATTRIB_PRESENCE, null); assertEquals("One rule is set", 1, ss.size()); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "*", null, rf .createAttribute(null, false, Selector.Operator.NO_OPERATOR, "href")); assertArrayEquals("Rule 1 contains one combined selector *[href]", cslist.toArray(), ((RuleSet) ss.get(0)).getSelectors()); List<Term<?>> terms = DeclarationsUtil.appendTerm(null, null, tf .createIdent("Verdana")); DeclarationsUtil.appendCommaTerm(terms, tf.createIdent("monospace")); assertEquals( "Rule contains one declaration { text-decoration: underline }", DeclarationsUtil.appendDeclaration(null, "text-decoration", tf .createIdent("underline")), ((RuleSet) ss.get(0)) .asList()); }
Example #2
Source File: Matrix3dImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Override public TermList setValue(List<Term<?>> value) { super.setValue(value); List<Term<?>> args = getSeparatedValues(DEFAULT_ARG_SEP, false); if (args != null && args.size() == 16) { values = new float[16]; setValid(true); for (int i = 0; i < 16; i++) { if (isNumberArg(args.get(i))) values[i] = getNumberArg(args.get(i)); else setValid(false); } } return this; }
Example #3
Source File: CountersImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Override public TermList setValue(List<Term<?>> value) { super.setValue(value); List<Term<?>> args = getSeparatedValues(DEFAULT_ARG_SEP, true); if (args != null && (args.size() == 2 || args.size() == 3)) { //check for name and separator if (args.get(0) instanceof TermIdent && args.get(1) instanceof TermString) { name = ((TermIdent) args.get(0)).getValue(); separator = ((TermString) args.get(1)).getValue(); setValid(true); } //an optional style if (args.size() == 3) { if (args.get(2) instanceof TermIdent) { final String styleString = ((TermIdent) args.get(2)).getValue(); style = CounterImpl.allowedStyles.get(styleString.toLowerCase()); if (style == null) { setValid(false); //unknown style } } else { setValid(false); } } } return this; }
Example #4
Source File: CollectionSpeedTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testLinkedHashSetWithReinit() { long time = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { Set<CSSProperty> properties = new LinkedHashSet<CSSProperty>(MAX); Set<Term<?>> terms = new LinkedHashSet<Term<?>>(MAX); insert(properties, terms); properties.clear(); terms.clear(); } time = System.currentTimeMillis() - time; log.debug("LinkedHashSet with reinitalization took {}ms.", time); }
Example #5
Source File: Variator.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
/** * Adds a property-value pair to a nested list in the destination value map. Creates a new * list when the corresponding value is not set or it is not a list. * @param dest the destination value map * @param key the key to use (property name) * @param property the property value to set * @param value an optional Term value to set * @param first {@code true} for the first value in the list (for generating separators properly) */ private void addToMap(Map<String, Term<?>> dest, String key, CSSProperty property, Term<?> value, boolean first) { final Term<?> cur = dest.get(key); TermList list; if (cur instanceof TermList) list = (TermList) cur; else { list = tf.createList(); dest.put(key, list); } //make a copy and remove the original operator from the value Term<?> vvalue = (value == null) ? null : value.shallowClone(); if (vvalue != null) vvalue.setOperator(null); //add the pair final TermPropertyValue pval = tf.createPropertyValue(property, vvalue); if (!first) pval.setOperator(Operator.COMMA); list.add(pval); }
Example #6
Source File: BackgroundVariator.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
private void setPositionValue(Term<?>[] s, int index, Term<?> term) { switch (index) { case -1: if (s[0] == null) //any position - use the free position s[0] = term; else s[1] = term; break; case 0: if (s[0] != null) //if the position is occupied, move the old value s[1] = s[0]; s[0] = term; break; case 1: if (s[1] != null) s[0] = s[1]; s[1] = term; break; } }
Example #7
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unused") private boolean processAnimationPlayState(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if(Decoder.genericOneIdent(AnimationPlayState.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(AnimationPlayState.class, null, (TermIdent) t); if (property == null) { return false; } } else { return false; } list.add(t); } properties.put(d.getProperty(), AnimationPlayState.list_values); values.put(d.getProperty(), list); return true; }
Example #8
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unused") private boolean processQuotes(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (d.size() == 1 && Decoder.genericTermIdent(Quotes.class, d.get(0), Decoder.ALLOW_INH, "quotes", properties)) { return true; } else { TermList list = tf.createList(); for (Term<?> term : d.asList()) { if (term instanceof TermString) list.add(term); else return false; } // there are pairs of quotes if (!list.isEmpty() && list.size() % 2 == 0) { properties.put("quotes", Quotes.list_values); values.put("quotes", list); return true; } return false; } }
Example #9
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 #10
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@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 #11
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") private boolean processContent(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { // content contains no explicit values if (d.size() == 1 && Decoder.genericOneIdent(Content.class, d, properties)) { return true; } else { // valid term idents final Set<String> validTermIdents = new HashSet<String>(Arrays .asList("open-quote", "close-quote", "no-open-quote", "no-close-quote")); TermList list = tf.createList(); for (Term<?> t : d.asList()) { // one of valid terms if (t instanceof TermIdent && validTermIdents.contains(((TermIdent) t).getValue() .toLowerCase())) list.add(t); else if (t instanceof TermString) list.add(t); else if (t instanceof TermURI) list.add(t); else if (t instanceof TermFunction.CounterFunction || t instanceof TermFunction.Attr) list.add(t); else return false; } // there is nothing in list after parsing if (list.isEmpty()) return false; properties.put("content", Content.list_values); values.put("content", list); return true; } }
Example #12
Source File: FitContentImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Override public TermList setValue(List<Term<?>> value) { super.setValue(value); List<Term<?>> args = getSeparatedValues(DEFAULT_ARG_SEP, true); if (args != null && args.size() == 1) { _max = getLengthOrPercentArg(args.get(0)); if (_max != null) { setValid(true); } } return this; }
Example #13
Source File: CollectionSpeedTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void initMasters() { this.mprop = new HashMap<String, CSSProperty>(css.getTotalProperties(), 1.0f); this.mterm = new HashMap<String, Term<?>>(css.getTotalProperties(), 1.0f); }
Example #14
Source File: BorderRadiusRepeater.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
private Term<?> stripSlash(Term<?> src) { if (src.getOperator() == Operator.SLASH) { if (src instanceof TermLength) return tf.createLength((java.lang.Float) src.getValue(), ((TermLength) src).getUnit()); else if (src instanceof TermPercent) return tf.createPercent((java.lang.Float) src.getValue()); else return src; } else return src; }
Example #15
Source File: CubicBezierImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
private boolean setValueAt(int index, List<Term<?>> argTerms) { if (argTerms.size() == 1) { Term<?> t = argTerms.get(0); if (t instanceof TermNumber) { float value = ((TermNumber) t).getValue(); if (index == 1 || index == 3 || value >= 0 && value <= 1) { _values[index] = value; return true; } } } return false; }
Example #16
Source File: Variator.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
/** * Assigns the default values to all the properties. * @param properties * @param values */ public void assignDefaults(Map<String, CSSProperty> properties, Map<String, Term<?>> values) { SupportedCSS css = CSSFactory.getSupportedCSS(); for (String name : names) { CSSProperty dp = css.getDefaultProperty(name); if (dp != null) properties.put(name, dp); Term<?> dv = css.getDefaultValue(name); if (dv != null) values.put(name, dv); } }
Example #17
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") private boolean processBackgroundImage(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { final Variator background = new BackgroundVariator(); return background.tryListOfOneTermVariant(BackgroundVariator.IMAGE, d, properties, values, BackgroundImage.nested_list); }
Example #18
Source File: PerspectiveImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Override public TermList setValue(List<Term<?>> value) { super.setValue(value); List<Term<?>> args = getSeparatedValues(DEFAULT_ARG_SEP, false); if (args != null && args.size() == 1 && (distance = getLengthArg(args.get(0))) != null) { setValid(true); } return this; }
Example #19
Source File: Decoder.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
public static <T extends CSSProperty> boolean genericOneIdentOrInteger( Class<T> type, T integerIdentification, 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) || genericTerm(TermInteger.class, d.get(0), d.getProperty(), integerIdentification, range, properties, values); }
Example #20
Source File: RotateYImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Override public TermList setValue(List<Term<?>> value) { super.setValue(value); List<Term<?>> args = getSeparatedValues(DEFAULT_ARG_SEP, false); if (args != null && args.size() == 1 && (angle = getAngleArg(args.get(0))) != null) { setValid(true); } return this; }
Example #21
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@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 #22
Source File: TermFactoryImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Override public TermRect createRect(TermFunction function) { if (function.getFunctionName().equalsIgnoreCase("rect")) { List<Term<?>> args = function.getValues(true); //try the rect(0 0 0 0) syntax if (args == null || args.size() != 4) args = function.getSeparatedValues(CSSFactory.getTermFactory().createOperator(','), true); //try the rect(0, 0, 0, 0) syntax if (args != null && args.size() == 4) { //check the argument count and types for (int i = 0; i < 4; i++) { Term<?> val = args.get(i); if (val instanceof TermIdent) { if (((TermIdent) val).getValue().equalsIgnoreCase("auto")) //replace 'auto' with null args.set(i, null); } else if (!(val instanceof TermLength)) { return null; } } return createRect((TermLength) args.get(0), (TermLength) args.get(1), (TermLength) args.get(2), (TermLength) args.get(3)); } else { return null; } } else { return null; } }
Example #23
Source File: RuleFontFaceImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
private String checkForFormat(Term<?> term) { if (term instanceof TermFunction && term.getOperator() == Operator.SPACE) { final TermFunction fn = (TermFunction) term; if (fn.getFunctionName().equalsIgnoreCase("format") && fn.size() == 1 && fn.get(0) instanceof TermString) { return ((TermString) fn.get(0)).getValue(); } else return null; } else return null; }
Example #24
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") private boolean processBorderTop(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { Variator borderSide = new BorderSideVariator("top"); borderSide.assignTermsFromDeclaration(d); borderSide.assignDefaults(properties, values); return borderSide.vary(properties, values); }
Example #25
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
private boolean processGridAutoFlow(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { if (Decoder.genericOneIdent(GridAutoFlow.class, d, properties)) { return !GridAutoFlow.DENSE.equals(properties.get(d.getProperty())); } boolean autoFlowSet = false; boolean denseSet = false; TermList list = tf.createList(); for (int i = 0; i < d.size(); i++) { Term<?> t = d.get(i); if (t instanceof TermIdent) { CSSProperty property = Decoder.genericPropertyRaw(GridAutoFlow.class, null, (TermIdent) t); if ((GridAutoFlow.ROW.equals(property) || GridAutoFlow.COLUMN.equals(property)) && !autoFlowSet) { autoFlowSet = true; } else if (GridAutoFlow.DENSE.equals(property) && !denseSet) { denseSet = true; } else { return false; } list.add(t); } else { return false; } } properties.put(d.getProperty(), GridAutoFlow.component_values); values.put(d.getProperty(), list); return true; }
Example #26
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@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 #27
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") private boolean processFontSize(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) { final Variator font = new FontVariator(); return font.tryOneTermVariant(FontVariator.SIZE, d, properties, values); }
Example #28
Source File: SingleMapNodeData.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
public NodeData push(Declaration d) { Map<String,CSSProperty> properties = new HashMap<String,CSSProperty>(COMMON_DECLARATION_SIZE); Map<String,Term<?>> terms = new HashMap<String, Term<?>>(COMMON_DECLARATION_SIZE); boolean result = transformer.parseDeclaration(d, properties, terms); // in case of false do not insert anything if(!result) return this; for(Entry<String, CSSProperty> entry : properties.entrySet()) { final String key = entry.getKey(); Quadruple q = map.get(key); if(q==null) q = new Quadruple(); q.curProp = entry.getValue(); q.curValue = terms.get(key); q.curSource = d; // remove operator if((q.curValue!=null) && (q.curValue.getOperator() != null)) { q.curValue = q.curValue.shallowClone().setOperator(null); } map.put(key, q); } return this; }
Example #29
Source File: DeclarationTransformerImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
private List<Term<?>> decodeCounterList(List<Term<?>> terms, int defaultValue) { List<Term<?>> ret = new ArrayList<>(); int i = 0; while (i < terms.size()) { final Term<?> term = terms.get(i); if (term instanceof TermIdent) { final String counterName = ((TermIdent) term).getValue(); if (i + 1 < terms.size() && terms.get(i + 1) instanceof TermInteger) { //integer value specified after the counter name int counterValue = ((TermInteger) terms.get(i + 1)).getIntValue(); ret.add(tf.createPair(counterName, counterValue)); i += 2; } else { //only the counter name, use the default value ret.add(tf.createPair(counterName, defaultValue)); i++; } } else { return null; } } return ret; }
Example #30
Source File: TranslateZImpl.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Override public TermList setValue(List<Term<?>> value) { super.setValue(value); List<Term<?>> args = getSeparatedValues(DEFAULT_ARG_SEP, false); if (args != null && args.size() == 1 && (translate = getLengthOrPercentArg(args.get(0))) != null) { setValid(true); } return this; }