Skip to content

Commit

Permalink
Backport for #33
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Oct 20, 2016
1 parent 88704a7 commit a4078bf
Show file tree
Hide file tree
Showing 11 changed files with 481 additions and 110 deletions.
56 changes: 51 additions & 5 deletions ph-css/src/main/java/com/helger/css/handler/CSSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import com.helger.css.decl.CSSDeclarationList;
import com.helger.css.decl.CascadingStyleSheet;
import com.helger.css.parser.CSSNode;
import com.helger.css.reader.CSSReader;
import com.helger.css.reader.errorhandler.ICSSInterpretErrorHandler;

/**
* This class is the entry point for converting AST nodes from the parser to
* domain objects. This class is only used internally.
*
*
* @author Philip Helger
*/
@Immutable
Expand All @@ -44,43 +46,87 @@ private CSSHandler ()

/**
* Create a {@link CascadingStyleSheet} object from a parsed object.
*
*
* @param eVersion
* The CSS version to use. May not be <code>null</code>.
* @param aNode
* The parsed CSS object to read. May not be <code>null</code>.
* @return Never <code>null</code>.
*/
@Nonnull
@Deprecated
public static CascadingStyleSheet readCascadingStyleSheetFromNode (@Nonnull final ECSSVersion eVersion,
@Nonnull final CSSNode aNode)
{
return readCascadingStyleSheetFromNode (eVersion, aNode, CSSReader.getDefaultInterpretErrorHandler ());
}

/**
* Create a {@link CascadingStyleSheet} object from a parsed object.
*
* @param eVersion
* The CSS version to use. May not be <code>null</code>.
* @param aNode
* The parsed CSS object to read. May not be <code>null</code>.
* @param aErrorHandler
* The error handler to be used. May not be <code>null</code>.
* @return Never <code>null</code>.
* @since 4.1.6
*/
@Nonnull
public static CascadingStyleSheet readCascadingStyleSheetFromNode (@Nonnull final ECSSVersion eVersion,
@Nonnull final CSSNode aNode,
@Nonnull final ICSSInterpretErrorHandler aErrorHandler)
{
ValueEnforcer.notNull (eVersion, "Version");
ValueEnforcer.notNull (aNode, "Node");
if (!ECSSNodeType.ROOT.isNode (aNode, eVersion))
throw new CSSHandlingException (aNode, "Passed node is not a root node!");
ValueEnforcer.notNull (aErrorHandler, "ErrorHandler");

return new CSSNodeToDomainObject (eVersion).createCascadingStyleSheetFromNode (aNode);
return new CSSNodeToDomainObject (eVersion, aErrorHandler).createCascadingStyleSheetFromNode (aNode);
}

/**
* Create a {@link CSSDeclarationList} object from a parsed object.
*
*
* @param eVersion
* The CSS version to use. May not be <code>null</code>.
* @param aNode
* The parsed CSS object to read. May not be <code>null</code>.
* @return Never <code>null</code>.
*/
@Nonnull
@Deprecated
public static CSSDeclarationList readDeclarationListFromNode (@Nonnull final ECSSVersion eVersion,
@Nonnull final CSSNode aNode)
{
return readDeclarationListFromNode (eVersion, aNode, CSSReader.getDefaultInterpretErrorHandler ());
}

/**
* Create a {@link CSSDeclarationList} object from a parsed object.
*
* @param eVersion
* The CSS version to use. May not be <code>null</code>.
* @param aNode
* The parsed CSS object to read. May not be <code>null</code>.
* @param aErrorHandler
* The error handler to be used. May not be <code>null</code>.
* @return Never <code>null</code>.
* @since 4.1.6
*/
@Nonnull
public static CSSDeclarationList readDeclarationListFromNode (@Nonnull final ECSSVersion eVersion,
@Nonnull final CSSNode aNode,
@Nonnull final ICSSInterpretErrorHandler aErrorHandler)
{
ValueEnforcer.notNull (eVersion, "Version");
ValueEnforcer.notNull (aNode, "Node");
if (!ECSSNodeType.STYLEDECLARATIONLIST.isNode (aNode, eVersion))
throw new CSSHandlingException (aNode, "Passed node is not a style declaration node!");
ValueEnforcer.notNull (aErrorHandler, "ErrorHandler");

return new CSSNodeToDomainObject (eVersion).createDeclarationListFromNode (aNode);
return new CSSNodeToDomainObject (eVersion, aErrorHandler).createDeclarationListFromNode (aNode);
}
}
Loading

0 comments on commit a4078bf

Please sign in to comment.