org.w3c.css.sac.CSSException Java Examples

The following examples show how to use org.w3c.css.sac.CSSException. 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: CssParser.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void startSelector( SelectorList selectors ) throws CSSException
{
	// Create the style rule and add it to the rule list

	StyleRule sr = new StyleRule( selectors );
	if ( !nodeStack.empty( ) )
	{
		( (StyleSheet) nodeStack.peek( ) ).add( sr );
	}

	// Create the style declaration
	StyleDeclaration decl = new StyleDeclaration( );
	sr.setStyle( decl );
	nodeStack.push( sr );
	nodeStack.push( decl );
}
 
Example #2
Source File: CSSDocumentHandler.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void property(String name, LexicalUnit value, boolean arg2) throws CSSException {
	if (currentStyle != null) {
		if ("color".equals(name)) {
			currentStyle.setColor(createRGB(value));
		} else if ("background-color".equals(name)) {
			currentStyle.setBackgroundColor(createRGB(value));
		} else if ("font-weight".equals(name)) {
			currentStyle.setBold(value.getStringValue().toUpperCase().contains("BOLD"));
		} else if ("font-style".equals(name)) {
			currentStyle.setItalic(value.getStringValue().toUpperCase().contains("ITALIC"));
		}
		if ("text-decoration".equals(name)) {
			String decoration = value.getStringValue().toUpperCase();
			if (decoration.contains("UNDERLINE")) {
				currentStyle.setUnderline(true);
			}
			if (decoration.contains("LINE-THROUGH")) {
				currentStyle.setStrikeThrough(true);
			}
		}
	}
}
 
Example #3
Source File: CssParser.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void startDocument( InputSource source ) throws CSSException
{
	if ( nodeStack.empty( ) )
	{
		StyleSheet ss = new StyleSheet( );

		nodeStack.push( ss );
	}
	else
	{
		// Error
	}
}
 
Example #4
Source File: FixNamespaceConditionFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public AttributeCondition createBeginHyphenAttributeCondition( final String localName,
                                                               final String namespaceURI,
                                                               final boolean specified,
                                                               final String value )
  throws CSSException {
  if ( namespaceURI != null ) {
    return parent.createBeginHyphenAttributeCondition
      ( localName, namespaceURI, specified, value );
  } else {
    final String[] ns = StyleSheetParserUtil.parseNamespaceIdent( localName );
    return parent.createBeginHyphenAttributeCondition( ns[ 1 ], ns[ 0 ], specified, value );
  }
}
 
Example #5
Source File: Parser.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String parseNamespaceToken( InputSource source )
  throws CSSException, IOException {
  this.source = source;
  ReInit( getCharStreamWithLurk( source ) );

  if ( selectorFactory == null ) {
    selectorFactory = new SelectorFactoryImpl();
  }
  if ( conditionFactory == null ) {
    conditionFactory = new ConditionFactoryImpl();
  }
  return _parseNamespaceToken();
}
 
Example #6
Source File: ConditionFactoryImpl.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a "one of" attribute condition
 *
 * @param localName    the localName of the attribute
 * @param namespaceURI the namespace URI of the attribute
 * @param specified    <code>true</code> if the attribute must be specified in the document.
 * @param value        the value of this attribute.
 * @return A "one of" attribute condition
 * @throws CSSException if this exception is not supported.
 */
public AttributeCondition createOneOfAttributeCondition( String localName,
                                                         String namespaceURI,
                                                         boolean specified,
                                                         String value )
  throws CSSException {
  if ( ( namespaceURI != null ) || specified ) {
    throw new CSSException( CSSException.SAC_NOT_SUPPORTED_ERR );
  } else {
    return new OneOfAttributeConditionImpl( localName, value );
  }
}
 
Example #7
Source File: CssErrorHandler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void warning( CSSParseException exception ) throws CSSException
{
	StringBuffer sb = new StringBuffer( );
	if ( !StringUtil.isBlank( exception.getURI( ) ) )
		sb.append( exception.getURI( ) ).append( " " );; //$NON-NLS-1$
	sb.append( "[" ).append( //$NON-NLS-1$
			exception.getLineNumber( ) ).append( ":" ).append( //$NON-NLS-1$
			exception.getColumnNumber( ) ).append( "] " ).append( //$NON-NLS-1$
			exception.getMessage( ) );
	System.err.println( sb.toString( ) );
	warnings.add( sb.toString( ) );
}
 
