Author: alexsmirnov
Date: 2007-10-31 21:00:43 -0400 (Wed, 31 Oct 2007)
New Revision: 3661
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java
trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterBean.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletBean.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java
Log:
Continue to implement JSR-301 bridge. Finish requrements from PLT 6.
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2007-11-01
01:00:16 UTC (rev 3660)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2007-11-01
01:00:43 UTC (rev 3661)
@@ -56,8 +56,6 @@
import org.ajax4jsf.application.AjaxViewHandler;
import org.ajax4jsf.component.AjaxContainer;
import org.ajax4jsf.component.AjaxViewRoot;
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.context.ViewIdHolder;
import org.ajax4jsf.renderkit.AjaxContainerRenderer;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.HeaderResourceProducer;
@@ -794,8 +792,11 @@
"Illegal view Id for build AJAX Action URL: " + viewId);
}
ViewHandler viewHandler = context.getApplication().getViewHandler();
+ String actionURL = viewHandler.getActionURL(context, viewId);
+ // Mark Ajax action url as transparent with jsf-portlet bridge.
+ actionURL = actionURL +
((actionURL.lastIndexOf('?')>0)?"&":"?")+"javax.portlet.faces.DirectLink=true";
return context.getExternalContext().encodeActionURL(
- viewHandler.getActionURL(context, viewId));
+ actionURL);
}
/**
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java 2007-11-01
01:00:16 UTC (rev 3660)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java 2007-11-01
01:00:43 UTC (rev 3661)
@@ -110,7 +110,7 @@
}
}
}
- if(context.getResponseComplete()){
+ if (context.getResponseComplete()) {
ajaxContext.release();
}
}
@@ -132,27 +132,28 @@
AjaxContext.getCurrentInstance(context).setViewIdHolder(null);
UIViewRoot root = context.getViewRoot();
-if (null != root) {
- log.debug(Messages.getMessage(
- Messages.ENTER_BEFORE_RENDER_VIEW_PHASE, root.getViewId(),
- root.getRenderKitId()));
+ if (null != root) {
+ log.debug(Messages.getMessage(
+ Messages.ENTER_BEFORE_RENDER_VIEW_PHASE, root
+ .getViewId(), root.getRenderKitId()));
- // TODO - create special skin-config.xml configuration.
- String renderKitId = null;
- try {
- renderKitId = SkinFactory.getInstance().getSkin(context)
- .getRenderKitId(context);
- } catch (Exception e) {
- log.error("Exception on get current Skin ", e);
+ // TODO - create special skin-config.xml configuration.
+ String renderKitId = null;
+ try {
+ renderKitId = SkinFactory.getInstance().getSkin(context)
+ .getRenderKitId(context);
+ } catch (Exception e) {
+ log.error("Exception on get current Skin ", e);
+ }
+ if (null != renderKitId) {
+ log.debug(Messages.getMessage(
+ Messages.SET_RENDER_KIT_ID_INFO, renderKitId));
+ root.setRenderKitId(renderKitId);
+ }
+
}
- if (null != renderKitId) {
- log.debug(Messages.getMessage(Messages.SET_RENDER_KIT_ID_INFO,
- renderKitId));
- root.setRenderKitId(renderKitId);
- }
+ } else if (phaseId == PhaseId.RESTORE_VIEW) {
- } } else if (phaseId == PhaseId.RESTORE_VIEW) {
-
}
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java 2007-11-01
01:00:16 UTC (rev 3660)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java 2007-11-01
01:00:43 UTC (rev 3661)
@@ -46,8 +46,8 @@
*/
public class InitPhaseListener implements PhaseListener {
- private boolean removed= false;
- private boolean initialized = false;
+ private volatile boolean removed= false;
+ private volatile boolean initialized = false;
private static final Log log = LogFactory.getLog(InitPhaseListener.class);
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterBean.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterBean.java 2007-11-01
01:00:16 UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterBean.java 2007-11-01
01:00:43 UTC (rev 3661)
@@ -21,6 +21,7 @@
package org.ajax4jsf.webapp;
+import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@@ -29,7 +30,7 @@
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:58 $
*
*/
-public class FilterBean {
+public class FilterBean implements Serializable {
private String _filterName;
private String _filterClass;
private String _displayName;
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletBean.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletBean.java 2007-11-01
01:00:16 UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletBean.java 2007-11-01
01:00:43 UTC (rev 3661)
@@ -21,6 +21,7 @@
package org.ajax4jsf.webapp;
+import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@@ -29,7 +30,7 @@
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:59 $
*
*/
-public class ServletBean {
+public class ServletBean implements Serializable {
private String _servletName;
private String _servletClass;
private String _displayName;
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java 2007-11-01 01:00:16
UTC (rev 3660)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java 2007-11-01 01:00:43
UTC (rev 3661)
@@ -29,6 +29,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
@@ -58,16 +59,17 @@
public static final String CONTEXT_ATTRIBUTE = WebXml.class.getName();
/**
- *
- */
- private static final long serialVersionUID = -9042908418843695017L;
+ *
+ */
+ private static final long serialVersionUID = -9042908418843695017L;
private static final Log _log = LogFactory.getLog(WebXml.class);
static final String WEB_XML = "/WEB-INF/web.xml";
-
- public static final String RESOURCE_URI_PREFIX =
"a4j_"+VersionBean.MAJOR_VERSION+"_"+VersionBean.MINOR_VERSION+"_"+VersionBean.REVISION;
+ public static final String RESOURCE_URI_PREFIX = "a4j_"
+ + VersionBean.MAJOR_VERSION + "_" + VersionBean.MINOR_VERSION +
"_"
+ + VersionBean.REVISION;
static final String RESOURCE_URI_PREFIX_WITH_SLASH = "/"
+ RESOURCE_URI_PREFIX;
@@ -86,6 +88,10 @@
*/
private String _facesFilterSuffix = null;
+ private String _facesServletPrefix = null;
+
+ private String _facesServletSuffix = null;
+
private boolean _prefixMapping = false;
private String _filterName;
@@ -99,91 +105,109 @@
*/
private String _resourcePrefix = RESOURCE_URI_PREFIX_WITH_SLASH;
-
/**
* Parse application web.xml configuration and detect mapping for resources
* and logs.
+ *
* @param context
* @param filterName
* @throws ServletException
*/
- public void init(ServletContext context, String filterName) throws ServletException {
- InputStream webXml = context.getResourceAsStream(WEB_XML);
- if (null == webXml) {
- throw new ServletException(Messages.getMessage(
- Messages.GET_RESOURCE_AS_STREAM_ERROR, WEB_XML));
- }
- Digester dig = new Digester();
- dig.setDocumentLocator(new LocatorImpl());
- // Disable xml validations at all - web.xml already validated by
- // container
- dig.setValidating(false);
- dig.setEntityResolver(new EntityResolver() {
- // Dummi resolver - alvays do nothing
- public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException, IOException {
- return new InputSource(new StringReader(""));
- }
+ public void init(ServletContext context, String filterName)
+ throws ServletException {
+ InputStream webXml = context.getResourceAsStream(WEB_XML);
+ if (null == webXml) {
+ throw new ServletException(Messages.getMessage(
+ Messages.GET_RESOURCE_AS_STREAM_ERROR, WEB_XML));
+ }
+ Digester dig = new Digester();
+ dig.setDocumentLocator(new LocatorImpl());
+ // Disable xml validations at all - web.xml already validated by
+ // container
+ dig.setValidating(false);
+ dig.setEntityResolver(new EntityResolver() {
+ // Dummi resolver - alvays do nothing
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException, IOException {
+ return new InputSource(new StringReader(""));
+ }
- });
- dig.setNamespaceAware(false);
- // dig.setUseContextClassLoader(true);
- dig.setClassLoader(this.getClass().getClassLoader());
- // Parsing rules.
- // Servlets.
- String path = "web-app/servlet";
- dig.addObjectCreate(path, ServletBean.class);
- dig.addBeanPropertySetter(path + "/servlet-name",
"servletName");
- dig.addBeanPropertySetter(path + "/servlet-class",
"servletClass");
- dig.addBeanPropertySetter(path + "/display-name",
"displayName");
- dig.addBeanPropertySetter(path + "/description");
- dig.addSetNext(path, "addServlet");
- // Filters
- path = "web-app/filter";
- dig.addObjectCreate(path, FilterBean.class);
- dig.addBeanPropertySetter(path + "/filter-name", "filterName");
- dig.addBeanPropertySetter(path + "/filter-class",
"filterClass");
- dig.addBeanPropertySetter(path + "/display-name",
"displayName");
- dig.addBeanPropertySetter(path + "/description");
- dig.addSetNext(path, "addFilter");
- // Servlet mappings
- path = "web-app/servlet-mapping";
- dig.addCallMethod(path, "addServletMapping", 2);
- dig.addCallParam(path + "/servlet-name", 0);
- dig.addCallParam(path + "/url-pattern", 1);
- // Filter mappings
- // TODO - parse dispatcher.
- path = "web-app/filter-mapping";
- dig.addCallMethod(path, "addFilterMapping", 3);
- dig.addCallParam(path + "/filter-name", 0);
- dig.addCallParam(path + "/url-pattern", 1);
- dig.addCallParam(path + "/servlet-name", 2);
- dig.push(this);
- try {
- dig.parse(webXml);
- this.setFilterName(filterName, context);
- // Store Instance to context attribute.
- context.setAttribute(CONTEXT_ATTRIBUTE,this);
- } catch (IOException e) {
- String message = Messages
- .getMessage(Messages.PARSING_WEB_XML_IO_ERROR);
- _log.error(message, e);
- throw new ServletException(message, e);
- } catch (SAXException e) {
- String message = Messages
- .getMessage(Messages.PARSING_WEB_XML_SAX_ERROR);
- _log.error(message, e);
- throw new ServletException(message, e);
- } finally {
- try {
- webXml.close();
- } catch (IOException e) {
- // this exception don't affect any aspects of work and can be
- // ignored.
- }
- }
+ });
+ dig.setNamespaceAware(false);
+ // dig.setUseContextClassLoader(true);
+ dig.setClassLoader(this.getClass().getClassLoader());
+ // Parsing rules.
+ // Servlets.
+ String path = "web-app/servlet";
+ dig.addObjectCreate(path, ServletBean.class);
+ dig.addBeanPropertySetter(path + "/servlet-name", "servletName");
+ dig.addBeanPropertySetter(path + "/servlet-class",
"servletClass");
+ dig.addBeanPropertySetter(path + "/display-name", "displayName");
+ dig.addBeanPropertySetter(path + "/description");
+ dig.addSetNext(path, "addServlet");
+ // Filters
+ path = "web-app/filter";
+ dig.addObjectCreate(path, FilterBean.class);
+ dig.addBeanPropertySetter(path + "/filter-name", "filterName");
+ dig.addBeanPropertySetter(path + "/filter-class", "filterClass");
+ dig.addBeanPropertySetter(path + "/display-name", "displayName");
+ dig.addBeanPropertySetter(path + "/description");
+ dig.addSetNext(path, "addFilter");
+ // Servlet mappings
+ path = "web-app/servlet-mapping";
+ dig.addCallMethod(path, "addServletMapping", 2);
+ dig.addCallParam(path + "/servlet-name", 0);
+ dig.addCallParam(path + "/url-pattern", 1);
+ // Filter mappings
+ // TODO - parse dispatcher.
+ path = "web-app/filter-mapping";
+ dig.addCallMethod(path, "addFilterMapping", 3);
+ dig.addCallParam(path + "/filter-name", 0);
+ dig.addCallParam(path + "/url-pattern", 1);
+ dig.addCallParam(path + "/servlet-name", 2);
+ dig.push(this);
+ try {
+ dig.parse(webXml);
+ this.setFilterName(filterName, context);
+ this.findFacesServlet(context);
+ // Store Instance to context attribute.
+ context.setAttribute(CONTEXT_ATTRIBUTE, this);
+ } catch (IOException e) {
+ String message = Messages
+ .getMessage(Messages.PARSING_WEB_XML_IO_ERROR);
+ _log.error(message, e);
+ throw new ServletException(message, e);
+ } catch (SAXException e) {
+ String message = Messages
+ .getMessage(Messages.PARSING_WEB_XML_SAX_ERROR);
+ _log.error(message, e);
+ throw new ServletException(message, e);
+ } finally {
+ try {
+ webXml.close();
+ } catch (IOException e) {
+ // this exception don't affect any aspects of work and can be
+ // ignored.
+ }
+ }
}
+ private void findFacesServlet(ServletContext context) {
+ for (Iterator<Entry<String, ServletBean>> servletsIterator = _servlets
+ .entrySet().iterator(); servletsIterator.hasNext();) {
+ Entry<String, ServletBean> servletEntry = servletsIterator.next();
+ String servletClass = servletEntry.getValue().getServletClass();
+ if("javax.faces.webapp.FacesServlet".equals(servletClass)){
+ Mapping mapping = checkMapping(servletEntry.getValue().getMappings());
+ if(null != mapping){
+ this._facesServletPrefix = mapping.getPrefix();
+ this._facesServletSuffix = mapping.getSuffix();
+ }
+ }
+ }
+
+ }
+
public void addServlet(ServletBean bean) {
String name = bean.getServletName();
if (null != name) {
@@ -220,12 +244,11 @@
}
/**
- * Convert {@link org.ajax4jsf.resource.InternetResource } key to
- * real URL for handle by chameleon filter, depend of mapping in WEB.XML .
- * For prefix or * mapping, prepend servlet prefix and default Resource
- * prefix to key. For suffix mapping, prepend with resource prefix and
- * append default faces suffix to URL ( before request param ). After
- * conversion, call
+ * Convert {@link org.ajax4jsf.resource.InternetResource } key to real URL
+ * for handle by chameleon filter, depend of mapping in WEB.XML . For prefix
+ * or * mapping, prepend servlet prefix and default Resource prefix to key.
+ * For suffix mapping, prepend with resource prefix and append default faces
+ * suffix to URL ( before request param ). After conversion, call
* {@link
javax.faces.application.ViewHandler#getResourceURL(javax.faces.context.FacesContext,
java.lang.String)}
* and
* {@link javax.faces.context.ExternalContext#encodeResourceURL(java.lang.String)} .
@@ -360,7 +383,8 @@
*
* @param filterName
* The filterName to set.
- * @param context TODO
+ * @param context
+ * TODO
*/
void setFilterName(String filterName, ServletContext context) {
if (null == filterName) {
@@ -377,21 +401,30 @@
Messages.FILTER_NOT_FOUND_ERROR, filterName));
}
// find faces servlet
- checkMapping(filter.getMappings());
+ Mapping mapping = checkMapping(filter.getMappings());
// Filter mapped only to servlet.
- if (_facesFilterPrefix == null && _facesFilterSuffix == null) {
+ if (null == mapping) {
for (Iterator sevlets = filter.getServlets().iterator(); sevlets
.hasNext()
&& _facesFilterPrefix == null && _facesFilterSuffix == null;) {
String servletname = (String) sevlets.next();
ServletBean servlet = (ServletBean) _servlets.get(servletname);
if (null != servlet) {
- checkMapping(servlet.getMappings());
+ mapping = checkMapping(servlet.getMappings());
}
}
}
- String resourcePrefix = (String) context.getAttribute(RESOURCE_URI_PREFIX_PARAM);
- if(null == resourcePrefix){
+ if (null != mapping) {
+ setFacesFilterPrefix(mapping.getPrefix());
+ setFacesFilterSuffix(mapping.getSuffix());
+ } else {
+ throw new IllegalStateException(Messages.getMessage(
+ Messages.NO_PREFIX_OR_SUFFIX_IN_FILTER_MAPPING_ERROR,
+ filterName));
+ }
+ String resourcePrefix = (String) context
+ .getAttribute(RESOURCE_URI_PREFIX_PARAM);
+ if (null == resourcePrefix) {
resourcePrefix = RESOURCE_URI_PREFIX;
}
if (null != _facesFilterPrefix) {
@@ -399,37 +432,42 @@
if (_facesFilterPrefix.endsWith("/")) {
setResourcePrefix(resourcePrefix);
} else {
- setResourcePrefix("/"+resourcePrefix);
+ setResourcePrefix("/" + resourcePrefix);
}
} else if (null != _facesFilterSuffix) {
_prefixMapping = false;
- setResourcePrefix("/"+resourcePrefix);
- } else {
- throw new IllegalStateException(Messages.getMessage(
- Messages.NO_PREFIX_OR_SUFFIX_IN_FILTER_MAPPING_ERROR,
- filterName));
+ setResourcePrefix("/" + resourcePrefix);
}
}
- private void checkMapping(Set mappings) {
+ private Mapping checkMapping(Set mappings) {
+ Mapping mapping = null;
if (null != mappings) {
for (Iterator iter = mappings.iterator(); iter.hasNext();) {
- String mapping = (String) iter.next();
+ String mappingPattern = (String) iter.next();
// first test - for prefix, like /xxx/*
// TODO - select correct dispatcher.
- if (mapping.endsWith("*")) {
- setFacesFilterPrefix(mapping.substring(0,
- mapping.length() - 1));
+ if (mappingPattern.endsWith("*")) {
+ if (null == mapping) {
+ mapping = new Mapping();
+ }
+ int cut = mappingPattern.endsWith("/*")?2:1;
+ mapping.setPrefix(mappingPattern.substring(0,
+ mappingPattern.length() - cut));
break;
} else
// test for suffix mapping, eg *.xxx
- if (mapping.startsWith("*")) {
- setFacesFilterSuffix(mapping.substring(1));
+ if (mappingPattern.startsWith("*")) {
+ if (null == mapping) {
+ mapping = new Mapping();
+ }
+ mapping.setSuffix(mappingPattern.substring(1));
} else {
// Fixed mapping - do not use it.
}
}
}
+ return mapping;
}
/**
@@ -438,4 +476,53 @@
public boolean isPrefixMapping() {
return _prefixMapping;
}
+
+ private static class Mapping {
+ private String prefix;
+ private String suffix;
+
+ /**
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * @param prefix
+ * the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * @return the suffix
+ */
+ public String getSuffix() {
+ return suffix;
+ }
+
+ /**
+ * @param suffix
+ * the suffix to set
+ */
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+ }
+
+ /**
+ * @return the facesServletPrefix
+ */
+ public String getFacesServletPrefix() {
+ return _facesServletPrefix;
+ }
+
+ /**
+ * @return the facesServletSuffix
+ */
+ public String getFacesServletSuffix() {
+ return _facesServletSuffix;
+ }
}