/**
   * Creates INHERIT value of given class
   *
   * @param i Ordinal in list of types
   * @return Created CSSProperty with value inherit
   * @throws UnsupportedOperationException If class does not provide INHERIT or is not
   *     implementation of CSSProperty
   */
  private CSSProperty createInherit(int i) {

    try {
      Class<? extends CSSProperty> clazz = types.get(i);
      CSSProperty property = CSSProperty.Translator.createInherit(clazz);
      if (property != null) return property;

      throw new IllegalAccessException("No inherit value for: " + clazz.getName());
    } catch (Exception e) {
      throw new UnsupportedOperationException("Unable to create inherit value", e);
    }
  }
Exemplo n.º 2
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.");
    }
  }