コード例 #1
0
 private void write(Condition condition) {
   switch (condition.getConditionType()) {
     case Condition.SAC_PSEUDO_CLASS_CONDITION:
       {
         AttributeCondition pseudoClassCond = (AttributeCondition) condition;
         write(":");
         write(pseudoClassCond.getValue());
         break;
       }
     case Condition.SAC_CLASS_CONDITION:
       {
         AttributeCondition classCond = (AttributeCondition) condition;
         write(".");
         write(classCond.getValue());
         break;
       }
     case Condition.SAC_ATTRIBUTE_CONDITION:
       {
         AttributeCondition attributeCond = (AttributeCondition) condition;
         write("[");
         write(attributeCond.getLocalName());
         write("=");
         write(attributeCond.getValue());
         write("]");
         break;
       }
     case Condition.SAC_AND_CONDITION:
       {
         CombinatorCondition andCond = (CombinatorCondition) condition;
         Condition first = andCond.getFirstCondition();
         Condition second = andCond.getSecondCondition();
         write(first);
         write(second);
         break;
       }
     case Condition.SAC_ID_CONDITION:
       {
         AttributeCondition idCond = (AttributeCondition) condition;
         write("#");
         write(idCond.getValue());
         break;
       }
     default:
       throw new UnsupportedOperationException(
           "condition type = "
               + condition.getConditionType()
               + " with class "
               + condition.getClass().getName());
   }
 }
コード例 #2
0
 public String toString() {
   return selector.toString() + condition.toString();
 }
コード例 #3
0
ファイル: StylesContainer.java プロジェクト: param108/zflop
  public void extractStyles(StyleSheet styleSheet, boolean local) throws Exception {
    RuleList sheetRules = styleSheet.getCssRules();

    if (sheetRules != null) {
      //    aggregate rules by selector

      Iterator ruleIterator = sheetRules.iterator();
      while (ruleIterator.hasNext()) {
        Rule rule = (Rule) ruleIterator.next();

        if (rule instanceof StyleRule) {
          // for each selector in this rule
          SelectorList selectors = ((StyleRule) rule).getSelectorList();
          int nSelectors = selectors.getLength();
          for (int i = 0; i < nSelectors; i++) {
            Selector selector = selectors.item(i);
            int lineNumber = rule.getStyle().getLineNumber();

            if (selector instanceof AbstractSelector) {
              lineNumber = ((AbstractSelector) selector).getLineNumber();
            }

            if (selector.getSelectorType() == Selector.SAC_CONDITIONAL_SELECTOR) {
              Condition condition = ((ConditionalSelector) selector).getCondition();

              if (condition.getConditionType() == Condition.SAC_CLASS_CONDITION) {
                String name = ((AttributeCondition) condition).getValue();
                assert name != null : "parsed CSS class selector name is null";

                addStyleClassSelector(name, rule, lineNumber);
              } else {
                ConditionTypeNotSupported conditionTypeNotSupported =
                    new ConditionTypeNotSupported(
                        compilationUnit.getSource().getName(), lineNumber, condition.toString());
                ThreadLocalToolkit.log(conditionTypeNotSupported);
              }
            } else if (selector.getSelectorType() == Selector.SAC_ELEMENT_NODE_SELECTOR) {
              //    pick up type selectors only from root (application)
              if (compilationUnit.isRoot()) {
                String name = ((ElementSelector) selector).getLocalName();

                // Batik seems to generate an empty element
                // selector when @charset, so filter those out.
                if (name != null) {
                  addStyleTypeSelector(name, rule, local, lineNumber);
                }
              } else {
                // [preilly] This restriction should be removed once the
                // app model supports encapsulation of CSS styles.
                ComponentTypeSelectorsNotSupported componentTypeSelectorsNotSupported =
                    new ComponentTypeSelectorsNotSupported(
                        compilationUnit.getSource().getName(), lineNumber, selector.toString());
                ThreadLocalToolkit.log(componentTypeSelectorsNotSupported);
              }
            } else {
              SelectorTypeNotSupported selectorTypeNotSupported =
                  new SelectorTypeNotSupported(
                      compilationUnit.getSource().getName(), lineNumber, selector.toString());
              ThreadLocalToolkit.log(selectorTypeNotSupported);
            }
          }
        } else if (rule instanceof FontFaceRule) {
          addFontFaceRule((FontFaceRule) rule);
        }
      }
    }
  }