Example #8
Source File: CssErrorHandler.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void error( CSSParseException exception ) throws CSSException
{
	StringBuffer sb = new StringBuffer( );
	if ( !StringUtil.isBlank( exception.getURI( ) ) )
		sb.append( exception.getURI( ) ).append( " " );; //$NON-NLS-1$
	sb.append( "[" ).append( //$NON-NLS-1$
			exception.getLineNumber( ) ).append( ":" ).append( //$NON-NLS-1$
			exception.getColumnNumber( ) ).append( "] " ).append( //$NON-NLS-1$
			exception.getMessage( ) );
	System.err.println( sb.toString( ) );
	errors.add( sb.toString( ) );
}
 
Example #9
Source File: Parser.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method parses only one rule (style rule or at-rule, except @charset).
 *
 * @param source the source of the rule.
 * @throws IOException  the source can't be parsed.
 * @throws CSSException the source is not CSS valid.
 */
public void parseRule( InputSource source )
  throws CSSException, IOException {
  this.source = source;
  ReInit( getCharStreamWithLurk( source ) );

  if ( selectorFactory == null ) {
    selectorFactory = new SelectorFactoryImpl();
  }
  if ( conditionFactory == null ) {
    conditionFactory = new ConditionFactoryImpl();
  }
  _parseRule();
}
 
Example #10
Source File: Parser.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Main parse methods
 *
 * @param source the source of the style sheet.
 * @throws IOException  the source can't be parsed.
 * @throws CSSException the source is not CSS valid.
 */
public void parseStyleSheet( InputSource source )
  throws CSSException, IOException {
  this.source = source;
  ReInit( getCharStreamWithLurk( source ) );
  if ( selectorFactory == null ) {
    selectorFactory = new SelectorFactoryImpl();
  }
  if ( conditionFactory == null ) {
    conditionFactory = new ConditionFactoryImpl();
  }

  parserUnit();
}
 
Example #11
Source File: CssParser.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void endSelector( SelectorList selectors ) throws CSSException
{

	// Pop both the style declaration and the style rule nodes
	nodeStack.pop( );
	root = nodeStack.pop( );
}
 
Example #12
Source File: SelectorFactoryImpl.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a pseudo element selector.
 *
 * @param pseudoName the pseudo element name. <code>NULL</code> if this element selector can match any pseudo
 *                   element.</p>
 * @return the element selector
 * @throws CSSException If this selector is not supported.
 */
public ElementSelector createPseudoElementSelector( String namespaceURI,
                                                    String pseudoName )
  throws CSSException {
  if ( namespaceURI != null ) {
    throw new CSSException( CSSException.SAC_NOT_SUPPORTED_ERR );
  } else {
    return new PseudoElementSelectorImpl( pseudoName );
  }
}
 
Example #13
Source File: StyleSheetHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Receive notification of a import statement in the style sheet.
 *
 * @param uri                 The URI of the imported style sheet.
 * @param media               The intended destination media for style information.
 * @param defaultNamespaceURI The default namespace URI for the imported style sheet.
 * @throws CSSException Any CSS exception, possibly wrapping another exception.
 */
