org.w3c.css.sac.LexicalUnit Java Examples

The following examples show how to use org.w3c.css.sac.LexicalUnit. 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: SpacingLimitReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private CSSValue parseSingleSpacingValue( final LexicalUnit value ) {
  if ( value == null ) {
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( value.getStringValue().equalsIgnoreCase( "normal" ) ) {
      return SpacingLimitReadHandler.NORMAL;
    }
    return null;
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }

  return CSSValueFactory.createLengthValue( value );
}
 
Example #2
Source File: ListOfPairReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public synchronized CSSValue createValue( StyleKey name, LexicalUnit value ) {
  ArrayList values = new ArrayList();

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

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

    addToResultList( values, firstPosition, secondPosition );
    value = CSSValueFactory.parseComma( value );
  }

  return new CSSValueList( values );
}
 
Example #3
Source File: IdentifierManager.java    From birt with Eclipse Public License 1.0 6 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;

		case LexicalUnit.SAC_IDENT :
			String s = lu.getStringValue( ).toLowerCase( ).intern( );
			Object v = getIdentifiers( ).get( s );
			if ( v == null )
			{
				throw createInvalidIdentifierDOMException( lu
						.getStringValue( ) );
			}
			return (Value) v;

		default :
			throw createInvalidLexicalUnitDOMException( lu
					.getLexicalUnitType( ) );
	}
}
 
Example #4
Source File: OverflowClipReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static CSSRectangleValue getRectangle
  ( CSSRectangleType type, LexicalUnit value ) {
  final CSSNumericValue[] list = new CSSNumericValue[ 4 ];
  for ( int index = 0; index < 4; index++ ) {
    if ( value == null ) {
      return null;
    }
    CSSNumericValue nval = CSSValueFactory.createLengthValue( value );
    if ( nval != null ) {
      list[ index ] = nval;
    } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      list[ index ] = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      return null;
    }
    value = CSSValueFactory.parseComma( value );
  }

  return new CSSRectangleValue( type, list[ 0 ], list[ 1 ], list[ 2 ], list[ 3 ] );
}
 
Example #5
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 #6
Source File: SpacingManager.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public Value createValue( LexicalUnit lu, CSSEngine engine )
		throws DOMException
{
	switch ( lu.getLexicalUnitType( ) )
	{
		case LexicalUnit.SAC_IDENT :
			String s = lu.getStringValue( ).toLowerCase( ).intern( );
			Object v = values.get( s );
			if ( v == null )
			{
				throw createInvalidIdentifierDOMException( lu
						.getStringValue( ) );
			}
			return (Value) v;
		case LexicalUnit.SAC_PERCENTAGE :
			throw createInvalidLexicalUnitDOMException( lu
					.getLexicalUnitType( ) );
	}
	return super.createValue( lu, engine );
}
 
Example #7
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 #8
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 #9
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 #10
Source File: ListOfValuesReadHandler.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 ) {
  final ArrayList list = new ArrayList();
  int count = 0;
  while ( value != null && count < maxCount ) {
    final CSSValue pvalue = parseValue( value );
    if ( pvalue == null ) {
      return null;
    }
    if ( distinctValues == false ||
      list.contains( pvalue ) == false ) {
      list.add( pvalue );
    }
    value = CSSValueFactory.parseComma( value );
    count += 1;
  }

  return new CSSValueList( list );
}
 
Example #11
Source File: TextIndentReadHandler.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 ) {

    CSSValue cssvalue = null;
    if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
      cssvalue = CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() );
    } else {
      cssvalue = CSSValueFactory.createLengthValue( value );
    }

    value = value.getNextLexicalUnit();
    if ( value != null ) {
      if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
        return null;
      }
      if ( value.getStringValue().equalsIgnoreCase( "hanging" ) ) {
        return new CSSValueList( new CSSValue[] { cssvalue, new CSSConstant( "hanging" ) } );
      } else {
        return null;
      }
    }

    return new CSSValueList( new CSSValue[] { cssvalue } );
  }
 
Example #12
Source File: BorderRadiusReadHandler.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 ) {
  CSSNumericValue firstValue = CSSValueFactory.createLengthValue( value );
  if ( firstValue == null ) {
    return null;
  }
  value = value.getNextLexicalUnit();
  CSSNumericValue secondValue;
  if ( value == null ) {
    secondValue = firstValue;
  } else {
    secondValue = CSSValueFactory.createLengthValue( value );
    if ( secondValue == null ) {
      return null;
    }
  }

  return new CSSValuePair( firstValue, secondValue );
}
 
Example #13
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 #14
Source File: DropInitialAfterAdjustReadHandler.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 constant = super.lookupValue( value );
  if ( constant != null ) {
    return constant;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }

  return CSSValueFactory.createLengthValue( value );

}
 
Example #15
Source File: XAndYReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseWidth( final LexicalUnit value ) {
  if ( CSSValueFactory.isNumericValue( value ) ) {
    return CSSValueFactory.createNumericValue( value );
  } else {
    return super.parseWidth( value );
  }
}
 
Example #16
Source File: ColumnSpanReadHandler.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 ) {
    if ( value.getStringValue().equalsIgnoreCase( "none" ) ) {
      return new CSSConstant( "none" );
    }
    if ( value.getStringValue().equalsIgnoreCase( "all" ) ) {
      return new CSSConstant( "all" );
    }
    return null;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) {
    return CSSNumericValue.createValue( CSSNumericType.NUMBER,
      value.getIntegerValue() );
  }
  return null;
}
 
