Package org.w3c.css.sac

Examples of org.w3c.css.sac.LexicalUnit


  throws DOMException {
  try {
      ValueFactory f;
            f = factories.get(propertyName.toLowerCase().intern());
      InputSource is = new InputSource(new StringReader(value));
      LexicalUnit lu = parser.parsePropertyValue(is);
      f.createCSSValue(lu, this, prio);
  } catch (Exception e) {
            e.printStackTrace();
      throw CSSDOMExceptionFactory.createDOMException
    (DOMException.INVALID_ACCESS_ERR,
View Full Code Here


     * Converts a hash unit to a RGB color.
     */
    protected LexicalUnit hexcolor(LexicalUnit prev) {
        String val = scanner.currentValue();
        int len = val.length();
        LexicalUnit params = null;
        switch (len) {
        case 3:
            char rc = Character.toLowerCase(val.charAt(0));
            char gc = Character.toLowerCase(val.charAt(1));
            char bc = Character.toLowerCase(val.charAt(2));
            if (!ScannerUtilities.isCSSHexadecimalCharacter(rc) ||
                !ScannerUtilities.isCSSHexadecimalCharacter(gc) ||
                !ScannerUtilities.isCSSHexadecimalCharacter(bc)) {
                throw createCSSParseException("rgb.color");
            }
            int t;
            int r = t = (rc >= '0' && rc <= '9') ? rc - '0' : rc - 'a' + 10;
            t <<= 4;
            r |= t;
            int g = t = (gc >= '0' && gc <= '9') ? gc - '0' : gc - 'a' + 10;
            t <<= 4;
            g |= t;
            int b = t = (bc >= '0' && bc <= '9') ? bc - '0' : bc - 'a' + 10;
            t <<= 4;
            b |= t;
            params = CSSLexicalUnit.createInteger(r, null);
            LexicalUnit tmp;
            tmp = CSSLexicalUnit.createSimple(LexicalUnit.SAC_OPERATOR_COMMA, params);
            tmp = CSSLexicalUnit.createInteger(g, tmp);
            tmp = CSSLexicalUnit.createSimple(LexicalUnit.SAC_OPERATOR_COMMA, tmp);
            tmp = CSSLexicalUnit.createInteger(b, tmp);
            break;
View Full Code Here

   *          <code>(VAL COMMA VAL COMMA VAL)</code> where VAL can be an INT or
   *          a PERCENT (which is then converted to INT)
   * @return the minimal hex expression for the RGB color values
   */
  private static Value colorValue(LexicalUnit colors) {
    LexicalUnit red = colors;
    int r = getRgbComponentValue(red);
    LexicalUnit green = red.getNextLexicalUnit().getNextLexicalUnit();
    int g = getRgbComponentValue(green);
    LexicalUnit blue = green.getNextLexicalUnit().getNextLexicalUnit();
    int b = getRgbComponentValue(blue);

    String sr = Integer.toHexString(r);
    if (sr.length() == 1) {
      sr = "0" + sr;
View Full Code Here

    }

    private static LexicalUnitImpl adjust(LexicalUnitImpl color,
            float amountByPercent, ColorOperation op, LexicalUnitImpl pre) {
        if (color.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION) {
            LexicalUnit funcParam = color.getParameters();
            if ("hsl".equals(color.getFunctionName())) {
                LexicalUnit lightness = funcParam;
                for (int index = 0; index < 4; index++) {
                    lightness = lightness.getNextLexicalUnit();
                }
                float newValue = 0f;
                if (op == ColorOperation.Darken) {
                    newValue = lightness.getFloatValue() - amountByPercent;
                    newValue = newValue < 0 ? 0 : newValue;
                } else if (op == ColorOperation.Lighten) {
                    newValue = lightness.getFloatValue() + amountByPercent;
                    newValue = newValue > 100 ? 100 : newValue;
                }
                ((LexicalUnitImpl) lightness).setFloatValue(newValue);
                return LexicalUnitImpl.createFunction(color.getLineNumber(),
                        color.getColumnNumber(), pre, color.getFunctionName(),
View Full Code Here

        return adjust(color, amount, ColorOperation.Lighten, pre);
    }

    private static float getAmountValue(LexicalUnitImpl color) {
        LexicalUnit next = color.getNextLexicalUnit();
        float amount = 10f;
        if (next != null && next.getNextLexicalUnit() != null) {
            next = next.getNextLexicalUnit();
            amount = next.getFloatValue();
        }
        return amount;
    }
View Full Code Here

    if (styleSheetParserUtil == null)
    {
      styleSheetParserUtil = StyleSheetParserUtil.getInstance();
    }

    final LexicalUnit cssValue = styleSheetParserUtil.parseLexicalStyleValue(
        text);
    return CSSValueFactory.createLengthValue(cssValue);
  }
View Full Code Here

        if (styleSheetParserUtil == null)
        {
            styleSheetParserUtil = StyleSheetParserUtil.getInstance();
        }

        final LexicalUnit cssValue = styleSheetParserUtil.parseLexicalStyleValue(
                text);
        return CSSValueFactory.createLengthValue(cssValue);
    }
View Full Code Here

   *          <code>(VAL COMMA VAL COMMA VAL)</code>
   *     where VAL can be an INT or a PERCENT (which is then converted to INT)
   * @return the minimal hex expression for the RGB color values
   */
  private static Value colorValue(LexicalUnit colors) {
    LexicalUnit red = colors;
    int r = getRgbComponentValue(red);
    LexicalUnit green = red.getNextLexicalUnit().getNextLexicalUnit();
    int g = getRgbComponentValue(green);
    LexicalUnit blue = green.getNextLexicalUnit().getNextLexicalUnit();
    int b = getRgbComponentValue(blue);

    String sr = Integer.toHexString(r);
    if (sr.length() == 1) {
      sr = "0" + sr;
View Full Code Here

    }

    final String attrName = parameters.getStringValue().trim();
    final String[] name = StyleSheetParserUtil.parseNamespaceIdent(attrName);

    final LexicalUnit afterComma = parseComma(parameters);
    if (afterComma == null)
    {
      return new CSSAttrFunction(name[0], name[1]);
    }
View Full Code Here

  {
    if (isFunctionValue(unit) == false)
    {
      return null;
    }
    LexicalUnit parameters = unit.getParameters();
    final String functionName = unit.getFunctionName();
    if (parameters == null)
    {
      // no-parameter function include the date() function...
      return new CSSFunctionValue(functionName, new CSSValue[0]);
    }
    if ("attr".equalsIgnoreCase(functionName))
    {
      return parseComplexAttrFn(unit.getParameters());
    }


    final ArrayList contentList = new ArrayList();
    while (parameters != null)
    {
      if (parameters.getLexicalUnitType() == LexicalUnit.SAC_IDENT)
      {
        contentList.add(new CSSConstant(parameters.getStringValue()));
      }
      else if (parameters.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE)
      {
        contentList.add(new CSSStringValue(CSSStringType.STRING,
                parameters.getStringValue()));
      }
      else if (CSSValueFactory.isNumericValue(parameters))
      {
        final CSSNumericValue numericValue =
                CSSValueFactory.createNumericValue(parameters);
        if (numericValue == null)
        {
          return null;
        }
        contentList.add(numericValue);
      }
      else if (CSSValueFactory.isLengthValue(parameters))
      {
        final CSSNumericValue lengthValue =
                CSSValueFactory.createLengthValue(parameters);
        if (lengthValue == null)
        {
          return null;
        }
        contentList.add(lengthValue);
      }
      else if (parameters.getLexicalUnitType() == LexicalUnit.SAC_ATTR)
      {
        final CSSAttrFunction attrFn =
                CSSValueFactory.parseAttrFunction(parameters);
        if (attrFn == null)
        {
          return null;
        }
        contentList.add(attrFn);
      }
      else if (parameters.getLexicalUnitType() == LexicalUnit.SAC_URI)
      {
        final CSSStringValue uriValue = CSSValueFactory.createUriValue(
                parameters);
        if (uriValue == null)
        {
View Full Code Here

TOP

Related Classes of org.w3c.css.sac.LexicalUnit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.