jvelociter (SVN) wrote:
Author: jvelociter
Date: 2008-11-09 20:00:37 +0100 (Sun, 09 Nov 2008)
New Revision: 14062
Added:
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/AbstractSxAction.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/CssExtension.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/Extension.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/JsExtension.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/SxCompressor.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/SxDocumentSource.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/SxResourceSource.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/sx/SxSource.java
platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/CssResourceSkinExtensionPlugin.java
platform/xwiki-plugins/trunk/skinx/src/main/java/com/xpn/xwiki/plugin/skinx/JsResourceSkinExtensionPlugin.java
Modified:
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/JsxAction.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SsxAction.java
Log:
XSKINX-12 Ability to load extension files from JAR resources
You forgot to modify this one to support resource extensions:
Modified:
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SsxAction.java
===================================================================
---
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SsxAction.java 2008-11-08
18:00:54 UTC (rev 14061)
+++
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SsxAction.java 2008-11-09
19:00:37 UTC (rev 14062)
@@ -20,23 +20,20 @@
*/
package com.xpn.xwiki.web;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.Date;
+import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.lang.BooleanUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.doc.XWikiDocument;
-import com.xpn.xwiki.objects.BaseObject;
-import com.yahoo.platform.yui.compressor.CssCompressor;
+import com.xpn.xwiki.web.sx.AbstractSxAction;
+import com.xpn.xwiki.web.sx.CssExtension;
+import com.xpn.xwiki.web.sx.Extension;
+import com.xpn.xwiki.web.sx.SxDocumentSource;
+import com.xpn.xwiki.web.sx.SxSource;
+
/**
* <p>
* Action for serving css skin extensions.
@@ -45,22 +42,11 @@
* @version $Id$
* @since 1.4M2
*/
-public class SsxAction extends XWikiAction
+public class SsxAction extends AbstractSxAction
{
- enum CachePolicies
- {
- LONG, SHORT, DEFAULT, FORBID
- }
-
- protected static final long LONG_CACHE_DURATION = 30 * 24 * 3600 * 1000L;
-
- protected static final long SHORT_CACHE_DURATION = 1 * 24 * 3600 * 1000L;
-
/** Logging helper. */
private static final Log LOG = LogFactory.getLog(SsxAction.class);
-
- public static final String SSX_CLASS_NAME = "XWiki.StyleSheetExtension";
-
+
/**
* {@inheritDoc}
*
@@ -69,77 +55,25 @@
@Override
public String render(XWikiContext context) throws XWikiException
{
- XWiki xwiki = context.getWiki();
- XWikiRequest request = context.getRequest();
- XWikiResponse response = context.getResponse();
- XWikiDocument doc = context.getDoc();
-
- if (doc.isNew()) {
- response.setStatus(404);
+ if (context.getDoc().isNew()) {
+ context.getResponse().setStatus(HttpServletResponse.SC_NOT_FOUND);
return "docdoesnotexist";
}
- CachePolicies finalCache = CachePolicies.LONG;
- StringBuilder resultBuilder = new StringBuilder();
+ SxSource sxSource;
- if (doc.getObjects(SSX_CLASS_NAME) != null) {
- for (BaseObject sxObj : doc.getObjects(SSX_CLASS_NAME)) {
- String sxContent = sxObj.getLargeStringValue("code");
- int parse = sxObj.getIntValue("parse");
- try {
- CachePolicies cache =
-
CachePolicies.valueOf(StringUtils.upperCase(StringUtils.defaultIfEmpty(sxObj
- .getStringValue("cache"), "LONG")));
- if (cache.compareTo(finalCache) > 0) {
- finalCache = cache;
- }
- } catch (Exception ex) {
- LOG.warn(String.format("JSX object [%s#%s] has an invalid cache
policy: [%s]", doc.getFullName(),
- sxObj.getStringValue("name"),
sxObj.getStringValue("cache")));
- }
+ Extension sxType = new CssExtension();
- if (parse == 1) {
- sxContent = xwiki.getRenderingEngine().interpretText(sxContent, doc,
context);
- }
- // Also add a newline, in case the different object contents don't
end with a blank
- // line, and could cause syntax errors when concatenated.
- resultBuilder.append(sxContent + "\n");
- }
- }
+ sxSource = new SxDocumentSource(context, sxType);
- String result = resultBuilder.toString();
-
- response.setContentType("text/css; charset=UTF-8");
- response.setDateHeader("Last-Modified", doc.getDate().getTime());
- if (finalCache != CachePolicies.FORBID) {
- response.setHeader("Cache-Control", "public");
- }
-
- if (finalCache == CachePolicies.LONG) {
- // Cache for one month (30 days)
- response.setDateHeader("Expires", (new Date()).getTime() +
LONG_CACHE_DURATION);
- } else if (finalCache == CachePolicies.SHORT) {
- // Cache for one day
- response.setDateHeader("Expires", (new Date()).getTime() +
SHORT_CACHE_DURATION);
- } else if (finalCache == CachePolicies.FORBID) {
- response.setHeader("Cache-Control", "no-cache, no-store,
must-revalidate");
- }
- if
(BooleanUtils.toBoolean(StringUtils.defaultIfEmpty(request.get("minify"),
"true"))) {
- try {
- CssCompressor compressor = new CssCompressor(new StringReader(result));
- StringWriter out = new StringWriter();
- compressor.compress(out, -1);
- result = out.toString();
- } catch (IOException ex) {
- LOG.warn(String.format("Exception compressing the SSX code for
[%s]", doc.getFullName()), ex);
- }
- }
- try {
- response.setContentLength(result.getBytes("UTF-8").length);
- response.getOutputStream().write(result.getBytes("UTF-8"));
- } catch (IOException ex) {
- LOG.warn("Failed to send SSX content: " + ex.getMessage());
- }
+ super.renderExtension(sxSource, sxType, context);
return null;
}
--
Sergiu Dumitriu
http://purl.org/net/sergiu/