Java Code Examples for org.w3c.css.sac.LexicalUnit#getStringValue()

The following examples show how to use org.w3c.css.sac.LexicalUnit#getStringValue() . 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: FitPositionReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    final String stringValue = value.getStringValue();
    if ( stringValue.equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
  }

  final CSSValue firstPosition = parseFirstPosition( value );
  if ( firstPosition == null ) {
    return null;
  }

  value = value.getNextLexicalUnit();
  final CSSValue secondPosition = parseSecondPosition( value, firstPosition );
  if ( secondPosition == null ) {
    return null;
  }

  return createResultList( firstPosition, secondPosition );
}
 
Example 2
Source File: XStringDefineReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
    return null;
  }
  final String mayBeNone = value.getStringValue();
  if ( "none".equalsIgnoreCase( mayBeNone ) ) {
    return new CSSConstant( "none" );
  }

  final ArrayList counterSpecs = new ArrayList();
  while ( value != null ) {
    if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
      return null;
    }
    final String identifier = value.getStringValue();
    value = value.getNextLexicalUnit();
    counterSpecs.add( new CSSConstant( identifier ) );
  }

  return new CSSValueList( counterSpecs );

}
 
Example 3
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 4
Source File: OverflowClipReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    final String stringValue = value.getStringValue();
    if ( stringValue.equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION ) {
    if ( value.getFunctionName().equalsIgnoreCase( "inset-rect" ) ) {
      return getRectangle( CSSRectangleType.INSET_RECT, value.getParameters() );
    }
    return null;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_RECT_FUNCTION ) {
    return getRectangle( CSSRectangleType.RECT, value.getParameters() );
  }
  return null;
}
 
Example 5
Source File: CropReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    final String stringValue = value.getStringValue();
    if ( stringValue.equalsIgnoreCase( "auto" ) ||
      stringValue.equalsIgnoreCase( "none" ) ) {
      return CSSAutoValue.getInstance();
    }
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION ) {
    if ( value.getFunctionName().equalsIgnoreCase( "inset-rect" ) ) {
      return getRectangle( CSSRectangleType.INSET_RECT, value.getParameters() );
    }
    return null;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_RECT_FUNCTION ) {
    return getRectangle( CSSRectangleType.RECT, value.getParameters() );
  }
  return null;
}
 
Example 6
Source File: CSSValueFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static CSSStringValue createUriValue( LexicalUnit value ) {
  if ( value.getLexicalUnitType() != LexicalUnit.SAC_URI ) {
    return null;
  }

  final String uri = value.getStringValue();
  return new CSSStringValue( CSSStringType.URI, uri );
}
 
Example 7
Source File: CSSValueFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String parseAttributeType( LexicalUnit unit ) {
  if ( unit == null ) {
    return null;
  }
  if ( unit.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    return unit.getStringValue();
  }
  return null;
}
 
Example 8
Source File: PageReadHandler.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_IDENT ) {
    return null;
  }
  String ident = value.getStringValue();
  if ( ident.equalsIgnoreCase( "auto" ) ) {
    return CSSAutoValue.getInstance();
  }

  return new CSSConstant( ident );
}
 
Example 9
Source File: CounterModificationReadHandler.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_IDENT ) {
    return null;
  }
  final String mayBeNone = value.getStringValue();
  if ( "none".equalsIgnoreCase( mayBeNone ) ) {
    return new CSSConstant( "none" );
  }

  final ArrayList counterSpecs = new ArrayList();
  while ( value != null ) {
    if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
      return null;
    }
    final String identifier = value.getStringValue();
    value = value.getNextLexicalUnit();
    CSSValue counterValue = ZERO;
    if ( value != null ) {
      if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) {
        counterValue = CSSNumericValue.createValue
          ( CSSNumericType.NUMBER, value.getIntegerValue() );
        value = value.getNextLexicalUnit();
      } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_ATTR ) {
        counterValue = CSSValueFactory.parseAttrFunction( value );
        value = value.getNextLexicalUnit();
      } else if ( CSSValueFactory.isFunctionValue( value ) ) {
        counterValue = CSSValueFactory.parseFunction( value );
        value = value.getNextLexicalUnit();
      }
    }
    counterSpecs.add( new CSSValuePair
      ( new CSSConstant( identifier ), counterValue ) );
  }

  return new CSSValueList( counterSpecs );
}
 
Example 10
Source File: WhitespaceReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Parses the LexicalUnit and returns a map of (StyleKey, CSSValue) pairs.
 *
 * @param unit
 * @return
 */