public void importStyle( String uri,
                         SACMediaList media,
                         String defaultNamespaceURI )
  throws CSSException {
  //  instantiate a new parser and parse the stylesheet.
  final ResourceManager manager = getResourceManager();
  if ( manager == null ) {
    // there is no source set, so we have no resource manager, and thus
    // we do no parsing.
    //
    // This should only be the case if we parse style-values; in that case
    // include-statement are not supported anyway.
    return;
  }
  try {
    CSSParserContext.getContext().setDefaultNamespace( defaultNamespaceURI );
    final ResourceKey key;
    if ( source == null ) {
      key = manager.createKey( uri );
    } else {
      key = manager.deriveKey( source, uri );
    }

    final Resource res = manager.create( key, source, StyleSheet.class );
    if ( res == null ) {
      return;
    }
    final StyleSheet styleSheet = (StyleSheet) res.getResource();
    this.styleSheet.addStyleSheet( styleSheet );
  } catch ( ResourceException e ) {
    // ignore ..
  } finally {
    CSSParserContext.getContext().setStyleKeyRegistry( styleKeyRegistry );
    CSSParserContext.getContext().setSource( getSource() );
    CSSParserContext.getContext().setNamespaces( namespaces );
    CSSParserContext.getContext().setDefaultNamespace( defaultNamespace );
  }
}
 
Example #14
Source File: FixNamespaceConditionFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Condition createOnlyTypeCondition() throws CSSException {
  return parent.createOnlyTypeCondition();
}
 
Example #15
Source File: CssParser.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void importStyle( String uri, SACMediaList media,
		String defaultNamespaceURI ) throws CSSException
{
	unsupportedRule( uri );
}
 
Example #16
Source File: FixNamespaceSelectorFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public CharacterDataSelector createCommentSelector( final String data ) throws CSSException {
  return parent.createCommentSelector( data );
}
 
Example #17
Source File: FixNamespaceConditionFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public PositionalCondition createPositionalCondition( final int position, final boolean typeNode, final boolean type )
  throws CSSException {
  return parent.createPositionalCondition( position, typeNode, type );
}
 
Example #18
Source File: FixNamespaceSelectorFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ConditionalSelector createConditionalSelector( final SimpleSelector selector, final Condition condition )
  throws CSSException {
  return parent.createConditionalSelector( selector, condition );
}
 
Example #19
Source File: FixNamespaceConditionFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Condition createOnlyTypeCondition()
  throws CSSException {
  return parent.createOnlyTypeCondition();
}
 
Example #20
Source File: CssParser.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void startPage( String name, String pseudo_page )
		throws CSSException
{
	unsupportedRule( name + pseudo_page );
}
 
Example #21
Source File: FixNamespaceSelectorFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public CharacterDataSelector createCDataSectionSelector( final String data )
  throws CSSException {
  return parent.createCDataSectionSelector( data );
}
 
Example #22
Source File: FixNamespaceConditionFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public NegativeCondition createNegativeCondition( final Condition condition ) throws CSSException {
  return parent.createNegativeCondition( condition );
}
 
Example #23
Source File: CSSEngine.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <b>SAC</b>: Implements {@link
 * DocumentHandler#startDocument(InputSource)}.
 */
public void startDocument( InputSource source ) throws CSSException
{
	throw new InternalError( );
}
 
Example #24
Source File: FixNamespaceConditionFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public NegativeCondition createNegativeCondition( final Condition condition )
  throws CSSException {
  return parent.createNegativeCondition( condition );
}
 
Example #25
Source File: CSSConditionFactory.java    From tm4e with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public AttributeCondition createClassCondition(String namespaceURI, String value) throws CSSException {
	return new CSSClassCondition(null, "class", value);
}
 
Example #26
Source File: FixNamespaceConditionFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public PositionalCondition createPositionalCondition( final int position,
                                                      final boolean typeNode,
                                                      final boolean type )
  throws CSSException {
  return parent.createPositionalCondition( position, typeNode, type );
}
 
Example #27
Source File: FixNamespaceSelectorFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public DescendantSelector createChildSelector( final Selector parent, final SimpleSelector child )
  throws CSSException {
  return this.parent.createChildSelector( parent, child );
}
 
Example #28
Source File: CssParser.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void startFontFace( ) throws CSSException
{
	unsupportedRule( null );
}
 
Example #29
Source File: FixNamespaceConditionFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public AttributeCondition createClassCondition( final String namespaceURI, final String value ) throws CSSException {
  return parent.createClassCondition( namespaceURI, value );
}
 
Example #30
Source File: CssParser.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void startMedia( SACMediaList media ) throws CSSException
{
	unsupportedRule( media.toString( ) );
}