Package org.w3c.flex.forks.css.sac

Examples of org.w3c.flex.forks.css.sac.LexicalUnit


                return;
            }
        }
        }

        LexicalUnit fontStyle   = null;
        LexicalUnit fontVariant = null;
        LexicalUnit fontWeight  = null;
        LexicalUnit fontSize    = null;
        LexicalUnit lineHeight  = null;
        LexicalUnit fontFamily  = null;

        ValueManager[]vMgrs = eng.getValueManagers();
        int fst, fv, fw, fsz, lh, ff;
        fst = eng.getPropertyIndex(CSSConstants.CSS_FONT_STYLE_PROPERTY);
        fv  = eng.getPropertyIndex(CSSConstants.CSS_FONT_VARIANT_PROPERTY);
        fw  = eng.getPropertyIndex(CSSConstants.CSS_FONT_WEIGHT_PROPERTY);
        fsz = eng.getPropertyIndex(CSSConstants.CSS_FONT_SIZE_PROPERTY);
        lh  = eng.getPropertyIndex(CSSConstants.CSS_LINE_HEIGHT_PROPERTY);
        ff  = eng.getPropertyIndex(CSSConstants.CSS_FONT_FAMILY_PROPERTY);

        IdentifierManager fstVM = (IdentifierManager)vMgrs[fst];
        IdentifierManager fvVM  = (IdentifierManager)vMgrs[fv];
        IdentifierManager fwVM  = (IdentifierManager)vMgrs[fw];
        FontSizeManager fszVM = (FontSizeManager)vMgrs[fsz];
        ValueManager      ffVM  = vMgrs[ff];

        StringMap fstSM = fstVM.getIdentifiers();
        StringMap fvSM  = fvVM.getIdentifiers();
        StringMap fwSM  = fwVM.getIdentifiers();
        StringMap fszSM = fszVM.getIdentifiers();


        // Check for font-style, font-varient, & font-weight
        // These are all optional.

        boolean svwDone= false;
        LexicalUnit intLU = null;;
        while (!svwDone && (lu != null)) {
            switch (lu.getLexicalUnitType()) {
            case LexicalUnit.SAC_IDENT: {
                String s= lu.getStringValue().toLowerCase().intern();
                if ((fontStyle   == null) && (fstSM.get(s) != null)) {
                    fontStyle   = lu;
                    if (intLU != null) {
                        if (fontWeight == null) {
                            fontWeight = intLU;
                            intLU = null;
                        } else
                            throw createInvalidLexicalUnitDOMException
                                (intLU.getLexicalUnitType());
                    }
                    break;
                }

                if ((fontVariant == null) && (fvSM.get(s!= null)) {
                    fontVariant = lu;
                    if (intLU != null) {
                        if (fontWeight == null) {
                            fontWeight = intLU;
                            intLU = null;
                        } else
                            throw createInvalidLexicalUnitDOMException
                                (intLU.getLexicalUnitType());
                    }
                    break;
                }

                if ((intLU == null) && (fontWeight  == null) &&
                    (fwSM.get(s!= null)) {
                    fontWeight = lu;
                    break;
                }

                svwDone = true;
                break;
            }
            case LexicalUnit.SAC_INTEGER:
                if ((intLU == null) && (fontWeight == null)) {
                    intLU = lu;
                    break;
                }
                svwDone = true;
                break;

            default: // All other must be size,'/line-height', family
                svwDone = true;
                break;
            }
            if (!svwDone) lu = lu.getNextLexicalUnit();
        }

        // Must have font-size.
        if (lu == null)
            throw createMalformedLexicalUnitDOMException();

        // Now we need to get font-size
        switch (lu.getLexicalUnitType()) {
        case LexicalUnit.SAC_IDENT: {
            String s= lu.getStringValue().toLowerCase().intern();
            if (fszSM.get(s) != null) {
                fontSize = lu; // This is a font-size ident.
                lu = lu.getNextLexicalUnit();
            }
        }
            break;

  case LexicalUnit.SAC_EM:
  case LexicalUnit.SAC_EX:
  case LexicalUnit.SAC_PIXEL:
  case LexicalUnit.SAC_CENTIMETER:
  case LexicalUnit.SAC_MILLIMETER:
  case LexicalUnit.SAC_INCH:
  case LexicalUnit.SAC_POINT:
  case LexicalUnit.SAC_PICA:
  case LexicalUnit.SAC_INTEGER:
  case LexicalUnit.SAC_REAL:
  case LexicalUnit.SAC_PERCENTAGE:
            fontSize = lu;
            lu = lu.getNextLexicalUnit();
            break;
        }
       

        if (fontSize == null) {
            // We must have a font-size so see if we can use intLU...
            if (intLU != null) {
                fontSize = intLU;  // Yup!
                intLU = null;
            } else {
                throw createInvalidLexicalUnitDOMException
                    (lu.getLexicalUnitType());
            }
        }

        if (intLU != null) {
            // We have a intLU left see if we can use it as font-weight
            if (fontWeight == null) {
                fontWeight = intLU; // use intLU as font-weight.
            } else {
                // we have an 'extra' integer in property.
                throw createInvalidLexicalUnitDOMException
                    (intLU.getLexicalUnitType());
            }
        }
       
        // Must have Font-Family, so if it's null now we are done!
        if (lu == null)
View Full Code Here


  }

  public String getIdentAsString()
  {
    StringBuilder sb = new StringBuilder();
    LexicalUnit lexicalUnit = value;

    while (lexicalUnit != null)
    {
      try
      {
        switch(lexicalUnit.getLexicalUnitType())
        {
          case LexicalUnit.SAC_IDENT:
            sb.append(lexicalUnit.getStringValue());
            break;
          case LexicalUnit.SAC_OPERATOR_COMMA:
            sb.append(',');
            break;
          case LexicalUnit.SAC_INTEGER:
            sb.append(lexicalUnit.getIntegerValue());
            break;
          default:
            sb.append(lexicalUnit.getStringValue());
            break;
        }
      }
      catch(IllegalStateException ise)
      {
        UnparsableCSS unparsableCSS = new UnparsableCSS();
        unparsableCSS.path = path;
        unparsableCSS.line = lineNumber;
        ThreadLocalToolkit.log(unparsableCSS);
      }

      lexicalUnit = lexicalUnit.getNextLexicalUnit();
    }

    return sb.toString();
  }
View Full Code Here

            }
        case LexicalUnit.SAC_RGBCOLOR:
            {
                StringBuilder stringBuffer = new StringBuilder("0x");

                LexicalUnit parameter = lexicalUnit.getParameters();

                while (parameter != null)
                {
                    int digit;

                    switch(parameter.getLexicalUnitType())
                    {
                    case LexicalUnit.SAC_INTEGER:
                        {
                            digit = parameter.getIntegerValue();
                            stringBuffer.append(Character.forDigit((digit >> 4) & 15, 16));
                            stringBuffer.append(Character.forDigit(digit & 15, 16));
                            break;
                        }
                    case LexicalUnit.SAC_PERCENTAGE:
                        {
                            digit = ((new Float(parameter.getFloatValue())).intValue() * 255) / 100;
                            stringBuffer.append(Character.forDigit((digit >> 4) & 15, 16));
                            stringBuffer.append(Character.forDigit(digit & 15, 16));
                            break;
                        }
                    }

                    parameter = parameter.getNextLexicalUnit();
                }

                color = stringBuffer.toString();
                break;
            }
