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

The following examples show how to use org.w3c.css.sac.LexicalUnit#SAC_STRING_VALUE . 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: FontFamilyReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected CSSValue parseValue( final LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( value.getStringValue().equalsIgnoreCase( "serif" ) ) {
      return FontFamilyValues.SERIF;
    }
    if ( value.getStringValue().equalsIgnoreCase( "sans-serif" ) ) {
      return FontFamilyValues.SANS_SERIF;
    }
    if ( value.getStringValue().equalsIgnoreCase( "fantasy" ) ) {
      return FontFamilyValues.FANTASY;
    }
    if ( value.getStringValue().equalsIgnoreCase( "cursive" ) ) {
      return FontFamilyValues.CURSIVE;
    }
    if ( value.getStringValue().equalsIgnoreCase( "monospace" ) ) {
      return FontFamilyValues.MONOSPACE;
    }
    return null;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE ) {
    return new CSSStringValue( CSSStringType.STRING, value.getStringValue() );
  }
  return null;
}
 
Example 2
Source File: Measure.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
public String getStringValue() throws DOMException {
	short lexicalUnit = value.getLexicalUnitType();
	if ((lexicalUnit == LexicalUnit.SAC_IDENT) || (lexicalUnit == LexicalUnit.SAC_STRING_VALUE)
			|| (lexicalUnit == LexicalUnit.SAC_URI))
		return value.getStringValue();
	// TODO There are more cases to catch of getLexicalUnitType()
	throw new UnsupportedOperationException("NOT YET IMPLEMENTED");
}
 
Example 3
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 4
Source File: TextOverflowEllipsisReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseValue( final LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_URI ) {
    return new CSSStringValue( CSSStringType.URI, value.getStringValue() );
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE ) {
    return new CSSStringValue( CSSStringType.STRING, value.getStringValue() );
  }
  return null;
}
 
Example 5
Source File: TextAlignReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue lookupValue( final LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE ) {
    return new CSSStringValue( CSSStringType.STRING, value.getStringValue() );
  }

  return super.lookupValue( value );
}
 
Example 6
Source File: QuotesReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseSecondPosition( final LexicalUnit value,
                                        final CSSValue first ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE ) {
    return new CSSStringValue( CSSStringType.STRING, value.getStringValue() );
  }
  return null;
}
 
Example 7
Source File: LangReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE ||
    value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    return new CSSStringValue( CSSStringType.STRING, value.getStringValue() );
  }
  return null;
}
 
Example 8
Source File: PseudoclassReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseValue( final LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE ||
    value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    return new CSSStringValue( CSSStringType.STRING, value.getStringValue() );
  }
  return null;
}
 
Example 9
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 10
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 11
Source File: CSSValue.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public short getPrimitiveType( )
{
	if ( value instanceof LexicalUnit )
	{
		LexicalUnit lu = (LexicalUnit) value;
		switch ( lu.getLexicalUnitType( ) )
		{
			case LexicalUnit.SAC_INHERIT :
				return CSS_IDENT;
			case LexicalUnit.SAC_INTEGER :
			case LexicalUnit.SAC_REAL :
				return CSS_NUMBER;
			case LexicalUnit.SAC_EM :
				return CSS_EMS;
			case LexicalUnit.SAC_EX :
				return CSS_EXS;
			case LexicalUnit.SAC_PIXEL :
				return CSS_PX;
			case LexicalUnit.SAC_INCH :
				return CSS_IN;
			case LexicalUnit.SAC_CENTIMETER :
				return CSS_CM;
			case LexicalUnit.SAC_MILLIMETER :
				return CSS_MM;
			case LexicalUnit.SAC_POINT :
				return CSS_PT;
			case LexicalUnit.SAC_PICA :
				return CSS_PC;
			case LexicalUnit.SAC_PERCENTAGE :
				return CSS_PERCENTAGE;
			case LexicalUnit.SAC_URI :
				return CSS_URI;
			case LexicalUnit.SAC_DEGREE :
				return CSS_DEG;
			case LexicalUnit.SAC_GRADIAN :
				return CSS_GRAD;
			case LexicalUnit.SAC_RADIAN :
				return CSS_RAD;
			case LexicalUnit.SAC_MILLISECOND :
				return CSS_MS;
			case LexicalUnit.SAC_SECOND :
				return CSS_S;
			case LexicalUnit.SAC_HERTZ :
				return CSS_KHZ;
			case LexicalUnit.SAC_KILOHERTZ :
				return CSS_HZ;
			case LexicalUnit.SAC_IDENT :
				return CSS_IDENT;
			case LexicalUnit.SAC_STRING_VALUE :
				return CSS_STRING;
			case LexicalUnit.SAC_ATTR :
				return CSS_ATTR;
			case LexicalUnit.SAC_UNICODERANGE :
			case LexicalUnit.SAC_SUB_EXPRESSION :
			case LexicalUnit.SAC_FUNCTION :
				return CSS_STRING;
			case LexicalUnit.SAC_DIMENSION :
				return CSS_DIMENSION;
		}
	}
	return CSS_UNKNOWN;
}
 
Example 12
Source File: CSSValueFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static CSSFunctionValue parseFunction( LexicalUnit unit ) {
  if ( isFunctionValue( unit ) == false ) {
    return null;
  }
  LexicalUnit parameters = unit.getParameters();
  String functionName = unit.getFunctionName();
  if ( parameters == null ) {
    // no-parameter function include the date() function...
    return new CSSFunctionValue( functionName, EMPTY_PARAMETERS );
  }
  if ( "attr".equalsIgnoreCase( functionName ) ) {
    return parseComplexAttrFn( unit.getParameters() );
  }
  if ( "color".equalsIgnoreCase( functionName ) ) {
    // for some strange reason, flute translates "rgb" functions into "color" functions which
    // are not even mentioned in the CSS specs. We therefore translate it back into RGB.
    functionName = "rgb";
  }

  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 ) {
        return null;
      }
      contentList.add( uriValue );
    } else if ( isFunctionValue( parameters ) ) {
      final CSSFunctionValue functionValue = parseFunction( parameters );
      if ( functionValue == null ) {
        return null;
      }
      contentList.add( functionValue );
    } else {
      // parse error: Something we do not understand ...
      return null;
    }
    parameters = CSSValueFactory.parseComma( parameters );
  }
  final CSSValue[] paramVals = (CSSValue[])
    contentList.toArray( new CSSValue[ contentList.size() ] );

  return new CSSFunctionValue( functionName, paramVals );
}
 
Example 13
Source File: QuotesReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected CSSValue parseFirstPosition( final LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE ) {
    return new CSSStringValue( CSSStringType.STRING, value.getStringValue() );
  }
  return null;
}
 
Example 14
Source File: TargetNameReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected CSSValue lookupValue( final LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE ) {
    return new CSSStringValue( CSSStringType.STRING, value.getStringValue() );
  }
  return super.lookupValue( value );
}