Java Code Examples for org.w3c.css.sac.LexicalUnit#SAC_OPERATOR_COMMA

The following examples show how to use org.w3c.css.sac.LexicalUnit#SAC_OPERATOR_COMMA . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Measure.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
public short getPrimitiveType() {
	switch (value.getLexicalUnitType()) {
	case LexicalUnit.SAC_IDENT:
		return CSS_IDENT;
	case LexicalUnit.SAC_INTEGER:
	case LexicalUnit.SAC_REAL:
		return CSS_NUMBER;
	case LexicalUnit.SAC_URI:
		return CSS_URI;
	case LexicalUnit.SAC_PERCENTAGE:
		return CSS_PERCENTAGE;
	case LexicalUnit.SAC_PIXEL:
		return CSS_PX;
	case LexicalUnit.SAC_CENTIMETER:
		return CSS_CM;
	case LexicalUnit.SAC_EM:
		return CSS_EMS;
	case LexicalUnit.SAC_EX:
		return CSS_EXS;
	case LexicalUnit.SAC_INCH:
		return CSS_IN;
	case LexicalUnit.SAC_STRING_VALUE:
		return CSS_STRING;
	case LexicalUnit.SAC_DIMENSION:
		return CSS_DIMENSION;
	case LexicalUnit.SAC_OPERATOR_COMMA:
		return CSS_CUSTOM; // TODO don't think this is right, see bug
							// #278139
	case LexicalUnit.SAC_INHERIT:
		return CSS_INHERIT;
	}
	// TODO Auto-generated method stub
	throw new UnsupportedOperationException(
			"NOT YET IMPLEMENTED - LexicalUnit type: " + value.getLexicalUnitType());
}
 
Example 2
Source File: Measure.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
public String getCssText() {
	// TODO: All LexicalUnit.SAC_OPERATOR_* except for COMMA left undone for
	// now as it's not even clear whether they should be treated as measures
	// see bug #278139
	switch (value.getLexicalUnitType()) {
	case LexicalUnit.SAC_INTEGER:
		return String.valueOf(value.getIntegerValue());
	case LexicalUnit.SAC_REAL:
		return String.valueOf(value.getFloatValue());
	case LexicalUnit.SAC_PERCENTAGE:
	case LexicalUnit.SAC_PIXEL:
	case LexicalUnit.SAC_CENTIMETER:
	case LexicalUnit.SAC_EM:
	case LexicalUnit.SAC_EX:
	case LexicalUnit.SAC_PICA:
	case LexicalUnit.SAC_POINT:
	case LexicalUnit.SAC_INCH:
	case LexicalUnit.SAC_DEGREE:
		return String.valueOf(value.getFloatValue()) + value.getDimensionUnitText();
	case LexicalUnit.SAC_URI:
		return "url(" + value.getStringValue() + ")";
	case LexicalUnit.SAC_OPERATOR_COMMA:
		return ",";
	case LexicalUnit.SAC_INHERIT:
		return "inherit";
	}
	return value.getStringValue();
}
 
Example 3
Source File: CSSValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor
 * 
 * @param value
 *            the lexical unit of the value
 * @param forcePrimitive
 *            status identifying whether the value is forced to be primitive
 */

public CSSValue( LexicalUnit value, boolean forcePrimitive )
{
	if ( value.getParameters( ) != null )
	{
		this.value = value;
	}
	else if ( forcePrimitive || ( value.getNextLexicalUnit( ) == null ) )
	{

		// We need to be a CSSPrimitiveValue
		this.value = value;
	}
	else
	{

		// We need to be a CSSValueList
		// Values in an "expr" can be seperated by "operator"s, which are
		// either '/' or ',' - ignore these operators
		Vector v = new Vector( );
		LexicalUnit lu = value;
		while ( lu != null )
		{
			if ( ( lu.getLexicalUnitType( ) != LexicalUnit.SAC_OPERATOR_COMMA )
					&& ( lu.getLexicalUnitType( ) != LexicalUnit.SAC_OPERATOR_SLASH ) )
			{
				v.addElement( new CSSValue( lu, true ) );
			}
			lu = lu.getNextLexicalUnit( );
		}
		this.value = v;
	}
}
 
Example 4
Source File: CSSValueFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static LexicalUnit parseComma( final LexicalUnit value ) {
  if ( value == null ) {
    return null;
  }

  LexicalUnit maybeComma = value.getNextLexicalUnit();
  if ( maybeComma == null ) {
    return null;
  }
  if ( maybeComma.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA ) {
    return maybeComma.getNextLexicalUnit();
  }
  return null;
}
 
Example 5
Source File: VisibleFormatManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
 */
