Index: plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxResourceSource.java =================================================================== --- plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxResourceSource.java (revision 24694) +++ plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxResourceSource.java (working copy) @@ -26,7 +26,7 @@ import org.apache.commons.io.IOUtils; /** - * JAR resource source for Skin Extensions + * JAR resource source for Skin Extensions. * * @version $Id$ * @since 1.7M2 Index: plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxCompressor.java =================================================================== --- plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxCompressor.java (revision 24694) +++ plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxCompressor.java (working copy) @@ -28,5 +28,11 @@ */ public interface SxCompressor { + /** + * Compresses the given script, making it smaller and less readable but perform the same. + * + * @param source The uncompressed script + * @return A compressed version of the input source + */ String compress(String source); -} \ No newline at end of file +} Index: plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/JsExtension.java =================================================================== --- plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/JsExtension.java (revision 24694) +++ plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/JsExtension.java (working copy) @@ -70,45 +70,75 @@ */ public SxCompressor getCompressor() { - return new SxCompressor() + return (SxCompressor) new JsCompressor(); + } + + /** + * The compressor which is returned by getCompressor. + */ + private class JsCompressor implements SxCompressor + { + /** + * {@inheritDoc} + * + * @see SxCompressor#compress() + */ + public String compress(String source) { - public String compress(String source) + try { + ErrorReporter reporter = (ErrorReporter) this.new CustomErrorReporter(); + JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(source), reporter); + StringWriter out = new StringWriter(); + compressor.compress(out, -1, true, false, false, false); + return out.toString(); + } catch (IOException ex) { + LOG.info("Failed to write the compressed output: " + ex.getMessage()); + } catch (EvaluatorException ex) { + LOG.info("Failed to parse the JS extension: " + ex.getMessage()); + } catch (Exception ex) { + LOG.warn("Failed to compress JS extension: " + ex.getMessage()); + } + return source; + } + + /** + * A Javascript error reporter which logs errors with log4j. + */ + private class CustomErrorReporter implements ErrorReporter + { + /** + * {@inheritDoc} + * + * @see ErrorReporter#error(String, String, int, String, int) + */ + public void error(String message, String filename, int lineNumber, String context, int column) { - try { - ErrorReporter reporter = new ErrorReporter() - { - public void error(String message, String filename, int lineNumber, String context, int column) - { - LOG.warn(MessageFormat.format("Error at line {2}, column {3}: {0}. Caused by: [{1}]", - message, context, lineNumber, column)); - } + LOG.warn(MessageFormat.format("Error at line {2}, column {3}: {0}. Caused by: [{1}]", + message, context, lineNumber, column)); + } - public EvaluatorException runtimeError(String message, String filename, int lineNumber, - String context, int column) - { - LOG.error(MessageFormat.format("Runtime error minimizing JSX object: {0}", message)); - return null; - } + /** + * {@inheritDoc} + * + * @see ErrorReporter#runtimeError(String, String, int, String, int) + */ + public EvaluatorException runtimeError(String message, String filename, int lineNumber, + String context, int column) + { + LOG.error(MessageFormat.format("Runtime error minimizing JSX object: {0}", message)); + return null; + } - public void warning(String message, String filename, int lineNumber, String context, int column) - { - LOG.info(MessageFormat.format("Warning at line {2}, column {3}: {0}. Caused by: [{1}]", - message, context, lineNumber, column)); - } - }; - JavaScriptCompressor compressor = new JavaScriptCompressor(new StringReader(source), reporter); - StringWriter out = new StringWriter(); - compressor.compress(out, -1, true, false, false, false); - return out.toString(); - } catch (IOException ex) { - LOG.info("Failed to write the compressed output: " + ex.getMessage()); - } catch (EvaluatorException ex) { - LOG.info("Failed to parse the JS extension: " + ex.getMessage()); - } catch (Exception ex) { - LOG.warn("Failed to compress JS extension: " + ex.getMessage()); - } - return source; + /** + * {@inheritDoc} + * + * @see ErrorReporter#warning(String, String, int, String, int) + */ + public void warning(String message, String filename, int lineNumber, String context, int column) + { + LOG.info(MessageFormat.format("Warning at line {2}, column {3}: {0}. Caused by: [{1}]", + message, context, lineNumber, column)); } - }; + } } } Index: plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxDocumentSource.java =================================================================== --- plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxDocumentSource.java (revision 24694) +++ plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxDocumentSource.java (working copy) @@ -37,20 +37,32 @@ */ public class SxDocumentSource implements SxSource { + /** The name of the property in the script extension object which contains the script content. */ + private static final String CODE_PROPERTY_NAME = "code"; + + /** The name of the property in the script extension object which tells us if the code should be parsed. */ + private static final String PARSE_CODE_PROPERTY_NAME = "parse"; + + /** The name of the property in the script extension object which contains the cache policy. */ + private static final String CACHE_POLICY_PROPERTY_NAME = "cache"; + + /** Logging helper. */ + private static final Log LOG = LogFactory.getLog(SxDocumentSource.class); + + /** The document to get the script from. */ private XWikiDocument document; + /** The XWikiContext for getting the document containing the script. */ private XWikiContext context; + /** The type of Extension for getting the right kind of object from the document. */ private Extension extension; - /** Logging helper. */ - private static final Log LOG = LogFactory.getLog(SxDocumentSource.class); - /** * Constructor for this source. * - * @param context - * @param type + * @param context The XWikiContext + * @param extension The Extension type */ public SxDocumentSource(XWikiContext context, Extension extension) { @@ -76,13 +88,15 @@ try { CachePolicy cache = CachePolicy.valueOf(StringUtils.upperCase(StringUtils.defaultIfEmpty(sxObj - .getStringValue("cache"), "LONG"))); + .getStringValue(CACHE_POLICY_PROPERTY_NAME), "LONG"))); if (cache.compareTo(finalCache) > 0) { finalCache = cache; } } catch (Exception ex) { - LOG.warn(String.format("SX object [%s#%s] has an invalid cache policy: [%s]", this.document - .getFullName(), sxObj.getStringValue("name"), sxObj.getStringValue("cache"))); + LOG.warn(String.format("SX object [%s#%s] has an invalid cache policy: [%s]", + this.document.getFullName(), + sxObj.getStringValue("name"), + sxObj.getStringValue(CACHE_POLICY_PROPERTY_NAME))); } } } @@ -103,8 +117,8 @@ if (sxObj == null) { continue; } - String sxContent = sxObj.getLargeStringValue("code"); - int parse = sxObj.getIntValue("parse"); + String sxContent = sxObj.getLargeStringValue(CODE_PROPERTY_NAME); + int parse = sxObj.getIntValue(PARSE_CODE_PROPERTY_NAME); if (parse == 1) { sxContent = this.context.getWiki().getRenderingEngine().interpretText(sxContent, this.document, Index: plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxSource.java =================================================================== --- plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxSource.java (revision 24694) +++ plugins/skinx/src/main/java/com/xpn/xwiki/web/sx/SxSource.java (working copy) @@ -29,11 +29,31 @@ public interface SxSource { /** - * Cache policies available for extensions + * Cache policies available for extensions. */ public enum CachePolicy { - LONG, SHORT, DEFAULT, FORBID + /** + * Cache for a long time. + * @see AbstractSxAction#LONG_CACHE_DURATION + */ + LONG, + + /** + * Cache for a short time. + * @see AbstractSxAction#SHORT_CACHE_DURATION + */ + SHORT, + + /** + * Cache for the proxy/browser's default time, It will be held in the + * server cache an amount of time specified in AbstractSxAction. + * @see AbstractSxAction.DEFAULT_CACHE_DURATION + */ + DEFAULT, + + /** Do not cache at all in server cache or in proxy/browser. */ + FORBID } /** Index: plugins/skinx/pom.xml =================================================================== --- plugins/skinx/pom.xml (revision 24694) +++ plugins/skinx/pom.xml (working copy) @@ -69,15 +69,6 @@ org.apache.maven.plugins maven-checkstyle-plugin - - - **/web/sx/JsExtension.java, - **/web/sx/SxSource.java, - **/web/sx/SxDocumentSource.java, - **/web/sx/SxResourceSource.java, - **/web/sx/SxCompressor.java, - -