Пример #1
0
 /**
  * Creates a single property declaration.
  *
  * @param property Property name.
  * @param term Property value.
  * @return The resulting declaration.
  */
 protected Declaration createDeclaration(String property, Term<?> term) {
   Declaration d = CSSFactory.getRuleFactory().createDeclaration();
   d.unlock();
   d.setProperty(property);
   d.add(term);
   return d;
 }
  /**
   * 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);
  }
Пример #3
0
  /**
   * Construct terms array to be used by repeated object from available terms (in size 1 to 4)
   * according to CSS rules.
   *
   * <p>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
   *
   * @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.");
    }
  }
 /**
  * Assigns terms from declaration
  *
  * @param d Declaration which contains terms
  */
 public void assignTermsFromDeclaration(Declaration d) {
   this.terms = d.asList();
 }