public Map createValues( LexicalUnit unit ) {
  // http://cheeaun.phoenity.com/weblog/2005/06/whitespace-and-generated-content.html
  // is a good overview about the whitespace stuff ..

  CSSValue whitespace;
  CSSValue textWrap;
  if ( unit.getLexicalUnitType() == LexicalUnit.SAC_INHERIT ) {
    whitespace = CSSInheritValue.getInstance();
    textWrap = CSSInheritValue.getInstance();
  } else if ( unit.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    String strVal = unit.getStringValue();
    if ( strVal.equalsIgnoreCase( "normal" ) ) {
      whitespace = WhitespaceCollapse.COLLAPSE;
      textWrap = TextWrap.NORMAL;
    } else if ( strVal.equalsIgnoreCase( "pre" ) ) {
      whitespace = WhitespaceCollapse.PRESERVE;
      textWrap = TextWrap.SUPPRESS;
    } else if ( strVal.equalsIgnoreCase( "pre-line" ) ) {
      whitespace = WhitespaceCollapse.PRESERVE_BREAKS;
      textWrap = TextWrap.NORMAL;
    } else if ( strVal.equalsIgnoreCase( "pre-wrap" ) ) {
      whitespace = WhitespaceCollapse.PRESERVE;
      textWrap = TextWrap.NORMAL;
    } else {
      return null;
    }
  } else {
    return null;
  }

  Map map = new HashMap();
  map.put( TextStyleKeys.WHITE_SPACE_COLLAPSE, whitespace );
  map.put( TextStyleKeys.TEXT_WRAP, textWrap );
  return map;
}
 
Example 11
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 12
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 13
Source File: ImageOrientationReadHandler.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_IDENT ) {
    String ident = value.getStringValue();
    if ( ident.equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
    return null;
  }
  if ( value.getLexicalUnitType() != LexicalUnit.SAC_DEGREE ) {
    return null;
  }
  return CSSNumericValue.createValue( CSSNumericType.DEG, value.getFloatValue() );
}
 
Example 14
Source File: MoveToReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue lookupValue( final LexicalUnit value ) {
  CSSValue content = super.lookupValue( value );
  if ( content != null ) {
    return content;
  }

  if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
    return null;
  }
  return new CSSConstant( value.getStringValue() );
}
 
Example 15
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 16
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 );
}
 
Example 17
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 18
Source File: SizeReadHandler.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 ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    String ident = value.getStringValue();
    if ( ident.equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
    final PageSize ps = PageSizeFactory.getInstance().getPageSizeByName( ident );
    if ( ps == null ) {
      return null;
    }

    value = value.getNextLexicalUnit();
    int pageOrientation = PageFormat.PORTRAIT;
    if ( value != null ) {
      if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
        return null;
      }

      if ( value.getStringValue().equalsIgnoreCase( "landscape" ) ) {
        pageOrientation = PageFormat.LANDSCAPE;
      } else if ( value.getStringValue().equalsIgnoreCase( "reverse-landscape" ) ) {
        pageOrientation = PageFormat.REVERSE_LANDSCAPE;
      } else if ( value.getStringValue().equalsIgnoreCase( "portrait" ) ) {
        pageOrientation = PageFormat.PORTRAIT;
      } else {
        return null;
      }
    }

    if ( pageOrientation == PageFormat.LANDSCAPE ||
      pageOrientation == PageFormat.REVERSE_LANDSCAPE ) {
      return new CSSValuePair( CSSNumericValue.createPtValue( ps.getHeight() ),
        CSSNumericValue.createPtValue( ps.getWidth() ) );
    } else {
      return new CSSValuePair( CSSNumericValue.createPtValue( ps.getWidth() ),
        CSSNumericValue.createPtValue( ps.getHeight() ) );
    }
  } else {
    final CSSNumericValue horizontalWidth = (CSSNumericValue) parseWidth( value );
    if ( horizontalWidth == null ) {
      return null;
    }

    value = value.getNextLexicalUnit();

    final CSSNumericValue verticalWidth;
    if ( value == null ) {
      verticalWidth = horizontalWidth;
    } else {
      verticalWidth = (CSSNumericValue) parseWidth( value );
      if ( verticalWidth == null ) {
        return null;
      }
    }

    return new CSSValuePair( horizontalWidth, verticalWidth );
  }
}
 
Example 19
Source File: BackgroundRepeatReadHandler.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 ) {
    if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
      return null;
    }

    final CSSConstant horizontal;
    final CSSConstant vertical;

    final String horizontalString = value.getStringValue();
    if ( horizontalString.equalsIgnoreCase( "repeat-x" ) ) {
      horizontal = BackgroundRepeat.REPEAT;
      vertical = BackgroundRepeat.NOREPEAT;
    } else if ( value.getStringValue().equalsIgnoreCase( "repeat-y" ) ) {
      horizontal = BackgroundRepeat.NOREPEAT;
      vertical = BackgroundRepeat.REPEAT;
    } else {
      horizontal = translateRepeat( horizontalString );
      if ( horizontal == null ) {
        return null;
      }

      value = value.getNextLexicalUnit();
      if ( value == null ) {
        vertical = horizontal;
      } else if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
        return null;
      } else {
        vertical = translateRepeat( value.getStringValue() );
        if ( vertical == null ) {
          return null;
        }
      }
    }

    values.add( new CSSValuePair( horizontal, vertical ) );
    value = CSSValueFactory.parseComma( value );
  }

  return new CSSValueList( values );
}
 
Example 20
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();
		}
	}
}