public Value createValue(LexicalUnit lu, CSSEngine engine)
		throws DOMException {
	switch (lu.getLexicalUnitType()) {
	case LexicalUnit.SAC_INHERIT:
		return CSSValueConstants.INHERIT_VALUE;

	default:
		throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());

	case LexicalUnit.SAC_IDENT:
	case LexicalUnit.SAC_STRING_VALUE:
	}
	ListValue result = new ListValue();
	for (;;) {
		switch (lu.getLexicalUnitType()) {
		case LexicalUnit.SAC_STRING_VALUE:
			result.append(new StringValue(CSSPrimitiveValue.CSS_STRING, lu
					.getStringValue()));
			lu = lu.getNextLexicalUnit();
			break;

		case LexicalUnit.SAC_IDENT:
			StringBuffer sb = new StringBuffer(lu.getStringValue());
			lu = lu.getNextLexicalUnit();
			if (lu != null
					&& lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
				do {
					sb.append(' ');
					sb.append(lu.getStringValue());
					lu = lu.getNextLexicalUnit();
				} while (lu != null
						&& lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT);
				result.append(new StringValue(CSSPrimitiveValue.CSS_STRING,
						sb.toString()));
			} else {
				String id = sb.toString();
				String s = id.toLowerCase().intern();
				CSSValue v = (CSSValue) values.get(s);
				result.append((v != null) ? v : new StringValue(
						CSSPrimitiveValue.CSS_STRING, id));
			}
		}
		if (lu == null) {
			return result;
		}
		if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
			throw createInvalidLexicalUnitDOMException(lu
					.getLexicalUnitType());
		}
		lu = lu.getNextLexicalUnit();
		if (lu == null) {
			throw createMalformedLexicalUnitDOMException();
		}
	}
}
 
Example 6
Source File: FontFamilyManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
 */
public Value createValue(LexicalUnit lu, CSSEngine engine)
		throws DOMException {
	switch (lu.getLexicalUnitType()) {
	case LexicalUnit.SAC_INHERIT:
		return CSSValueConstants.INHERIT_VALUE;

	default:
		throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());

	case LexicalUnit.SAC_IDENT:
	case LexicalUnit.SAC_STRING_VALUE:
	}
	ListValue result = new ListValue();
	for (;;) {
		switch (lu.getLexicalUnitType()) {
		case LexicalUnit.SAC_STRING_VALUE:
			result.append(new StringValue(CSSPrimitiveValue.CSS_STRING, lu
					.getStringValue()));
			lu = lu.getNextLexicalUnit();
			break;

		case LexicalUnit.SAC_IDENT:
			StringBuffer sb = new StringBuffer(lu.getStringValue());
			lu = lu.getNextLexicalUnit();
			if (lu != null
					&& lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
				do {
					sb.append(' ');
					sb.append(lu.getStringValue());
					lu = lu.getNextLexicalUnit();
				} while (lu != null
						&& lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT);
				result.append(new StringValue(CSSPrimitiveValue.CSS_STRING,
						sb.toString()));
			} else {
				String id = sb.toString();
				String s = id.toLowerCase().intern();
				CSSValue v = (CSSValue) values.get(s);
				result.append((v != null) ? v : new StringValue(
						CSSPrimitiveValue.CSS_STRING, id));
			}
		}
		if (lu == null) {
			return result;
		}
		if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
			throw createInvalidLexicalUnitDOMException(lu
					.getLexicalUnitType());
		}
		lu = lu.getNextLexicalUnit();
		if (lu == null) {
			throw createMalformedLexicalUnitDOMException();
		}
	}
}
 
Example 7
Source File: BackgroundSizeReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  ArrayList values = new ArrayList();

  while ( value != null ) {
    CSSValue firstValue;
    if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
      if ( value.getStringValue().equalsIgnoreCase( "round" ) ) {
        values.add( createList( CSSAutoValue.getInstance(),
          CSSAutoValue.getInstance(),
          BackgroundSize.ROUND ) );

        value = CSSValueFactory.parseComma( value );
        continue;
      }

      if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) {
        firstValue = CSSAutoValue.getInstance();
      } else {
        return null;
      }
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      firstValue = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      firstValue = CSSValueFactory.createLengthValue( value );
      if ( firstValue == null ) {
        return null;
      }
    }

    value = value.getNextLexicalUnit();
    if ( value == null ) {
      values.add( createList( firstValue,
        CSSAutoValue.getInstance(),
        BackgroundSize.ROUND ) );
      continue;
    }

    CSSValue secondValue;
    if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
      if ( value.getStringValue().equalsIgnoreCase( "round" ) ) {
        values.add( createList( firstValue,
          CSSAutoValue.getInstance(),
          BackgroundSize.ROUND ) );
        value = CSSValueFactory.parseComma( value );
        continue;
      } else if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) {
        secondValue = CSSAutoValue.getInstance();
      } else {
        return null;
      }
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA ) {
      values.add( createList( firstValue,
        CSSAutoValue.getInstance(),
        BackgroundSize.ROUND ) );
      value = value.getNextLexicalUnit();
      continue;
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      secondValue = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      secondValue = CSSValueFactory.createLengthValue( value );
      if ( secondValue == null ) {
        return null;
      }
    }

    value = value.getNextLexicalUnit();
    if ( value == null ) {
      values.add( createList( firstValue,
        secondValue,
        BackgroundSize.NO_ROUND ) );
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA ) {
      values.add( createList( firstValue,
        secondValue,
        BackgroundSize.NO_ROUND ) );
      value = value.getNextLexicalUnit();
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
      if ( value.getStringValue().equalsIgnoreCase( "round" ) == false ) {
        return null;
      }
      values.add( createList( firstValue,
        secondValue,
        BackgroundSize.ROUND ) );
      value = CSSValueFactory.parseComma( value );
    } else {
      return null;
    }
  }

  return new CSSValueList( values );
}