View Full Code Here

    private static String getListAsString(String name, LexicalUnit value, boolean quoteIdentifier)
        throws CompilerError
    {
        StringBuilder stringBuffer = new StringBuilder();

        LexicalUnit current = value;

        while (current != null)
        {
            stringBuffer.append( getLexicalUnitAsString(name, current, quoteIdentifier) );

            LexicalUnit next = current.getNextLexicalUnit();

            if (next != null)
            {
                if (next.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA)
                {
                    current = next.getNextLexicalUnit();
                    stringBuffer.append(", ");
                }
                else if (next.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_SLASH)
                {
                    current = next.getNextLexicalUnit();
                    stringBuffer.append(" = ");
                }
                else
                {
                    throw new InvalidFormat();
View Full Code Here

     */
    public String getValueAsString() throws CompilerError
    {
        String valueString;

        LexicalUnit next = value.getNextLexicalUnit();

        if ((next != null) && (next.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA))
        {
            valueString = ("[" + getListAsString(name, value) + "]");
        }
        else
        {
View Full Code Here

        }

        Parser cssParser = new Parser();
        // see if the property supports the value 'inherit'
        try {
            LexicalUnit lu = cssParser.parsePropertyValue("inherit");
            Value v = manager.createValue(lu, null);
            String s = v.getCssText();
            if (!"inherit".equalsIgnoreCase(s)) {
                report.setErrorCode(ERROR_INHERIT_VALUE);
                report.setPassed(false);
                report.addDescriptionEntry(ERROR_INHERIT_VALUE, "inherit");
            }
        } catch (Exception ex) {
            report.setErrorCode(ERROR_INHERIT_VALUE);
            report.setPassed(false);
            report.addDescriptionEntry(ERROR_INHERIT_VALUE, ex.getMessage());
        }

        // test all possible identifiers
        if (identValues != null) {
            try {
                for (int i=0; i < identValues.length; ++i) {
                    LexicalUnit lu = cssParser.parsePropertyValue(identValues[i]);
                    Value v = manager.createValue(lu, null);
                    String s = v.getCssText();
                    if (!identValues[i].equalsIgnoreCase(s)) {
                        report.setErrorCode(ERROR_INVALID_VALUE);
                        report.setPassed(false);
View Full Code Here

TOP

Related Classes of org.w3c.flex.forks.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.