Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/phax/ph-css
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Oct 21, 2016
2 parents 8b9d7bb + d0b73a4 commit 0a0a96e
Show file tree
Hide file tree
Showing 15 changed files with 538 additions and 130 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ ph-css and ph-csscompress-maven-plugin are both licensed under the **Apache 2.0
## News and noteworthy

* v5.0.2 - 2016-xx-yy
* Made tab size configurable (issue #29)
* Improved media expressions (issue #30)
* Made tab size configurable (issue #29)
* Improved media expressions (issue #30)
* Allowing to disable consistency checks in class `CSSValue`
* Made CSS interpretation warnings customizable with class `ICSSInterpretErrorHandler` (issue #33)
* v5.0.1 - 2016-08-17
* Using "modern java template" for JavaCC parser - results in quicker execution
* Enhancement issue #27
* Intergated `ph-csscompress-maven-plugin` into this repository
* Integrated `ph-csscompress-maven-plugin` into this repository
* Bug fix wrong OutputStream (issue #28)
* v5.0.0 - 2016-06-12
* Using JDK8 as the basis
* removed explicit grammar for CSS 2.1 (issue #20)
* Added browser compliant error handler
* v4.1.6 - 2016-xx-yy
* Made CSS interpretation warnings customizable with class `ICSSInterpretErrorHandler` (issue #33)
* v4.1.5 - 2016-09-16
* Improved media expressions (issue #30)
* Integrated ph-csscompress-maven-plugin into this project (compatibility to 5.x)
Expand Down
6 changes: 4 additions & 2 deletions ph-css/src/main/java/com/helger/css/ECSSVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
public enum ECSSVersion implements IHasVersion
{
// Sort fields according to the version!
@DevelopersNote ("No CSS parser is available for 1.0!") CSS10(new Version (1, 0)),
@DevelopersNote ("Up to version 4.x of ph-css a special CSS 2.1 parser was available") CSS21(new Version (2, 1)),
@DevelopersNote ("No CSS parser is available for 1.0!")
CSS10(new Version (1, 0)),
@DevelopersNote ("Up to version 4.x of ph-css a special CSS 2.1 parser was available. Now it is the same as CSS 3.0")
CSS21(new Version (2, 1)),
CSS30 (new Version (3, 0));

/** Latest version is CSS 3.0 */
Expand Down
58 changes: 56 additions & 2 deletions ph-css/src/main/java/com/helger/css/handler/CSSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
package com.helger.css.handler;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.Immutable;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.PresentForCodeCoverage;
import com.helger.commons.concurrent.SimpleReadWriteLock;
import com.helger.css.ECSSVersion;
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;
import com.helger.css.reader.errorhandler.LoggingCSSInterpretErrorHandler;

/**
* This class is the entry point for converting AST nodes from the parser to
Expand All @@ -35,6 +40,11 @@
@Immutable
public final class CSSHandler
{
private static final SimpleReadWriteLock s_aRWLock = new SimpleReadWriteLock ();

@GuardedBy ("s_aRWLock")
private static ICSSInterpretErrorHandler s_aDefaultInterpretErrorHandler = new LoggingCSSInterpretErrorHandler ();

@PresentForCodeCoverage
private static final CSSHandler s_aInstance = new CSSHandler ();

Expand All @@ -51,15 +61,37 @@ private CSSHandler ()
* @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 5.0.2
*/
@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);
}

/**
Expand All @@ -72,14 +104,36 @@ public static CascadingStyleSheet readCascadingStyleSheetFromNode (@Nonnull fina
* @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 5.0.2
*/
@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 0a0a96e

Please sign in to comment.