Author: nbelaevski
Date: 2008-04-08 15:47:23 -0400 (Tue, 08 Apr 2008)
New Revision: 7682
Modified:
branches/3.1.x/framework/api/src/main/java/org/ajax4jsf/context/AjaxContext.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/io/parser/FastHtmlParser.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/HtmlParser.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java
Log:
http://jira.jboss.com/jira/browse/RF-1627
http://jira.jboss.com/jira/browse/RF-3002
Modified:
branches/3.1.x/framework/api/src/main/java/org/ajax4jsf/context/AjaxContext.java
===================================================================
---
branches/3.1.x/framework/api/src/main/java/org/ajax4jsf/context/AjaxContext.java 2008-04-08
19:45:38 UTC (rev 7681)
+++
branches/3.1.x/framework/api/src/main/java/org/ajax4jsf/context/AjaxContext.java 2008-04-08
19:47:23 UTC (rev 7682)
@@ -79,6 +79,7 @@
public static final String SCRIPTS_PARAMETER =
"org.ajax4jsf.framework.HEADER_SCRIPTS";
public static final String STYLES_PARAMETER =
"org.ajax4jsf.framework.HEADER_STYLES";
+ public static final String USER_STYLES_PARAMETER =
"org.ajax4jsf.framework.HEADER_USER_STYLES";
public static final String RESPONSE_DATA_KEY = "_ajax:data";
private static final String SERVICE_RESOURCE = "META-INF/services/"
+ AjaxContext.class.getName();
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2008-04-08
19:45:38 UTC (rev 7681)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2008-04-08
19:47:23 UTC (rev 7682)
@@ -409,6 +409,7 @@
}
requestMap.put(SCRIPTS_PARAMETER, scripts);
}
+
Set styles = viewResources.getStyles();
if (styles.size() > 0) {
if (log.isDebugEnabled()) {
@@ -422,6 +423,20 @@
}
requestMap.put(STYLES_PARAMETER, styles);
}
+
+ Set usersStyles = viewResources.getUserStyles();
+ if (usersStyles.size() > 0) {
+ if (log.isDebugEnabled()) {
+ StringBuffer buff = new StringBuffer(
+ "User styles for insert into head : \n");
+ for (Iterator iter = usersStyles.iterator(); iter.hasNext();) {
+ String style = (String) iter.next();
+ buff.append(style).append("\n");
+ }
+ log.debug(buff.toString());
+ }
+ requestMap.put(USER_STYLES_PARAMETER, usersStyles);
+ }
// Mark as processed.
requestMap.put(RESOURCES_PROCESSED, Boolean.TRUE);
// Save viewId for a parser selection
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2008-04-08
19:45:38 UTC (rev 7681)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2008-04-08
19:47:23 UTC (rev 7682)
@@ -39,7 +39,7 @@
renderKit = rkFactory.getRenderKit(context, context
.getViewRoot().getRenderKitId());
processHeadResources(context, root);
- styles.addAll(userStyles);
+ //styles.addAll(userStyles);
scripts.addAll(userScripts);
}
@@ -156,6 +156,13 @@
return styles;
}
+ /**
+ * @return user styles
+ */
+ public Set getUserStyles() {
+ return userStyles;
+ }
+
public void addScript(String scriptUrl) {
scripts.add(scriptUrl);
}
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/io/parser/FastHtmlParser.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/io/parser/FastHtmlParser.java 2008-04-08
19:45:38 UTC (rev 7681)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/io/parser/FastHtmlParser.java 2008-04-08
19:47:23 UTC (rev 7682)
@@ -50,6 +50,8 @@
private Set styles;
+ private Set userStyles;
+
private String encoding;
private String doctype;
@@ -62,7 +64,7 @@
boolean haveHtml = false;
boolean haveHead = false;
boolean closingElement = false;
- if (null != scripts || null != styles) {
+ if (null != scripts || null != styles || null != userStyles) {
ParsingStateManager stateManager = ParsingStateManager
.getInstance();
ParserState state = stateManager.getInitialState();
@@ -174,11 +176,21 @@
if (null != styles) {
for (Iterator iter = styles.iterator(); iter.hasNext();) {
String style = (String) iter.next();
- out.write("<link rel='stylesheet' type='text/css'
href='");
+ out.write("<link rel='stylesheet' class='" +
COMPONENT_RESOURCE_LINK_CLASS + "'" +
+ " type='text/css' href='");
out.write(style);
out.write("' />");
}
}
+ if (null != userStyles) {
+ for (Iterator iter = userStyles.iterator(); iter.hasNext();) {
+ String style = (String) iter.next();
+ out.write("<link rel='stylesheet' class='" +
USER_RESOURCE_LINK_CLASS + "'" +
+ " type='text/css' href='");
+ out.write(style);
+ out.write("' />");
+ }
+ }
if (null != scripts) {
for (Iterator iter = scripts.iterator(); iter.hasNext();) {
String script = (String) iter.next();
@@ -223,6 +235,21 @@
this.styles = styles;
}
+ /**
+ * @return Returns the user styles.
+ */
+ public Set getUserStyles() {
+ return userStyles;
+ }
+
+ /**
+ * @param styles
+ * The user styles to set.
+ */
+ public void setUserStyles(Set userStyles) {
+ this.userStyles = userStyles;
+ }
+
public void parseHtml(InputStream input, Writer output) throws IOException {
parse(new InputStreamReader(input, encoding), output);
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java 2008-04-08
19:45:38 UTC (rev 7681)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java 2008-04-08
19:47:23 UTC (rev 7682)
@@ -291,6 +291,8 @@
.getAttribute(AjaxContext.SCRIPTS_PARAMETER));
parser.setStyles((Set) request
.getAttribute(AjaxContext.STYLES_PARAMETER));
+ parser.setUserStyles((Set) request
+ .getAttribute(AjaxContext.USER_STYLES_PARAMETER));
// Process parsing.
long startTimeMills = System.currentTimeMillis();
servletResponseWrapper.parseContent(output, parser);
Modified: branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/HtmlParser.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/HtmlParser.java 2008-04-08
19:45:38 UTC (rev 7681)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/HtmlParser.java 2008-04-08
19:47:23 UTC (rev 7682)
@@ -59,6 +59,11 @@
*/
public abstract void setStyles(Set styles);
+ /**
+ * @param styles The user styles to set
+ */
+ public abstract void setUserStyles(Set styles);
+
public abstract void setDoctype(String doctype);
/**
@@ -68,4 +73,7 @@
public abstract boolean setMime(String mimeType);
+ public static final String COMPONENT_RESOURCE_LINK_CLASS = "component";
+
+ public static final String USER_RESOURCE_LINK_CLASS = "user";
}
\ No newline at end of file
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java 2008-04-08
19:45:38 UTC (rev 7681)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java 2008-04-08
19:47:23 UTC (rev 7682)
@@ -94,6 +94,8 @@
private Set _styles;
+ private Set _userStyles;
+
private String _viewState;
private String _encoding;
@@ -163,6 +165,7 @@
public void reset() {
_scripts = null;
_styles = null;
+ _userStyles = null;
_viewState = null;
_parser.reset();
_serializer.reset();
@@ -289,6 +292,10 @@
}
+ public void setUserStyles(Set styles) {
+ _userStyles = styles;
+ }
+
/*
* (non-Javadoc)
*
@@ -421,23 +428,37 @@
super.endElement(element, augs);
}
+ private void insertStyle(String style, String className) {
+ QName element = new QName(null, "link", "link", null);
+ XMLAttributes attrs = new XMLAttributesImpl();
+ attrs.addAttribute(new QName(null, "href", "href", null),
+ "CDATA", style);
+ attrs.addAttribute(new QName(null, "type", "type", null),
+ "CDATA", "text/css");
+ attrs.addAttribute(new QName(null, "rel", "rel", null),
+ "CDATA", "stylesheet");
+ attrs.addAttribute(new QName(null, "class", "class", null),
+ "CDATA", className);
+ Augmentations augs = new HTMLAugmentations();
+ super.emptyElement(element, attrs, augs);
+ }
+
private void insertResources() {
headParsed = true;
if (null != _styles) {
for (Iterator iter = _styles.iterator(); iter.hasNext();) {
String style = (String) iter.next();
- QName element = new QName(null, "link", "link", null);
- XMLAttributes attrs = new XMLAttributesImpl();
- attrs.addAttribute(new QName(null, "href", "href", null),
- "CDATA", style);
- attrs.addAttribute(new QName(null, "type", "type", null),
- "CDATA", "text/css");
- attrs.addAttribute(new QName(null, "rel", "rel", null),
- "CDATA", "stylesheet");
- Augmentations augs = new HTMLAugmentations();
- super.emptyElement(element, attrs, augs);
+ insertStyle(style, COMPONENT_RESOURCE_LINK_CLASS);
}
}
+
+ if (null != _userStyles) {
+ for (Iterator iter = _userStyles.iterator(); iter.hasNext();) {
+ String style = (String) iter.next();
+ insertStyle(style, USER_RESOURCE_LINK_CLASS);
+ }
+ }
+
if (null != _scripts) {
for (Iterator iter = _scripts.iterator(); iter.hasNext();) {
String script = (String) iter.next();
Modified:
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java
===================================================================
---
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java 2008-04-08
19:45:38 UTC (rev 7681)
+++
branches/3.1.x/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java 2008-04-08
19:47:23 UTC (rev 7682)
@@ -59,6 +59,8 @@
private Set _styles;
+ private Set _userStyles;
+
private String _viewState;
private String _encoding;
@@ -138,7 +140,7 @@
}
// Inserts scripts and styles to head.
- if (null != _scripts || null != _styles || null != _viewState) {
+ if (null != _scripts || null != _styles || null != _userStyles || null != _viewState)
{
// find head
org.w3c.dom.Node head = documentElement
.getElementsByTagName("head").item(0);
@@ -168,9 +170,21 @@
style.setAttribute("type", "text/css");
style.setAttribute("rel", "stylesheet");
style.setAttribute("href", url);
+ style.setAttribute("class", COMPONENT_RESOURCE_LINK_CLASS);
head.insertBefore(style, child);
}
}
+ if (null != _userStyles) {
+ for (Iterator iter = _userStyles.iterator(); iter.hasNext();) {
+ String url = (String) iter.next();
+ Element style = document.createElement("link");
+ style.setAttribute("type", "text/css");
+ style.setAttribute("rel", "stylesheet");
+ style.setAttribute("href", url);
+ style.setAttribute("class", USER_RESOURCE_LINK_CLASS);
+ head.insertBefore(style, child);
+ }
+ }
// Scripts
if (null != _scripts) {
for (Iterator iter = _scripts.iterator(); iter
@@ -385,6 +399,10 @@
public void setStyles(Set styles) {
this._styles = styles;
}
+
+ public void setUserStyles(Set styles) {
+ this._userStyles = styles;
+ }
/*
* (non-Javadoc)