Example #17
Source File: TextAutoSpaceReadHandler.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 ) {
    if ( value.getStringValue().equalsIgnoreCase( "none" ) ) {
      return new CSSValueList( new CSSValue[] { TextAutoSpace.NONE } );
    }
  }
  return super.createValue( name, value );
}
 
Example #18
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 #19
Source File: BaselineShiftReadHandler.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 constant = super.lookupValue( value );
  if ( constant != null ) {
    return constant;
  } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }

  return CSSValueFactory.createLengthValue( value );

}
 
Example #20
Source File: AbstractWidthReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseWidth( final LexicalUnit value ) {
  if ( allowPercentages &&
    value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  } else if ( allowAuto &&
    value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
    return null;
  } else {
    return CSSValueFactory.createLengthValue( value );
  }
}
 
Example #21
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 #22
Source File: FitPositionReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseFirstPosition( final LexicalUnit value ) {
  if ( value == null ) {
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( "left".equalsIgnoreCase( value.getStringValue() ) ) {
      return LEFT;
    } else if ( "center".equalsIgnoreCase( value.getStringValue() ) ) {
      return CENTER;
    } else if ( "right".equalsIgnoreCase( value.getStringValue() ) ) {
      return RIGHT;
    } else if ( "top".equalsIgnoreCase( value.getStringValue() ) ) {
      return TOP;
    } else if ( "bottom".equalsIgnoreCase( value.getStringValue() ) ) {
      return BOTTOM;
    }

    // ignore this rule.
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }
  if ( CSSValueFactory.isLengthValue( value ) ) {
    return CSSValueFactory.createLengthValue( value );
  }
  // contains errors, we ignore this rule.
  return null;
}
 
Example #23
Source File: CSSValueFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean isFunctionValue( LexicalUnit unit ) {
  final short lexicalUnitType = unit.getLexicalUnitType();
  return ( lexicalUnitType == LexicalUnit.SAC_FUNCTION ||
    lexicalUnitType == LexicalUnit.SAC_COUNTER_FUNCTION ||
    lexicalUnitType == LexicalUnit.SAC_COUNTERS_FUNCTION ||
    lexicalUnitType == LexicalUnit.SAC_RGBCOLOR ||
    lexicalUnitType == LexicalUnit.SAC_RECT_FUNCTION );
}
 
Example #24
Source File: CSSValueFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private CSSValue createValue( StyleKey key, LexicalUnit value ) {
  final CSSValueReadHandler module =
    (CSSValueReadHandler) handlers.get( key.getName() );
  if ( module == null ) {
    //  || module instanceof CSSCompoundValueReadHandler
    // Compund handler are more important than simple handlers ..
    return null;
  }

  return module.createValue( key, value );
}
 
Example #25
Source File: XColSpanReadHandler.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_INTEGER ) {
    return CSSNumericValue.createValue( CSSNumericType.NUMBER,
      value.getIntegerValue() );
  }
  return null;
}
 
Example #26
Source File: Parser.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public LexicalUnit parsePropertyValue( InputSource source )
  throws CSSException, IOException {
  this.source = source;
  ReInit( getCharStreamWithLurk( source ) );

  return expr();
}
 
Example #27
Source File: BackgroundPositionReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CSSValue parseFirstPosition( final LexicalUnit value ) {
  if ( value == null ) {
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( "left".equalsIgnoreCase( value.getStringValue() ) ) {
      return LEFT;
    } else if ( "center".equalsIgnoreCase( value.getStringValue() ) ) {
      return CENTER;
    } else if ( "right".equalsIgnoreCase( value.getStringValue() ) ) {
      return RIGHT;
    } else if ( "top".equalsIgnoreCase( value.getStringValue() ) ) {
      return TOP;
    } else if ( "bottom".equalsIgnoreCase( value.getStringValue() ) ) {
      return BOTTOM;
    }

    // ignore this rule.
    return null;
  }

  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  }
  if ( CSSValueFactory.isLengthValue( value ) ) {
    return CSSValueFactory.createLengthValue( value );
  }
  // contains errors, we ignore this rule.
  return null;
}
 
Example #28
Source File: BackgroundPositionReadHandler.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 firstValue ) {
  if ( value == null ) {
    return CENTER;
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    if ( "left".equalsIgnoreCase( value.getStringValue() ) ) {
      return LEFT;
    } else if ( "center".equalsIgnoreCase( value.getStringValue() ) ) {
      return CENTER;
    } else if ( "right".equalsIgnoreCase( value.getStringValue() ) ) {
      return RIGHT;
    } else if ( "top".equalsIgnoreCase( value.getStringValue() ) ) {
      return TOP;
    } else if ( "bottom".equalsIgnoreCase( value.getStringValue() ) ) {
      return BOTTOM;
    }
    return null; // ignore this rule, it contains errors.
  }
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) {
    return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE,
      value.getFloatValue() );
  } else if ( CSSValueFactory.isLengthValue( value ) ) {
    return CSSValueFactory.createLengthValue( value );
  }
  return CENTER;
}
 
Example #29
Source File: CSSValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public float getFloatValue( short unitType ) throws DOMException
{
	if ( value instanceof LexicalUnit )
	{
		LexicalUnit lu = (LexicalUnit) value;
		return lu.getFloatValue( );
	}
	return 0;
}
 
Example #30
Source File: KerningModeReadHandler.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 ) {
    if ( value.getStringValue().equalsIgnoreCase( "none" ) ) {
      return new CSSValueList( new CSSValue[] { KerningMode.NONE } );
    }
  }
  return super.createValue( name, value );
}