Author: nbelaevski
Date: 2009-07-24 05:02:57 -0400 (Fri, 24 Jul 2009)
New Revision: 14999
Removed:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/resource/TemplateCSSRenderer.java
Modified:
root/framework/trunk/api/src/main/java/org/ajax4jsf/context/AjaxContext.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/resource/InternetResourceService.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
root/framework/trunk/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
Log:
Moving component APIs into ui-sandbox
Legacy resources API removal
Modified: root/framework/trunk/api/src/main/java/org/ajax4jsf/context/AjaxContext.java
===================================================================
---
root/framework/trunk/api/src/main/java/org/ajax4jsf/context/AjaxContext.java 2009-07-24
08:56:25 UTC (rev 14998)
+++
root/framework/trunk/api/src/main/java/org/ajax4jsf/context/AjaxContext.java 2009-07-24
09:02:57 UTC (rev 14999)
@@ -43,8 +43,6 @@
+ AjaxContext.class.getName();
private static final String DEFAULT_CONTEXT_CLASS =
"org.ajax4jsf.context.AjaxContextImpl";
- public static final String HEAD_EVENTS_PARAMETER =
"org.ajax4jsf.framework.HEAD_EVENTS_LIST";
-
/**
* Key for keep request state information in request-scope attributes.
*/
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java 2009-07-24
08:56:25 UTC (rev 14998)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java 2009-07-24
09:02:57 UTC (rev 14999)
@@ -52,8 +52,6 @@
*/
public class AjaxViewHandler extends ViewHandlerWrapper {
- public static final String RESOURCES_PROCESSED =
"org.ajax4jsf.framework.HEADER_PROCESSED";
-
public static final String STATE_MARKER_KEY = "org.ajax4jsf.view.state";
public static final String SERIALIZED_STATE_KEY =
"org.ajax4jsf.view.serializedstate";
@@ -184,21 +182,6 @@
FilterServletResponseWrapper filterServletResponseWrapper =
(FilterServletResponseWrapper)
requestMap.get(BaseFilter.RESPONSE_WRAPPER_ATTRIBUTE);
if (null != filterServletResponseWrapper) {
- if (!filterServletResponseWrapper.isError()) {
- if (!Boolean.TRUE.equals(requestMap.get(RESOURCES_PROCESSED))) {
-
- ViewResources viewResources = new ViewResources();
-
- viewResources.initialize(context);
- viewResources.processHeadResources(context);
-
- requestMap.put(AjaxContext.HEAD_EVENTS_PARAMETER, viewResources.getHeadEvents());
-
- // Mark as processed.
- requestMap.put(RESOURCES_PROCESSED, Boolean.TRUE);
- }
- }
-
// Save viewId for a parser selection
requestMap.put(AjaxViewHandler.VIEW_ID_KEY, context.getViewRoot().getViewId());
}
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2009-07-24
08:56:25 UTC (rev 14998)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2009-07-24
09:02:57 UTC (rev 14999)
@@ -21,614 +21,573 @@
package org.ajax4jsf.context;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import javax.el.ExpressionFactory;
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.component.UIComponent;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.RenderKit;
-import javax.faces.render.RenderKitFactory;
-import javax.faces.render.Renderer;
-
-import org.ajax4jsf.component.QueueRegistry;
-import org.ajax4jsf.io.SAXResponseWriter;
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.ajax4jsf.resource.InternetResource;
-import org.ajax4jsf.resource.InternetResourceBase;
-import org.ajax4jsf.resource.InternetResourceBuilder;
-import org.ajax4jsf.resource.ResourceNotFoundException;
-import org.ajax4jsf.resource.ResourceRenderer;
-import org.ajax4jsf.resource.URIInternetResource;
-import org.ajax4jsf.util.ELUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.richfaces.skin.Skin;
-import org.richfaces.skin.SkinFactory;
-import org.richfaces.skin.SkinNotFoundException;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
/**
* @author Nick Belaevski
*/
//TODO remove -
https://jira.jboss.org/jira/browse/RFPL-42
public class ViewResources {
- private static final String INIT_PARAMETER_PREFIX = "_init_parameter_";
- private static final Object NULL = new Object();
-
- private String scriptStrategy;
-
- private String styleStrategy;
-
- private boolean useStdControlsSkinning;
-
- private boolean useStdControlsSkinningClasses;
-
- private HeadResponseWriter componentWriter;
-
- private HeadResponseWriter userWriter;
-
- private RenderKit renderKit;
-
- private Node[] headNodes = null;
-
- private static final String EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY =
ViewResources.class.getName() + "EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY";
-
- private static final InternetResource EXTENDED_SKINNING_ON_RESOURCE = new
InternetResourceBase() {
-
- private final String RESOURCE_KEY = this.getClass().getName();
-
- @Override
- public void encode(FacesContext context, Object data)
- throws IOException {
-
- encode(context, data, Collections.EMPTY_MAP);
- }
-
- @Override
- public void encode(FacesContext context, Object data,
- Map<String, Object> attributes) throws IOException {
-
- Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
- if (requestMap.get(RESOURCE_KEY) == null) {
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement(HTML.SCRIPT_ELEM, null);
-
- if (!attributes.containsKey(HTML.TYPE_ATTR)) {
- writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
- }
-
- for (Map.Entry<String, Object> entry : attributes.entrySet()) {
- writer.writeAttribute(entry.getKey(), entry.getValue(), null);
- }
-
- writer.writeText("window.RICH_FACES_EXTENDED_SKINNING_ON=true;", null);
-
- writer.endElement(HTML.SCRIPT_ELEM);
-
- requestMap.put(RESOURCE_KEY, Boolean.TRUE);
- }
- }
- };
-
- public void setScriptStrategy(String scriptsStrategy) {
- this.scriptStrategy = scriptsStrategy;
- }
-
- public void setStyleStrategy(String stylesStrategy) {
- this.styleStrategy = stylesStrategy;
- }
-
- public void setUseStdControlsSkinning(boolean stdControlsSkinning) {
- this.useStdControlsSkinning = stdControlsSkinning;
- }
-
- public void setUseStdControlsSkinningClasses(boolean stdControlsSkinningClasses) {
- this.useStdControlsSkinningClasses = stdControlsSkinningClasses;
- }
-
- public void setExtendedSkinningAllowed(boolean extendedSkinningAllowed) {
- this.extendedSkinningAllowed = extendedSkinningAllowed;
- }
-
- private static String SCRIPT = HTML.SCRIPT_ELEM;
- private static String SCRIPT_UC = SCRIPT.toUpperCase(Locale.US);
-
- private static String SRC = HTML.src_ATTRIBUTE;
- private static String SRC_UC = SRC.toUpperCase(Locale.US);
-
- private void mergeHeadResourceNode(List<Node> nodes, Set<String>
renderedScripts, Node node) {
- boolean shouldAdd = true;
-
- String nodeName = node.getNodeName();
- if (SCRIPT.equals(nodeName) || SCRIPT_UC.equals(nodeName)) {
- if (node.getFirstChild() == null) {
- //no text content etc.
-
- NamedNodeMap attributes = node.getAttributes();
- if (attributes != null) {
- Node item = attributes.getNamedItem(SRC);
- if (item == null) {
- attributes.getNamedItem(SRC_UC);
- }
-
- if (item != null) {
- String src = item.getNodeValue();
- if (src != null) {
- if (renderedScripts.contains(src)) {
- shouldAdd = false;
- } else {
- renderedScripts.add(src);
- }
- }
- }
- }
- }
- }
-
- if (shouldAdd) {
- nodes.add(node);
- }
- }
-
- private Node[] mergeHeadResourceNodes() {
- List<Node> result = new ArrayList<Node>();
-
- Set<String> scripts = new HashSet<String>();
-
- for (Node node : componentWriter.getNodes()) {
- mergeHeadResourceNode(result, scripts, node);
- }
-
- for (Node node : userWriter.getNodes()) {
- mergeHeadResourceNode(result, scripts, node);
- }
-
- return result.toArray(new Node[result.size()]);
- }
-
- public Node[] getHeadEvents() {
- if (headNodes == null) {
- headNodes = mergeHeadResourceNodes();
- }
-
- return headNodes;
- }
-
- private static final Log log = LogFactory.getLog(ViewResources.class);
-
- //todo
-
- private static final Map<String, Object> EXTENDED_SKINNING = new
HashMap<String, Object>(1);
-
- static {
- EXTENDED_SKINNING.put(HTML.media_ATTRIBUTE, "rich-extended-skinning");
- }
-
- public static final String SKINNING_STYLES_PATH =
"/org/richfaces/renderkit/html/css/";
-
- public static final String QUEUE_SCRIPT_RESOURCE =
"org.ajax4jsf.renderkit.html.scripts.QueueScript";
-
- private boolean extendedSkinningAllowed;
-
- private boolean processScripts;
-
- private boolean processStyles;
-
- private boolean useSkinning;
-
- private InternetResourceBuilder resourceBuilder;
-
- private boolean ajaxRequest;
-
- public static final String COMPONENT_RESOURCE_LINK_CLASS = "component";
-
- public static final String USER_RESOURCE_LINK_CLASS = "user";
-
- class HeadResponseWriter extends SAXResponseWriter {
-
- public Node[] getNodes() {
- return ((ResponseWriterContentHandler) getXmlConsumer()).getNodes();
- }
-
- public HeadResponseWriter(String linkClass) {
- super(new ResponseWriterContentHandler(linkClass));
-
- }
- }
-
- private void encodeResources(FacesContext context, ResourceRenderer renderer,
Set<String> set) throws IOException {
-
- if (set != null) {
- URIInternetResource resourceImpl = new URIInternetResource();
-
- for (String uri : set) {
- resourceImpl.setUri(uri);
- renderer.encode(resourceImpl, context, null);
- }
- }
- }
-
- private boolean encodeSkinningResources(FacesContext context, InternetResourceBuilder
resourceBuilder) throws IOException, FacesException {
- String resourceSuffix = null;
-
- if (useStdControlsSkinning) {
- if (useStdControlsSkinningClasses) {
- resourceSuffix = "_both.xcss";
- } else {
- resourceSuffix = ".xcss";
- }
- } else {
- if (useStdControlsSkinningClasses) {
- resourceSuffix = "_classes.xcss";
- } else {
- //no resources
- }
- }
-
- if (resourceSuffix != null) {
- resourceBuilder.createResource(
- this,
SKINNING_STYLES_PATH.concat("basic").concat(resourceSuffix)).encode(context,
null);
-
- if (extendedSkinningAllowed) {
- resourceBuilder.createResource(
- this,
SKINNING_STYLES_PATH.concat("extended").concat(resourceSuffix)).encode(context,
null, EXTENDED_SKINNING);
- }
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Find renderer for given component.
- *
- * @param context
- * @param comp
- * @param renderKit
- * @return
- */
- private Renderer getRenderer(FacesContext context, UIComponent comp) {
-
- String rendererType = comp.getRendererType();
- if (rendererType != null) {
- return (renderKit.getRenderer(comp.getFamily(), rendererType));
- } else {
- return (null);
- }
- }
-
- public void processHeadResources(FacesContext context) throws FacesException {
-
- RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder
- .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- renderKit = rkFactory.getRenderKit(context, context
- .getViewRoot().getRenderKitId());
-
- boolean scriptsOff = false;
-
- processStyles = true;
- processScripts = true;
- useSkinning = false;
-
- ajaxRequest = AjaxContext.getCurrentInstance(context).isAjaxRequest(context);
-
- if (log.isDebugEnabled()) {
- log
- .debug("Process component tree for collect used scripts and styles");
- }
-
- String skinStyleSheetUri = null;
- String skinExtendedStyleSheetUri = null;
-
- Skin skin = null;
- try {
- skin = SkinFactory.getInstance().getSkin(context);
- // For a "NULL" skin, do not collect components stylesheets
- if ("false".equals(skin.getParameter(context,
- Skin.loadStyleSheets))) {
- processStyles = false;
- }
- // Set default style sheet for current skin.
- skinStyleSheetUri = (String) skin.getParameter(context,
- Skin.generalStyleSheet);
- // Set default style sheet for current skin.
- skinExtendedStyleSheetUri = (String) skin.getParameter(context,
- Skin.extendedStyleSheet);
- } catch (SkinNotFoundException e) {
- if (log.isWarnEnabled()) {
- log.warn("Current Skin is not found", e);
- }
- }
-
- resourceBuilder = InternetResourceBuilder.getInstance();
-
- ResponseWriter oldResponseWriter = context.getResponseWriter();
-
- componentWriter = new HeadResponseWriter("component");
- userWriter = new HeadResponseWriter("user");
-
- try {
- componentWriter.startDocument();
- userWriter.startDocument();
-
- context.setResponseWriter(componentWriter);
-
- // Check init parameters for a resources processing.
- if (null != scriptStrategy) {
- if (InternetResourceBuilder.LOAD_NONE
- .equals(scriptStrategy)) {
- scriptsOff = true;
- processScripts = false;
- } else if (InternetResourceBuilder.LOAD_ALL
- .equals(scriptStrategy)) {
- processScripts = false;
- // For an "ALL" strategy, it is not necessary to load scripts in the ajax
request
- if (!ajaxRequest) {
- try {
- resourceBuilder
- .createResource(
- this,
- InternetResourceBuilder.COMMON_FRAMEWORK_SCRIPT).encode(context, null);
- resourceBuilder
- .createResource(
- this,
- InternetResourceBuilder.COMMON_UI_SCRIPT).encode(context, null);
-
- } catch (ResourceNotFoundException e) {
- if (log.isWarnEnabled()) {
- log
- .warn("No aggregated javaScript library found "
- + e.getMessage());
- }
- }
-
- }
- }
- }
-
- if (InternetResourceBuilder.LOAD_NONE.equals(styleStrategy)) {
- processStyles = false;
- } else if (InternetResourceBuilder.LOAD_ALL
- .equals(styleStrategy)) {
- processStyles = false;
- // For an "ALL" strategy, it is not necessary to load styles
- // in the ajax request
- if (!ajaxRequest) {
-
- try {
- useSkinning = encodeSkinningResources(context, resourceBuilder);
-
- resourceBuilder
- .createResource(this, InternetResourceBuilder.COMMON_STYLE).encode(context, null);
-
- } catch (ResourceNotFoundException e) {
- if (log.isWarnEnabled()) {
- log.warn("No stylesheet found "
- + e.getMessage());
- }
- }
-
- }
- } else {
- useSkinning = encodeSkinningResources(context, resourceBuilder);
- }
-
- //traverse components
- //traverse(context, context.getViewRoot());
-
- context.setResponseWriter(componentWriter);
-
- QueueRegistry queueRegistry = QueueRegistry.getInstance(context);
- if (Boolean.valueOf(getInitParameterValue(context,
"org.richfaces.queue.global.enabled"))) {
- queueRegistry.setShouldCreateDefaultGlobalQueue();
- }
-
- if (queueRegistry.hasQueuesToEncode()) {
- InternetResource queueScriptResource =
resourceBuilder.getResource(QUEUE_SCRIPT_RESOURCE);
- queueScriptResource.encode(context, null);
- }
-
- // Append Skin StyleSheet after a
- if (null != skinStyleSheetUri) {
- String resourceURL = context.getApplication()
- .getViewHandler().getResourceURL(context,
- skinStyleSheetUri);
-
- URIInternetResource resourceImpl = new URIInternetResource();
- resourceImpl.setUri(resourceURL);
- resourceImpl.setRenderer(resourceBuilder.getStyleRenderer());
- resourceImpl.encode(context, null);
-
- useSkinning = true;
- }
-
- if (null != skinExtendedStyleSheetUri && extendedSkinningAllowed) {
- String resourceURL =
context.getApplication().getViewHandler().getResourceURL(context,
- skinExtendedStyleSheetUri);
-
- URIInternetResource resourceImpl = new URIInternetResource();
- resourceImpl.setUri(resourceURL);
- resourceImpl.setRenderer(resourceBuilder.getStyleRenderer());
- resourceImpl.encode(context, null, EXTENDED_SKINNING);
-
- useSkinning = true;
- }
-
- if (useSkinning && extendedSkinningAllowed) {
- if (!ajaxRequest) {
- if (!scriptsOff) {
- //skinning levels aren't dynamic, page-level setting cannot be changed
- //by AJAX request
- EXTENDED_SKINNING_ON_RESOURCE.encode(context, null);
- } else {
-
- Map<String, Object> applicationMap =
context.getExternalContext().getApplicationMap();
- if (applicationMap.get(EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY) == null) {
- //do it once per application life - strategies can be changed dynamically
- ResponseWriter writer = context.getResponseWriter();
- try {
- StringWriter stringWriter = new StringWriter();
-
- if (oldResponseWriter != null) {
- context.setResponseWriter(oldResponseWriter.cloneWithWriter(stringWriter));
- } else {
- context.setResponseWriter(this.renderKit.createResponseWriter(
- stringWriter, "text/html",
- "US-ASCII"));
- }
-
-
- EXTENDED_SKINNING_ON_RESOURCE.encode(context, null);
-
- stringWriter.flush();
-
- if (log.isInfoEnabled()) {
- log.info("Extended skinning is on and NONE scripts loading strategy was
detected. " +
- "Do not forget that one of " +
InternetResourceBuilder.SKINNING_SCRIPT + " or " +
- InternetResourceBuilder.COMMON_FRAMEWORK_SCRIPT + " resources should be
presented " +
- "on the page together with the following code: \n" +
stringWriter.getBuffer().toString() +
- "\nfor extended level of skinning to work.");
- }
- } finally {
- if (writer != null) {
- context.setResponseWriter(writer);
- }
- }
-
- applicationMap.put(EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY, Boolean.TRUE);
- }
- }
- }
-
- if (processScripts) {
- InternetResource resource = resourceBuilder.createResource(null,
- InternetResourceBuilder.SKINNING_SCRIPT);
-
- resource.encode(context, null);
- }
- }
-
- componentWriter.endDocument();
- userWriter.endDocument();
- } catch (IOException e) {
- throw new FacesException(e.getLocalizedMessage(), e);
- } finally {
- if (oldResponseWriter != null) {
- context.setResponseWriter(oldResponseWriter);
- }
- }
- }
-
- private static String getInitParameterValue(FacesContext context, String parameterName)
{
-
- String key = INIT_PARAMETER_PREFIX + parameterName;
-
- ExternalContext externalContext = context.getExternalContext();
- Map<String, Object> applicationMap = externalContext.getApplicationMap();
- Object mutex = externalContext.getRequest();
- Object parameterValue = null;
-
- synchronized (mutex) {
- parameterValue = applicationMap.get(key);
-
- if (parameterValue == null) {
-
- String initParameter = externalContext.getInitParameter(parameterName);
- if (initParameter != null) {
-
- if (ELUtils.isValueReference(initParameter)) {
- Application application = context.getApplication();
- ExpressionFactory expressionFactory = application.getExpressionFactory();
-
- parameterValue = expressionFactory.createValueExpression(context.getELContext(),
- initParameter,
- String.class);
- } else {
- parameterValue = initParameter;
- }
-
- } else {
- parameterValue = NULL;
- }
-
- applicationMap.put(key, parameterValue);
- }
- }
-
- return evaluate(context, parameterValue);
- }
-
- private static String evaluate(FacesContext context, Object parameterValue) {
- if (parameterValue == NULL || parameterValue == null) {
- return null;
- } else if (parameterValue instanceof ValueExpression) {
- ValueExpression expression = (ValueExpression) parameterValue;
-
- return (String) expression.getValue(context.getELContext());
- } else {
- return parameterValue.toString();
- }
- }
-
- public void initialize(FacesContext context) {
- boolean extendedSkinningAllowed = true;
- String skinningLevel = getInitParameterValue(context,
InternetResourceBuilder.CONTROL_SKINNING_LEVEL);
- if (skinningLevel != null && skinningLevel.length() > 0) {
- if (InternetResourceBuilder.BASIC.equals(skinningLevel)) {
- extendedSkinningAllowed = false;
- } else if (!InternetResourceBuilder.EXTENDED.equals(skinningLevel)) {
- throw new IllegalArgumentException("Value: " + skinningLevel +
- " of " + InternetResourceBuilder.CONTROL_SKINNING_LEVEL
- + " init parameter is invalid! Only " + InternetResourceBuilder.EXTENDED
- + ", " + InternetResourceBuilder.BASIC + " can be used");
- }
- }
-
- this.setExtendedSkinningAllowed(extendedSkinningAllowed);
-
- this.setScriptStrategy(getInitParameterValue(context,
- InternetResourceBuilder.LOAD_SCRIPT_STRATEGY_PARAM));
-
- boolean useStdControlsSkinning = false;
-
- String stdControlsSkinning = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_PARAM);
- if (stdControlsSkinning != null) {
- useStdControlsSkinning = InternetResourceBuilder.ENABLE.equals(stdControlsSkinning);
- }
-
- this.setUseStdControlsSkinning(useStdControlsSkinning);
-
- boolean useStdControlsSkinningClasses = true;
-
- String stdControlsSkinningClasses = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_CLASSES_PARAM);
- if (stdControlsSkinningClasses != null) {
- useStdControlsSkinningClasses =
InternetResourceBuilder.ENABLE.equals(stdControlsSkinningClasses);
- }
-
- this.setUseStdControlsSkinningClasses(useStdControlsSkinningClasses);
-
- this.setStyleStrategy(getInitParameterValue(context,
- InternetResourceBuilder.LOAD_STYLE_STRATEGY_PARAM));
-
-
- }
-
+// private static final String INIT_PARAMETER_PREFIX = "_init_parameter_";
+// private static final Object NULL = new Object();
+//
+// private String scriptStrategy;
+//
+// private String styleStrategy;
+//
+// private boolean useStdControlsSkinning;
+//
+// private boolean useStdControlsSkinningClasses;
+//
+// private HeadResponseWriter componentWriter;
+//
+// private HeadResponseWriter userWriter;
+//
+// private RenderKit renderKit;
+//
+// private Node[] headNodes = null;
+//
+// private static final String EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY =
ViewResources.class.getName() + "EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY";
+//
+// private static final InternetResource EXTENDED_SKINNING_ON_RESOURCE = new
InternetResourceBase() {
+//
+// private final String RESOURCE_KEY = this.getClass().getName();
+//
+// @Override
+// public void encode(FacesContext context, Object data)
+// throws IOException {
+//
+// encode(context, data, Collections.EMPTY_MAP);
+// }
+//
+// @Override
+// public void encode(FacesContext context, Object data,
+// Map<String, Object> attributes) throws IOException {
+//
+// Map<String, Object> requestMap =
context.getExternalContext().getRequestMap();
+// if (requestMap.get(RESOURCE_KEY) == null) {
+// ResponseWriter writer = context.getResponseWriter();
+// writer.startElement(HTML.SCRIPT_ELEM, null);
+//
+// if (!attributes.containsKey(HTML.TYPE_ATTR)) {
+// writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+// }
+//
+// for (Map.Entry<String, Object> entry : attributes.entrySet()) {
+// writer.writeAttribute(entry.getKey(), entry.getValue(), null);
+// }
+//
+// writer.writeText("window.RICH_FACES_EXTENDED_SKINNING_ON=true;", null);
+//
+// writer.endElement(HTML.SCRIPT_ELEM);
+//
+// requestMap.put(RESOURCE_KEY, Boolean.TRUE);
+// }
+// }
+// };
+//
+// public void setScriptStrategy(String scriptsStrategy) {
+// this.scriptStrategy = scriptsStrategy;
+// }
+//
+// public void setStyleStrategy(String stylesStrategy) {
+// this.styleStrategy = stylesStrategy;
+// }
+//
+// public void setUseStdControlsSkinning(boolean stdControlsSkinning) {
+// this.useStdControlsSkinning = stdControlsSkinning;
+// }
+//
+// public void setUseStdControlsSkinningClasses(boolean stdControlsSkinningClasses) {
+// this.useStdControlsSkinningClasses = stdControlsSkinningClasses;
+// }
+//
+// public void setExtendedSkinningAllowed(boolean extendedSkinningAllowed) {
+// this.extendedSkinningAllowed = extendedSkinningAllowed;
+// }
+//
+// private static String SCRIPT = HTML.SCRIPT_ELEM;
+// private static String SCRIPT_UC = SCRIPT.toUpperCase(Locale.US);
+//
+// private static String SRC = HTML.src_ATTRIBUTE;
+// private static String SRC_UC = SRC.toUpperCase(Locale.US);
+//
+// private void mergeHeadResourceNode(List<Node> nodes, Set<String>
renderedScripts, Node node) {
+// boolean shouldAdd = true;
+//
+// String nodeName = node.getNodeName();
+// if (SCRIPT.equals(nodeName) || SCRIPT_UC.equals(nodeName)) {
+// if (node.getFirstChild() == null) {
+// //no text content etc.
+//
+// NamedNodeMap attributes = node.getAttributes();
+// if (attributes != null) {
+// Node item = attributes.getNamedItem(SRC);
+// if (item == null) {
+// attributes.getNamedItem(SRC_UC);
+// }
+//
+// if (item != null) {
+// String src = item.getNodeValue();
+// if (src != null) {
+// if (renderedScripts.contains(src)) {
+// shouldAdd = false;
+// } else {
+// renderedScripts.add(src);
+// }
+// }
+// }
+// }
+// }
+// }
+//
+// if (shouldAdd) {
+// nodes.add(node);
+// }
+// }
+//
+// private Node[] mergeHeadResourceNodes() {
+// List<Node> result = new ArrayList<Node>();
+//
+// Set<String> scripts = new HashSet<String>();
+//
+// for (Node node : componentWriter.getNodes()) {
+// mergeHeadResourceNode(result, scripts, node);
+// }
+//
+// for (Node node : userWriter.getNodes()) {
+// mergeHeadResourceNode(result, scripts, node);
+// }
+//
+// return result.toArray(new Node[result.size()]);
+// }
+//
+// public Node[] getHeadEvents() {
+// if (headNodes == null) {
+// headNodes = mergeHeadResourceNodes();
+// }
+//
+// return headNodes;
+// }
+//
+// private static final Log log = LogFactory.getLog(ViewResources.class);
+//
+// //todo
+//
+// private static final Map<String, Object> EXTENDED_SKINNING = new
HashMap<String, Object>(1);
+//
+// static {
+// EXTENDED_SKINNING.put(HTML.media_ATTRIBUTE, "rich-extended-skinning");
+// }
+//
+// public static final String SKINNING_STYLES_PATH =
"/org/richfaces/renderkit/html/css/";
+//
+// public static final String QUEUE_SCRIPT_RESOURCE =
"org.ajax4jsf.renderkit.html.scripts.QueueScript";
+//
+// private boolean extendedSkinningAllowed;
+//
+// private boolean processScripts;
+//
+// private boolean processStyles;
+//
+// private boolean useSkinning;
+//
+// private InternetResourceBuilder resourceBuilder;
+//
+// private boolean ajaxRequest;
+//
+// public static final String COMPONENT_RESOURCE_LINK_CLASS = "component";
+//
+// public static final String USER_RESOURCE_LINK_CLASS = "user";
+//
+// class HeadResponseWriter extends SAXResponseWriter {
+//
+// public Node[] getNodes() {
+// return ((ResponseWriterContentHandler) getXmlConsumer()).getNodes();
+// }
+//
+// public HeadResponseWriter(String linkClass) {
+// super(new ResponseWriterContentHandler(linkClass));
+//
+// }
+// }
+//
+// private void encodeResources(FacesContext context, ResourceRenderer renderer,
Set<String> set) throws IOException {
+//
+// if (set != null) {
+// URIInternetResource resourceImpl = new URIInternetResource();
+//
+// for (String uri : set) {
+// resourceImpl.setUri(uri);
+// renderer.encode(resourceImpl, context, null);
+// }
+// }
+// }
+//
+// private boolean encodeSkinningResources(FacesContext context, InternetResourceBuilder
resourceBuilder) throws IOException, FacesException {
+// String resourceSuffix = null;
+//
+// if (useStdControlsSkinning) {
+// if (useStdControlsSkinningClasses) {
+// resourceSuffix = "_both.xcss";
+// } else {
+// resourceSuffix = ".xcss";
+// }
+// } else {
+// if (useStdControlsSkinningClasses) {
+// resourceSuffix = "_classes.xcss";
+// } else {
+// //no resources
+// }
+// }
+//
+// if (resourceSuffix != null) {
+// resourceBuilder.createResource(
+// this,
SKINNING_STYLES_PATH.concat("basic").concat(resourceSuffix)).encode(context,
null);
+//
+// if (extendedSkinningAllowed) {
+// resourceBuilder.createResource(
+// this,
SKINNING_STYLES_PATH.concat("extended").concat(resourceSuffix)).encode(context,
null, EXTENDED_SKINNING);
+// }
+//
+// return true;
+// }
+//
+// return false;
+// }
+//
+// /**
+// * Find renderer for given component.
+// *
+// * @param context
+// * @param comp
+// * @param renderKit
+// * @return
+// */
+// private Renderer getRenderer(FacesContext context, UIComponent comp) {
+//
+// String rendererType = comp.getRendererType();
+// if (rendererType != null) {
+// return (renderKit.getRenderer(comp.getFamily(), rendererType));
+// } else {
+// return (null);
+// }
+// }
+//
+// public void processHeadResources(FacesContext context) throws FacesException {
+//
+// RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder
+// .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+// renderKit = rkFactory.getRenderKit(context, context
+// .getViewRoot().getRenderKitId());
+//
+// boolean scriptsOff = false;
+//
+// processStyles = true;
+// processScripts = true;
+// useSkinning = false;
+//
+// ajaxRequest = AjaxContext.getCurrentInstance(context).isAjaxRequest(context);
+//
+// if (log.isDebugEnabled()) {
+// log
+// .debug("Process component tree for collect used scripts and styles");
+// }
+//
+// String skinStyleSheetUri = null;
+// String skinExtendedStyleSheetUri = null;
+//
+// Skin skin = null;
+// try {
+// skin = SkinFactory.getInstance().getSkin(context);
+// // For a "NULL" skin, do not collect components stylesheets
+// if ("false".equals(skin.getParameter(context,
+// Skin.loadStyleSheets))) {
+// processStyles = false;
+// }
+// // Set default style sheet for current skin.
+// skinStyleSheetUri = (String) skin.getParameter(context,
+// Skin.generalStyleSheet);
+// // Set default style sheet for current skin.
+// skinExtendedStyleSheetUri = (String) skin.getParameter(context,
+// Skin.extendedStyleSheet);
+// } catch (SkinNotFoundException e) {
+// if (log.isWarnEnabled()) {
+// log.warn("Current Skin is not found", e);
+// }
+// }
+//
+// resourceBuilder = InternetResourceBuilder.getInstance();
+//
+// ResponseWriter oldResponseWriter = context.getResponseWriter();
+//
+// componentWriter = new HeadResponseWriter("component");
+// userWriter = new HeadResponseWriter("user");
+//
+// try {
+// componentWriter.startDocument();
+// userWriter.startDocument();
+//
+// context.setResponseWriter(componentWriter);
+//
+// // Check init parameters for a resources processing.
+// if (null != scriptStrategy) {
+// if (InternetResourceBuilder.LOAD_NONE
+// .equals(scriptStrategy)) {
+// scriptsOff = true;
+// processScripts = false;
+// } else if (InternetResourceBuilder.LOAD_ALL
+// .equals(scriptStrategy)) {
+// processScripts = false;
+// // For an "ALL" strategy, it is not necessary to load scripts in the
ajax request
+// if (!ajaxRequest) {
+// try {
+// resourceBuilder
+// .createResource(
+// this,
+// InternetResourceBuilder.COMMON_FRAMEWORK_SCRIPT).encode(context, null);
+// resourceBuilder
+// .createResource(
+// this,
+// InternetResourceBuilder.COMMON_UI_SCRIPT).encode(context, null);
+//
+// } catch (ResourceNotFoundException e) {
+// if (log.isWarnEnabled()) {
+// log
+// .warn("No aggregated javaScript library found "
+// + e.getMessage());
+// }
+// }
+//
+// }
+// }
+// }
+//
+// if (InternetResourceBuilder.LOAD_NONE.equals(styleStrategy)) {
+// processStyles = false;
+// } else if (InternetResourceBuilder.LOAD_ALL
+// .equals(styleStrategy)) {
+// processStyles = false;
+// // For an "ALL" strategy, it is not necessary to load styles
+// // in the ajax request
+// if (!ajaxRequest) {
+//
+// try {
+// useSkinning = encodeSkinningResources(context, resourceBuilder);
+//
+// resourceBuilder
+// .createResource(this, InternetResourceBuilder.COMMON_STYLE).encode(context,
null);
+//
+// } catch (ResourceNotFoundException e) {
+// if (log.isWarnEnabled()) {
+// log.warn("No stylesheet found "
+// + e.getMessage());
+// }
+// }
+//
+// }
+// } else {
+// useSkinning = encodeSkinningResources(context, resourceBuilder);
+// }
+//
+// //traverse components
+// //traverse(context, context.getViewRoot());
+//
+// context.setResponseWriter(componentWriter);
+//
+// QueueRegistry queueRegistry = QueueRegistry.getInstance(context);
+// if (Boolean.valueOf(getInitParameterValue(context,
"org.richfaces.queue.global.enabled"))) {
+// queueRegistry.setShouldCreateDefaultGlobalQueue();
+// }
+//
+// if (queueRegistry.hasQueuesToEncode()) {
+// InternetResource queueScriptResource =
resourceBuilder.getResource(QUEUE_SCRIPT_RESOURCE);
+// queueScriptResource.encode(context, null);
+// }
+//
+// // Append Skin StyleSheet after a
+// if (null != skinStyleSheetUri) {
+// String resourceURL = context.getApplication()
+// .getViewHandler().getResourceURL(context,
+// skinStyleSheetUri);
+//
+// URIInternetResource resourceImpl = new URIInternetResource();
+// resourceImpl.setUri(resourceURL);
+// resourceImpl.setRenderer(resourceBuilder.getStyleRenderer());
+// resourceImpl.encode(context, null);
+//
+// useSkinning = true;
+// }
+//
+// if (null != skinExtendedStyleSheetUri && extendedSkinningAllowed) {
+// String resourceURL =
context.getApplication().getViewHandler().getResourceURL(context,
+// skinExtendedStyleSheetUri);
+//
+// URIInternetResource resourceImpl = new URIInternetResource();
+// resourceImpl.setUri(resourceURL);
+// resourceImpl.setRenderer(resourceBuilder.getStyleRenderer());
+// resourceImpl.encode(context, null, EXTENDED_SKINNING);
+//
+// useSkinning = true;
+// }
+//
+// if (useSkinning && extendedSkinningAllowed) {
+// if (!ajaxRequest) {
+// if (!scriptsOff) {
+// //skinning levels aren't dynamic, page-level setting cannot be changed
+// //by AJAX request
+// EXTENDED_SKINNING_ON_RESOURCE.encode(context, null);
+// } else {
+//
+// Map<String, Object> applicationMap =
context.getExternalContext().getApplicationMap();
+// if (applicationMap.get(EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY) == null) {
+// //do it once per application life - strategies can be changed dynamically
+// ResponseWriter writer = context.getResponseWriter();
+// try {
+// StringWriter stringWriter = new StringWriter();
+//
+// if (oldResponseWriter != null) {
+// context.setResponseWriter(oldResponseWriter.cloneWithWriter(stringWriter));
+// } else {
+// context.setResponseWriter(this.renderKit.createResponseWriter(
+// stringWriter, "text/html",
+// "US-ASCII"));
+// }
+//
+//
+// EXTENDED_SKINNING_ON_RESOURCE.encode(context, null);
+//
+// stringWriter.flush();
+//
+// if (log.isInfoEnabled()) {
+// log.info("Extended skinning is on and NONE scripts loading strategy was
detected. " +
+// "Do not forget that one of " +
InternetResourceBuilder.SKINNING_SCRIPT + " or " +
+// InternetResourceBuilder.COMMON_FRAMEWORK_SCRIPT + " resources should be
presented " +
+// "on the page together with the following code: \n" +
stringWriter.getBuffer().toString() +
+// "\nfor extended level of skinning to work.");
+// }
+// } finally {
+// if (writer != null) {
+// context.setResponseWriter(writer);
+// }
+// }
+//
+// applicationMap.put(EXTENDED_SKINNING_ON_NO_SCRIPTS_INFO_KEY, Boolean.TRUE);
+// }
+// }
+// }
+//
+// if (processScripts) {
+// InternetResource resource = resourceBuilder.createResource(null,
+// InternetResourceBuilder.SKINNING_SCRIPT);
+//
+// resource.encode(context, null);
+// }
+// }
+//
+// componentWriter.endDocument();
+// userWriter.endDocument();
+// } catch (IOException e) {
+// throw new FacesException(e.getLocalizedMessage(), e);
+// } finally {
+// if (oldResponseWriter != null) {
+// context.setResponseWriter(oldResponseWriter);
+// }
+// }
+// }
+//
+// private static String getInitParameterValue(FacesContext context, String
parameterName) {
+//
+// String key = INIT_PARAMETER_PREFIX + parameterName;
+//
+// ExternalContext externalContext = context.getExternalContext();
+// Map<String, Object> applicationMap = externalContext.getApplicationMap();
+// Object mutex = externalContext.getRequest();
+// Object parameterValue = null;
+//
+// synchronized (mutex) {
+// parameterValue = applicationMap.get(key);
+//
+// if (parameterValue == null) {
+//
+// String initParameter = externalContext.getInitParameter(parameterName);
+// if (initParameter != null) {
+//
+// if (ELUtils.isValueReference(initParameter)) {
+// Application application = context.getApplication();
+// ExpressionFactory expressionFactory = application.getExpressionFactory();
+//
+// parameterValue = expressionFactory.createValueExpression(context.getELContext(),
+// initParameter,
+// String.class);
+// } else {
+// parameterValue = initParameter;
+// }
+//
+// } else {
+// parameterValue = NULL;
+// }
+//
+// applicationMap.put(key, parameterValue);
+// }
+// }
+//
+// return evaluate(context, parameterValue);
+// }
+//
+// private static String evaluate(FacesContext context, Object parameterValue) {
+// if (parameterValue == NULL || parameterValue == null) {
+// return null;
+// } else if (parameterValue instanceof ValueExpression) {
+// ValueExpression expression = (ValueExpression) parameterValue;
+//
+// return (String) expression.getValue(context.getELContext());
+// } else {
+// return parameterValue.toString();
+// }
+// }
+//
+// public void initialize(FacesContext context) {
+// boolean extendedSkinningAllowed = true;
+// String skinningLevel = getInitParameterValue(context,
InternetResourceBuilder.CONTROL_SKINNING_LEVEL);
+// if (skinningLevel != null && skinningLevel.length() > 0) {
+// if (InternetResourceBuilder.BASIC.equals(skinningLevel)) {
+// extendedSkinningAllowed = false;
+// } else if (!InternetResourceBuilder.EXTENDED.equals(skinningLevel)) {
+// throw new IllegalArgumentException("Value: " + skinningLevel +
+// " of " + InternetResourceBuilder.CONTROL_SKINNING_LEVEL
+// + " init parameter is invalid! Only " +
InternetResourceBuilder.EXTENDED
+// + ", " + InternetResourceBuilder.BASIC + " can be used");
+// }
+// }
+//
+// this.setExtendedSkinningAllowed(extendedSkinningAllowed);
+//
+// this.setScriptStrategy(getInitParameterValue(context,
+// InternetResourceBuilder.LOAD_SCRIPT_STRATEGY_PARAM));
+//
+// boolean useStdControlsSkinning = false;
+//
+// String stdControlsSkinning = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_PARAM);
+// if (stdControlsSkinning != null) {
+// useStdControlsSkinning =
InternetResourceBuilder.ENABLE.equals(stdControlsSkinning);
+// }
+//
+// this.setUseStdControlsSkinning(useStdControlsSkinning);
+//
+// boolean useStdControlsSkinningClasses = true;
+//
+// String stdControlsSkinningClasses = getInitParameterValue(context,
InternetResourceBuilder.STD_CONTROLS_SKINNING_CLASSES_PARAM);
+// if (stdControlsSkinningClasses != null) {
+// useStdControlsSkinningClasses =
InternetResourceBuilder.ENABLE.equals(stdControlsSkinningClasses);
+// }
+//
+// this.setUseStdControlsSkinningClasses(useStdControlsSkinningClasses);
+//
+// this.setStyleStrategy(getInitParameterValue(context,
+// InternetResourceBuilder.LOAD_STYLE_STRATEGY_PARAM));
+//
+//
+// }
+//
}
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/resource/InternetResourceService.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/resource/InternetResourceService.java 2009-07-24
08:56:25 UTC (rev 14998)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/resource/InternetResourceService.java 2009-07-24
09:02:57 UTC (rev 14999)
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.util.Date;
import java.util.Map;
import java.util.Properties;
@@ -46,7 +45,6 @@
import org.ajax4jsf.cache.ServletContextInitMap;
import org.ajax4jsf.resource.util.URLToStreamHelper;
import org.ajax4jsf.webapp.BaseFilter;
-import org.ajax4jsf.webapp.CacheContent;
import org.ajax4jsf.webapp.WebXml;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -74,8 +72,6 @@
private ResourceLifecycle lifecycle;
- private InternetResourceBuilder resourceBuilder;
-
private WebXml webXml;
public InternetResourceService() {
@@ -125,7 +121,7 @@
}
}
- public boolean serviceResource(HttpServletRequest httpServletRequest,
+ /*public boolean serviceResource(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws ServletException,
IOException {
String resourceKey = webXml.getFacesResourceKey(httpServletRequest);
@@ -135,9 +131,9 @@
return true;
}
return false;
- }
+ }*/
- public void serviceResource(String resourceKey, HttpServletRequest request,
+ /*public void serviceResource(String resourceKey, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
InternetResource resource;// getInternetResource(request);
try {
@@ -240,7 +236,7 @@
} finally {
resourceContext.release();
}
- }
+ }*/
/**
* @param resource
@@ -326,15 +322,4 @@
request, response, getLifecycle());
}
- /**
- * @return the resourceBuilder
- */
- protected InternetResourceBuilder getResourceBuilder() {
- if (resourceBuilder == null) {
- // Create resource builder for this filter.
- resourceBuilder = InternetResourceBuilder.getInstance();
- }
- return resourceBuilder;
- }
-
}
Deleted:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/resource/TemplateCSSRenderer.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/resource/TemplateCSSRenderer.java 2009-07-24
08:56:25 UTC (rev 14998)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/resource/TemplateCSSRenderer.java 2009-07-24
09:02:57 UTC (rev 14999)
@@ -1,168 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.resource;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.nio.ByteBuffer;
-
-import javax.faces.FacesException;
-import javax.faces.FactoryFinder;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.RenderKit;
-import javax.faces.render.RenderKitFactory;
-
-import org.ajax4jsf.css.CssCompressor;
-import org.ajax4jsf.renderkit.RendererBase;
-import org.ajax4jsf.renderkit.compiler.HtmlCompiler;
-import org.ajax4jsf.renderkit.compiler.PreparedTemplate;
-import org.ajax4jsf.renderkit.compiler.TemplateContext;
-import org.richfaces.skin.SkinFactory;
-
-/**
- * @author shura
- *
- */
-public class TemplateCSSRenderer extends StyleRenderer {
-
- private static final String COMPILED_TEMPLATE_PROPERTY = "compiled-template";
-
- /** Parameter allows switch on/off comressing for css */
- private static final String COMPRESS_STYLE_PARAMETER =
"org.ajax4jsf.COMPRESS_STYLE";
-
- private RendererBase renderer = new RendererBase() {
-
- protected Class<? extends UIComponent> getComponentClass() {
- // TODO Auto-generated method stub
- return UIComponent.class;
- }
-
- };
- /* (non-Javadoc)
- * @see
org.ajax4jsf.resource.BaseResourceRenderer#send(org.ajax4jsf.resource.InternetResource,
org.ajax4jsf.resource.ResourceContext)
- */
- public int send(InternetResource base, ResourceContext context) throws IOException {
- PreparedTemplate template = null;
- CountingOutputWriter countingOutputWriter = new CountingOutputWriter();
- template = getTemplate(base, context);
- FacesContext facesContext = FacesContext.getCurrentInstance();
- boolean _CompressStyleOn = !"false".equals(facesContext.getExternalContext()
- .getInitParameter(COMPRESS_STYLE_PARAMETER));
- Writer writer = context.getWriter();
- int bytesLength;
- if(null != facesContext) {
- // Create responseWriter.
- String defaultRenderKitId = facesContext.getApplication().getDefaultRenderKitId();
- if (null == defaultRenderKitId) {
- defaultRenderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
- }
- RenderKitFactory renderKitFactory = (RenderKitFactory)
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- RenderKit renderKit = renderKitFactory.getRenderKit(facesContext,defaultRenderKitId);
- // TODO - handle response encoding
-
- ResponseWriter responseWriter =
renderKit.createResponseWriter(countingOutputWriter,null,"UTF-8");
- facesContext.setResponseWriter(responseWriter);
- responseWriter.startDocument();
-
- // TODO - parameters and mock renderer/component ?
- // for first time, this template only allow skin or faces variables interaction
- template.encode(renderer,facesContext,null);
- responseWriter.endDocument();
- responseWriter.flush();
- responseWriter.close();
-
- if (_CompressStyleOn) {
- CssCompressor compressor = new CssCompressor(countingOutputWriter.getContent());
// Compressing css document and printing result in response stream
- bytesLength = compressor.compress(writer, -1);
- writer.flush();
- writer.close();
- } else {
- writer.write(countingOutputWriter.getContent().toString()); // Write not
compressed style content
- bytesLength = countingOutputWriter.getWritten();
- writer.flush();
- writer.close();
- }
-
- } else {
- throw new FacesException("FacesContext for resource from template
"+base.getKey()+" is null");
- }
- return bytesLength;
- }
-
- /**
- * @param base
- * @param context
- * @return
- * @throws IOException
- */
- public synchronized PreparedTemplate getTemplate(InternetResource base,
- ResourceContext context) throws IOException {
- PreparedTemplate template;
- // if(base.isCacheable()){
- template = (PreparedTemplate) base
- .getProperty(COMPILED_TEMPLATE_PROPERTY);
- // }
- if (null == template) {
- HtmlCompiler compiler = new HtmlCompiler();
- InputStream resourceAsStream = base.getResourceAsStream(context);
- if (null != resourceAsStream) {
- template = compiler.compile(resourceAsStream, base.getKey());
- base.setProperty(COMPILED_TEMPLATE_PROPERTY, template);
- resourceAsStream.close();
- } else {
- throw new IOException("CSS Template "+base.getKey()+" not
found");
- }
- }
- return template;
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.resource.BaseResourceRenderer#requireFacesContext()
- */
- public boolean requireFacesContext() {
- return true;
- }
-
- public Object getData(InternetResource base, FacesContext context, Object data) {
- ResourceContext resourceContext = new FacesResourceContext(context);
- PreparedTemplate template;
- try {
- template = getTemplate(base, resourceContext);
- } catch (IOException e) {
- return null;
- }
- UIComponent component = (UIComponent) (data instanceof UIComponent ? data:null);
- TemplateContext templateContext = new TemplateContext(null,context,component);
- Object value = template.getValue(templateContext);
- if(null == value){
- SkinFactory skinFactory = SkinFactory.getInstance();
- int hashCode = skinFactory.getSkin(context).hashCode(context);
- int baseHashCode = skinFactory.getBaseSkin(context).hashCode(context);
- value = ByteBuffer.allocate(4*2).putInt(hashCode).putInt(baseHashCode).array();
- }
- return value;
- }
-
-}
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java 2009-07-24
08:56:25 UTC (rev 14998)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java 2009-07-24
09:02:57 UTC (rev 14999)
@@ -505,15 +505,15 @@
httpServletResponse.setContentLength(0);
} else
// check for resource request
- if (!getResourceService().serviceResource(httpServletRequest,
- httpServletResponse)) {
+ //if (!getResourceService().serviceResource(httpServletRequest,
+ // httpServletResponse)) {
// Not request to resource - perform filtering.
// first stage - detect/set encoding of request. Same as in
// Myfaces External Context.
setupRequestEncoding(httpServletRequest);
checkMyFacesExtensionsFilter(httpServletRequest);
processUploadsAndHandleRequest(httpServletRequest, httpServletResponse, chain);
- }
+ //}
} finally {
// Remove filter marker from response, to enable sequence calls ( for example,
forward to error page )
request.removeAttribute(FILTER_PERFORMED);
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java 2009-07-24
08:56:25 UTC (rev 14998)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java 2009-07-24
09:02:57 UTC (rev 14999)
@@ -40,12 +40,10 @@
import org.ajax4jsf.Messages;
import org.ajax4jsf.application.AjaxViewHandler;
-import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.context.ContextInitParameters;
import org.ajax4jsf.renderkit.AjaxContainerRenderer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Node;
public abstract class BaseXMLFilter {
public static final String AJAX_EXPIRED = "Ajax-Expired";
@@ -204,8 +202,6 @@
}
String viewId = (String) request
.getAttribute(AjaxViewHandler.VIEW_ID_KEY);
- Node[] headEvents = (Node[]) request
- .getAttribute(AjaxContext.HEAD_EVENTS_PARAMETER);
HtmlParser parser = null;
// setup response
@@ -295,7 +291,7 @@
boolean forcenotrf = isForcenotrf();
if (forcenotrf || !servletResponseWrapper.isError()) {
- if (forcenotrf || (headEvents != null && headEvents.length != 0)) {
+ if (forcenotrf) {
if (contentTypeCharset != null) {
if (contentTypeCharset.indexOf("charset") < 0
&& null != characterEncoding) {
@@ -360,8 +356,6 @@
}
try {
- // Setup scripts and styles
- parser.setHeadNodes(headEvents);
// Process parsing.
long startTimeMills = System.currentTimeMillis();
servletResponseWrapper.parseContent(output, parser);
Modified:
root/framework/trunk/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
===================================================================
---
root/framework/trunk/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java 2009-07-24
08:56:25 UTC (rev 14998)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java 2009-07-24
09:02:57 UTC (rev 14999)
@@ -12,7 +12,6 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import org.ajax4jsf.resource.InternetResource;
import org.richfaces.test.AbstractFacesTest;
public class CompositeRendererTest extends AbstractFacesTest {
@@ -127,105 +126,6 @@
assertEquals("3", map.get("generic"));
}
- public final void testGetScripts() {
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
- MockDecodeContributor contributor;
-
- inputContributor = new MockDecodeContributor(UIComponent.class, new String[] {
"input_script" }, null);
- formContributor = new MockDecodeContributor(UIComponent.class, new String[] {
"form_script" }, null);
- contributor = new MockDecodeContributor(UIComponent.class, null, null);
-
- compositeRenderer.addContributor(contributor);
- compositeRenderer.addContributor(formContributor);
- compositeRenderer.addContributor(inputContributor);
-
- InternetResource[] scripts = compositeRenderer.getScripts();
-
- assertEquals(2, scripts.length);
-
- assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/form_script"));
- assertTrue(scripts[1].getKey().contains("org/richfaces/renderkit/input_script"));
- }
-
- public final void testGetStyles() {
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
- MockDecodeContributor contributor;
-
- inputContributor = new MockDecodeContributor(UIComponent.class, null, new String[] {
"input_style" });
- formContributor = new MockDecodeContributor(UIComponent.class, null, new String[] {
"form_style" });
- contributor = new MockDecodeContributor(UIComponent.class, null, null);
-
- compositeRenderer.addContributor(contributor);
- compositeRenderer.addContributor(inputContributor);
- compositeRenderer.addContributor(formContributor);
-
- InternetResource[] scripts = compositeRenderer.getStyles();
-
- assertEquals(2, scripts.length);
-
- assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/input_style"));
- assertTrue(scripts[1].getKey().contains("org/richfaces/renderkit/form_style"));
- }
-
- public final void testGetScriptsClass() {
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
- MockDecodeContributor contributor;
-
- inputContributor = new MockDecodeContributor(UIInput.class, new String[] {
"input_script" }, null);
- formContributor = new MockDecodeContributor(NamingContainer.class, new String[] {
"form_script" }, null);
- contributor = new MockDecodeContributor(UIComponent.class, null, null);
-
- compositeRenderer.addContributor(contributor);
- compositeRenderer.addContributor(formContributor);
- compositeRenderer.addContributor(inputContributor);
-
- InternetResource[] scripts = compositeRenderer.getScripts(UIInput.class);
-
- assertEquals(1, scripts.length);
-
- assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/input_script"));
-
- scripts = compositeRenderer.getScripts(NamingContainer.class);
-
- assertEquals(1, scripts.length);
-
- assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/form_script"));
-
- scripts = compositeRenderer.getStyles(String.class);
- assertNull(scripts);
- }
-
- public final void testGetStylesClass() {
- MockDecodeContributor inputContributor;
- MockDecodeContributor formContributor;
- MockDecodeContributor contributor;
-
- inputContributor = new MockDecodeContributor(UIInput.class, null, new String[] {
"input_style" });
- formContributor = new MockDecodeContributor(NamingContainer.class, null, new String[] {
"form_style" });
- contributor = new MockDecodeContributor(UIComponent.class, null, null);
-
- compositeRenderer.addContributor(contributor);
- compositeRenderer.addContributor(formContributor);
- compositeRenderer.addContributor(inputContributor);
-
- InternetResource[] styles = compositeRenderer.getStyles(UIInput.class);
-
- assertEquals(1, styles.length);
-
- assertTrue(styles[0].getKey().contains("org/richfaces/renderkit/input_style"));
-
- styles = compositeRenderer.getStyles(NamingContainer.class);
-
- assertEquals(1, styles.length);
- assertTrue(styles[0].getKey().contains("org/richfaces/renderkit/form_style"));
-
- styles = compositeRenderer.getStyles(String.class);
- assertNull(styles);
- }
-
public final void testGetScriptContributionsStringFacesContextUIComponent() {
MockDecodeContributor inputContributor;
MockDecodeContributor formContributor;