Author: nbelaevski
Date: 2008-07-24 12:25:23 -0400 (Thu, 24 Jul 2008)
New Revision: 9773
Modified:
trunk/ui/core/src/main/config/component/loadStyle.xml
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/LoadResourceRendererBase.java
Log:
https://jira.jboss.org/jira/browse/RF-3687
Modified: trunk/ui/core/src/main/config/component/loadStyle.xml
===================================================================
--- trunk/ui/core/src/main/config/component/loadStyle.xml 2008-07-24 16:25:11 UTC (rev
9772)
+++ trunk/ui/core/src/main/config/component/loadStyle.xml 2008-07-24 16:25:23 UTC (rev
9773)
@@ -38,6 +38,9 @@
]]>
</description>
</property>
-
+ <property>
+ <name>media</name>
+ <classname>java.lang.String</classname>
+ </property>
</component>
</components>
Modified:
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/LoadResourceRendererBase.java
===================================================================
---
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/LoadResourceRendererBase.java 2008-07-24
16:25:11 UTC (rev 9772)
+++
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/LoadResourceRendererBase.java 2008-07-24
16:25:23 UTC (rev 9773)
@@ -21,76 +21,75 @@
package org.ajax4jsf.renderkit;
-import java.util.LinkedHashSet;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.ajax4jsf.component.UIResource;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.resource.InternetResource;
+import org.ajax4jsf.resource.InternetResourceBuilder;
+import org.ajax4jsf.resource.ResourceRenderer;
+import org.ajax4jsf.resource.URIInternetResource;
/**
* @author shura
*
*/
-public class LoadResourceRendererBase extends RendererBase implements
UserResourceRenderer {
+public class LoadResourceRendererBase extends RendererBase implements
UserResourceRenderer2 {
private static final String
SCRIPT_COMPONENT_FAMILY="org.ajax4jsf.LoadScript";
private static final String STYLE_COMPONENT_FAMILY="org.ajax4jsf.LoadStyle";
/* (non-Javadoc)
- * @see
org.ajax4jsf.renderkit.HeaderResourceProducer#getHeaderScripts(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
- */
- public LinkedHashSet getHeaderScripts(FacesContext context, UIComponent component) {
- UIResource resource = (UIResource) component;
- if (SCRIPT_COMPONENT_FAMILY.equals(resource.getFamily())) {
- return getResources(context, resource);
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see
org.ajax4jsf.renderkit.HeaderResourceProducer#getHeaderStyles(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
- */
- public LinkedHashSet getHeaderStyles(FacesContext context, UIComponent component) {
- UIResource resource = (UIResource) component;
- if (STYLE_COMPONENT_FAMILY.equals(resource.getFamily())) {
- return getResources(context, resource);
- }
- return null;
- }
-
- /* (non-Javadoc)
* @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
*/
protected Class getComponentClass() {
return UIResource.class;
}
- private LinkedHashSet getResources(FacesContext context, UIResource resource) {
+ public void encodeToHead(FacesContext context, UIComponent component) throws IOException
{
+ UIResource resource = (UIResource) component;
Object src = resource.getSrc();
- if(null == src){
+ if(null == src) {
throw new FacesException("Source for resource is null for component
"+resource.getClientId(context));
}
- LinkedHashSet set = new LinkedHashSet(1);
- String uri = null ;
- if(src instanceof InternetResource){
- uri=((InternetResource)src).getUri(context, resource);
+
+ String family = resource.getFamily();
+ ResourceRenderer renderer = null;
+ InternetResource internetResource = null;
+ Map<String, Object> attributes = Collections.EMPTY_MAP;
+
+ if (SCRIPT_COMPONENT_FAMILY.equals(family)) {
+ renderer = InternetResourceBuilder.getInstance().getScriptRenderer();
+ } else if (STYLE_COMPONENT_FAMILY.equals(family)) {
+ renderer = InternetResourceBuilder.getInstance().getStyleRenderer();
+ String media = (String) resource.getAttributes().get(HTML.media_ATTRIBUTE);
+ if (media != null && media.length() != 0) {
+ attributes = new HashMap<String, Object>();
+ attributes.put(HTML.media_ATTRIBUTE, media);
+ }
+ }
+
+ if (src instanceof InternetResource) {
+ internetResource = (InternetResource) src;
} else {
- // Process as ordinary url, same as for h:graphicsImage.
if(resource.isRendered()){
- uri=context.getApplication().getViewHandler().
- getResourceURL(context, src.toString());
- uri=context.getExternalContext().encodeResourceURL(uri);
- }
+ String uri = context.getApplication().getViewHandler().
+ getResourceURL(context, src.toString());
+ uri = context.getExternalContext().encodeResourceURL(uri);
+ internetResource = new URIInternetResource(uri);
+ }
}
-
- if (uri != null) {
- set.add(uri);
- }
- return set;
+ if (internetResource != null) {
+ renderer.encode(internetResource, context, null, attributes);
+ }
}
}