Author: alexsmirnov
Date: 2007-07-09 20:58:39 -0400 (Mon, 09 Jul 2007)
New Revision: 1559
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterServletResponseWrapper.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/HtmlParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/Log4JConfigurator.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/NekkoFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserConfig.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletStreamWriter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/TidyFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/XMLResponseWriterState.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionState.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java
Removed:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContent.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/FilterServletResponseWrapper.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/HtmlParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/Log4JConfigurator.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ParserConfig.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/PollEventsManager.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ServletStreamWriter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/TidyFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/XMLResponseWriterState.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionState.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/FastFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/Filter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/HeaderResourcesRendererBase.java
trunk/framework/impl/src/main/java/org/ajax4jsf/io/parser/FastHtmlParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/CachedResourceContext.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceService.java
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
trunk/framework/impl/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/HtmlCorrectionFilterTestCase.java
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/AllTests.java
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContentTest.java
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoParserTest.java
trunk/framework/test/src/test/java/org/ajax4jsf/framework/renderer/BeforeRendererListenerTestCase.java
trunk/ui/core/src/main/java/org/ajax4jsf/component/UIPush.java
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/AjaxPageRenderer.java
Log:
packages and classes refactor in the "impl" project
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/FastFilter.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/FastFilter.java 2007-07-10 00:39:15
UTC (rev 1558)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/FastFilter.java 2007-07-10 00:58:39
UTC (rev 1559)
@@ -22,6 +22,6 @@
package org.ajax4jsf;
public class FastFilter extends
- org.ajax4jsf.framework.ajax.xmlfilter.NekkoFilter {
+ org.ajax4jsf.webapp.NekkoFilter {
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/Filter.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/Filter.java 2007-07-10 00:39:15 UTC
(rev 1558)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/Filter.java 2007-07-10 00:58:39 UTC
(rev 1559)
@@ -21,7 +21,7 @@
package org.ajax4jsf;
-import org.ajax4jsf.framework.ajax.xmlfilter.ConfigurableFilter;
+import org.ajax4jsf.webapp.ConfigurableFilter;
/**
* Proxy for resource/ajax xml parsing filter.
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -58,12 +58,12 @@
import org.ajax4jsf.component.AjaxViewRoot;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.context.ViewIdHolder;
-import org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter;
-import org.ajax4jsf.framework.ajax.xmlfilter.FilterServletResponseWrapper;
import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
import org.ajax4jsf.renderkit.HeaderResourceProducer;
+import org.ajax4jsf.webapp.BaseFilter;
+import org.ajax4jsf.webapp.FilterServletResponseWrapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.richfaces.skin.Skin;
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseFilter.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,388 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.Date;
-import java.util.Enumeration;
-
-import javax.faces.application.ViewHandler;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.ajax.PushEventsCounter;
-import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
-import org.ajax4jsf.resource.InternetResourceService;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Base class for request processing filters, with convert Htmp content to XML
- * for ajax requests, and serve request to application off-page resources
- *
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:21 $
- *
- */
-public abstract class BaseFilter implements Filter {
-
- public static final String AJAX_PUSH_KEY_HEADER = "Ajax-Push-Key";
-
- private static final Log log = LogFactory.getLog(BaseFilter.class);
-
- public static final boolean DEBUG = true;
-
- private FilterConfig filterConfig;
-
- private static final String FUNCTION_NAME_PARAMETER = "function";
-
- private String function = "alert('Data
received');JSHttpRequest.dataReady";
-
- private String attributesNames;
-
- private boolean rewriteid = false;
-
- public static final String REWRITEID_PARAMETER = "rewriteid";
-
- public static final String STYLESHEET_PARAMETER = "xsl";
-
- public static final String ABSOLUTE_TAGS_PARAMETER =
"absolute-attributes";
-
- // private WebXml webXml;
- // private String xsl;
- // private Templates xslTemplates;
- /**
- *
- */
- private static final long serialVersionUID = -2295534611886142935L;
-
- public static final String DATA_PARAMETER = "DATA";
-
- public static final String DEFAULT_SERVLET_PATH = "/resource";
-
- public static final String RENDERER_PREFIX = "/renderer";
-
- public static final String CACHEABLE_PREFIX = "/cache";
-
- // private static final Pattern rendererPattern =
- // Pattern.compile(RENDERER_PREFIX+"/([^/]+)/([^/]+)/([^/]+)/(.*)");
- // private static final Pattern builderPattern =
- // Pattern.compile(CACHEABLE_PREFIX+"/(.*)");
- public static final String FILTER_PERFORMED = "com.exade.vcp.Filter.done";
-
- public static final String RESPONSE_WRAPPER_ATTRIBUTE =
"com.exade.vcp.Filter.ResponseWrapper";
-
- protected BaseXMLFilter xmlFilter = null;
-
- protected InternetResourceService resourceService = null;
-
- protected PollEventsManager eventsManager;
-
- /**
- * Initialize the filter.
- */
- public void init(FilterConfig config) throws ServletException {
- if (log.isDebugEnabled()) {
- log.debug("Init ajax4jsf filter with nane: "
- + config.getFilterName());
- Enumeration parameterNames = config.getInitParameterNames();
- StringBuffer parameters = new StringBuffer("Init parameters :\n");
- while (parameterNames.hasMoreElements()) {
- String name = (String) parameterNames.nextElement();
- parameters.append(name).append(" : '").append(
- config.getInitParameter(name)).append('\n');
- }
- log.debug(parameters);
- // log.debug("Stack Trace", new Exception());
- }
- // Save config
- filterConfig = config;
- setFunction((String) nz(filterConfig
- .getInitParameter(FUNCTION_NAME_PARAMETER), getFunction()));
- setAttributesNames(filterConfig
- .getInitParameter(ABSOLUTE_TAGS_PARAMETER));
- xmlFilter.init(config);
- if ("true".equalsIgnoreCase(filterConfig
- .getInitParameter(REWRITEID_PARAMETER))) {
- this.setRewriteid(true);
- }
-
- String prefix = filterConfig.getServletContext().getRealPath("/");
- String file = filterConfig.getInitParameter("log4j-init-file");
- // if the log4j-init-file is not set, then no point in trying
- if (file != null) {
- Log4JConfigurator log4jconfig = new Log4JConfigurator(prefix);
- log4jconfig.doConfigure(file);
- }
- resourceService = new InternetResourceService();
- // Caching initialization.
- resourceService.init(filterConfig);
- eventsManager = new PollEventsManager();
- eventsManager.init(filterConfig.getServletContext());
- }
-
- /**
- * @param httpServletRequest
- * @throws UnsupportedEncodingException
- */
- protected void setupRequestEncoding(HttpServletRequest httpServletRequest)
- throws UnsupportedEncodingException {
- String contentType = httpServletRequest.getHeader("Content-Type");
-
- String characterEncoding = lookupCharacterEncoding(contentType);
-
- if (characterEncoding == null) {
- HttpSession session = httpServletRequest.getSession(false);
-
- if (session != null) {
- characterEncoding = (String) session
- .getAttribute(ViewHandler.CHARACTER_ENCODING_KEY);
- }
-
- if (characterEncoding != null) {
- httpServletRequest.setCharacterEncoding(characterEncoding);
- }
- }
- }
-
- /**
- * Detect request encoding from Content-Type header
- *
- * @param contentType
- * @return - charset, if present.
- */
- private String lookupCharacterEncoding(String contentType) {
- String characterEncoding = null;
-
- if (contentType != null) {
- int charsetFind = contentType.indexOf("charset=");
- if (charsetFind != -1) {
- if (charsetFind == 0) {
- // charset at beginning of Content-Type, curious
- characterEncoding = contentType.substring(8);
- } else {
- char charBefore = contentType.charAt(charsetFind - 1);
- if (charBefore == ';' || Character.isWhitespace(charBefore)) {
- // Correct charset after mime type
- characterEncoding = contentType
- .substring(charsetFind + 8);
- }
- }
- if (log.isDebugEnabled())
- log.debug(Messages.getMessage(
- Messages.CONTENT_TYPE_ENCODING, characterEncoding));
- } else {
- if (log.isDebugEnabled())
- log.debug(Messages.getMessage(
- Messages.CONTENT_TYPE_NO_ENCODING, contentType));
- }
- }
- return characterEncoding;
- }
-
- /**
- * @param initParameter
- * @param function2
- * @return
- */
- private Object nz(Object param, Object def) {
- return param != null ? param : def;
- }
-
- /**
- * Execute the filter.
- */
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
- long startTimeMills = 0;
- // Detect case of request - normal, AJAX, AJAX - JavaScript
- // TODO - detect first processing in filter.
- HttpServletRequest httpServletRequest = (HttpServletRequest) request;
- HttpServletResponse httpServletResponse = (HttpServletResponse) response;
- if (log.isDebugEnabled()) {
- startTimeMills = System.currentTimeMillis();
- log.debug(Messages.getMessage(Messages.FILTER_START_INFO, new Date(
- startTimeMills), httpServletRequest.getRequestURI()));
- }
-
- if (request.getAttribute(FILTER_PERFORMED) != Boolean.TRUE) {
- // mark - and not processing same request twice.
- request.setAttribute(FILTER_PERFORMED, Boolean.TRUE);
- String ajaxPushHeader = httpServletRequest.getHeader(AJAX_PUSH_KEY_HEADER);
- // check for a push check request.
- if (httpServletRequest.getMethod().equals("HEAD")
- && null != ajaxPushHeader) {
- PushEventsCounter listener = eventsManager.getListener(ajaxPushHeader);
- if(listener.isPerformed()){
- listener.processed();
- httpServletResponse.setStatus(200);
- if (log.isDebugEnabled()) {
- log.debug("Occurs event for a id "+ajaxPushHeader);
- }
- } else {
- // Response code - 'No content'
- httpServletResponse.setStatus(204);
- if (log.isDebugEnabled()) {
- log.debug("No event for a id "+ajaxPushHeader);
- }
- }
- } else
- // check for resource request
- 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);
- // check ajax request parameter
- // TODO - check for JSF page.
- if (true) {
- if (log.isDebugEnabled()) {
- log.debug(Messages
- .getMessage(Messages.FILTER_XML_OUTPUT));
- }
-
- // Execute the rest of the filter chain, including the
- // JSP
- xmlFilter.doXmlFilter(chain, httpServletRequest,
- httpServletResponse);
- } else {
- // normal request, execute chain ...
- if (log.isDebugEnabled()) {
- log.debug(Messages
- .getMessage(Messages.FILTER_NO_XML_CHAIN));
- }
- chain.doFilter(request, response);
-
- }
- }
- } else {
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.FILTER_NO_XML_CHAIN_2));
- }
- chain.doFilter(request, response);
-
- }
- if (log.isDebugEnabled()) {
- startTimeMills = System.currentTimeMillis() - startTimeMills;
- log.debug(Messages.getMessage(Messages.FILTER_STOP_INFO, ""
- + startTimeMills, httpServletRequest.getRequestURI()));
- }
- }
-
- /**
- * @param request
- * @return
- */
- protected boolean isAjaxRequest(ServletRequest request) {
- try {
- return null != request
- .getParameter(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
- } catch (Exception e) {
- // OCJ 10 - throw exception for static resources.
- return false;
- }
- }
-
- /**
- * Destroy the filter.
- */
- public void destroy() {
- }
-
- /**
- * @return Returns the servletContext.
- */
- ServletContext getServletContext() {
- return filterConfig.getServletContext();
- }
-
- /**
- * @return the resourceService
- * @throws ServletException
- */
- protected synchronized InternetResourceService getResourceService()
- throws ServletException {
- // if (resourceService == null) {
- // resourceService = new InternetResourceService();
- // // Caching initialization.
- // resourceService.init(filterConfig);
- //
- // }
- return resourceService;
- }
-
- /**
- * @param function
- * The function to set.
- */
- protected void setFunction(String function) {
- this.function = function;
- }
-
- /**
- * @return Returns the function.
- */
- protected String getFunction() {
- return function;
- }
-
- /**
- * @param rewriteid
- * The rewriteid to set.
- */
- protected void setRewriteid(boolean rewriteid) {
- this.rewriteid = rewriteid;
- }
-
- /**
- * @return Returns the rewriteid.
- */
- protected boolean isRewriteid() {
- return rewriteid;
- }
-
- /**
- * @param attributesNames
- * The attributesNames to set.
- */
- protected void setAttributesNames(String attributesNames) {
- this.attributesNames = attributesNames;
- }
-
- /**
- * @return Returns the attributesNames.
- */
- protected String getAttributesNames() {
- return attributesNames;
- }
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,429 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.ServletRequest;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.application.AjaxViewHandler;
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public abstract class BaseXMLFilter {
- private static final Log log = LogFactory.getLog(BaseXMLFilter.class);
-
- public static final String RESPONSE_WRAPPER_ATTRIBUTE =
"com.exade.vcp.Filter.ResponseWrapper";
-
- private String mimetype = "text/xml";
-
- private String publicid = "-//W3C//DTD XHTML 1.0 Transitional//EN";
-
- private String systemid =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
-
- private String namespace = "http://www.w3.org/1999/xhtml";
-
- private static final String MIME_TYPE_PARAMETER = "mime-type";
-
- private static final String PUBLICID_PARAMETER = "publicid";
-
- private static final String SYSTEMID_PARAMETER = "systemid";
-
- private static final String NAMESPACE_PARAMETER = "namespace";
-
- private boolean forcexml = false;
-
-
- private static final String FORCEXML_PARAMETER = "forceparser";
-
- private static final String INIT_PARAMETER_PREFIX =
"org.ajax4jsf.xmlfilter.";
-
- public BaseFilter filter;
-
- public void setFilter(BaseFilter filter) {
- this.filter = filter;
- }
-
- public void init(FilterConfig config) throws ServletException {
- if (log.isDebugEnabled()) {
- log.debug("init XML filter service with class "
- + this.getClass().getName());
- }
- String forceXmlParameter = config
- .getInitParameter(FORCEXML_PARAMETER);
- setupForceXml(forceXmlParameter);
- forceXmlParameter =
config.getServletContext().getInitParameter(INIT_PARAMETER_PREFIX+FORCEXML_PARAMETER);
- setMimetype((String) nz(config.getInitParameter(MIME_TYPE_PARAMETER),
- "text/xml"));
- setPublicid((String) nz(config.getInitParameter(PUBLICID_PARAMETER),
- getPublicid()));
- setSystemid((String) nz(config.getInitParameter(SYSTEMID_PARAMETER),
- getSystemid()));
- setNamespace((String) nz(config.getInitParameter(NAMESPACE_PARAMETER),
- getNamespace()));
- }
-
- /**
- * @param forceXmlParameter
- */
- private void setupForceXml(String forceXmlParameter) {
- if ("false".equalsIgnoreCase(forceXmlParameter)) {
- this.forcexml = false;
- }
- if ("true"
- .equalsIgnoreCase(forceXmlParameter)) {
- this.forcexml = true;
- }
- }
-
- /**
- * Perform filter chain with xml parsing and transformation. Subclasses
- * must implement concrete HTML to XML parsing, nesseasary
- * transformations and serialization.
- *
- * @param chain
- * @param httpServletRequest
- * @param httpServletResponse
- * @throws ServletException
- * @throws IOException
- */
- protected void doXmlFilter(FilterChain chain, HttpServletRequest request,
- final HttpServletResponse response) throws IOException,
- ServletException {
- if (log.isDebugEnabled()) {
- log.debug("XML filter service start processing request");
- }
- FilterServletResponseWrapper servletResponseWrapper = getWrapper(response);
- // HACK - to avoid MyFaces <f:view> incompabilites and bypass
- // intermediaty filters
- // in chain, self-rendered region write directly to wrapper stored in
- // request-scope attribute.
- request
- .setAttribute(RESPONSE_WRAPPER_ATTRIBUTE,
- servletResponseWrapper);
- chain.doFilter(request, servletResponseWrapper);
- String viewId = (String) request.getAttribute(AjaxViewHandler.VIEW_ID_KEY);
- HtmlParser parser = null;
- // setup response
- // Redirect in AJAX request - convert to special response recognized by
- // client.
- String redirectLocation = servletResponseWrapper.getRedirectLocation();
- String characterEncoding = servletResponseWrapper
- .getCharacterEncoding();
- Writer output;
- if (null != redirectLocation) {
- if (isAjaxRequest(request)) {
- // Special handling of redirect - client-side script must
- // Check for response and perform redirect by window.location
- if (log.isDebugEnabled()) {
- log.debug("Create AJAX redirect response to url: "
- + redirectLocation);
- }
- response.reset();
- // Keep cookies.
- for (Iterator iter = servletResponseWrapper.getCookies().iterator(); iter.hasNext();)
{
- Cookie cookie = (Cookie) iter.next();
- response.addCookie(cookie);
- }
- // Copy response headers
- Map headers = servletResponseWrapper.getHeaders();
- for (Iterator iter = headers.entrySet().iterator(); iter
- .hasNext();) {
- Map.Entry header = (Map.Entry) iter.next();
- response.setHeader((String) header.getKey(),
- (String) header.getValue());
- }
- response.setHeader(AjaxContainerRenderer.AJAX_FLAG_HEADER,
- "redirect");
- // Not caching AJAX request
- response.setHeader("Cache-Control",
- "no-cache, must-revalidate, max_age=0, no-store");
- response.setHeader("Expires", "0");
- response.setHeader("Pragma", "no-cache");
- response.setContentType(getMimetype() + ";charset=UTF-8");
- response.setHeader(AjaxContainerRenderer.AJAX_LOCATION_HEADER,
- redirectLocation);
- output = createResponseWriter(response, "UTF-8");
- // For buggy XmlHttpRequest realisations repeat headers in
- // <meta>
- output.write("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n"
- + "<html
xmlns=\"http://www.w3.org/1999/xhtml\"><head>"
- + "<meta name=\""
- + AjaxContainerRenderer.AJAX_FLAG_HEADER
- + "\" content=\"redirect\" />" + "<meta
name=\""
- + AjaxContainerRenderer.AJAX_LOCATION_HEADER
- + "\" content=\"" + redirectLocation + "\" />"
- + "</head></html>");
- output.flush();
- response.flushBuffer();
- } else {
- response.sendRedirect(redirectLocation);
- }
- return;
- } else if ("true".equals(servletResponseWrapper.getHeaders().get(
- AjaxContainerRenderer.AJAX_FLAG_HEADER))) {
- if (log.isDebugEnabled()) {
- log
- .debug("Process response to well-formed XML for AJAX XMLHttpRequest
parser");
- }
- // Not caching AJAX request
- response.setHeader("Cache-Control",
- "no-cache, must-revalidate, max_age=0, no-store");
- response.setHeader("Expires", "0");
- response.setHeader("Pragma", "no-cache");
- // response.setCharacterEncoding(servletResponseWrapper
- // .getCharacterEncoding()); //
- // JSContentHandler.DEFAULT_ENCODING);
- // Set the content-type. For AJAX responses default encoding -
- // UTF8.
- // TODO - for null encoding, setup only Output encoding for
- // filter ?
- String outputEncoding = "UTF-8";
- String contentType = getMimetype() + ";charset=" + outputEncoding;
- response.setContentType(contentType);
- parser = getParser(getMimetype(), true, viewId);
- if (null == parser) {
- throw new ServletException(Messages.getMessage(
- Messages.PARSER_NOT_INSTANTIATED_ERROR, contentType));
- }
- output = createResponseWriter(response, outputEncoding);
- parser.setDoctype(getPublicid());
- parser.setInputEncoding(characterEncoding);
- parser.setOutputEncoding(outputEncoding);
- parser.setViewState((String) request
- .getAttribute(AjaxViewHandler.SERIALIZED_STATE_KEY));
- } else {
- // setup conversion reules for output contentType, send directly
- // if content not
- // supported by tidy.
- String contentType = servletResponseWrapper.getContentType();
- if (log.isDebugEnabled()) {
- log.debug("create HTML/XML parser for content type: "
- + contentType);
- }
- // if(contentType == null){
- // contentType = request.getContentType();
- // }
- if (contentType != null) {
- if (contentType.indexOf("charset") < 0
- && null != characterEncoding) {
- contentType += ";charset=" + characterEncoding;
- }
- parser = getParser(contentType, false, viewId);
- response.setContentType(contentType);
- }
- // null or unsupported content type
- if (null == parser) {
- if (log.isDebugEnabled()) {
- log
- .debug("Parser not have support for the such content type, send response
as-is");
- }
- try {
- if (servletResponseWrapper.isUseWriter()) {
- output = createResponseWriter(response,
- characterEncoding);
- servletResponseWrapper.sendContent(output);
- } else if (servletResponseWrapper.isUseStream()) {
- ServletOutputStream out = response.getOutputStream();
- servletResponseWrapper.sendContent(out);
- }
- } finally {
- // reuseWrapper(servletResponseWrapper);
- }
- return;
- }
- output = createResponseWriter(response, characterEncoding);
-
- parser.setInputEncoding(characterEncoding);
- parser.setOutputEncoding(characterEncoding);
- }
-
- try {
- // Setup scripts and styles
- parser.setScripts((Set) request
- .getAttribute(AjaxContext.SCRIPTS_PARAMETER));
- parser.setStyles((Set) request
- .getAttribute(AjaxContext.STYLES_PARAMETER));
- // Process parsing.
- long startTimeMills = System.currentTimeMillis();
- servletResponseWrapper.parseContent(output, parser);
- if (log.isDebugEnabled()) {
- startTimeMills = System.currentTimeMillis() - startTimeMills;
- log.debug(Messages.getMessage(Messages.PARSING_TIME_INFO, ""
- + startTimeMills));
- }
- } catch (Exception e) {
- throw new ServletException(Messages
- .getMessage(Messages.JTIDY_PARSING_ERROR), e);
- } finally {
- reuseParser(parser);
- }
- }
-
- /**
- * @param response
- * @return
- * @throws ServletException
- */
- protected FilterServletResponseWrapper getWrapper(
- HttpServletResponse response) throws ServletException {
- return new FilterServletResponseWrapper(response);
- }
-
- /**
- * @param request
- * @return
- */
- protected boolean isAjaxRequest(ServletRequest request) {
- try {
- return null != request
- .getParameter(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
- } catch (Exception e) {
- // OCJ 10 - throw exception for static resources.
- return false;
- }
- }
-
- /**
- * @param response
- * @param characterEncoding
- * @return
- * @throws IOException
- * @throws UnsupportedEncodingException
- */
- private Writer createResponseWriter(final HttpServletResponse response,
- String characterEncoding) throws IOException,
- UnsupportedEncodingException {
- Writer output;
- try {
- output = response.getWriter();
- } catch (IllegalStateException e) {
- if (null != characterEncoding) {
- output = new OutputStreamWriter(response.getOutputStream(),
- characterEncoding);
- } else {
- output = new OutputStreamWriter(response.getOutputStream());
- }
- }
- return output;
- }
-
- protected abstract void reuseParser(HtmlParser parser);
-
- protected abstract HtmlParser getParser(String mimetype, boolean isAjax, String
viewId);
-
- /**
- * @param publicid
- * The publicid to set.
- */
- protected void setPublicid(String publicid) {
- this.publicid = publicid;
- }
-
- /**
- * @return Returns the publicid.
- */
- public String getPublicid() {
- return publicid;
- }
-
- /**
- * @param systemid
- * The systemid to set.
- */
- protected void setSystemid(String systemid) {
- this.systemid = systemid;
- }
-
- /**
- * @return Returns the systemid.
- */
- public String getSystemid() {
- return systemid;
- }
-
- /**
- * @param namespace
- * The namespace to set.
- */
- protected void setNamespace(String namespace) {
- this.namespace = namespace;
- }
-
- /**
- * @return Returns the namespace.
- */
- public String getNamespace() {
- return namespace;
- }
-
- /**
- * @param mimetype
- * The mimetype to set.
- */
- protected void setMimetype(String mimetype) {
- this.mimetype = mimetype;
- }
-
- /**
- * @return Returns the mimetype.
- */
- protected String getMimetype() {
- return mimetype;
- }
-
- /**
- * @return Returns the forcexml.
- */
- public boolean isForcexml() {
- return this.forcexml;
- }
-
- /**
- * @param forcexml
- * The forcexml to set.
- */
- protected void setForcexml(boolean forcexml) {
- this.forcexml = forcexml;
- }
-
- private Object nz(Object param, Object def) {
- return param != null ? param : def;
- }
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContent.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContent.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContent.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,277 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.Serializable;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletResponse;
-
-import org.ajax4jsf.io.FastBufferOutputStream;
-import org.ajax4jsf.io.FastBufferWriter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:20 $
- *
- */
-public class CacheContent implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 8120940486890871177L;
-
- private static final Log _log = LogFactory.getLog(CacheContent.class);
-
- // private transient ByteArrayOutputStream outputStream ;
- private transient FastBufferOutputStream outputStream;
-
- private transient FastBufferWriter stringOutputWriter;
-
- private transient PrintWriter servletWriter;
-
- private transient ServletOutputStream servletStream;
-
- // content to send.
- private byte[] content = null;
-
- private String writerContent = null;
-
- boolean filledOutputStream = false;
-
- boolean filledOutputWriter = false;
-
- private Map headers = new HashMap();
-
- private String contentType;
-
- /**
- * Send saved content to http responce
- *
- * @param response
- * @throws IOException
- */
- public void send(HttpServletResponse response) throws IOException {
- if (filledOutputStream) {
- OutputStream out = response.getOutputStream();
- if (content != null) {
- out.write(content);
- } else {
- this.outputStream.writeTo(out);
- }
- // out.flush();
- // out.close();
- } else if (filledOutputWriter) {
- Writer out = response.getWriter();
- if (null != writerContent) {
- out.write(writerContent);
- } else {
- stringOutputWriter.writeTo(out);
- }
- // out.flush();
- // out.close();
- }
- }
-
- /**
- * Send saved headers to http responce.
- *
- * @param response
- */
- public void sendHeaders(HttpServletResponse response) {
- for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
- Map.Entry element = (Map.Entry) iter.next();
- String header = (String) element.getKey();
- Object headerValue = element.getValue();
- try {
- if (headerValue instanceof Long) {
- Long time = (Long) headerValue;
- response.setDateHeader(header, time.longValue());
- } else if (headerValue instanceof Integer) {
- Integer value = (Integer) headerValue;
- response.setIntHeader(header, value.intValue());
- } else {
- response.setHeader(header, (String) headerValue);
- }
-
- } catch (Exception e) {
- _log.error("Error set response header "+header+"for value
"+headerValue, e);
- }
- // set real content-length.
- // / if (null != content) {
- if (filledOutputStream) {
- // / response.setIntHeader("Content-Length", content.length);
- response.setIntHeader("Content-Length", outputStream
- .getLength());
- } // TODO - calculate content-lenght for writer ?
- if (null != contentType) {
- response.setContentType(this.contentType);
- }
- }
- }
-
- public void setDateHeader(String name, long value) {
- // Expires not stored in cache - must be re-calculated for every
- // response.
- if (!"Expires".equals(name)) {
- headers.put(name, new Long(value));
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.resource.ResourceContext#setHeader(java.lang.String,
- * java.lang.String)
- */
- public void setHeader(String name, String value) {
- headers.put(name, value);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.resource.ResourceContext#setIntHeader(java.lang.String,
- * int)
- */
- public void setIntHeader(String name, int value) {
- headers.put(name, new Integer(value));
- }
-
- /**
- * Create UNIX command 'tee' like stream - send all data to servlet
- *
- * @param responseStream
- * @return
- */
- public OutputStream getOutputStream() {
- if (null == servletStream) {
- outputStream = new FastBufferOutputStream(1024);
- servletStream = new ServletOutputStream() {
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.OutputStream#close()
- */
- public void close() throws IOException {
- filledOutputStream = true;
- // / content = outputStream.toByteArray();
- content = null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.OutputStream#flush()
- */
- public void flush() throws IOException {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.OutputStream#write(byte[], int, int)
- */
- public void write(byte[] b, int off, int len)
- throws IOException {
- outputStream.write(b, off, len);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.OutputStream#write(byte[])
- */
- public void write(byte[] b) throws IOException {
- outputStream.write(b);
- }
-
- public void write(int b) throws IOException {
- outputStream.write(b);
- }
-
- };
- }
- return servletStream;
- }
-
- public PrintWriter getWriter() {
- if (null == servletWriter) {
- stringOutputWriter = new FastBufferWriter(1024);
- Writer out = new Writer() {
-
- public void write(char[] cbuf, int off, int len)
- throws IOException {
- stringOutputWriter.write(cbuf, off, len);
- }
-
- public void flush() throws IOException {
- }
-
- public void close() throws IOException {
- // / writerContent = stringOutputWriter.toString();
- filledOutputWriter = true;
- writerContent = null;
- }
-
- };
- servletWriter = new PrintWriter(out);
- }
- return servletWriter;
- }
-
- public void setContentType(String contentType) {
- this.contentType = contentType;
-
- }
-
- /**
- * @return Returns the contentType.
- */
- public String getContentType() {
- return contentType;
- }
-
- private void writeObject(java.io.ObjectOutputStream s) throws IOException {
- if (filledOutputStream) {
- if (outputStream != null) {
- content = outputStream.toByteArray();
- }
- } else if (filledOutputWriter) {
- if (stringOutputWriter != null) {
- char[] cs = stringOutputWriter.toCharArray();
- writerContent = new String(cs);
- }
- }
- s.defaultWriteObject();
- }
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableFilter.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,20 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.framework.ajax.xmlfilter;
-
-/**
- * @author asmirnov
- *
- */
-public class ConfigurableFilter extends BaseFilter {
-
- /**
- *
- */
- public ConfigurableFilter() {
- xmlFilter = new ConfigurableXMLFilter();
- xmlFilter.setFilter(this);
- }
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableXMLFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableXMLFilter.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableXMLFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,237 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.framework.ajax.xmlfilter;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.EmptyStackException;
-import java.util.Properties;
-import java.util.regex.PatternSyntaxException;
-
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.framework.ajax.xmlfilter.nekko.NekkoParser;
-import org.ajax4jsf.framework.ajax.xmlfilter.tidy.TidyParser;
-import org.ajax4jsf.io.parser.FastHtmlParser;
-import org.apache.commons.collections.ArrayStack;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author asmirnov
- *
- */
-public class ConfigurableXMLFilter extends BaseXMLFilter {
-
- private static final Log log = LogFactory
- .getLog(ConfigurableXMLFilter.class);
-
- private static final String PARSERS_LIST_PARAMETER =
"org.ajax4jsf.xmlparsers";
-
- private static final String VIEW_ID_PATTERN_PARAMETER =
"org.ajax4jsf.xmlparser.";
-
- /**
- * map of the parsers names and viewId patterns for all parser type.
- */
- private ParserConfig parsers = new TidyParserConfig();
-
- // private ParserConfig passParserConfig = new PassParserConfig();
-
- public void init(FilterConfig config) throws ServletException {
- super.init(config);
- ServletContext servletContext = config.getServletContext();
- String parsersParameter = servletContext
- .getInitParameter(PARSERS_LIST_PARAMETER);
- if (null != parsersParameter) {
- configureParsers(servletContext, parsersParameter);
- }
- }
-
- /**
- * @param servletContext
- * @param parsersParameter
- * @throws ServletException
- */
- public void configureParsers(ServletContext servletContext,
- String parsersParameter) throws ServletException {
- String[] parsersNames = parsersParameter.split("\\s*,\\s*");
- for (int i = parsersNames.length - 1; i >= 0; i--) {
- String parserName = parsersNames[i];
- ParserConfig parserConfig;
- if ("TIDY".equals(parserName)) {
- parserConfig = new TidyParserConfig();
- } else if ("NEKO".equals(parserName)) {
- parserConfig = new NekoParserConfig();
- } else if ("PASS".equals(parserName)) {
- parserConfig = new PassParserConfig();
- } else {
- throw new ServletException(
- "Unknown XML parser type in config parameter "
- + parserName);
- }
- parserConfig.setNext(parsers);
- if (null != servletContext) {
- try {
- String parserViewPattern = servletContext
- .getInitParameter(VIEW_ID_PATTERN_PARAMETER
- + parserName);
- parserConfig.setPatterns(parserViewPattern);
-
- } catch (PatternSyntaxException e) {
- throw new ServletException("Invalid pattern for a parser "
- + parserName + " :" + e.getMessage());
- }
- }
- parsers = parserConfig;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter#getParser(java.lang.String,
- * boolean, java.lang.String)
- */
- protected HtmlParser getParser(String mimetype, boolean isAjax,
- String viewId) {
- HtmlParser parser = null;
- if (isAjax || isForcexml()) {
- parser = parsers.getParser(viewId, mimetype);
- } else if (mimetype.startsWith("text/html")
- || mimetype.startsWith("application/xhtml+xml")) {
- parser = new FastHtmlParser();
- }
- return parser;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter#reuseParser(org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser)
- */
- protected void reuseParser(HtmlParser parser) {
- parsers.reuseParser(parser);
-
- }
-
- private static final int STACK_SIZE = 100;
-
- private ArrayStack _xhtmlParsersPool = new ArrayStack(STACK_SIZE);
-
- private class NekoParserConfig extends ParserConfig {
-
- protected HtmlParser createParser(String mime) {
- NekkoParser parser;
- try {
- synchronized (_xhtmlParsersPool) {
- parser = (NekkoParser) _xhtmlParsersPool.pop();
- }
- } catch (EmptyStackException e) {
- parser = new NekkoParser();
- parser.setPublicId(getPublicid());
- parser.setSystemid(getSystemid());
- parser.setNamespace(getNamespace());
- // If tidy not handle all requests, disable reorganising
- // of html
- // parser.setMoveElements(isForcexml());
- }
- // TODO - set header scripts/styles filter.
- return parser;
- }
-
- boolean storeParser(HtmlParser parser) {
- if (null != parser && parser instanceof NekkoParser) {
- synchronized (_xhtmlParsersPool) {
- if (_xhtmlParsersPool.size() < STACK_SIZE) {
- ((NekkoParser) parser).reset();
- _xhtmlParsersPool.push(parser);
- }
-
- }
- return true;
- }
- return false;
- }
- }
-
- private class TidyParserConfig extends ParserConfig {
-
- protected HtmlParser createParser(String mime) {
- // TODO Auto-generated method stub
- TidyParser tidyParser = new TidyParser(getTidyProperties());
- tidyParser.setMoveElements(isForcexml());
- tidyParser.setMime(mime);
- return tidyParser;
- }
-
- }
-
- private class PassParserConfig extends ParserConfig {
-
- protected HtmlParser createParser(String mime) {
- return new FastHtmlParser();
- }
-
- }
-
- private Properties _tidyProperties;
-
- private Properties getTidyProperties() {
- if (null == _tidyProperties) {
- _tidyProperties = new Properties();
- InputStream defaultprops = null;
- InputStream props = null;
- try {
- defaultprops = TidyParser.class
- .getResourceAsStream("tidy.properties");
- if (null != defaultprops) {
- _tidyProperties.load(defaultprops);
- if (log.isDebugEnabled()) {
- log.debug("default tidy parser properties loaded");
- }
- } else if (log.isDebugEnabled()) {
- log.debug("No default tidy parser properties found");
- }
-
- // Second part - user-defined properties.
- props = Thread.currentThread().getContextClassLoader()
- .getResourceAsStream("tidy.properties");
- if (null != props) {
- _tidyProperties.load(props);
- if (log.isDebugEnabled()) {
- log.debug("application-specific tidy parser properties loaded");
- }
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- log.warn(Messages
- .getMessage(Messages.READING_TIDY_PROPERTIES_ERROR), e);
- } finally {
- if (null != props) {
- try {
- props.close();
- } catch (IOException e) {
- // can be ignored
- }
- }
- if (null != defaultprops) {
- try {
- defaultprops.close();
- } catch (IOException e) {
- // can be ignored
- }
- }
- }
- }
- return _tidyProperties;
- }
-
- public ParserConfig getParsers() {
- return parsers;
- }
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/FilterServletResponseWrapper.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/FilterServletResponseWrapper.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/FilterServletResponseWrapper.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,653 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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
- */
-
-/*
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is XML RenderKit for JSF.
- *
- * The Initial Developer of the Original Code is
- * Orbeon, Inc (info(a)orbeon.com)
- * Portions created by the Initial Developer are Copyright (C) 2002
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- */
-package org.ajax4jsf.framework.ajax.xmlfilter;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.io.FastBufferInputStream;
-import org.ajax4jsf.io.FastBufferOutputStream;
-import org.ajax4jsf.io.FastBufferReader;
-import org.ajax4jsf.io.FastBufferWriter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.xml.sax.InputSource;
-
-/**
- * Base wrapper save JSF page response, for parse to XML with different parsers
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:17 $
- *
- */
-public class FilterServletResponseWrapper extends HttpServletResponseWrapper {
-
- private static final Log log = LogFactory.getLog(FilterServletResponseWrapper.class);
-
- public static final String DEFAULT_ENCODING = "UTF-8";
-
-
- protected FastBufferOutputStream byteStream = null;
- private ServletOutputStream servletOutputStream;
- private boolean useStream = false;
-
- private FastBufferWriter stringWriter;
- private PrintWriter printWriter;
- private boolean useWriter = false;
-
- private String contentType;
-
- private String charterEncoding = null;
-
- private HashMap headers = new HashMap();
-
- private int bufferSize = 2048;
-
- private int contentLength = Integer.MIN_VALUE;
-
- private String redirectLocation = null;
-
- private boolean useNullStream = false;
-
- private List cookies = new ArrayList();
-
- public FilterServletResponseWrapper(HttpServletResponse response) {
- super(response);
- }
-
- /**
- * Convert saved context to stream for parsing
- * @return stream from saved content
- */
- public InputStream getContentAsStream() {
- int length = 0;
- FastBufferInputStream result = null;
- String encoding = this.getCharacterEncoding() ;
-/// byte[] content;
- if (isUseStream()) {
- try {
- servletOutputStream.flush();
- } catch (IOException ex) {
- log.warn(Messages.getMessage(Messages.FLUSH_BUFFERED_STREAM_ERROR), ex);
- }
-/// content = byteStream.toByteArray();
- result = new FastBufferInputStream(byteStream);
- } else if (isUseWriter()) {
- printWriter.flush();
- printWriter.close();
- length = stringWriter.getLength();
-/// String stringContent = stringWriter.toString();
- try {
- FastBufferOutputStream stream = stringWriter.convertToOutputStream(encoding);
- result = new FastBufferInputStream(stream);
-/// content = stringContent.getBytes(encoding);
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- log.warn(Messages.getMessage(Messages.UNSUPPORTED_ENCODING_WARNING));
- FastBufferOutputStream stream = stringWriter.convertToOutputStream();
- result = new FastBufferInputStream(stream);
-/// content = stringContent.getBytes();
- }
- } else {
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.NO_WRITER_CALLED_INFO));
- }
- return null;
- }
-/// if (content.length > 0) {
- if (length > 0) {
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.PARSE_XML_DOCUMENT_INFO));
-// try {
-// log.debug(new String(content, encoding));
-// } catch (UnsupportedEncodingException e) {
-// }
- }
- }
- return result;
-/// return new ByteArrayInputStream(content);
- }
-
- /**
- * Convert saved context to stream for parsing
- * @return stream from saved content
- */
- public Reader getContentAsReader() {
- FastBufferReader result = null;
- String encoding = this.getCharacterEncoding() ;
-/// String content;
- if (isUseWriter()) {
- printWriter.flush();
- printWriter.close();
- result = new FastBufferReader(stringWriter);
-/// content = stringWriter.toString();
- } else if (isUseStream()) {
- try {
- servletOutputStream.flush();
- } catch (IOException ex) {
- log.warn(Messages.getMessage(Messages.FLUSH_BUFFERED_STREAM_ERROR), ex);
- }
- try {
- FastBufferWriter writer = byteStream.convertToWriter(encoding);
- result = new FastBufferReader(writer);
-/// content = byteStream.toString(encoding);
- } catch (UnsupportedEncodingException e) {
- log.warn(Messages.getMessage(Messages.UNSUPPORTED_ENCODING_WARNING_2), e);
- FastBufferWriter writer = byteStream.convertToWriter();
- result = new FastBufferReader(writer);
-/// content = byteStream.toString();
- }
- } else {
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.NO_WRITER_CALLED_INFO));
- }
- return null;
- }
-// if (content.length() > 0) {
-// if (log.isDebugEnabled()) {
-// log.debug("XML document to parse in filter, return as Reader:
");
-// log.debug(content);
-// }
-// }
-/// return new StringReader(content);
- return result;
- }
-
- public PrintWriter getWriter() throws IOException {
- if (useStream) {
- throw new
IllegalStateException(Messages.getMessage(Messages.NO_WRITER_POSSIBLE_ERROR));
- }
- if (printWriter == null) {
- printWriter = new PrintWriter(new ServletStringWriter());
- }
- if(log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.CREATE_WRITER_INFO));
- }
- useWriter = true;
- return printWriter;
- }
-
- public ServletOutputStream getOutputStream() throws IOException {
- if (useWriter) {
- if (isUseNullStream()) {
- return new NullServletOutputStream();
- }
- throw new
IllegalStateException(Messages.getMessage(Messages.NO_STREAM_POSSIBLE_ERROR));
- }
- if (servletOutputStream == null) {
-// byteStream = new ByteArrayOutputStream();
- servletOutputStream = new ByteArrayServletOutputStream();
- }
- if(log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.CREATE_STREAM_INFO));
- }
- useStream = true;
- return servletOutputStream;
- }
-
-
- public class ByteArrayServletOutputStream extends ServletOutputStream {
-
- private boolean opened = true;
-
- /* (non-Javadoc)
- * @see java.io.OutputStream#close()
- */
- public void close() throws IOException {
- flush();
- opened=false;
- }
-
-
- /* (non-Javadoc)
- * @see java.io.OutputStream#write(byte[])
- */
- public void write(byte[] b) throws IOException {
- // TODO Auto-generated method stub
- if (opened) {
- byteStream.write(b);
- }
- }
-
-
- public ByteArrayServletOutputStream() {
- byteStream = new FastBufferOutputStream(bufferSize);
- }
-
- public void write(int b) throws IOException {
- if (opened) {
- byteStream.write(b);
- }
- }
-
- /* (non-Javadoc)
- * @see java.io.OutputStream#write(byte[], int, int)
- */
- public void write(byte[] b, int off, int len) throws IOException {
- if (opened) {
- byteStream.write(b, off, len);
- }
- }
- }
-
- public static class NullServletOutputStream extends ServletOutputStream {
-
-
- /* (non-Javadoc)
- * @see java.io.OutputStream#write(byte[], int, int)
- */
- public void write(byte[] b, int off, int len) throws IOException {
- // this-is null stream, do nothing !
- }
-
- /* (non-Javadoc)
- * @see java.io.OutputStream#write(byte[])
- */
- public void write(byte[] b) throws IOException {
- // this-is null stream, do nothing !
- }
-
- public void write(int b) throws IOException {
- // this-is null stream, do nothing !
-
- }
-
- }
-
- public class ServletStringWriter extends Writer {
-
- private boolean opened = true;
-
- public ServletStringWriter() {
- super();
- stringWriter = new FastBufferWriter(bufferSize);
- }
-
- public void write(char[] cbuf, int off, int len) throws IOException {
- if (opened) {
- stringWriter.write(cbuf, off, len);
- }
- }
-
- /* (non-Javadoc)
- * @see java.io.Writer#write(char[])
- */
- public void write(char[] cbuf) throws IOException {
- // TODO Auto-generated method stub
- if (opened) {
- stringWriter.write(cbuf);
- }
- }
-
- /* (non-Javadoc)
- * @see java.io.Writer#write(int)
- */
- public void write(int c) throws IOException {
- // TODO Auto-generated method stub
- if (opened) {
- stringWriter.write(c);
- }
- }
-
- public void flush() throws IOException {
- stringWriter.flush();
- }
-
- public void close() throws IOException {
- stringWriter.close();
- opened = false;
- }
-
- }
-
-// public boolean isCommitted() {
-// // NOTE: What makes sense here?
-// return false;
-// }
-
- /**
- * Return a charset from a content-type.
- */
- public static String getContentTypeCharset(String contentType) {
- if (contentType == null)
- return null;
- int semicolumnIndex = contentType.indexOf(";");
- if (semicolumnIndex == -1)
- return null;
- int charsetIndex = contentType.indexOf("charset=", semicolumnIndex);
- if (charsetIndex == -1)
- return null;
- // FIXME: There may be other attributes after charset, right?
- String afterCharset = contentType.substring(charsetIndex + 8);
- afterCharset = afterCharset.replace('"', ' ');
- return afterCharset.trim();
- }
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String,
java.lang.String)
- */
- public void addHeader(String name, String value) {
- if("Content-Type".equals(name)){
- setContentType(value);
- } else {
- this.headers.put(name,value);
- super.addHeader(name, value);
- }
- }
- /* (non-Javadoc)
- * @see javax.servlet.http.HttpServletResponse#setHeader(java.lang.String,
java.lang.String)
- */
- public void setHeader(String name, String value) {
- // HACK - weblogic do not use setContentType, instead directly set header !
- if("Content-Type".equals(name)){
- setContentType(value);
- } else {
- this.headers.put(name,value);
- super.setHeader(name, value);
- }
- }
-
- public Map getHeaders(){
- return this.headers;
- }
- /* (non-Javadoc)
- * @see javax.servlet.ServletResponse#getCharacterEncoding()
- */
- public String getCharacterEncoding() {
-// return this.charterEncoding;
- if (null != this.charterEncoding) {
- return this.charterEncoding;
- } else {
- // For cases of implicit setting
- return super.getCharacterEncoding();
- }
- }
- /* (non-Javadoc)
- * @see javax.servlet.ServletResponse#setCharacterEncoding(java.lang.String)
- */
- public void setCharacterEncoding(String charset) {
- this.charterEncoding = charset;
- //super.setCharacterEncoding(charset);
- }
- public void setContentType(String type) {
- String contentTypeCharset = getContentTypeCharset(type);
- if (null != contentTypeCharset) {
- this.charterEncoding = contentTypeCharset;
- }
- this.contentType = type;
-// super.setContentType(type);
- }
- public void setLocale(Locale loc) {
- super.setLocale(loc);
- }
-
- public String getContentType() {
- return contentType;
- }
-
- /**
- * Send buffered content directly to output stream.
- * @param outputStream
- * @throws IOException
- */
- public void sendContent(ServletOutputStream outputStream) throws IOException {
- if(getContentLength() >0 ){
- super.setContentLength(getContentLength());
- }
- if (isUseWriter()) {
- printWriter.flush();
- printWriter.close();
- stringWriter.printTo(outputStream);
-/// outputStream.print(stringWriter.toString());
- } else if (isUseStream()) {
- try {
- servletOutputStream.flush();
- } catch (IOException ex) {
- log.warn(Messages.getMessage(Messages.FLUSH_BUFFERED_STREAM_ERROR), ex);
- }
- byteStream.writeTo(outputStream);
- }
- }
-
- /**
- * Send buffered content directly to output stream.
- * @param outputStream
- * @throws IOException
- */
- public void sendContent(Writer output) throws IOException {
- if(getContentLength() >0 ){
- super.setContentLength(getContentLength());
- }
- if (isUseWriter()) {
- printWriter.flush();
- printWriter.close();
- stringWriter.writeTo(output);
-/// outputStream.print(stringWriter.toString());
- } else if (isUseStream()) {
- try {
- servletOutputStream.flush();
- } catch (IOException ex) {
- log.warn(Messages.getMessage(Messages.FLUSH_BUFFERED_STREAM_ERROR), ex);
- }
- byteStream.writeTo(output,getCharacterEncoding());
- }
- }
- /**
- * @return Returns the useStream.
- */
- public boolean isUseStream() {
- return this.useStream;
- }
-
- /**
- * @return Returns the useWriter.
- */
- public boolean isUseWriter() {
- return this.useWriter;
- }
-
- /**
- * @return
- * @throws RuntimeException
- */
- public InputSource getContentAsInputSource() throws RuntimeException {
- // Create InputSource
- InputSource inputSource = null;
- String encoding = this.getCharacterEncoding() ;
- if(isUseWriter()) {
- inputSource = new InputSource(getContentAsReader());
- } else if(isUseStream()) {
- inputSource = new InputSource(getContentAsStream());
- if (encoding != null)
- inputSource.setEncoding(encoding);
- } else {
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.NO_WRITER_CALLED_INFO));
- }
- return null;
- }
- return inputSource;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletResponseWrapper#flushBuffer()
- */
- public void flushBuffer() throws IOException {
- if(isUseStream()){
- servletOutputStream.flush();
- } else if(isUseWriter()){
- printWriter.flush();
- }
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletResponseWrapper#getBufferSize()
- */
- public int getBufferSize() {
- // TODO Auto-generated method stub
- return bufferSize;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletResponseWrapper#resetBuffer()
- */
- public void resetBuffer() {
- this.printWriter = null;
- this.stringWriter = null;
- this.servletOutputStream = null;
- this.byteStream = null;
- this.useStream = false;
- this.useWriter = false;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletResponseWrapper#setBufferSize(int)
- */
- public void setBufferSize(int arg0) {
- // TODO Auto-generated method stub
- bufferSize = arg0;
- }
-
- /* (non-Javadoc)
- * @see javax.servlet.ServletResponseWrapper#reset()
- */
- public void reset() {
- // TODO Auto-generated method stub
- this.resetBuffer();
- this.headers = new HashMap();
- this.contentType=null;
- this.charterEncoding=null;
- super.reset();
- }
-
- /**
- * @return Returns the contentLength.
- */
- public int getContentLength() {
- return contentLength;
- }
-
- /**
- * @param contentLength The contentLength to set.
- */
- public void setContentLength(int contentLength) {
- this.contentLength = contentLength;
- }
-
- /**
- * Parse saved content to output stream ( and store as Dom Document tree )
- * @param out stream to send parsed content, if null - only build dom tree.
- * @return parsed document as dom tree.
- * @throws IOException
- */
- public void parseContent(Writer out,HtmlParser parser) throws IOException {
- parser.setInputEncoding(getCharacterEncoding());
- if (isUseWriter()) {
- parser.parseHtml(getContentAsReader(),out);
- } else if(isUseStream()){
- parser.parseHtml(getContentAsStream(),out);
- }
- }
-
- public void sendRedirect(String arg0) throws IOException {
- // TODO Auto-generated method stub
- this.redirectLocation = arg0;
- }
-
- public String getRedirectLocation() {
- return redirectLocation;
- }
-
- /**
- * @return the useNullStream
- */
- public boolean isUseNullStream() {
- return useNullStream;
- }
-
- /**
- * @param useNullStream the useNullStream to set
- */
- public void setUseNullStream(boolean useNullStream) {
- this.useNullStream = useNullStream;
- }
-
-
-
- public void addCookie(Cookie cookie) {
- cookies.add(cookie);
- super.addCookie(cookie);
- }
-
- public Collection getCookies() {
- return cookies;
- }
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/HtmlParser.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/HtmlParser.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/HtmlParser.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,71 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Set;
-
-public interface HtmlParser {
-
- public abstract void parseHtml(InputStream input, Writer output)
- throws IOException;
-
- public abstract void parseHtml(Reader input, Writer output)
- throws IOException;
- /**
- * @param encoding
- */
- public abstract void setInputEncoding(String encoding);
-
- /**
- * @param encoding
- */
- public abstract void setOutputEncoding(String encoding);
- /**
- * Setup, must tidy move style etc. elements to head or not.
- * @param move
- */
- public abstract void setMoveElements(boolean move);
-
- /**
- * @param scripts The scripts to set.
- */
- public abstract void setScripts(Set scripts);
-
- /**
- * @param styles The styles to set.
- */
- public abstract void setStyles(Set styles);
-
- public abstract void setDoctype(String doctype);
-
- /**
- * @param viewState The viewState to set.
- */
- public abstract void setViewState(String viewState);
-
- public abstract boolean setMime(String mimeType);
-
-}
\ No newline at end of file
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/Log4JConfigurator.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/Log4JConfigurator.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/Log4JConfigurator.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,75 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import java.util.Properties;
-
-import org.ajax4jsf.Messages;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.helpers.LogLog;
-import org.apache.log4j.helpers.OptionConverter;
-import org.apache.log4j.xml.DOMConfigurator;
-
-/**
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:18 $
- *
- */
-class Log4JConfigurator {
- private static final String CONTEXT_ROOT_VARIABLE = "context-root";
- private Properties props = new Properties();
- private String prefix;
-
- DOMConfigurator domConfig;
-
- void doConfigure(String file){
- domConfig.doConfigure(prefix + file, LogManager.getLoggerRepository());
- }
-
-
- /**
- * @param prefix
- */
- public Log4JConfigurator(String prefix) {
- this.prefix = prefix;
- props.setProperty(CONTEXT_ROOT_VARIABLE, prefix);
- domConfig = new DOMConfigurator() {
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.log4j.xml.DOMConfigurator#subst(java.lang.String)
- * append context-related properties for variable
- * substitution.
- */
- protected String subst(String value) {
- try {
- return OptionConverter.substVars(value, props);
- } catch (IllegalArgumentException e) {
- LogLog.warn(Messages.getMessage(Messages.VARIABLE_SUBSTITUTION_WARNING), e);
- return value;
- }
- };
-
- };
- }
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoFilter.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,50 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import org.ajax4jsf.framework.ajax.xmlfilter.nekko.NekkoXMLFilter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- * This class implements a simple Servlet filter that convert basic html
- * output of JSF to valid XML or JavaScript, for parsing different versions
- * of XmlHttpRequest's on client side.
- */
-public class NekkoFilter extends BaseFilter implements javax.servlet.Filter {
- static final Log log = LogFactory.getLog(NekkoFilter.class);
-
- /**
- *
- */
- public NekkoFilter() {
- super();
- // default - not force
-// setForcexml(false);
- xmlFilter = new NekkoXMLFilter();
- xmlFilter.setFilter(this);
- }
-
-}
-
-
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ParserConfig.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ParserConfig.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ParserConfig.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,67 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.framework.ajax.xmlfilter;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-abstract class ParserConfig {
-
- private static final Pattern[] ALL_VIEWS_PATTERN = { Pattern.compile(".*")
};
-
- private static final Pattern SEPARATOR_PATTERN =
Pattern.compile("\\s*,\\s*");
-
- private Pattern[] patterns = ALL_VIEWS_PATTERN;
-
- private ParserConfig next;
-
- protected abstract HtmlParser createParser(String mimetype);
-
- boolean storeParser(HtmlParser parser) {
- return false;
- }
-
- HtmlParser getParser(String viewId, String mimetype) {
- HtmlParser result = null;
- for (int i = 0; i < patterns.length && null == result; i++) {
- Matcher matcher = patterns[i].matcher(viewId);
- if (matcher.matches()) {
- result = createParser(mimetype);
- }
- }
- if (null == result && null != next) {
- result = next.getParser(viewId, mimetype);
- }
- return result;
- }
-
- public void reuseParser(HtmlParser parser) {
- if (!storeParser(parser) && null != next) {
- next.reuseParser(parser);
- }
- }
-
- public ParserConfig getNext() {
- return next;
- }
-
- public void setNext(ParserConfig next) {
- this.next = next;
- }
-
- public void setPatterns(String patternsString) {
- if (null != patternsString) {
- String[] split = SEPARATOR_PATTERN.split(patternsString);
- patterns = new Pattern[split.length];
- for (int i = 0; i < split.length; i++) {
- patterns[i]=Pattern.compile(split[i].trim());
- }
- }
- }
-
- public Pattern[] getPatterns() {
- return patterns;
- }
-
-}
\ No newline at end of file
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/PollEventsManager.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/PollEventsManager.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/PollEventsManager.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,64 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.framework.ajax.xmlfilter;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.faces.FacesException;
-import javax.servlet.ServletContext;
-
-import org.ajax4jsf.ajax.PushEventsCounter;
-import org.ajax4jsf.cache.Cache;
-import org.ajax4jsf.cache.CacheConfigurationLoader;
-import org.ajax4jsf.cache.CacheException;
-import org.ajax4jsf.cache.CacheFactory;
-import org.ajax4jsf.cache.CacheLoader;
-import org.ajax4jsf.cache.CacheManager;
-import org.ajax4jsf.cache.ServletContextInitMap;
-
-/**
- * @author asmirnov
- *
- */
-public class PollEventsManager implements Serializable, CacheLoader,
CacheConfigurationLoader {
-
- public static final String EVENTS_MANAGER_KEY=PollEventsManager.class.getName();
-
- private Cache cache;
-
- public void init(ServletContext servletContext) {
- try {
- CacheManager cacheManager = CacheManager.getInstance();
- Map env = new ServletContextInitMap(servletContext);
- CacheFactory cacheFactory = cacheManager.getCacheFactory(env);
- this.cache = cacheFactory.createCache(env, this, this);
- servletContext.setAttribute(EVENTS_MANAGER_KEY, this);
- } catch (CacheException e) {
- throw new FacesException(e.getMessage(), e);
- }
-
- }
-
- public PushEventsCounter getListener(String key){
- if(null == cache){
- throw new FacesException("Poll events manager not initialized");
- }
- try {
- return (PushEventsCounter) cache.get(key, null);
- } catch (CacheException e) {
- throw new FacesException("error get push events listener for key
"+key,e);
- }
- }
-
- public Object load(Object key, Object context) throws CacheException {
- // TODO Auto-generated method stub
- return new PushEventsCounter();
- }
-
- public Properties loadProperties(String name) {
- return new Properties();
- }
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ServletStreamWriter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ServletStreamWriter.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ServletStreamWriter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,111 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import javax.servlet.ServletOutputStream;
-
-/**
- * HACK - for case if servlet response already use Writer, create wrapper to stream -
- * since most of serializers use outputStream. In future, must be replaced by Dual
serialization
- * capabilites.
- * @author shura
- *
- */
-final class ServletStreamWriter extends ServletOutputStream {
-
- private PrintWriter _writer;
-
- private byte[] buff = new byte[1024];
-
- private int point = 0;
-
- private String _charset;
-
- /**
- * @param writer
- * @param charset
- */
- public ServletStreamWriter(PrintWriter writer, String charset) {
- super();
- // TODO Auto-generated constructor stub
- _writer = writer;
- _charset = charset;
- }
-
- public ServletStreamWriter(PrintWriter writer) {
- this._writer = writer;
- }
-
- public void write(int b) throws IOException {
- buff[point++]=(byte) b;
- if(point==buff.length){
- point = 0;
- String string = null==_charset?new String(buff):new String(buff,_charset);
- _writer.write(string);
- }
- }
-
- /**
- * @return Returns the charset.
- */
- public String getCharset() {
- return _charset;
- }
-
- /**
- * @param charset The charset to set.
- */
- public void setCharset(String charset) {
- _charset = charset;
- }
-
- /* (non-Javadoc)
- * @see java.io.OutputStream#close()
- */
- public void close() throws IOException {
- this.flush();
- super.close();
- }
-
- /* (non-Javadoc)
- * @see java.io.OutputStream#flush()
- */
- public void flush() throws IOException {
- if(point>0){
- String string = null==_charset?new String(buff,0,point):new
String(buff,0,point,_charset);
- _writer.write(string);
- point = 0;
- }
- }
-
- /* (non-Javadoc)
- * @see java.io.OutputStream#write(byte[], int, int)
- */
- public void write(byte[] b, int off, int len) throws IOException {
- this.flush();
- String string = null==_charset?new String(b,off,len):new String(b,off,len,_charset);
- _writer.write(string);
- }
-}
\ No newline at end of file
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/TidyFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/TidyFilter.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/TidyFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,44 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import org.ajax4jsf.framework.ajax.xmlfilter.tidy.TidyXMLFilter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- * Convert Html Output to XML using Jtidy.
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:20 $
- */
-public class TidyFilter extends BaseFilter {
- static final Log log = LogFactory.getLog(TidyFilter.class);
-
- public TidyFilter() {
- // For Tidy, publicId can be pre-defined omit | auto | strict | loose | ignore | [fpi]
- xmlFilter = new TidyXMLFilter();
- xmlFilter.setFilter(this);
- xmlFilter.setPublicid("omit");
- }
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/XMLResponseWriterState.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/XMLResponseWriterState.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/XMLResponseWriterState.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,134 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter;
-
-import java.io.IOException;
-
-import javax.faces.component.UIComponent;
-
-import org.ajax4jsf.Messages;
-
-/**
- * @author shura Class to implement state pattern for
- * <code>ResponceWriter</code> Real states must extend this. By
- * default, block any events, ignore output.
- *
- */
-class XMLResponseWriterState {
- // private ResponseWriter writer;
- /**
- * @throws java.io.IOException
- */
- private static final String ILLEGAL_METOD_STATE =
Messages.getMessage(Messages.ILLEGAL_METHOD_STATE);
-
- void endDocument() throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- * @param name
- * @throws java.io.IOException
- */
- void endElement(String name) throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- * @throws java.io.IOException
- */
- void startDocument() throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- * @param name
- * @param component
- * @throws java.io.IOException
- */
- void startElement(String name, UIComponent component) throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- * @param name
- * @param value
- * @param property
- * @throws java.io.IOException
- */
- void writeAttribute(String name, Object value, String property)
- throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- * @param comment
- * @throws java.io.IOException
- */
- void writeComment(Object comment) throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- * @param text
- * @param off
- * @param len
- * @throws java.io.IOException
- */
- void writeText(char[] text, int off, int len) throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- * @param text
- * @param property
- * @throws java.io.IOException
- */
- void writeText(Object text, String property) throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- * @param name
- * @param value
- * @param property
- * @throws java.io.IOException
- */
- void writeURIAttribute(String name, Object value, String property)
- throws IOException {
- throw new IOException(ILLEGAL_METOD_STATE);
- }
-
- /**
- *
- * Main hook for realise <code>Writer</code>. In document writed as
- * comment, outside of document do nothing ....
- *
- * @param cbuf
- * @param off
- * @param len
- * @throws IOException
- */
- void write(char[] cbuf, int off, int len) throws IOException {
- // DO NOTHING
-
- }
-}
\ No newline at end of file
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/HeaderResourcesRendererBase.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/HeaderResourcesRendererBase.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/HeaderResourcesRendererBase.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -27,9 +27,9 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter;
import org.ajax4jsf.renderkit.HeaderResourceProducer;
import org.ajax4jsf.resource.InternetResource;
+import org.ajax4jsf.webapp.BaseFilter;
/**
* Base renderer for components used JavaScripts and Styles in header. In real
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/io/parser/FastHtmlParser.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/io/parser/FastHtmlParser.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/io/parser/FastHtmlParser.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -30,8 +30,8 @@
import java.util.Iterator;
import java.util.Set;
-import org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser;
import org.ajax4jsf.io.FastBufferReader;
+import org.ajax4jsf.webapp.HtmlParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/CachedResourceContext.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/CachedResourceContext.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/CachedResourceContext.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -26,8 +26,8 @@
import java.io.OutputStream;
import java.io.PrintWriter;
-import org.ajax4jsf.framework.ajax.xmlfilter.CacheContent;
import org.ajax4jsf.resource.ResourceContext;
+import org.ajax4jsf.webapp.CacheContent;
/**
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceService.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceService.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceService.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -47,13 +47,13 @@
import org.ajax4jsf.cache.CacheLoader;
import org.ajax4jsf.cache.CacheManager;
import org.ajax4jsf.cache.ServletContextInitMap;
-import org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter;
-import org.ajax4jsf.framework.ajax.xmlfilter.CacheContent;
import org.ajax4jsf.framework.util.config.WebXml;
import org.ajax4jsf.resource.InternetResource;
import org.ajax4jsf.resource.InternetResourceBuilder;
import org.ajax4jsf.resource.ResourceContext;
import org.ajax4jsf.resource.ResourceNotFoundException;
+import org.ajax4jsf.webapp.BaseFilter;
+import org.ajax4jsf.webapp.CacheContent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java (from rev
1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseFilter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,388 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+import java.util.Enumeration;
+
+import javax.faces.application.ViewHandler;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.ajax.PushEventsCounter;
+import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
+import org.ajax4jsf.resource.InternetResourceService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Base class for request processing filters, with convert Htmp content to XML
+ * for ajax requests, and serve request to application off-page resources
+ *
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:21 $
+ *
+ */
+public abstract class BaseFilter implements Filter {
+
+ public static final String AJAX_PUSH_KEY_HEADER = "Ajax-Push-Key";
+
+ private static final Log log = LogFactory.getLog(BaseFilter.class);
+
+ public static final boolean DEBUG = true;
+
+ private FilterConfig filterConfig;
+
+ private static final String FUNCTION_NAME_PARAMETER = "function";
+
+ private String function = "alert('Data
received');JSHttpRequest.dataReady";
+
+ private String attributesNames;
+
+ private boolean rewriteid = false;
+
+ public static final String REWRITEID_PARAMETER = "rewriteid";
+
+ public static final String STYLESHEET_PARAMETER = "xsl";
+
+ public static final String ABSOLUTE_TAGS_PARAMETER =
"absolute-attributes";
+
+ // private WebXml webXml;
+ // private String xsl;
+ // private Templates xslTemplates;
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2295534611886142935L;
+
+ public static final String DATA_PARAMETER = "DATA";
+
+ public static final String DEFAULT_SERVLET_PATH = "/resource";
+
+ public static final String RENDERER_PREFIX = "/renderer";
+
+ public static final String CACHEABLE_PREFIX = "/cache";
+
+ // private static final Pattern rendererPattern =
+ // Pattern.compile(RENDERER_PREFIX+"/([^/]+)/([^/]+)/([^/]+)/(.*)");
+ // private static final Pattern builderPattern =
+ // Pattern.compile(CACHEABLE_PREFIX+"/(.*)");
+ public static final String FILTER_PERFORMED = "com.exade.vcp.Filter.done";
+
+ public static final String RESPONSE_WRAPPER_ATTRIBUTE =
"com.exade.vcp.Filter.ResponseWrapper";
+
+ protected BaseXMLFilter xmlFilter = null;
+
+ protected InternetResourceService resourceService = null;
+
+ protected PollEventsManager eventsManager;
+
+ /**
+ * Initialize the filter.
+ */
+ public void init(FilterConfig config) throws ServletException {
+ if (log.isDebugEnabled()) {
+ log.debug("Init ajax4jsf filter with nane: "
+ + config.getFilterName());
+ Enumeration parameterNames = config.getInitParameterNames();
+ StringBuffer parameters = new StringBuffer("Init parameters :\n");
+ while (parameterNames.hasMoreElements()) {
+ String name = (String) parameterNames.nextElement();
+ parameters.append(name).append(" : '").append(
+ config.getInitParameter(name)).append('\n');
+ }
+ log.debug(parameters);
+ // log.debug("Stack Trace", new Exception());
+ }
+ // Save config
+ filterConfig = config;
+ setFunction((String) nz(filterConfig
+ .getInitParameter(FUNCTION_NAME_PARAMETER), getFunction()));
+ setAttributesNames(filterConfig
+ .getInitParameter(ABSOLUTE_TAGS_PARAMETER));
+ xmlFilter.init(config);
+ if ("true".equalsIgnoreCase(filterConfig
+ .getInitParameter(REWRITEID_PARAMETER))) {
+ this.setRewriteid(true);
+ }
+
+ String prefix = filterConfig.getServletContext().getRealPath("/");
+ String file = filterConfig.getInitParameter("log4j-init-file");
+ // if the log4j-init-file is not set, then no point in trying
+ if (file != null) {
+ Log4JConfigurator log4jconfig = new Log4JConfigurator(prefix);
+ log4jconfig.doConfigure(file);
+ }
+ resourceService = new InternetResourceService();
+ // Caching initialization.
+ resourceService.init(filterConfig);
+ eventsManager = new PollEventsManager();
+ eventsManager.init(filterConfig.getServletContext());
+ }
+
+ /**
+ * @param httpServletRequest
+ * @throws UnsupportedEncodingException
+ */
+ protected void setupRequestEncoding(HttpServletRequest httpServletRequest)
+ throws UnsupportedEncodingException {
+ String contentType = httpServletRequest.getHeader("Content-Type");
+
+ String characterEncoding = lookupCharacterEncoding(contentType);
+
+ if (characterEncoding == null) {
+ HttpSession session = httpServletRequest.getSession(false);
+
+ if (session != null) {
+ characterEncoding = (String) session
+ .getAttribute(ViewHandler.CHARACTER_ENCODING_KEY);
+ }
+
+ if (characterEncoding != null) {
+ httpServletRequest.setCharacterEncoding(characterEncoding);
+ }
+ }
+ }
+
+ /**
+ * Detect request encoding from Content-Type header
+ *
+ * @param contentType
+ * @return - charset, if present.
+ */
+ private String lookupCharacterEncoding(String contentType) {
+ String characterEncoding = null;
+
+ if (contentType != null) {
+ int charsetFind = contentType.indexOf("charset=");
+ if (charsetFind != -1) {
+ if (charsetFind == 0) {
+ // charset at beginning of Content-Type, curious
+ characterEncoding = contentType.substring(8);
+ } else {
+ char charBefore = contentType.charAt(charsetFind - 1);
+ if (charBefore == ';' || Character.isWhitespace(charBefore)) {
+ // Correct charset after mime type
+ characterEncoding = contentType
+ .substring(charsetFind + 8);
+ }
+ }
+ if (log.isDebugEnabled())
+ log.debug(Messages.getMessage(
+ Messages.CONTENT_TYPE_ENCODING, characterEncoding));
+ } else {
+ if (log.isDebugEnabled())
+ log.debug(Messages.getMessage(
+ Messages.CONTENT_TYPE_NO_ENCODING, contentType));
+ }
+ }
+ return characterEncoding;
+ }
+
+ /**
+ * @param initParameter
+ * @param function2
+ * @return
+ */
+ private Object nz(Object param, Object def) {
+ return param != null ? param : def;
+ }
+
+ /**
+ * Execute the filter.
+ */
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ long startTimeMills = 0;
+ // Detect case of request - normal, AJAX, AJAX - JavaScript
+ // TODO - detect first processing in filter.
+ HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+ HttpServletResponse httpServletResponse = (HttpServletResponse) response;
+ if (log.isDebugEnabled()) {
+ startTimeMills = System.currentTimeMillis();
+ log.debug(Messages.getMessage(Messages.FILTER_START_INFO, new Date(
+ startTimeMills), httpServletRequest.getRequestURI()));
+ }
+
+ if (request.getAttribute(FILTER_PERFORMED) != Boolean.TRUE) {
+ // mark - and not processing same request twice.
+ request.setAttribute(FILTER_PERFORMED, Boolean.TRUE);
+ String ajaxPushHeader = httpServletRequest.getHeader(AJAX_PUSH_KEY_HEADER);
+ // check for a push check request.
+ if (httpServletRequest.getMethod().equals("HEAD")
+ && null != ajaxPushHeader) {
+ PushEventsCounter listener = eventsManager.getListener(ajaxPushHeader);
+ if(listener.isPerformed()){
+ listener.processed();
+ httpServletResponse.setStatus(200);
+ if (log.isDebugEnabled()) {
+ log.debug("Occurs event for a id "+ajaxPushHeader);
+ }
+ } else {
+ // Response code - 'No content'
+ httpServletResponse.setStatus(204);
+ if (log.isDebugEnabled()) {
+ log.debug("No event for a id "+ajaxPushHeader);
+ }
+ }
+ } else
+ // check for resource request
+ 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);
+ // check ajax request parameter
+ // TODO - check for JSF page.
+ if (true) {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages
+ .getMessage(Messages.FILTER_XML_OUTPUT));
+ }
+
+ // Execute the rest of the filter chain, including the
+ // JSP
+ xmlFilter.doXmlFilter(chain, httpServletRequest,
+ httpServletResponse);
+ } else {
+ // normal request, execute chain ...
+ if (log.isDebugEnabled()) {
+ log.debug(Messages
+ .getMessage(Messages.FILTER_NO_XML_CHAIN));
+ }
+ chain.doFilter(request, response);
+
+ }
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.FILTER_NO_XML_CHAIN_2));
+ }
+ chain.doFilter(request, response);
+
+ }
+ if (log.isDebugEnabled()) {
+ startTimeMills = System.currentTimeMillis() - startTimeMills;
+ log.debug(Messages.getMessage(Messages.FILTER_STOP_INFO, ""
+ + startTimeMills, httpServletRequest.getRequestURI()));
+ }
+ }
+
+ /**
+ * @param request
+ * @return
+ */
+ protected boolean isAjaxRequest(ServletRequest request) {
+ try {
+ return null != request
+ .getParameter(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
+ } catch (Exception e) {
+ // OCJ 10 - throw exception for static resources.
+ return false;
+ }
+ }
+
+ /**
+ * Destroy the filter.
+ */
+ public void destroy() {
+ }
+
+ /**
+ * @return Returns the servletContext.
+ */
+ ServletContext getServletContext() {
+ return filterConfig.getServletContext();
+ }
+
+ /**
+ * @return the resourceService
+ * @throws ServletException
+ */
+ protected synchronized InternetResourceService getResourceService()
+ throws ServletException {
+ // if (resourceService == null) {
+ // resourceService = new InternetResourceService();
+ // // Caching initialization.
+ // resourceService.init(filterConfig);
+ //
+ // }
+ return resourceService;
+ }
+
+ /**
+ * @param function
+ * The function to set.
+ */
+ protected void setFunction(String function) {
+ this.function = function;
+ }
+
+ /**
+ * @return Returns the function.
+ */
+ protected String getFunction() {
+ return function;
+ }
+
+ /**
+ * @param rewriteid
+ * The rewriteid to set.
+ */
+ protected void setRewriteid(boolean rewriteid) {
+ this.rewriteid = rewriteid;
+ }
+
+ /**
+ * @return Returns the rewriteid.
+ */
+ protected boolean isRewriteid() {
+ return rewriteid;
+ }
+
+ /**
+ * @param attributesNames
+ * The attributesNames to set.
+ */
+ protected void setAttributesNames(String attributesNames) {
+ this.attributesNames = attributesNames;
+ }
+
+ /**
+ * @return Returns the attributesNames.
+ */
+ protected String getAttributesNames() {
+ return attributesNames;
+ }
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java (from
rev 1557,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,429 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.application.AjaxViewHandler;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public abstract class BaseXMLFilter {
+ private static final Log log = LogFactory.getLog(BaseXMLFilter.class);
+
+ public static final String RESPONSE_WRAPPER_ATTRIBUTE =
"com.exade.vcp.Filter.ResponseWrapper";
+
+ private String mimetype = "text/xml";
+
+ private String publicid = "-//W3C//DTD XHTML 1.0 Transitional//EN";
+
+ private String systemid =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
+
+ private String namespace = "http://www.w3.org/1999/xhtml";
+
+ private static final String MIME_TYPE_PARAMETER = "mime-type";
+
+ private static final String PUBLICID_PARAMETER = "publicid";
+
+ private static final String SYSTEMID_PARAMETER = "systemid";
+
+ private static final String NAMESPACE_PARAMETER = "namespace";
+
+ private boolean forcexml = false;
+
+
+ private static final String FORCEXML_PARAMETER = "forceparser";
+
+ private static final String INIT_PARAMETER_PREFIX =
"org.ajax4jsf.xmlfilter.";
+
+ public BaseFilter filter;
+
+ public void setFilter(BaseFilter filter) {
+ this.filter = filter;
+ }
+
+ public void init(FilterConfig config) throws ServletException {
+ if (log.isDebugEnabled()) {
+ log.debug("init XML filter service with class "
+ + this.getClass().getName());
+ }
+ String forceXmlParameter = config
+ .getInitParameter(FORCEXML_PARAMETER);
+ setupForceXml(forceXmlParameter);
+ forceXmlParameter =
config.getServletContext().getInitParameter(INIT_PARAMETER_PREFIX+FORCEXML_PARAMETER);
+ setMimetype((String) nz(config.getInitParameter(MIME_TYPE_PARAMETER),
+ "text/xml"));
+ setPublicid((String) nz(config.getInitParameter(PUBLICID_PARAMETER),
+ getPublicid()));
+ setSystemid((String) nz(config.getInitParameter(SYSTEMID_PARAMETER),
+ getSystemid()));
+ setNamespace((String) nz(config.getInitParameter(NAMESPACE_PARAMETER),
+ getNamespace()));
+ }
+
+ /**
+ * @param forceXmlParameter
+ */
+ private void setupForceXml(String forceXmlParameter) {
+ if ("false".equalsIgnoreCase(forceXmlParameter)) {
+ this.forcexml = false;
+ }
+ if ("true"
+ .equalsIgnoreCase(forceXmlParameter)) {
+ this.forcexml = true;
+ }
+ }
+
+ /**
+ * Perform filter chain with xml parsing and transformation. Subclasses
+ * must implement concrete HTML to XML parsing, nesseasary
+ * transformations and serialization.
+ *
+ * @param chain
+ * @param httpServletRequest
+ * @param httpServletResponse
+ * @throws ServletException
+ * @throws IOException
+ */
+ protected void doXmlFilter(FilterChain chain, HttpServletRequest request,
+ final HttpServletResponse response) throws IOException,
+ ServletException {
+ if (log.isDebugEnabled()) {
+ log.debug("XML filter service start processing request");
+ }
+ FilterServletResponseWrapper servletResponseWrapper = getWrapper(response);
+ // HACK - to avoid MyFaces <f:view> incompabilites and bypass
+ // intermediaty filters
+ // in chain, self-rendered region write directly to wrapper stored in
+ // request-scope attribute.
+ request
+ .setAttribute(RESPONSE_WRAPPER_ATTRIBUTE,
+ servletResponseWrapper);
+ chain.doFilter(request, servletResponseWrapper);
+ String viewId = (String) request.getAttribute(AjaxViewHandler.VIEW_ID_KEY);
+ HtmlParser parser = null;
+ // setup response
+ // Redirect in AJAX request - convert to special response recognized by
+ // client.
+ String redirectLocation = servletResponseWrapper.getRedirectLocation();
+ String characterEncoding = servletResponseWrapper
+ .getCharacterEncoding();
+ Writer output;
+ if (null != redirectLocation) {
+ if (isAjaxRequest(request)) {
+ // Special handling of redirect - client-side script must
+ // Check for response and perform redirect by window.location
+ if (log.isDebugEnabled()) {
+ log.debug("Create AJAX redirect response to url: "
+ + redirectLocation);
+ }
+ response.reset();
+ // Keep cookies.
+ for (Iterator iter = servletResponseWrapper.getCookies().iterator(); iter.hasNext();)
{
+ Cookie cookie = (Cookie) iter.next();
+ response.addCookie(cookie);
+ }
+ // Copy response headers
+ Map headers = servletResponseWrapper.getHeaders();
+ for (Iterator iter = headers.entrySet().iterator(); iter
+ .hasNext();) {
+ Map.Entry header = (Map.Entry) iter.next();
+ response.setHeader((String) header.getKey(),
+ (String) header.getValue());
+ }
+ response.setHeader(AjaxContainerRenderer.AJAX_FLAG_HEADER,
+ "redirect");
+ // Not caching AJAX request
+ response.setHeader("Cache-Control",
+ "no-cache, must-revalidate, max_age=0, no-store");
+ response.setHeader("Expires", "0");
+ response.setHeader("Pragma", "no-cache");
+ response.setContentType(getMimetype() + ";charset=UTF-8");
+ response.setHeader(AjaxContainerRenderer.AJAX_LOCATION_HEADER,
+ redirectLocation);
+ output = createResponseWriter(response, "UTF-8");
+ // For buggy XmlHttpRequest realisations repeat headers in
+ // <meta>
+ output.write("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n"
+ + "<html
xmlns=\"http://www.w3.org/1999/xhtml\"><head>"
+ + "<meta name=\""
+ + AjaxContainerRenderer.AJAX_FLAG_HEADER
+ + "\" content=\"redirect\" />" + "<meta
name=\""
+ + AjaxContainerRenderer.AJAX_LOCATION_HEADER
+ + "\" content=\"" + redirectLocation + "\" />"
+ + "</head></html>");
+ output.flush();
+ response.flushBuffer();
+ } else {
+ response.sendRedirect(redirectLocation);
+ }
+ return;
+ } else if ("true".equals(servletResponseWrapper.getHeaders().get(
+ AjaxContainerRenderer.AJAX_FLAG_HEADER))) {
+ if (log.isDebugEnabled()) {
+ log
+ .debug("Process response to well-formed XML for AJAX XMLHttpRequest
parser");
+ }
+ // Not caching AJAX request
+ response.setHeader("Cache-Control",
+ "no-cache, must-revalidate, max_age=0, no-store");
+ response.setHeader("Expires", "0");
+ response.setHeader("Pragma", "no-cache");
+ // response.setCharacterEncoding(servletResponseWrapper
+ // .getCharacterEncoding()); //
+ // JSContentHandler.DEFAULT_ENCODING);
+ // Set the content-type. For AJAX responses default encoding -
+ // UTF8.
+ // TODO - for null encoding, setup only Output encoding for
+ // filter ?
+ String outputEncoding = "UTF-8";
+ String contentType = getMimetype() + ";charset=" + outputEncoding;
+ response.setContentType(contentType);
+ parser = getParser(getMimetype(), true, viewId);
+ if (null == parser) {
+ throw new ServletException(Messages.getMessage(
+ Messages.PARSER_NOT_INSTANTIATED_ERROR, contentType));
+ }
+ output = createResponseWriter(response, outputEncoding);
+ parser.setDoctype(getPublicid());
+ parser.setInputEncoding(characterEncoding);
+ parser.setOutputEncoding(outputEncoding);
+ parser.setViewState((String) request
+ .getAttribute(AjaxViewHandler.SERIALIZED_STATE_KEY));
+ } else {
+ // setup conversion reules for output contentType, send directly
+ // if content not
+ // supported by tidy.
+ String contentType = servletResponseWrapper.getContentType();
+ if (log.isDebugEnabled()) {
+ log.debug("create HTML/XML parser for content type: "
+ + contentType);
+ }
+ // if(contentType == null){
+ // contentType = request.getContentType();
+ // }
+ if (contentType != null) {
+ if (contentType.indexOf("charset") < 0
+ && null != characterEncoding) {
+ contentType += ";charset=" + characterEncoding;
+ }
+ parser = getParser(contentType, false, viewId);
+ response.setContentType(contentType);
+ }
+ // null or unsupported content type
+ if (null == parser) {
+ if (log.isDebugEnabled()) {
+ log
+ .debug("Parser not have support for the such content type, send response
as-is");
+ }
+ try {
+ if (servletResponseWrapper.isUseWriter()) {
+ output = createResponseWriter(response,
+ characterEncoding);
+ servletResponseWrapper.sendContent(output);
+ } else if (servletResponseWrapper.isUseStream()) {
+ ServletOutputStream out = response.getOutputStream();
+ servletResponseWrapper.sendContent(out);
+ }
+ } finally {
+ // reuseWrapper(servletResponseWrapper);
+ }
+ return;
+ }
+ output = createResponseWriter(response, characterEncoding);
+
+ parser.setInputEncoding(characterEncoding);
+ parser.setOutputEncoding(characterEncoding);
+ }
+
+ try {
+ // Setup scripts and styles
+ parser.setScripts((Set) request
+ .getAttribute(AjaxContext.SCRIPTS_PARAMETER));
+ parser.setStyles((Set) request
+ .getAttribute(AjaxContext.STYLES_PARAMETER));
+ // Process parsing.
+ long startTimeMills = System.currentTimeMillis();
+ servletResponseWrapper.parseContent(output, parser);
+ if (log.isDebugEnabled()) {
+ startTimeMills = System.currentTimeMillis() - startTimeMills;
+ log.debug(Messages.getMessage(Messages.PARSING_TIME_INFO, ""
+ + startTimeMills));
+ }
+ } catch (Exception e) {
+ throw new ServletException(Messages
+ .getMessage(Messages.JTIDY_PARSING_ERROR), e);
+ } finally {
+ reuseParser(parser);
+ }
+ }
+
+ /**
+ * @param response
+ * @return
+ * @throws ServletException
+ */
+ protected FilterServletResponseWrapper getWrapper(
+ HttpServletResponse response) throws ServletException {
+ return new FilterServletResponseWrapper(response);
+ }
+
+ /**
+ * @param request
+ * @return
+ */
+ protected boolean isAjaxRequest(ServletRequest request) {
+ try {
+ return null != request
+ .getParameter(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
+ } catch (Exception e) {
+ // OCJ 10 - throw exception for static resources.
+ return false;
+ }
+ }
+
+ /**
+ * @param response
+ * @param characterEncoding
+ * @return
+ * @throws IOException
+ * @throws UnsupportedEncodingException
+ */
+ private Writer createResponseWriter(final HttpServletResponse response,
+ String characterEncoding) throws IOException,
+ UnsupportedEncodingException {
+ Writer output;
+ try {
+ output = response.getWriter();
+ } catch (IllegalStateException e) {
+ if (null != characterEncoding) {
+ output = new OutputStreamWriter(response.getOutputStream(),
+ characterEncoding);
+ } else {
+ output = new OutputStreamWriter(response.getOutputStream());
+ }
+ }
+ return output;
+ }
+
+ protected abstract void reuseParser(HtmlParser parser);
+
+ protected abstract HtmlParser getParser(String mimetype, boolean isAjax, String
viewId);
+
+ /**
+ * @param publicid
+ * The publicid to set.
+ */
+ protected void setPublicid(String publicid) {
+ this.publicid = publicid;
+ }
+
+ /**
+ * @return Returns the publicid.
+ */
+ public String getPublicid() {
+ return publicid;
+ }
+
+ /**
+ * @param systemid
+ * The systemid to set.
+ */
+ protected void setSystemid(String systemid) {
+ this.systemid = systemid;
+ }
+
+ /**
+ * @return Returns the systemid.
+ */
+ public String getSystemid() {
+ return systemid;
+ }
+
+ /**
+ * @param namespace
+ * The namespace to set.
+ */
+ protected void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ /**
+ * @return Returns the namespace.
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+
+ /**
+ * @param mimetype
+ * The mimetype to set.
+ */
+ protected void setMimetype(String mimetype) {
+ this.mimetype = mimetype;
+ }
+
+ /**
+ * @return Returns the mimetype.
+ */
+ protected String getMimetype() {
+ return mimetype;
+ }
+
+ /**
+ * @return Returns the forcexml.
+ */
+ public boolean isForcexml() {
+ return this.forcexml;
+ }
+
+ /**
+ * @param forcexml
+ * The forcexml to set.
+ */
+ protected void setForcexml(boolean forcexml) {
+ this.forcexml = forcexml;
+ }
+
+ private Object nz(Object param, Object def) {
+ return param != null ? param : def;
+ }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java (from rev
1557,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContent.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/CacheContent.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,277 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ajax4jsf.io.FastBufferOutputStream;
+import org.ajax4jsf.io.FastBufferWriter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:20 $
+ *
+ */
+public class CacheContent implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8120940486890871177L;
+
+ private static final Log _log = LogFactory.getLog(CacheContent.class);
+
+ // private transient ByteArrayOutputStream outputStream ;
+ private transient FastBufferOutputStream outputStream;
+
+ private transient FastBufferWriter stringOutputWriter;
+
+ private transient PrintWriter servletWriter;
+
+ private transient ServletOutputStream servletStream;
+
+ // content to send.
+ private byte[] content = null;
+
+ private String writerContent = null;
+
+ boolean filledOutputStream = false;
+
+ boolean filledOutputWriter = false;
+
+ private Map headers = new HashMap();
+
+ private String contentType;
+
+ /**
+ * Send saved content to http responce
+ *
+ * @param response
+ * @throws IOException
+ */
+ public void send(HttpServletResponse response) throws IOException {
+ if (filledOutputStream) {
+ OutputStream out = response.getOutputStream();
+ if (content != null) {
+ out.write(content);
+ } else {
+ this.outputStream.writeTo(out);
+ }
+ // out.flush();
+ // out.close();
+ } else if (filledOutputWriter) {
+ Writer out = response.getWriter();
+ if (null != writerContent) {
+ out.write(writerContent);
+ } else {
+ stringOutputWriter.writeTo(out);
+ }
+ // out.flush();
+ // out.close();
+ }
+ }
+
+ /**
+ * Send saved headers to http responce.
+ *
+ * @param response
+ */
+ public void sendHeaders(HttpServletResponse response) {
+ for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry element = (Map.Entry) iter.next();
+ String header = (String) element.getKey();
+ Object headerValue = element.getValue();
+ try {
+ if (headerValue instanceof Long) {
+ Long time = (Long) headerValue;
+ response.setDateHeader(header, time.longValue());
+ } else if (headerValue instanceof Integer) {
+ Integer value = (Integer) headerValue;
+ response.setIntHeader(header, value.intValue());
+ } else {
+ response.setHeader(header, (String) headerValue);
+ }
+
+ } catch (Exception e) {
+ _log.error("Error set response header "+header+"for value
"+headerValue, e);
+ }
+ // set real content-length.
+ // / if (null != content) {
+ if (filledOutputStream) {
+ // / response.setIntHeader("Content-Length", content.length);
+ response.setIntHeader("Content-Length", outputStream
+ .getLength());
+ } // TODO - calculate content-lenght for writer ?
+ if (null != contentType) {
+ response.setContentType(this.contentType);
+ }
+ }
+ }
+
+ public void setDateHeader(String name, long value) {
+ // Expires not stored in cache - must be re-calculated for every
+ // response.
+ if (!"Expires".equals(name)) {
+ headers.put(name, new Long(value));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.resource.ResourceContext#setHeader(java.lang.String,
+ * java.lang.String)
+ */
+ public void setHeader(String name, String value) {
+ headers.put(name, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.resource.ResourceContext#setIntHeader(java.lang.String,
+ * int)
+ */
+ public void setIntHeader(String name, int value) {
+ headers.put(name, new Integer(value));
+ }
+
+ /**
+ * Create UNIX command 'tee' like stream - send all data to servlet
+ *
+ * @param responseStream
+ * @return
+ */
+ public OutputStream getOutputStream() {
+ if (null == servletStream) {
+ outputStream = new FastBufferOutputStream(1024);
+ servletStream = new ServletOutputStream() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.OutputStream#close()
+ */
+ public void close() throws IOException {
+ filledOutputStream = true;
+ // / content = outputStream.toByteArray();
+ content = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.OutputStream#flush()
+ */
+ public void flush() throws IOException {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.OutputStream#write(byte[], int, int)
+ */
+ public void write(byte[] b, int off, int len)
+ throws IOException {
+ outputStream.write(b, off, len);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.OutputStream#write(byte[])
+ */
+ public void write(byte[] b) throws IOException {
+ outputStream.write(b);
+ }
+
+ public void write(int b) throws IOException {
+ outputStream.write(b);
+ }
+
+ };
+ }
+ return servletStream;
+ }
+
+ public PrintWriter getWriter() {
+ if (null == servletWriter) {
+ stringOutputWriter = new FastBufferWriter(1024);
+ Writer out = new Writer() {
+
+ public void write(char[] cbuf, int off, int len)
+ throws IOException {
+ stringOutputWriter.write(cbuf, off, len);
+ }
+
+ public void flush() throws IOException {
+ }
+
+ public void close() throws IOException {
+ // / writerContent = stringOutputWriter.toString();
+ filledOutputWriter = true;
+ writerContent = null;
+ }
+
+ };
+ servletWriter = new PrintWriter(out);
+ }
+ return servletWriter;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+
+ }
+
+ /**
+ * @return Returns the contentType.
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ private void writeObject(java.io.ObjectOutputStream s) throws IOException {
+ if (filledOutputStream) {
+ if (outputStream != null) {
+ content = outputStream.toByteArray();
+ }
+ } else if (filledOutputWriter) {
+ if (stringOutputWriter != null) {
+ char[] cs = stringOutputWriter.toCharArray();
+ writerContent = new String(cs);
+ }
+ }
+ s.defaultWriteObject();
+ }
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableFilter.java
(from rev 1557,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableFilter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableFilter.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package org.ajax4jsf.webapp;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ConfigurableFilter extends BaseFilter {
+
+ /**
+ *
+ */
+ public ConfigurableFilter() {
+ xmlFilter = new ConfigurableXMLFilter();
+ xmlFilter.setFilter(this);
+ }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableXMLFilter.java
(from rev 1557,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ConfigurableXMLFilter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableXMLFilter.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableXMLFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,237 @@
+/**
+ *
+ */
+package org.ajax4jsf.webapp;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.EmptyStackException;
+import java.util.Properties;
+import java.util.regex.PatternSyntaxException;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.io.parser.FastHtmlParser;
+import org.ajax4jsf.webapp.nekko.NekkoParser;
+import org.ajax4jsf.webapp.tidy.TidyParser;
+import org.apache.commons.collections.ArrayStack;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ConfigurableXMLFilter extends BaseXMLFilter {
+
+ private static final Log log = LogFactory
+ .getLog(ConfigurableXMLFilter.class);
+
+ private static final String PARSERS_LIST_PARAMETER =
"org.ajax4jsf.xmlparsers";
+
+ private static final String VIEW_ID_PATTERN_PARAMETER =
"org.ajax4jsf.xmlparser.";
+
+ /**
+ * map of the parsers names and viewId patterns for all parser type.
+ */
+ private ParserConfig parsers = new TidyParserConfig();
+
+ // private ParserConfig passParserConfig = new PassParserConfig();
+
+ public void init(FilterConfig config) throws ServletException {
+ super.init(config);
+ ServletContext servletContext = config.getServletContext();
+ String parsersParameter = servletContext
+ .getInitParameter(PARSERS_LIST_PARAMETER);
+ if (null != parsersParameter) {
+ configureParsers(servletContext, parsersParameter);
+ }
+ }
+
+ /**
+ * @param servletContext
+ * @param parsersParameter
+ * @throws ServletException
+ */
+ public void configureParsers(ServletContext servletContext,
+ String parsersParameter) throws ServletException {
+ String[] parsersNames = parsersParameter.split("\\s*,\\s*");
+ for (int i = parsersNames.length - 1; i >= 0; i--) {
+ String parserName = parsersNames[i];
+ ParserConfig parserConfig;
+ if ("TIDY".equals(parserName)) {
+ parserConfig = new TidyParserConfig();
+ } else if ("NEKO".equals(parserName)) {
+ parserConfig = new NekoParserConfig();
+ } else if ("PASS".equals(parserName)) {
+ parserConfig = new PassParserConfig();
+ } else {
+ throw new ServletException(
+ "Unknown XML parser type in config parameter "
+ + parserName);
+ }
+ parserConfig.setNext(parsers);
+ if (null != servletContext) {
+ try {
+ String parserViewPattern = servletContext
+ .getInitParameter(VIEW_ID_PATTERN_PARAMETER
+ + parserName);
+ parserConfig.setPatterns(parserViewPattern);
+
+ } catch (PatternSyntaxException e) {
+ throw new ServletException("Invalid pattern for a parser "
+ + parserName + " :" + e.getMessage());
+ }
+ }
+ parsers = parserConfig;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.BaseXMLFilter#getParser(java.lang.String,
+ * boolean, java.lang.String)
+ */
+ protected HtmlParser getParser(String mimetype, boolean isAjax,
+ String viewId) {
+ HtmlParser parser = null;
+ if (isAjax || isForcexml()) {
+ parser = parsers.getParser(viewId, mimetype);
+ } else if (mimetype.startsWith("text/html")
+ || mimetype.startsWith("application/xhtml+xml")) {
+ parser = new FastHtmlParser();
+ }
+ return parser;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.webapp.BaseXMLFilter#reuseParser(org.ajax4jsf.webapp.HtmlParser)
+ */
+ protected void reuseParser(HtmlParser parser) {
+ parsers.reuseParser(parser);
+
+ }
+
+ private static final int STACK_SIZE = 100;
+
+ private ArrayStack _xhtmlParsersPool = new ArrayStack(STACK_SIZE);
+
+ private class NekoParserConfig extends ParserConfig {
+
+ protected HtmlParser createParser(String mime) {
+ NekkoParser parser;
+ try {
+ synchronized (_xhtmlParsersPool) {
+ parser = (NekkoParser) _xhtmlParsersPool.pop();
+ }
+ } catch (EmptyStackException e) {
+ parser = new NekkoParser();
+ parser.setPublicId(getPublicid());
+ parser.setSystemid(getSystemid());
+ parser.setNamespace(getNamespace());
+ // If tidy not handle all requests, disable reorganising
+ // of html
+ // parser.setMoveElements(isForcexml());
+ }
+ // TODO - set header scripts/styles filter.
+ return parser;
+ }
+
+ boolean storeParser(HtmlParser parser) {
+ if (null != parser && parser instanceof NekkoParser) {
+ synchronized (_xhtmlParsersPool) {
+ if (_xhtmlParsersPool.size() < STACK_SIZE) {
+ ((NekkoParser) parser).reset();
+ _xhtmlParsersPool.push(parser);
+ }
+
+ }
+ return true;
+ }
+ return false;
+ }
+ }
+
+ private class TidyParserConfig extends ParserConfig {
+
+ protected HtmlParser createParser(String mime) {
+ // TODO Auto-generated method stub
+ TidyParser tidyParser = new TidyParser(getTidyProperties());
+ tidyParser.setMoveElements(isForcexml());
+ tidyParser.setMime(mime);
+ return tidyParser;
+ }
+
+ }
+
+ private class PassParserConfig extends ParserConfig {
+
+ protected HtmlParser createParser(String mime) {
+ return new FastHtmlParser();
+ }
+
+ }
+
+ private Properties _tidyProperties;
+
+ private Properties getTidyProperties() {
+ if (null == _tidyProperties) {
+ _tidyProperties = new Properties();
+ InputStream defaultprops = null;
+ InputStream props = null;
+ try {
+ defaultprops = TidyParser.class
+ .getResourceAsStream("tidy.properties");
+ if (null != defaultprops) {
+ _tidyProperties.load(defaultprops);
+ if (log.isDebugEnabled()) {
+ log.debug("default tidy parser properties loaded");
+ }
+ } else if (log.isDebugEnabled()) {
+ log.debug("No default tidy parser properties found");
+ }
+
+ // Second part - user-defined properties.
+ props = Thread.currentThread().getContextClassLoader()
+ .getResourceAsStream("tidy.properties");
+ if (null != props) {
+ _tidyProperties.load(props);
+ if (log.isDebugEnabled()) {
+ log.debug("application-specific tidy parser properties loaded");
+ }
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ log.warn(Messages
+ .getMessage(Messages.READING_TIDY_PROPERTIES_ERROR), e);
+ } finally {
+ if (null != props) {
+ try {
+ props.close();
+ } catch (IOException e) {
+ // can be ignored
+ }
+ }
+ if (null != defaultprops) {
+ try {
+ defaultprops.close();
+ } catch (IOException e) {
+ // can be ignored
+ }
+ }
+ }
+ }
+ return _tidyProperties;
+ }
+
+ public ParserConfig getParsers() {
+ return parsers;
+ }
+
+}
Copied:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterServletResponseWrapper.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/FilterServletResponseWrapper.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterServletResponseWrapper.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/FilterServletResponseWrapper.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,653 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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
+ */
+
+/*
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is XML RenderKit for JSF.
+ *
+ * The Initial Developer of the Original Code is
+ * Orbeon, Inc (info(a)orbeon.com)
+ * Portions created by the Initial Developer are Copyright (C) 2002
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ */
+package org.ajax4jsf.webapp;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.io.FastBufferInputStream;
+import org.ajax4jsf.io.FastBufferOutputStream;
+import org.ajax4jsf.io.FastBufferReader;
+import org.ajax4jsf.io.FastBufferWriter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.InputSource;
+
+/**
+ * Base wrapper save JSF page response, for parse to XML with different parsers
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:17 $
+ *
+ */
+public class FilterServletResponseWrapper extends HttpServletResponseWrapper {
+
+ private static final Log log = LogFactory.getLog(FilterServletResponseWrapper.class);
+
+ public static final String DEFAULT_ENCODING = "UTF-8";
+
+
+ protected FastBufferOutputStream byteStream = null;
+ private ServletOutputStream servletOutputStream;
+ private boolean useStream = false;
+
+ private FastBufferWriter stringWriter;
+ private PrintWriter printWriter;
+ private boolean useWriter = false;
+
+ private String contentType;
+
+ private String charterEncoding = null;
+
+ private HashMap headers = new HashMap();
+
+ private int bufferSize = 2048;
+
+ private int contentLength = Integer.MIN_VALUE;
+
+ private String redirectLocation = null;
+
+ private boolean useNullStream = false;
+
+ private List cookies = new ArrayList();
+
+ public FilterServletResponseWrapper(HttpServletResponse response) {
+ super(response);
+ }
+
+ /**
+ * Convert saved context to stream for parsing
+ * @return stream from saved content
+ */
+ public InputStream getContentAsStream() {
+ int length = 0;
+ FastBufferInputStream result = null;
+ String encoding = this.getCharacterEncoding() ;
+/// byte[] content;
+ if (isUseStream()) {
+ try {
+ servletOutputStream.flush();
+ } catch (IOException ex) {
+ log.warn(Messages.getMessage(Messages.FLUSH_BUFFERED_STREAM_ERROR), ex);
+ }
+/// content = byteStream.toByteArray();
+ result = new FastBufferInputStream(byteStream);
+ } else if (isUseWriter()) {
+ printWriter.flush();
+ printWriter.close();
+ length = stringWriter.getLength();
+/// String stringContent = stringWriter.toString();
+ try {
+ FastBufferOutputStream stream = stringWriter.convertToOutputStream(encoding);
+ result = new FastBufferInputStream(stream);
+/// content = stringContent.getBytes(encoding);
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ log.warn(Messages.getMessage(Messages.UNSUPPORTED_ENCODING_WARNING));
+ FastBufferOutputStream stream = stringWriter.convertToOutputStream();
+ result = new FastBufferInputStream(stream);
+/// content = stringContent.getBytes();
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.NO_WRITER_CALLED_INFO));
+ }
+ return null;
+ }
+/// if (content.length > 0) {
+ if (length > 0) {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.PARSE_XML_DOCUMENT_INFO));
+// try {
+// log.debug(new String(content, encoding));
+// } catch (UnsupportedEncodingException e) {
+// }
+ }
+ }
+ return result;
+/// return new ByteArrayInputStream(content);
+ }
+
+ /**
+ * Convert saved context to stream for parsing
+ * @return stream from saved content
+ */
+ public Reader getContentAsReader() {
+ FastBufferReader result = null;
+ String encoding = this.getCharacterEncoding() ;
+/// String content;
+ if (isUseWriter()) {
+ printWriter.flush();
+ printWriter.close();
+ result = new FastBufferReader(stringWriter);
+/// content = stringWriter.toString();
+ } else if (isUseStream()) {
+ try {
+ servletOutputStream.flush();
+ } catch (IOException ex) {
+ log.warn(Messages.getMessage(Messages.FLUSH_BUFFERED_STREAM_ERROR), ex);
+ }
+ try {
+ FastBufferWriter writer = byteStream.convertToWriter(encoding);
+ result = new FastBufferReader(writer);
+/// content = byteStream.toString(encoding);
+ } catch (UnsupportedEncodingException e) {
+ log.warn(Messages.getMessage(Messages.UNSUPPORTED_ENCODING_WARNING_2), e);
+ FastBufferWriter writer = byteStream.convertToWriter();
+ result = new FastBufferReader(writer);
+/// content = byteStream.toString();
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.NO_WRITER_CALLED_INFO));
+ }
+ return null;
+ }
+// if (content.length() > 0) {
+// if (log.isDebugEnabled()) {
+// log.debug("XML document to parse in filter, return as Reader:
");
+// log.debug(content);
+// }
+// }
+/// return new StringReader(content);
+ return result;
+ }
+
+ public PrintWriter getWriter() throws IOException {
+ if (useStream) {
+ throw new
IllegalStateException(Messages.getMessage(Messages.NO_WRITER_POSSIBLE_ERROR));
+ }
+ if (printWriter == null) {
+ printWriter = new PrintWriter(new ServletStringWriter());
+ }
+ if(log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.CREATE_WRITER_INFO));
+ }
+ useWriter = true;
+ return printWriter;
+ }
+
+ public ServletOutputStream getOutputStream() throws IOException {
+ if (useWriter) {
+ if (isUseNullStream()) {
+ return new NullServletOutputStream();
+ }
+ throw new
IllegalStateException(Messages.getMessage(Messages.NO_STREAM_POSSIBLE_ERROR));
+ }
+ if (servletOutputStream == null) {
+// byteStream = new ByteArrayOutputStream();
+ servletOutputStream = new ByteArrayServletOutputStream();
+ }
+ if(log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.CREATE_STREAM_INFO));
+ }
+ useStream = true;
+ return servletOutputStream;
+ }
+
+
+ public class ByteArrayServletOutputStream extends ServletOutputStream {
+
+ private boolean opened = true;
+
+ /* (non-Javadoc)
+ * @see java.io.OutputStream#close()
+ */
+ public void close() throws IOException {
+ flush();
+ opened=false;
+ }
+
+
+ /* (non-Javadoc)
+ * @see java.io.OutputStream#write(byte[])
+ */
+ public void write(byte[] b) throws IOException {
+ // TODO Auto-generated method stub
+ if (opened) {
+ byteStream.write(b);
+ }
+ }
+
+
+ public ByteArrayServletOutputStream() {
+ byteStream = new FastBufferOutputStream(bufferSize);
+ }
+
+ public void write(int b) throws IOException {
+ if (opened) {
+ byteStream.write(b);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.OutputStream#write(byte[], int, int)
+ */
+ public void write(byte[] b, int off, int len) throws IOException {
+ if (opened) {
+ byteStream.write(b, off, len);
+ }
+ }
+ }
+
+ public static class NullServletOutputStream extends ServletOutputStream {
+
+
+ /* (non-Javadoc)
+ * @see java.io.OutputStream#write(byte[], int, int)
+ */
+ public void write(byte[] b, int off, int len) throws IOException {
+ // this-is null stream, do nothing !
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.OutputStream#write(byte[])
+ */
+ public void write(byte[] b) throws IOException {
+ // this-is null stream, do nothing !
+ }
+
+ public void write(int b) throws IOException {
+ // this-is null stream, do nothing !
+
+ }
+
+ }
+
+ public class ServletStringWriter extends Writer {
+
+ private boolean opened = true;
+
+ public ServletStringWriter() {
+ super();
+ stringWriter = new FastBufferWriter(bufferSize);
+ }
+
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ if (opened) {
+ stringWriter.write(cbuf, off, len);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.Writer#write(char[])
+ */
+ public void write(char[] cbuf) throws IOException {
+ // TODO Auto-generated method stub
+ if (opened) {
+ stringWriter.write(cbuf);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.Writer#write(int)
+ */
+ public void write(int c) throws IOException {
+ // TODO Auto-generated method stub
+ if (opened) {
+ stringWriter.write(c);
+ }
+ }
+
+ public void flush() throws IOException {
+ stringWriter.flush();
+ }
+
+ public void close() throws IOException {
+ stringWriter.close();
+ opened = false;
+ }
+
+ }
+
+// public boolean isCommitted() {
+// // NOTE: What makes sense here?
+// return false;
+// }
+
+ /**
+ * Return a charset from a content-type.
+ */
+ public static String getContentTypeCharset(String contentType) {
+ if (contentType == null)
+ return null;
+ int semicolumnIndex = contentType.indexOf(";");
+ if (semicolumnIndex == -1)
+ return null;
+ int charsetIndex = contentType.indexOf("charset=", semicolumnIndex);
+ if (charsetIndex == -1)
+ return null;
+ // FIXME: There may be other attributes after charset, right?
+ String afterCharset = contentType.substring(charsetIndex + 8);
+ afterCharset = afterCharset.replace('"', ' ');
+ return afterCharset.trim();
+ }
+ /* (non-Javadoc)
+ * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String,
java.lang.String)
+ */
+ public void addHeader(String name, String value) {
+ if("Content-Type".equals(name)){
+ setContentType(value);
+ } else {
+ this.headers.put(name,value);
+ super.addHeader(name, value);
+ }
+ }
+ /* (non-Javadoc)
+ * @see javax.servlet.http.HttpServletResponse#setHeader(java.lang.String,
java.lang.String)
+ */
+ public void setHeader(String name, String value) {
+ // HACK - weblogic do not use setContentType, instead directly set header !
+ if("Content-Type".equals(name)){
+ setContentType(value);
+ } else {
+ this.headers.put(name,value);
+ super.setHeader(name, value);
+ }
+ }
+
+ public Map getHeaders(){
+ return this.headers;
+ }
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletResponse#getCharacterEncoding()
+ */
+ public String getCharacterEncoding() {
+// return this.charterEncoding;
+ if (null != this.charterEncoding) {
+ return this.charterEncoding;
+ } else {
+ // For cases of implicit setting
+ return super.getCharacterEncoding();
+ }
+ }
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletResponse#setCharacterEncoding(java.lang.String)
+ */
+ public void setCharacterEncoding(String charset) {
+ this.charterEncoding = charset;
+ //super.setCharacterEncoding(charset);
+ }
+ public void setContentType(String type) {
+ String contentTypeCharset = getContentTypeCharset(type);
+ if (null != contentTypeCharset) {
+ this.charterEncoding = contentTypeCharset;
+ }
+ this.contentType = type;
+// super.setContentType(type);
+ }
+ public void setLocale(Locale loc) {
+ super.setLocale(loc);
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * Send buffered content directly to output stream.
+ * @param outputStream
+ * @throws IOException
+ */
+ public void sendContent(ServletOutputStream outputStream) throws IOException {
+ if(getContentLength() >0 ){
+ super.setContentLength(getContentLength());
+ }
+ if (isUseWriter()) {
+ printWriter.flush();
+ printWriter.close();
+ stringWriter.printTo(outputStream);
+/// outputStream.print(stringWriter.toString());
+ } else if (isUseStream()) {
+ try {
+ servletOutputStream.flush();
+ } catch (IOException ex) {
+ log.warn(Messages.getMessage(Messages.FLUSH_BUFFERED_STREAM_ERROR), ex);
+ }
+ byteStream.writeTo(outputStream);
+ }
+ }
+
+ /**
+ * Send buffered content directly to output stream.
+ * @param outputStream
+ * @throws IOException
+ */
+ public void sendContent(Writer output) throws IOException {
+ if(getContentLength() >0 ){
+ super.setContentLength(getContentLength());
+ }
+ if (isUseWriter()) {
+ printWriter.flush();
+ printWriter.close();
+ stringWriter.writeTo(output);
+/// outputStream.print(stringWriter.toString());
+ } else if (isUseStream()) {
+ try {
+ servletOutputStream.flush();
+ } catch (IOException ex) {
+ log.warn(Messages.getMessage(Messages.FLUSH_BUFFERED_STREAM_ERROR), ex);
+ }
+ byteStream.writeTo(output,getCharacterEncoding());
+ }
+ }
+ /**
+ * @return Returns the useStream.
+ */
+ public boolean isUseStream() {
+ return this.useStream;
+ }
+
+ /**
+ * @return Returns the useWriter.
+ */
+ public boolean isUseWriter() {
+ return this.useWriter;
+ }
+
+ /**
+ * @return
+ * @throws RuntimeException
+ */
+ public InputSource getContentAsInputSource() throws RuntimeException {
+ // Create InputSource
+ InputSource inputSource = null;
+ String encoding = this.getCharacterEncoding() ;
+ if(isUseWriter()) {
+ inputSource = new InputSource(getContentAsReader());
+ } else if(isUseStream()) {
+ inputSource = new InputSource(getContentAsStream());
+ if (encoding != null)
+ inputSource.setEncoding(encoding);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.NO_WRITER_CALLED_INFO));
+ }
+ return null;
+ }
+ return inputSource;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletResponseWrapper#flushBuffer()
+ */
+ public void flushBuffer() throws IOException {
+ if(isUseStream()){
+ servletOutputStream.flush();
+ } else if(isUseWriter()){
+ printWriter.flush();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletResponseWrapper#getBufferSize()
+ */
+ public int getBufferSize() {
+ // TODO Auto-generated method stub
+ return bufferSize;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletResponseWrapper#resetBuffer()
+ */
+ public void resetBuffer() {
+ this.printWriter = null;
+ this.stringWriter = null;
+ this.servletOutputStream = null;
+ this.byteStream = null;
+ this.useStream = false;
+ this.useWriter = false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletResponseWrapper#setBufferSize(int)
+ */
+ public void setBufferSize(int arg0) {
+ // TODO Auto-generated method stub
+ bufferSize = arg0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.servlet.ServletResponseWrapper#reset()
+ */
+ public void reset() {
+ // TODO Auto-generated method stub
+ this.resetBuffer();
+ this.headers = new HashMap();
+ this.contentType=null;
+ this.charterEncoding=null;
+ super.reset();
+ }
+
+ /**
+ * @return Returns the contentLength.
+ */
+ public int getContentLength() {
+ return contentLength;
+ }
+
+ /**
+ * @param contentLength The contentLength to set.
+ */
+ public void setContentLength(int contentLength) {
+ this.contentLength = contentLength;
+ }
+
+ /**
+ * Parse saved content to output stream ( and store as Dom Document tree )
+ * @param out stream to send parsed content, if null - only build dom tree.
+ * @return parsed document as dom tree.
+ * @throws IOException
+ */
+ public void parseContent(Writer out,HtmlParser parser) throws IOException {
+ parser.setInputEncoding(getCharacterEncoding());
+ if (isUseWriter()) {
+ parser.parseHtml(getContentAsReader(),out);
+ } else if(isUseStream()){
+ parser.parseHtml(getContentAsStream(),out);
+ }
+ }
+
+ public void sendRedirect(String arg0) throws IOException {
+ // TODO Auto-generated method stub
+ this.redirectLocation = arg0;
+ }
+
+ public String getRedirectLocation() {
+ return redirectLocation;
+ }
+
+ /**
+ * @return the useNullStream
+ */
+ public boolean isUseNullStream() {
+ return useNullStream;
+ }
+
+ /**
+ * @param useNullStream the useNullStream to set
+ */
+ public void setUseNullStream(boolean useNullStream) {
+ this.useNullStream = useNullStream;
+ }
+
+
+
+ public void addCookie(Cookie cookie) {
+ cookies.add(cookie);
+ super.addCookie(cookie);
+ }
+
+ public Collection getCookies() {
+ return cookies;
+ }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/HtmlParser.java (from rev
1557,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/HtmlParser.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/HtmlParser.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/HtmlParser.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,71 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Set;
+
+public interface HtmlParser {
+
+ public abstract void parseHtml(InputStream input, Writer output)
+ throws IOException;
+
+ public abstract void parseHtml(Reader input, Writer output)
+ throws IOException;
+ /**
+ * @param encoding
+ */
+ public abstract void setInputEncoding(String encoding);
+
+ /**
+ * @param encoding
+ */
+ public abstract void setOutputEncoding(String encoding);
+ /**
+ * Setup, must tidy move style etc. elements to head or not.
+ * @param move
+ */
+ public abstract void setMoveElements(boolean move);
+
+ /**
+ * @param scripts The scripts to set.
+ */
+ public abstract void setScripts(Set scripts);
+
+ /**
+ * @param styles The styles to set.
+ */
+ public abstract void setStyles(Set styles);
+
+ public abstract void setDoctype(String doctype);
+
+ /**
+ * @param viewState The viewState to set.
+ */
+ public abstract void setViewState(String viewState);
+
+ public abstract boolean setMime(String mimeType);
+
+}
\ No newline at end of file
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/Log4JConfigurator.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/Log4JConfigurator.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/Log4JConfigurator.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/Log4JConfigurator.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,75 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import java.util.Properties;
+
+import org.ajax4jsf.Messages;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.helpers.OptionConverter;
+import org.apache.log4j.xml.DOMConfigurator;
+
+/**
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:18 $
+ *
+ */
+class Log4JConfigurator {
+ private static final String CONTEXT_ROOT_VARIABLE = "context-root";
+ private Properties props = new Properties();
+ private String prefix;
+
+ DOMConfigurator domConfig;
+
+ void doConfigure(String file){
+ domConfig.doConfigure(prefix + file, LogManager.getLoggerRepository());
+ }
+
+
+ /**
+ * @param prefix
+ */
+ public Log4JConfigurator(String prefix) {
+ this.prefix = prefix;
+ props.setProperty(CONTEXT_ROOT_VARIABLE, prefix);
+ domConfig = new DOMConfigurator() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.log4j.xml.DOMConfigurator#subst(java.lang.String)
+ * append context-related properties for variable
+ * substitution.
+ */
+ protected String subst(String value) {
+ try {
+ return OptionConverter.substVars(value, props);
+ } catch (IllegalArgumentException e) {
+ LogLog.warn(Messages.getMessage(Messages.VARIABLE_SUBSTITUTION_WARNING), e);
+ return value;
+ }
+ };
+
+ };
+ }
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/NekkoFilter.java (from rev
1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoFilter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/NekkoFilter.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/NekkoFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,50 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import org.ajax4jsf.webapp.nekko.NekkoXMLFilter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * This class implements a simple Servlet filter that convert basic html
+ * output of JSF to valid XML or JavaScript, for parsing different versions
+ * of XmlHttpRequest's on client side.
+ */
+public class NekkoFilter extends BaseFilter implements javax.servlet.Filter {
+ static final Log log = LogFactory.getLog(NekkoFilter.class);
+
+ /**
+ *
+ */
+ public NekkoFilter() {
+ super();
+ // default - not force
+// setForcexml(false);
+ xmlFilter = new NekkoXMLFilter();
+ xmlFilter.setFilter(this);
+ }
+
+}
+
+
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserConfig.java (from rev
1557,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ParserConfig.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserConfig.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserConfig.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,67 @@
+/**
+ *
+ */
+package org.ajax4jsf.webapp;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+abstract class ParserConfig {
+
+ private static final Pattern[] ALL_VIEWS_PATTERN = { Pattern.compile(".*")
};
+
+ private static final Pattern SEPARATOR_PATTERN =
Pattern.compile("\\s*,\\s*");
+
+ private Pattern[] patterns = ALL_VIEWS_PATTERN;
+
+ private ParserConfig next;
+
+ protected abstract HtmlParser createParser(String mimetype);
+
+ boolean storeParser(HtmlParser parser) {
+ return false;
+ }
+
+ HtmlParser getParser(String viewId, String mimetype) {
+ HtmlParser result = null;
+ for (int i = 0; i < patterns.length && null == result; i++) {
+ Matcher matcher = patterns[i].matcher(viewId);
+ if (matcher.matches()) {
+ result = createParser(mimetype);
+ }
+ }
+ if (null == result && null != next) {
+ result = next.getParser(viewId, mimetype);
+ }
+ return result;
+ }
+
+ public void reuseParser(HtmlParser parser) {
+ if (!storeParser(parser) && null != next) {
+ next.reuseParser(parser);
+ }
+ }
+
+ public ParserConfig getNext() {
+ return next;
+ }
+
+ public void setNext(ParserConfig next) {
+ this.next = next;
+ }
+
+ public void setPatterns(String patternsString) {
+ if (null != patternsString) {
+ String[] split = SEPARATOR_PATTERN.split(patternsString);
+ patterns = new Pattern[split.length];
+ for (int i = 0; i < split.length; i++) {
+ patterns[i]=Pattern.compile(split[i].trim());
+ }
+ }
+ }
+
+ public Pattern[] getPatterns() {
+ return patterns;
+ }
+
+}
\ No newline at end of file
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/PollEventsManager.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,64 @@
+/**
+ *
+ */
+package org.ajax4jsf.webapp;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.faces.FacesException;
+import javax.servlet.ServletContext;
+
+import org.ajax4jsf.ajax.PushEventsCounter;
+import org.ajax4jsf.cache.Cache;
+import org.ajax4jsf.cache.CacheConfigurationLoader;
+import org.ajax4jsf.cache.CacheException;
+import org.ajax4jsf.cache.CacheFactory;
+import org.ajax4jsf.cache.CacheLoader;
+import org.ajax4jsf.cache.CacheManager;
+import org.ajax4jsf.cache.ServletContextInitMap;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PollEventsManager implements Serializable, CacheLoader,
CacheConfigurationLoader {
+
+ public static final String EVENTS_MANAGER_KEY=PollEventsManager.class.getName();
+
+ private Cache cache;
+
+ public void init(ServletContext servletContext) {
+ try {
+ CacheManager cacheManager = CacheManager.getInstance();
+ Map env = new ServletContextInitMap(servletContext);
+ CacheFactory cacheFactory = cacheManager.getCacheFactory(env);
+ this.cache = cacheFactory.createCache(env, this, this);
+ servletContext.setAttribute(EVENTS_MANAGER_KEY, this);
+ } catch (CacheException e) {
+ throw new FacesException(e.getMessage(), e);
+ }
+
+ }
+
+ public PushEventsCounter getListener(String key){
+ if(null == cache){
+ throw new FacesException("Poll events manager not initialized");
+ }
+ try {
+ return (PushEventsCounter) cache.get(key, null);
+ } catch (CacheException e) {
+ throw new FacesException("error get push events listener for key
"+key,e);
+ }
+ }
+
+ public Object load(Object key, Object context) throws CacheException {
+ // TODO Auto-generated method stub
+ return new PushEventsCounter();
+ }
+
+ public Properties loadProperties(String name) {
+ return new Properties();
+ }
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletStreamWriter.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/ServletStreamWriter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletStreamWriter.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ServletStreamWriter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,111 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletOutputStream;
+
+/**
+ * HACK - for case if servlet response already use Writer, create wrapper to stream -
+ * since most of serializers use outputStream. In future, must be replaced by Dual
serialization
+ * capabilites.
+ * @author shura
+ *
+ */
+final class ServletStreamWriter extends ServletOutputStream {
+
+ private PrintWriter _writer;
+
+ private byte[] buff = new byte[1024];
+
+ private int point = 0;
+
+ private String _charset;
+
+ /**
+ * @param writer
+ * @param charset
+ */
+ public ServletStreamWriter(PrintWriter writer, String charset) {
+ super();
+ // TODO Auto-generated constructor stub
+ _writer = writer;
+ _charset = charset;
+ }
+
+ public ServletStreamWriter(PrintWriter writer) {
+ this._writer = writer;
+ }
+
+ public void write(int b) throws IOException {
+ buff[point++]=(byte) b;
+ if(point==buff.length){
+ point = 0;
+ String string = null==_charset?new String(buff):new String(buff,_charset);
+ _writer.write(string);
+ }
+ }
+
+ /**
+ * @return Returns the charset.
+ */
+ public String getCharset() {
+ return _charset;
+ }
+
+ /**
+ * @param charset The charset to set.
+ */
+ public void setCharset(String charset) {
+ _charset = charset;
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.OutputStream#close()
+ */
+ public void close() throws IOException {
+ this.flush();
+ super.close();
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.OutputStream#flush()
+ */
+ public void flush() throws IOException {
+ if(point>0){
+ String string = null==_charset?new String(buff,0,point):new
String(buff,0,point,_charset);
+ _writer.write(string);
+ point = 0;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.io.OutputStream#write(byte[], int, int)
+ */
+ public void write(byte[] b, int off, int len) throws IOException {
+ this.flush();
+ String string = null==_charset?new String(b,off,len):new String(b,off,len,_charset);
+ _writer.write(string);
+ }
+}
\ No newline at end of file
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/TidyFilter.java (from rev
1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/TidyFilter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/TidyFilter.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/TidyFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,44 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import org.ajax4jsf.webapp.tidy.TidyXMLFilter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * Convert Html Output to XML using Jtidy.
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:20 $
+ */
+public class TidyFilter extends BaseFilter {
+ static final Log log = LogFactory.getLog(TidyFilter.class);
+
+ public TidyFilter() {
+ // For Tidy, publicId can be pre-defined omit | auto | strict | loose | ignore | [fpi]
+ xmlFilter = new TidyXMLFilter();
+ xmlFilter.setFilter(this);
+ xmlFilter.setPublicid("omit");
+ }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/XMLResponseWriterState.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/XMLResponseWriterState.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/XMLResponseWriterState.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/XMLResponseWriterState.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,134 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+
+import org.ajax4jsf.Messages;
+
+/**
+ * @author shura Class to implement state pattern for
+ * <code>ResponceWriter</code> Real states must extend this. By
+ * default, block any events, ignore output.
+ *
+ */
+class XMLResponseWriterState {
+ // private ResponseWriter writer;
+ /**
+ * @throws java.io.IOException
+ */
+ private static final String ILLEGAL_METOD_STATE =
Messages.getMessage(Messages.ILLEGAL_METHOD_STATE);
+
+ void endDocument() throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ * @param name
+ * @throws java.io.IOException
+ */
+ void endElement(String name) throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ * @throws java.io.IOException
+ */
+ void startDocument() throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ * @param name
+ * @param component
+ * @throws java.io.IOException
+ */
+ void startElement(String name, UIComponent component) throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ * @param name
+ * @param value
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeAttribute(String name, Object value, String property)
+ throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ * @param comment
+ * @throws java.io.IOException
+ */
+ void writeComment(Object comment) throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ * @param text
+ * @param off
+ * @param len
+ * @throws java.io.IOException
+ */
+ void writeText(char[] text, int off, int len) throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ * @param text
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeText(Object text, String property) throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ * @param name
+ * @param value
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeURIAttribute(String name, Object value, String property)
+ throws IOException {
+ throw new IOException(ILLEGAL_METOD_STATE);
+ }
+
+ /**
+ *
+ * Main hook for realise <code>Writer</code>. In document writed as
+ * comment, outside of document do nothing ....
+ *
+ * @param cbuf
+ * @param off
+ * @param len
+ * @throws IOException
+ */
+ void write(char[] cbuf, int off, int len) throws IOException {
+ // DO NOTHING
+
+ }
+}
\ No newline at end of file
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko (from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko)
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/HtmlCorrectionFilter.java 2007-07-09
15:13:40 UTC (rev 1551)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,166 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter.nekko;
-
-import org.apache.xerces.util.XMLAttributesImpl;
-import org.apache.xerces.xni.Augmentations;
-import org.apache.xerces.xni.QName;
-import org.apache.xerces.xni.XMLAttributes;
-import org.apache.xerces.xni.XNIException;
-import org.apache.xerces.xni.parser.XMLComponentManager;
-import org.apache.xerces.xni.parser.XMLConfigurationException;
-import org.cyberneko.html.HTMLAugmentations;
-import org.cyberneko.html.filters.DefaultFilter;
-
-/**
- * Fix common DHTML incompabilites for html - insert ommited tbody tag in tables.
- * @author shura
- *
- */
-public class HtmlCorrectionFilter extends DefaultFilter{
-
- private HtmlCorrectionState _state;
-
-
- /**
- *
- */
- public HtmlCorrectionFilter() {
- super();
- _state = new BaseHtmlCorrectionState(null);
- }
-
- public void reset(XMLComponentManager componentManager)
- throws XMLConfigurationException {
- super.reset(componentManager);
- _state = new BaseHtmlCorrectionState(null);
- }
-
- /* (non-Javadoc)
- * @see org.cyberneko.html.filters.DefaultFilter#endElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.Augmentations)
- */
- public void endElement(QName element, Augmentations augs) throws XNIException {
- _state.endElement(element,augs);
- super.endElement(element, augs);
- }
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#startElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
- */
- public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
- _state.startElement(element,attributes,augs);
- super.startElement(element, attributes, augs);
- }
-
- void insertStartElement(String name, QName base) {
- QName element = createQName(name, base);
- XMLAttributes attrs = new XMLAttributesImpl();
- Augmentations augs = new HTMLAugmentations();
- super.startElement(element,attrs,augs);
- }
-
- /**
- * @param name
- * @param base
- * @return
- */
- private QName createQName(String name, QName base) {
- String prefix = base.prefix;
- String rawname = null != prefix && (!"".equals(prefix))?
prefix+':'+name:name;
- QName element = new QName(prefix,name,rawname,base.uri);
- return element;
- }
-
-
- void insertEndElement(String name, QName base) {
- QName element = createQName(name, base);
- Augmentations augs = new HTMLAugmentations();
- super.endElement(element,augs);
- }
-
- private class BaseHtmlCorrectionState implements HtmlCorrectionState {
- private int depth = 0;
- private HtmlCorrectionState previsiosState;
- /**
- * @param previsiosState
- */
- public BaseHtmlCorrectionState(HtmlCorrectionState previsiosState) {
- super();
- // TODO Auto-generated constructor stub
- this.previsiosState = previsiosState;
- }
- public void endElement(QName element, Augmentations augs) throws XNIException {
- depth--;
- if(depth<0 && previsiosState != null){
- _state = previsiosState;
- }
- }
-
- public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
- if(element.rawname.equalsIgnoreCase("table")){
- _state = new TableHtmlCorrectionState(this);
- } else {
- depth++;
- }
- }
-
-
- }
- private class TableHtmlCorrectionState implements HtmlCorrectionState {
- private int depth = 0;
- private boolean inTbody = false;
- private HtmlCorrectionState previsiosState;
- /**
- * @param previsiosState
- */
- public TableHtmlCorrectionState(HtmlCorrectionState previsiosState) {
- super();
- // TODO Auto-generated constructor stub
- this.previsiosState = previsiosState;
- }
-
- public void endElement(QName element, Augmentations augs) throws XNIException {
- if (inTbody) {
- insertEndElement("tbody", element);
- }
- _state = previsiosState;
- }
-
- public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
- if(element.rawname.equalsIgnoreCase("tr")){
- if(!inTbody){
- inTbody = true;
- insertStartElement("tbody", element);
- }
- } else {
- if (inTbody) {
- insertEndElement("tbody", element);
- inTbody = false;
- }
- }
- _state = new BaseHtmlCorrectionState(this);
- }
-
-
- }
-
-}
\ No newline at end of file
Copied:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionFilter.java
(from rev 1558,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/HtmlCorrectionFilter.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionFilter.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,166 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter.nekko;
+
+import org.apache.xerces.util.XMLAttributesImpl;
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XNIException;
+import org.apache.xerces.xni.parser.XMLComponentManager;
+import org.apache.xerces.xni.parser.XMLConfigurationException;
+import org.cyberneko.html.HTMLAugmentations;
+import org.cyberneko.html.filters.DefaultFilter;
+
+/**
+ * Fix common DHTML incompabilites for html - insert ommited tbody tag in tables.
+ * @author shura
+ *
+ */
+public class HtmlCorrectionFilter extends DefaultFilter{
+
+ private HtmlCorrectionState _state;
+
+
+ /**
+ *
+ */
+ public HtmlCorrectionFilter() {
+ super();
+ _state = new BaseHtmlCorrectionState(null);
+ }
+
+ public void reset(XMLComponentManager componentManager)
+ throws XMLConfigurationException {
+ super.reset(componentManager);
+ _state = new BaseHtmlCorrectionState(null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.cyberneko.html.filters.DefaultFilter#endElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.Augmentations)
+ */
+ public void endElement(QName element, Augmentations augs) throws XNIException {
+ _state.endElement(element,augs);
+ super.endElement(element, augs);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#startElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
+ */
+ public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
+ _state.startElement(element,attributes,augs);
+ super.startElement(element, attributes, augs);
+ }
+
+ void insertStartElement(String name, QName base) {
+ QName element = createQName(name, base);
+ XMLAttributes attrs = new XMLAttributesImpl();
+ Augmentations augs = new HTMLAugmentations();
+ super.startElement(element,attrs,augs);
+ }
+
+ /**
+ * @param name
+ * @param base
+ * @return
+ */
+ private QName createQName(String name, QName base) {
+ String prefix = base.prefix;
+ String rawname = null != prefix && (!"".equals(prefix))?
prefix+':'+name:name;
+ QName element = new QName(prefix,name,rawname,base.uri);
+ return element;
+ }
+
+
+ void insertEndElement(String name, QName base) {
+ QName element = createQName(name, base);
+ Augmentations augs = new HTMLAugmentations();
+ super.endElement(element,augs);
+ }
+
+ private class BaseHtmlCorrectionState implements HtmlCorrectionState {
+ private int depth = 0;
+ private HtmlCorrectionState previsiosState;
+ /**
+ * @param previsiosState
+ */
+ public BaseHtmlCorrectionState(HtmlCorrectionState previsiosState) {
+ super();
+ // TODO Auto-generated constructor stub
+ this.previsiosState = previsiosState;
+ }
+ public void endElement(QName element, Augmentations augs) throws XNIException {
+ depth--;
+ if(depth<0 && previsiosState != null){
+ _state = previsiosState;
+ }
+ }
+
+ public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
+ if(element.rawname.equalsIgnoreCase("table")){
+ _state = new TableHtmlCorrectionState(this);
+ } else {
+ depth++;
+ }
+ }
+
+
+ }
+ private class TableHtmlCorrectionState implements HtmlCorrectionState {
+ private int depth = 0;
+ private boolean inTbody = false;
+ private HtmlCorrectionState previsiosState;
+ /**
+ * @param previsiosState
+ */
+ public TableHtmlCorrectionState(HtmlCorrectionState previsiosState) {
+ super();
+ // TODO Auto-generated constructor stub
+ this.previsiosState = previsiosState;
+ }
+
+ public void endElement(QName element, Augmentations augs) throws XNIException {
+ if (inTbody) {
+ insertEndElement("tbody", element);
+ }
+ _state = previsiosState;
+ }
+
+ public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
+ if(element.rawname.equalsIgnoreCase("tr")){
+ if(!inTbody){
+ inTbody = true;
+ insertStartElement("tbody", element);
+ }
+ } else {
+ if (inTbody) {
+ insertEndElement("tbody", element);
+ inTbody = false;
+ }
+ }
+ _state = new BaseHtmlCorrectionState(this);
+ }
+
+
+ }
+
+}
\ No newline at end of file
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionState.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/HtmlCorrectionState.java 2007-07-09
15:13:40 UTC (rev 1551)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionState.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,33 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter.nekko;
-
-import org.apache.xerces.xni.Augmentations;
-import org.apache.xerces.xni.QName;
-import org.apache.xerces.xni.XMLAttributes;
-import org.apache.xerces.xni.XNIException;
-
-public interface HtmlCorrectionState {
-
- public void endElement(QName element, Augmentations augs) throws XNIException;
- public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException;
-}
Copied:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionState.java
(from rev 1558,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/HtmlCorrectionState.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionState.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/HtmlCorrectionState.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,33 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter.nekko;
+
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XNIException;
+
+public interface HtmlCorrectionState {
+
+ public void endElement(QName element, Augmentations augs) throws XNIException;
+ public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException;
+}
Deleted: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java 2007-07-09
15:13:40 UTC (rev 1551)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,644 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter.nekko;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.servlet.ServletException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
-import org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser;
-import org.ajax4jsf.xml.serializer.Method;
-import org.ajax4jsf.xml.serializer.OutputPropertiesFactory;
-import org.ajax4jsf.xml.serializer.Serializer;
-import org.ajax4jsf.xml.serializer.SerializerFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.html.dom.HTMLDocumentImpl;
-import org.apache.xerces.parsers.AbstractSAXParser;
-import org.apache.xerces.util.XMLAttributesImpl;
-import org.apache.xerces.xni.Augmentations;
-import org.apache.xerces.xni.QName;
-import org.apache.xerces.xni.XMLAttributes;
-import org.apache.xerces.xni.XMLString;
-import org.apache.xerces.xni.XNIException;
-import org.apache.xerces.xni.parser.XMLComponentManager;
-import org.apache.xerces.xni.parser.XMLConfigurationException;
-import org.apache.xerces.xni.parser.XMLDocumentFilter;
-import org.cyberneko.html.HTMLAugmentations;
-import org.cyberneko.html.HTMLConfiguration;
-import org.cyberneko.html.filters.DefaultFilter;
-import org.cyberneko.html.filters.ElementRemover;
-import org.cyberneko.html.filters.Purifier;
-import org.cyberneko.html.filters.Writer;
-import org.cyberneko.html.parsers.DOMFragmentParser;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- * @author shura
- *
- */
-public class NekkoParser implements HtmlParser {
-
- private static final Log _log = LogFactory.getLog(NekkoParser.class);
-
- private HtmlSAXParser _parser;
-
-// private HtmlWriter _writer= new HtmlWriter();
-
- private ElementRemover remover = new ElementRemover();
-
- private XMLDocumentFilter[] _filters = { new ViewStateFilter()/*,remover */, new
HtmlCorrectionFilter(), new Purifier() /*, _writer*/ };
-
- private DOMFragmentParser viewStateParser ;//= new DOMFragmentParser();
-
- private Document viewStateDocument ;//= new HTMLDocumentImpl();
-
- private DocumentFragment fragment = null;
-
- private Set _scripts;
-
- private Set _styles;
-
- private String _viewState;
-
- private String _encoding;
-
- private Serializer _serializer;
-
- private String _publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";
- private String _systemid =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
- private String _namespace = "http://www.w3.org/1999/xhtml";
-
- private String _outputEncoding;
- /**
- *
- */
- public NekkoParser() {
- _parser=new HtmlSAXParser(getHtmlConfig());
- Properties properties =
OutputPropertiesFactory.getDefaultMethodProperties(Method.XHTML);
-// properties.put("encoding",_encoding);
- _serializer = SerializerFactory.getSerializer(properties);
-// serializer.setOutputStream(output);
-// _parser.setContentHandler(serializer.asContentHandler());
- viewStateParser = new DOMFragmentParser();
- // Set parser features
- try {
- viewStateParser.setProperty(
- "http://cyberneko.org/html/properties/names/elems",
- "lower");
- viewStateParser.setProperty(
- "http://cyberneko.org/html/properties/names/attrs",
- "lower");
- } catch (SAXException e) {
- _log.error("Exception in DOM parser configuration", e);
- }
- try {
- // Create Document Builder Factory
- DocumentBuilderFactory docFactory = DocumentBuilderFactory
- .newInstance();
- // Create Document Builder
- DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
- viewStateDocument = docBuilder.newDocument();
- } catch (ParserConfigurationException e) {
- viewStateDocument = new HTMLDocumentImpl();
- _log.error("Error on create DOM Document by JAXP, use Xerxes implementation.
Check JAXP configuration ",e);
- }
-// viewStateDocument = new HTMLDocumentImpl();
- remover.removeElement("style");
- }
-
- /**
- * Reset parser state
- */
- public void reset(){
- _scripts=null;
- _styles=null;
- _viewState=null;
- _parser.reset();
- _serializer.reset();
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#parseHtml(java.io.InputStream,
java.io.OutputStream)
- */
- public void parseHtml(InputStream input, java.io.Writer output)
- throws IOException {
- InputSource src = new InputSource(input);
- parseSAXSource(src,output);
- }
-
- private void parseSAXSource(InputSource src, java.io.Writer output) throws IOException
{
-// PrintWriter printWriter = null;
- fragment = null;
- if(null != _viewState){
- fragment = viewStateDocument.createDocumentFragment();
- try {
- viewStateParser.parse(new InputSource(new StringReader(
- _viewState)), fragment);
- } catch (Exception e) {
- fragment = null;
- }
- // TODO - parse view state to DOM Fragment.
- }
- try {
-
_parser.setProperty("http://cyberneko.org/html/properties/default-en...;,
- _encoding);
- Properties properties = _serializer.getOutputFormat();
- properties.put("encoding",_outputEncoding);
- _serializer.setOutputFormat(properties);
- _serializer.setWriter(output);
-// _serializer.setOutputStream(new OutputStream(){
-//
-// public void write(int b) throws IOException {
-// // TODO Auto-generated method stub
-//
-// }});
- _parser.setContentHandler(_serializer.asContentHandler());
-// printWriter = new PrintWriter(output);
-// _writer.setWriter(printWriter);
-// _writer.setEncoding(_encoding);
- _parser.parse(src);
- } catch (SAXException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
-// _writer.setWriter(null);
-// if(null != printWriter){
-// printWriter.flush();
-// printWriter.close();
-// }
-
- }
-
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#parseHtml(java.io.Reader,
java.io.OutputStream)
- */
- public void parseHtml(Reader input, java.io.Writer output) throws IOException {
- InputSource src = new InputSource(input);
- parseSAXSource(src,output);
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setEncoding(java.lang.String)
- */
- public void setInputEncoding(String encoding) {
- _encoding = encoding;
- }
-
- public void setOutputEncoding(String encoding) {
- _outputEncoding = encoding;
- }
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setMoveElements(boolean)
- */
- public void setMoveElements(boolean move) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setScripts(java.util.Set)
- */
- public void setScripts(Set scripts) {
- _scripts = scripts;
-
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setStyles(java.util.Set)
- */
- public void setStyles(Set styles) {
- _styles = styles;
-
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setDoctype(java.lang.String)
- */
- public void setDoctype(String doctype) {
- this._publicId = doctype;
-
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setViewState(java.lang.String)
- */
- public void setViewState(String viewState) {
- _viewState = viewState;
-
- }
-
- private static class HtmlSAXParser extends AbstractSAXParser {
- /** Default constructor.
- * @throws ServletException */
- public HtmlSAXParser(HTMLConfiguration config) {
- super(config);
-
- }
- }
-
- private class ViewStateFilter extends DefaultFilter{
- private boolean haveHtml = false;
- private boolean haveHead = false;
- private boolean headParsed = false;
- private int stateMarkerLevel = -1;
-
-
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#reset(org.apache.xerces.xni.parser.XMLComponentManager)
- */
- public void reset(XMLComponentManager componentManager) throws
XMLConfigurationException {
- haveHead = false;
- haveHtml = false;
- headParsed = false;
- stateMarkerLevel = -1;
- super.reset(componentManager);
- }
-
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#startElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
- */
- public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
- if(stateMarkerLevel >=0){
- stateMarkerLevel++;
- if(null != fragment){
- return;
- }
- }
- if (!headParsed) {
- if("html".equalsIgnoreCase(element.rawname)){
- haveHtml = true;
- } else if("head".equalsIgnoreCase(element.rawname)){
- haveHead = true;
- super.startElement(element, attributes, augs);
- insertResources();
- return;
- } else {
- if(!haveHtml){
- insertStartElement("html");
- }
- insertStartElement("head");
- insertResources();
- insertEndElement("head");
- }
-
- }
- if(isStateMarker(element, attributes)){
- stateMarkerLevel = 0;
- return;
- };
- super.startElement(element, attributes, augs);
- }
-
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#characters(org.apache.xerces.xni.XMLString,
org.apache.xerces.xni.Augmentations)
- */
- public void characters(XMLString text, Augmentations augs) throws XNIException {
- if(stateMarkerLevel >=0){
- if(null != fragment){
- return;
- }
- }
- super.characters(text, augs);
- }
-
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#endElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.Augmentations)
- */
- public void endElement(QName element, Augmentations augs) throws XNIException {
- if(stateMarkerLevel >=0){
- stateMarkerLevel--;
- if(null != fragment || stateMarkerLevel == -1){
- return;
- }
- }
- super.endElement(element, 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);
- }
- }
- if(null != _scripts){
- for (Iterator iter = _scripts.iterator(); iter.hasNext();) {
- String script = (String) iter.next();
- QName element = new QName(null,"script","script",null);
- XMLAttributes attrs = new XMLAttributesImpl();
- attrs.addAttribute(new QName(null,"src","src",null),
"CDATA", script);
- attrs.addAttribute(new QName(null,"type","type",null),
"CDATA", "text/javascript");
- Augmentations augs = new HTMLAugmentations();
- super.startElement(element,attrs,augs);
- super.endElement(element, augs);
- }
- }
-
- }
-
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#emptyElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
- */
- public void emptyElement(QName name, XMLAttributes attributes, Augmentations
augmentation) throws XNIException {
- if(stateMarkerLevel >=0){
- if(null != fragment){
- return;
- }
- }
- if (!headParsed) {
- if("head".equalsIgnoreCase(name.rawname)){
- haveHead = true;
- super.startElement(name, attributes, augmentation);
- insertResources();
- insertEndElement(name.rawname);
- return;
- }
- }
- if(isStateMarker(name, attributes)){
- return;
- };
- super.emptyElement(name, attributes, augmentation);
- }
-
-
- /**
- * @param name
- * @param attributes
- */
- private boolean isStateMarker(QName name, XMLAttributes attributes) {
- if(name.rawname.equalsIgnoreCase("span") &&
AjaxViewHandler.STATE_MARKER_KEY.equals(attributes.getValue("id"))){
- // STATE marker element - out real content.
- if(null != fragment){
- try {
- _serializer.asDOMSerializer().serialize(fragment);
- } catch (IOException e) {
- // Break output.
- }
- }
- return true;
- }
- return false;
- }
-
- void insertStartElement(String name) {
- QName element = new QName(null,name,name,null);
- XMLAttributes attrs = new XMLAttributesImpl();
- Augmentations augs = new HTMLAugmentations();
- super.startElement(element,attrs,augs);
- }
-
-
- void insertEndElement(String name) {
- QName element = new QName(null,name,name,null);
-// XMLAttributes attrs = new XMLAttributesImpl();
- Augmentations augs = new HTMLAugmentations();
- super.endElement(element,augs);
- }
-
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#endDocument(org.apache.xerces.xni.Augmentations)
- */
- public void endDocument(Augmentations augs) throws XNIException {
- if (!haveHtml) {
- insertEndElement("html");
- }
- super.endDocument(augs);
- }
-
-
-
- }
-
- private static class HtmlWriter extends Writer {
-
- /**
- *
- */
- public HtmlWriter() {
- super();
- fEncoding = "UTF-8";
- }
-
- public void setEncoding(String encoding){
- this.fEncoding = encoding;
- }
-
- public void setWriter( PrintWriter writer){
- this.fPrinter = writer;
- }
-
- /* (non-Javadoc)
- * @see org.cyberneko.html.filters.Writer#emptyElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
- */
- public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
- // TODO Auto-generated method stub
- super.emptyElement(element, attributes, augs);
- printEndElement(element);
- }
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#endCDATA(org.apache.xerces.xni.Augmentations)
- */
- public void endCDATA(Augmentations augs) throws XNIException {
- // TODO Auto-generated method stub
- super.endCDATA(augs);
- }
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#startCDATA(org.apache.xerces.xni.Augmentations)
- */
- public void startCDATA(Augmentations augs) throws XNIException {
- // TODO Auto-generated method stub
- super.startCDATA(augs);
- }
-
- /* (non-Javadoc)
- * @see org.cyberneko.html.filters.DefaultFilter#textDecl(java.lang.String,
java.lang.String, org.apache.xerces.xni.Augmentations)
- */
- public void textDecl(String version, String encoding, Augmentations augs) throws
XNIException {
- // TODO Auto-generated method stub
- super.textDecl(version, encoding, augs);
- }
-
- /* (non-Javadoc)
- * @see org.cyberneko.html.filters.DefaultFilter#xmlDecl(java.lang.String,
java.lang.String, java.lang.String, org.apache.xerces.xni.Augmentations)
- */
- public void xmlDecl(String version, String encoding, String standalone, Augmentations
augs) throws XNIException {
- // TODO Auto-generated method stub
- super.xmlDecl(version, encoding, standalone, augs);
- }
-
-
- }
- /**
- * Factory method for create and configure HTML parser configuration.
- * Create configuration for use in parsing, set nessesary features and properties
- * @return
- * @throws ServletException
- */
- protected HTMLConfiguration getHtmlConfig() {
- HTMLConfiguration _config = new HTMLConfiguration();
- try {
- if (this.getPublicid() != null || this.getSystemid() != null) {
- _config.setFeature(
- "http://cyberneko.org/html/features/insert-doctype",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/override-doctype",
- true);
- }
- if (this.getPublicid() != null) {
- _config.setProperty(
- "http://cyberneko.org/html/properties/doctype/pubid",
- getPublicid());
-
- }
- if (this.getSystemid() != null) {
- _config.setProperty(
- "http://cyberneko.org/html/properties/doctype/sysid",
- getSystemid());
-
- }
- if (this.getNamespace() != null) {
- _config.setFeature(
- "http://xml.org/sax/features/namespaces",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/override-namespaces",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/insert-namespaces",
- true);
- _config.setProperty(
- "http://cyberneko.org/html/properties/namespaces-uri",
- getNamespace());
-
- }
- // config
- // .setFeature(
- //
"http://cyberneko.org/html/features/balance-tags/ignore-outside-content",
- // true);
- _config
- .setFeature(
- "http://cyberneko.org/html/features/scanner/cdata-sections",
- true);
- _config
- .setFeature(
- "http://cyberneko.org/html/features/scanner/script/strip-comment-delims",
- true);
- _config
- .setFeature(
- "http://cyberneko.org/html/features/scanner/style/strip-comment-delims",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/insert-doctype",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/insert-namespaces",
- true);
- //
- // Set properties
http://cyberneko.org/html/features/insert-namespaces
- // _config
- // .setProperty(
- // "http://cyberneko.org/html/properties/default-encoding",
- // encoding);
- _config.setProperty(
- "http://cyberneko.org/html/properties/names/elems",
- "lower");
- _config.setProperty(
- "http://cyberneko.org/html/properties/names/attrs",
- "lower");
-
_config.setProperty("http://cyberneko.org/html/properties/filters",
_filters);
- } catch (XMLConfigurationException e) {
-// throw new ServletException("error set Neko feature ", e);
- }
- return _config;
- }
-
- private String getNamespace() {
- // TODO Auto-generated method stub
- return this._namespace;
- }
-
- private String getSystemid() {
- // TODO Auto-generated method stub
- return this._systemid;
- }
-
- private String getPublicid() {
- // TODO Auto-generated method stub
- return this._publicId;
- }
-
- /**
- * @param namespace The namespace to set.
- */
- public void setNamespace(String namespace) {
- _namespace = namespace;
- }
-
- /**
- * @param publicId The publicId to set.
- */
- public void setPublicId(String publicId) {
- _publicId = publicId;
- }
-
- /**
- * @param systemid The systemid to set.
- */
- public void setSystemid(String systemid) {
- _systemid = systemid;
- }
-
-}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java
(from rev 1558,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoParser.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,649 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp.nekko;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.servlet.ServletException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.ajax4jsf.application.AjaxViewHandler;
+import org.ajax4jsf.webapp.HtmlParser;
+import org.ajax4jsf.xml.serializer.Method;
+import org.ajax4jsf.xml.serializer.OutputPropertiesFactory;
+import org.ajax4jsf.xml.serializer.Serializer;
+import org.ajax4jsf.xml.serializer.SerializerFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.html.dom.HTMLDocumentImpl;
+import org.apache.xerces.parsers.AbstractSAXParser;
+import org.apache.xerces.util.XMLAttributesImpl;
+import org.apache.xerces.xni.Augmentations;
+import org.apache.xerces.xni.QName;
+import org.apache.xerces.xni.XMLAttributes;
+import org.apache.xerces.xni.XMLString;
+import org.apache.xerces.xni.XNIException;
+import org.apache.xerces.xni.parser.XMLComponentManager;
+import org.apache.xerces.xni.parser.XMLConfigurationException;
+import org.apache.xerces.xni.parser.XMLDocumentFilter;
+import org.cyberneko.html.HTMLAugmentations;
+import org.cyberneko.html.HTMLConfiguration;
+import org.cyberneko.html.filters.DefaultFilter;
+import org.cyberneko.html.filters.ElementRemover;
+import org.cyberneko.html.filters.Purifier;
+import org.cyberneko.html.filters.Writer;
+import org.cyberneko.html.parsers.DOMFragmentParser;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * @author shura
+ *
+ */
+public class NekkoParser implements HtmlParser {
+
+ private static final Log _log = LogFactory.getLog(NekkoParser.class);
+
+ private HtmlSAXParser _parser;
+
+// private HtmlWriter _writer= new HtmlWriter();
+
+ private ElementRemover remover = new ElementRemover();
+
+ private XMLDocumentFilter[] _filters = { new ViewStateFilter()/*,remover */, new
HtmlCorrectionFilter(), new Purifier() /*, _writer*/ };
+
+ private DOMFragmentParser viewStateParser ;//= new DOMFragmentParser();
+
+ private Document viewStateDocument ;//= new HTMLDocumentImpl();
+
+ private DocumentFragment fragment = null;
+
+ private Set _scripts;
+
+ private Set _styles;
+
+ private String _viewState;
+
+ private String _encoding;
+
+ private Serializer _serializer;
+
+ private String _publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";
+ private String _systemid =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
+ private String _namespace = "http://www.w3.org/1999/xhtml";
+
+ private String _outputEncoding;
+ /**
+ *
+ */
+ public NekkoParser() {
+ _parser=new HtmlSAXParser(getHtmlConfig());
+// Properties properties =
OutputPropertiesFactory.getDefaultMethodProperties(Method.XHTML);
+ Properties properties =
OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
+// properties.put("encoding",_encoding);
+ _serializer = SerializerFactory.getSerializer(properties);
+// serializer.setOutputStream(output);
+// _parser.setContentHandler(serializer.asContentHandler());
+ viewStateParser = new DOMFragmentParser();
+ // Set parser features
+ try {
+ viewStateParser.setProperty(
+ "http://cyberneko.org/html/properties/names/elems",
+ "lower");
+ viewStateParser.setProperty(
+ "http://cyberneko.org/html/properties/names/attrs",
+ "lower");
+ } catch (SAXException e) {
+ _log.error("Exception in DOM parser configuration", e);
+ }
+ try {
+ // Create Document Builder Factory
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory
+ .newInstance();
+ // Create Document Builder
+ DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+ viewStateDocument = docBuilder.newDocument();
+ } catch (ParserConfigurationException e) {
+ viewStateDocument = new HTMLDocumentImpl();
+ _log.error("Error on create DOM Document by JAXP, use Xerxes implementation.
Check JAXP configuration ",e);
+ }
+// viewStateDocument = new HTMLDocumentImpl();
+ remover.removeElement("style");
+ }
+
+ /**
+ * Reset parser state
+ */
+ public void reset(){
+ _scripts=null;
+ _styles=null;
+ _viewState=null;
+ _parser.reset();
+ _serializer.reset();
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.webapp.HtmlParser#parseHtml(java.io.InputStream,
java.io.OutputStream)
+ */
+ public void parseHtml(InputStream input, java.io.Writer output)
+ throws IOException {
+ InputSource src = new InputSource(input);
+ parseSAXSource(src,output);
+ }
+
+ private void parseSAXSource(InputSource src, java.io.Writer output) throws IOException
{
+// PrintWriter printWriter = null;
+ fragment = null;
+ if(null != _viewState){
+ fragment = viewStateDocument.createDocumentFragment();
+ try {
+ viewStateParser.parse(new InputSource(new StringReader(
+ _viewState)), fragment);
+ } catch (Exception e) {
+ fragment = null;
+ }
+ // TODO - parse view state to DOM Fragment.
+ }
+ try {
+
_parser.setProperty("http://cyberneko.org/html/properties/default-en...;,
+ _encoding);
+ Properties properties = _serializer.getOutputFormat();
+ properties.put("encoding",_outputEncoding);
+ _serializer.setOutputFormat(properties);
+ _serializer.setWriter(output);
+// _serializer.setOutputStream(new OutputStream(){
+//
+// public void write(int b) throws IOException {
+// // TODO Auto-generated method stub
+//
+// }});
+ _parser.setContentHandler(_serializer.asContentHandler());
+// printWriter = new PrintWriter(output);
+// _writer.setWriter(printWriter);
+// _writer.setEncoding(_encoding);
+ _parser.parse(src);
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+// _writer.setWriter(null);
+// if(null != printWriter){
+// printWriter.flush();
+// printWriter.close();
+// }
+
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.webapp.HtmlParser#parseHtml(java.io.Reader, java.io.OutputStream)
+ */
+ public void parseHtml(Reader input, java.io.Writer output) throws IOException {
+ InputSource src = new InputSource(input);
+ parseSAXSource(src,output);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.webapp.HtmlParser#setEncoding(java.lang.String)
+ */
+ public void setInputEncoding(String encoding) {
+ _encoding = encoding;
+ }
+
+ public void setOutputEncoding(String encoding) {
+ _outputEncoding = encoding;
+ }
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.webapp.HtmlParser#setMoveElements(boolean)
+ */
+ public void setMoveElements(boolean move) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.webapp.HtmlParser#setScripts(java.util.Set)
+ */
+ public void setScripts(Set scripts) {
+ _scripts = scripts;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.webapp.HtmlParser#setStyles(java.util.Set)
+ */
+ public void setStyles(Set styles) {
+ _styles = styles;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.webapp.HtmlParser#setDoctype(java.lang.String)
+ */
+ public void setDoctype(String doctype) {
+ this._publicId = doctype;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.webapp.HtmlParser#setViewState(java.lang.String)
+ */
+ public void setViewState(String viewState) {
+ _viewState = viewState;
+
+ }
+
+ private static class HtmlSAXParser extends AbstractSAXParser {
+ /** Default constructor.
+ * @throws ServletException */
+ public HtmlSAXParser(HTMLConfiguration config) {
+ super(config);
+
+ }
+ }
+
+ private class ViewStateFilter extends DefaultFilter{
+ private boolean haveHtml = false;
+ private boolean haveHead = false;
+ private boolean headParsed = false;
+ private int stateMarkerLevel = -1;
+
+
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#reset(org.apache.xerces.xni.parser.XMLComponentManager)
+ */
+ public void reset(XMLComponentManager componentManager) throws
XMLConfigurationException {
+ haveHead = false;
+ haveHtml = false;
+ headParsed = false;
+ stateMarkerLevel = -1;
+ super.reset(componentManager);
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#startElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
+ */
+ public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
+ if(stateMarkerLevel >=0){
+ stateMarkerLevel++;
+ if(null != fragment){
+ return;
+ }
+ }
+ if (!headParsed) {
+ if("html".equalsIgnoreCase(element.rawname)){
+ haveHtml = true;
+ } else if("head".equalsIgnoreCase(element.rawname)){
+ haveHead = true;
+ super.startElement(element, attributes, augs);
+ insertResources();
+ return;
+ } else {
+ if(!haveHtml){
+ insertStartElement("html");
+ }
+ insertStartElement("head");
+ insertResources();
+ insertEndElement("head");
+ }
+
+ }
+ if(isStateMarker(element, attributes)){
+ stateMarkerLevel = 0;
+ return;
+ };
+ super.startElement(element, attributes, augs);
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#characters(org.apache.xerces.xni.XMLString,
org.apache.xerces.xni.Augmentations)
+ */
+ public void characters(XMLString text, Augmentations augs) throws XNIException {
+ if(stateMarkerLevel >=0){
+ if(null != fragment){
+ return;
+ }
+ }
+ super.characters(text, augs);
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#endElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.Augmentations)
+ */
+ public void endElement(QName element, Augmentations augs) throws XNIException {
+ if(stateMarkerLevel >=0){
+ stateMarkerLevel--;
+ if(null != fragment || stateMarkerLevel == -1){
+ return;
+ }
+ }
+ super.endElement(element, 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);
+ }
+ }
+ if(null != _scripts){
+ for (Iterator iter = _scripts.iterator(); iter.hasNext();) {
+ String script = (String) iter.next();
+ QName element = new QName(null,"script","script",null);
+ XMLAttributes attrs = new XMLAttributesImpl();
+ attrs.addAttribute(new QName(null,"src","src",null),
"CDATA", script);
+ attrs.addAttribute(new QName(null,"type","type",null),
"CDATA", "text/javascript");
+ Augmentations augs = new HTMLAugmentations();
+ super.startElement(element,attrs,augs);
+ super.endElement(element, augs);
+ }
+ }
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#emptyElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
+ */
+ public void emptyElement(QName name, XMLAttributes attributes, Augmentations
augmentation) throws XNIException {
+ if(stateMarkerLevel >=0){
+ if(null != fragment){
+ return;
+ }
+ }
+ if (!headParsed) {
+ if("head".equalsIgnoreCase(name.rawname)){
+ haveHead = true;
+ super.startElement(name, attributes, augmentation);
+ insertResources();
+ insertEndElement(name.rawname);
+ return;
+ }
+ }
+ if(isStateMarker(name, attributes)){
+ return;
+ };
+ super.emptyElement(name, attributes, augmentation);
+ }
+
+
+ /**
+ * @param name
+ * @param attributes
+ */
+ private boolean isStateMarker(QName name, XMLAttributes attributes) {
+ if(name.rawname.equalsIgnoreCase("span") &&
AjaxViewHandler.STATE_MARKER_KEY.equals(attributes.getValue("id"))){
+ // STATE marker element - out real content.
+ if(null != fragment){
+ try {
+ _serializer.asDOMSerializer().serialize(fragment);
+ } catch (IOException e) {
+ // Break output.
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ void insertStartElement(String name) {
+ QName element = new QName(null,name,name,null);
+ XMLAttributes attrs = new XMLAttributesImpl();
+ Augmentations augs = new HTMLAugmentations();
+ super.startElement(element,attrs,augs);
+ }
+
+
+ void insertEndElement(String name) {
+ QName element = new QName(null,name,name,null);
+// XMLAttributes attrs = new XMLAttributesImpl();
+ Augmentations augs = new HTMLAugmentations();
+ super.endElement(element,augs);
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#endDocument(org.apache.xerces.xni.Augmentations)
+ */
+ public void endDocument(Augmentations augs) throws XNIException {
+ if (!haveHtml) {
+ insertEndElement("html");
+ }
+ super.endDocument(augs);
+ }
+
+
+
+ }
+
+ private static class HtmlWriter extends Writer {
+
+ /**
+ *
+ */
+ public HtmlWriter() {
+ super();
+ fEncoding = "UTF-8";
+ }
+
+ public void setEncoding(String encoding){
+ this.fEncoding = encoding;
+ }
+
+ public void setWriter( PrintWriter writer){
+ this.fPrinter = writer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.cyberneko.html.filters.Writer#emptyElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
+ */
+ public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
+ // TODO Auto-generated method stub
+ super.emptyElement(element, attributes, augs);
+ printEndElement(element);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#endCDATA(org.apache.xerces.xni.Augmentations)
+ */
+ public void endCDATA(Augmentations augs) throws XNIException {
+ // TODO Auto-generated method stub
+ super.endCDATA(augs);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.cyberneko.html.filters.DefaultFilter#startCDATA(org.apache.xerces.xni.Augmentations)
+ */
+ public void startCDATA(Augmentations augs) throws XNIException {
+ // TODO Auto-generated method stub
+ super.startCDATA(augs);
+ }
+
+ /* (non-Javadoc)
+ * @see org.cyberneko.html.filters.DefaultFilter#textDecl(java.lang.String,
java.lang.String, org.apache.xerces.xni.Augmentations)
+ */
+ public void textDecl(String version, String encoding, Augmentations augs) throws
XNIException {
+ // TODO Auto-generated method stub
+ super.textDecl(version, encoding, augs);
+ }
+
+ /* (non-Javadoc)
+ * @see org.cyberneko.html.filters.DefaultFilter#xmlDecl(java.lang.String,
java.lang.String, java.lang.String, org.apache.xerces.xni.Augmentations)
+ */
+ public void xmlDecl(String version, String encoding, String standalone, Augmentations
augs) throws XNIException {
+ // TODO Auto-generated method stub
+ super.xmlDecl(version, encoding, standalone, augs);
+ }
+
+
+ }
+ /**
+ * Factory method for create and configure HTML parser configuration.
+ * Create configuration for use in parsing, set nessesary features and properties
+ * @return
+ * @throws ServletException
+ */
+ protected HTMLConfiguration getHtmlConfig() {
+ HTMLConfiguration _config = new HTMLConfiguration();
+ try {
+ if (this.getPublicid() != null || this.getSystemid() != null) {
+ _config.setFeature(
+ "http://cyberneko.org/html/features/insert-doctype",
+ true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/override-doctype",
+ true);
+ }
+ if (this.getPublicid() != null) {
+ _config.setProperty(
+ "http://cyberneko.org/html/properties/doctype/pubid",
+ getPublicid());
+
+ }
+ if (this.getSystemid() != null) {
+ _config.setProperty(
+ "http://cyberneko.org/html/properties/doctype/sysid",
+ getSystemid());
+
+ }
+ if (this.getNamespace() != null) {
+ _config.setFeature(
+ "http://xml.org/sax/features/namespaces",
+ true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/override-namespaces",
+ true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/insert-namespaces",
+ true);
+ _config.setProperty(
+ "http://cyberneko.org/html/properties/namespaces-uri",
+ getNamespace());
+
+ }
+ // config
+ // .setFeature(
+ //
"http://cyberneko.org/html/features/balance-tags/ignore-outside-content",
+ // true);
+ _config
+ .setFeature(
+ "http://cyberneko.org/html/features/scanner/cdata-sections",
+ true);
+ _config
+ .setFeature(
+ "http://cyberneko.org/html/features/scanner/script/strip-comment-delims",
+ true);
+ _config
+ .setFeature(
+ "http://cyberneko.org/html/features/scanner/style/strip-comment-delims",
+ true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/insert-doctype",
+ true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/insert-namespaces",
+ true);
+ //
+ // Set properties
http://cyberneko.org/html/features/insert-namespaces
+ // _config
+ // .setProperty(
+ // "http://cyberneko.org/html/properties/default-encoding",
+ // encoding);
+ _config.setProperty(
+ "http://cyberneko.org/html/properties/names/elems",
+ "lower");
+ _config.setProperty(
+ "http://cyberneko.org/html/properties/names/attrs",
+ "lower");
+
_config.setProperty("http://cyberneko.org/html/properties/filters",
_filters);
+ } catch (XMLConfigurationException e) {
+// throw new ServletException("error set Neko feature ", e);
+ }
+ return _config;
+ }
+
+ private String getNamespace() {
+ // TODO Auto-generated method stub
+ return this._namespace;
+ }
+
+ private String getSystemid() {
+ // TODO Auto-generated method stub
+ return this._systemid;
+ }
+
+ private String getPublicid() {
+ // TODO Auto-generated method stub
+ return this._publicId;
+ }
+
+ /**
+ * @param namespace The namespace to set.
+ */
+ public void setNamespace(String namespace) {
+ _namespace = namespace;
+ }
+
+ /**
+ * @param publicId The publicId to set.
+ */
+ public void setPublicId(String publicId) {
+ _publicId = publicId;
+ }
+
+ /**
+ * @param systemid The systemid to set.
+ */
+ public void setSystemid(String systemid) {
+ _systemid = systemid;
+ }
+
+ public boolean setMime(String mimeType) {
+ return false;
+ }
+
+}
Deleted: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoXMLFilter.java 2007-07-09
15:13:40 UTC (rev 1551)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,108 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter.nekko;
-
-import java.util.EmptyStackException;
-
-import javax.servlet.ServletException;
-
-import org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter;
-import org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser;
-import org.ajax4jsf.io.parser.FastHtmlParser;
-import org.apache.commons.collections.ArrayStack;
-
-public class NekkoXMLFilter extends BaseXMLFilter {
- private static final int STACK_SIZE = 100;
- private static ArrayStack _xhtmlParsersPool = new ArrayStack(STACK_SIZE);
-
- public NekkoXMLFilter() {}
-
- protected HtmlParser getParser(String mimetype, boolean isAjax) {
- HtmlParser parser = null;
- if( isAjax ){
- parser = getXmlParser();
- } else if (mimetype.startsWith("text/html") ||
mimetype.startsWith("application/xhtml+xml")) {
- parser = new FastHtmlParser();
- } else {
- return null;
- }
-// parser.setEncoding(characterEncoding);
- return parser;
- }
-
- /**
- * Peturn parser to pool
- * @param parser
- */
- protected void reuseParser(HtmlParser parser) {
- if (null != parser) {
- if (parser instanceof NekkoParser ) {
- synchronized (_xhtmlParsersPool) {
- if (_xhtmlParsersPool.size() < STACK_SIZE) {
- ((NekkoParser) parser).reset();
- _xhtmlParsersPool.push(parser);
- }
-
- }
- }
- }
- }
-
- /**
- * Factory method for create parsing object - contain chain of parsing,
- * transformation and serialization of response output
- * @param string Encodings for parser
- * @return
- * @throws ServletException
- */
- protected HtmlParser getXmlParser() {
- // TODO make pool of parsers-transformers.
- NekkoParser parser ;
- try {
- synchronized (_xhtmlParsersPool) {
- parser = (NekkoParser) _xhtmlParsersPool.pop();
- }
- } catch (EmptyStackException e) {
- parser = new NekkoParser();
- parser.setPublicId(getPublicid());
- parser.setSystemid(getSystemid());
- parser.setNamespace(getNamespace());
- // If tidy not handle all requests, disable reorganising of html
-// parser.setMoveElements(isForcexml());
- }
- // TODO - set header scripts/styles filter.
- return parser;
- }
-
-
- /* (non-Javadoc)
- * @see
org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter#getWrapper(javax.servlet.http.HttpServletResponse)
- */
-// protected FilterServletResponseWrapper getWrapper(HttpServletResponse response) throws
ServletException {
-// // TODO Auto-generated method stub
-// NekkoHtmlServletResponseWrapper wrapper = new
NekkoHtmlServletResponseWrapper(response);
-// // TODO - create pool of parsers.
-// wrapper.setParser(getParser());
-// return wrapper;
-// }
-
-}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java
(from rev 1558,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoXMLFilter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,108 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp.nekko;
+
+import java.util.EmptyStackException;
+
+import javax.servlet.ServletException;
+
+import org.ajax4jsf.io.parser.FastHtmlParser;
+import org.ajax4jsf.webapp.BaseXMLFilter;
+import org.ajax4jsf.webapp.HtmlParser;
+import org.apache.commons.collections.ArrayStack;
+
+public class NekkoXMLFilter extends BaseXMLFilter {
+ private static final int STACK_SIZE = 100;
+ private static ArrayStack _xhtmlParsersPool = new ArrayStack(STACK_SIZE);
+
+ public NekkoXMLFilter() {}
+
+ protected HtmlParser getParser(String mimetype, boolean isAjax, String viewId) {
+ HtmlParser parser = null;
+ if( isAjax ){
+ parser = getXmlParser();
+ } else if (mimetype.startsWith("text/html") ||
mimetype.startsWith("application/xhtml+xml")) {
+ parser = new FastHtmlParser();
+ } else {
+ return null;
+ }
+// parser.setEncoding(characterEncoding);
+ return parser;
+ }
+
+ /**
+ * Peturn parser to pool
+ * @param parser
+ */
+ protected void reuseParser(HtmlParser parser) {
+ if (null != parser) {
+ if (parser instanceof NekkoParser ) {
+ synchronized (_xhtmlParsersPool) {
+ if (_xhtmlParsersPool.size() < STACK_SIZE) {
+ ((NekkoParser) parser).reset();
+ _xhtmlParsersPool.push(parser);
+ }
+
+ }
+ }
+ }
+ }
+
+ /**
+ * Factory method for create parsing object - contain chain of parsing,
+ * transformation and serialization of response output
+ * @param string Encodings for parser
+ * @return
+ * @throws ServletException
+ */
+ protected HtmlParser getXmlParser() {
+ // TODO make pool of parsers-transformers.
+ NekkoParser parser ;
+ try {
+ synchronized (_xhtmlParsersPool) {
+ parser = (NekkoParser) _xhtmlParsersPool.pop();
+ }
+ } catch (EmptyStackException e) {
+ parser = new NekkoParser();
+ parser.setPublicId(getPublicid());
+ parser.setSystemid(getSystemid());
+ parser.setNamespace(getNamespace());
+ // If tidy not handle all requests, disable reorganising of html
+// parser.setMoveElements(isForcexml());
+ }
+ // TODO - set header scripts/styles filter.
+ return parser;
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.webapp.BaseFilter#getWrapper(javax.servlet.http.HttpServletResponse)
+ */
+// protected FilterServletResponseWrapper getWrapper(HttpServletResponse response) throws
ServletException {
+// // TODO Auto-generated method stub
+// NekkoHtmlServletResponseWrapper wrapper = new
NekkoHtmlServletResponseWrapper(response);
+// // TODO - create pool of parsers.
+// wrapper.setParser(getParser());
+// return wrapper;
+// }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy (from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy)
Deleted: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/TidyParser.java 2007-07-09
15:13:40 UTC (rev 1551)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,399 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter.tidy;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
-import org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser;
-import org.ajax4jsf.org.w3c.tidy.Lexer;
-import org.ajax4jsf.org.w3c.tidy.Node;
-import org.ajax4jsf.org.w3c.tidy.Tidy;
-import org.ajax4jsf.org.w3c.tidy.TidyMessage;
-import org.ajax4jsf.org.w3c.tidy.TidyMessageListener;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.impl.NoOpLog;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-/**
- * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:59:17 $
- *
- */
-public class TidyParser implements TidyMessageListener, HtmlParser {
-
- private static final Log log = LogFactory.getLog(TidyParser.class);
-
- private Tidy tidy;
-
- private Set _scripts;
-
- private Set _styles;
-
- private String _viewState;
-
- private String _encoding;
-
- private String _outputEncoding;
-
- private static final String[] _htmlTypes = { "text/html" };
-
- private static final String[] _xmlTypes = { "text/xml" };//
"text/xml"};
-
- private static final String[] _xhtmlTypes = { "application/xhtml+xml" };
-
- private static final String TIDY_MARK = "[TIDY_MESSAGE]";
-
- /**
- *
- */
- public TidyParser(Properties props) {
- tidy = new Tidy();
- tidy.setConfigurationFromProps(props);
- // tidy.setConfigurationFromProps(getProperties("tidy.properties"));
- PrintWriter errout = new PrintWriter(new ErrorWriter());
- tidy.setErrout(errout);
- tidy.setForceOutput(true);
- tidy.setHideEndTags(false);
- tidy.setMessageListener(this);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#parseHtml(java.lang.Object,
- * java.io.OutputStream)
- */
- public Document parseHtmlByTidy(Object input, Writer output)
- throws IOException {
- Document document = tidy.parseDOM(input, null);
- if (null != document) {
- Element documentElement = document.getDocumentElement();
- if (null != documentElement) {
- // Replace state elements with real stored.
-
- NodeList inputs = documentElement.getElementsByTagName("span");
- for (int i = 0; i < inputs.getLength(); i++) {
- Element node = (Element) inputs.item(i);
- if (AjaxViewHandler.STATE_MARKER_KEY.equals(node
- .getAttribute("id"))
- && AjaxViewHandler.STATE_MARKER_KEY.equals(node
- .getAttribute("name"))) {
- // State marker - replace with real.
- org.w3c.dom.Node parentNode = node.getParentNode();
- if (null != _viewState) {
- parentNode.replaceChild(document
- .createCDATASection(_viewState), node);
- } else {
- // Remove marker element, but keep it content.
- if (node.hasChildNodes()) {
- org.w3c.dom.Node nextSibling = node
- .getNextSibling();
- NodeList childNodes = node.getChildNodes();
- // Copy all nodes by temporary array ( since
- // moving nodes in iteration
- // modify NodeList with side effects.
- org.w3c.dom.Node[] childArray = new org.w3c.dom.Node[childNodes
- .getLength()];
- for (int j = 0; j < childArray.length; j++) {
- childArray[j] = childNodes.item(j);
- }
- for (int j = 0; j < childArray.length; j++) {
- parentNode.insertBefore(childArray[j],
- nextSibling);
- }
- }
- parentNode.removeChild(node);
- }
- }
- }
-
- // Inserts scripts and styles to head.
- if (null != _scripts || null != _styles || null != _viewState) {
- // find head
- org.w3c.dom.Node head = documentElement
- .getElementsByTagName("head").item(0);
- // Insert empty if not found
- if (null == head) {
- head = document.createElement("head");
- documentElement.insertBefore(head, documentElement
- .getFirstChild());
- }
- NodeList headChildren = head.getChildNodes();
- org.w3c.dom.Node child = null;
- for (int i = 0; i < headChildren.getLength(); i++) {
- child = headChildren.item(i);
- if (child instanceof Element) {
- String nodeName = ((Element) child).getNodeName();
- if (!("title".equalsIgnoreCase(nodeName) || "base"
- .equalsIgnoreCase(nodeName))) {
- break;
- }
- }
- child = null;
- }
- if (null != _styles) {
- for (Iterator iter = _styles.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);
- head.insertBefore(style, child);
- }
- }
- // Scripts
- if (null != _scripts) {
- for (Iterator iter = _scripts.iterator(); iter
- .hasNext();) {
- String url = (String) iter.next();
- Element script = document.createElement("script");
-
- script.setAttribute("type", "text/javascript");
- // script.setAttribute("defer", "defer");
- script.setAttribute("src", url);
- // script.appendChild(document.createTextNode(""));
- head.insertBefore(script, child);
- }
- }
- }
- }
- if (null != output) {
- tidy.pprint(document, output);
- }
- }
- return document;
- }
-
- public void parseHtml(InputStream input, Writer output) throws IOException {
- this.parseHtmlByTidy(input, output);
-
- }
-
- public void parseHtml(Reader input, Writer output) throws IOException {
- this.parseHtmlByTidy(input, output);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.w3c.tidy.TidyMessageListener#messageReceived(org.w3c.tidy.TidyMessage)
- */
- public void messageReceived(TidyMessage message) {
- // TODO record messages for output.
- // TODO change signature for receive current node and append message in
- // tree.
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.MESSAGE_PARSING_INFO,
- message.getMessage()));
- }
- // TODO - configurable output for reeors in page.
- if (false) {
- Lexer lexer = message.getLexer();
- Node element = message.getElement();
- if (null == element) {
- element = lexer.getLastNode();
- } else if ("style".equalsIgnoreCase(element.getElement())
- || "script".equalsIgnoreCase(element.getElement())) {
- element = lexer.getLastNode();
- }
- // Insert comment about error.
- if (null != element) {
- String messageText = message.getMessage();
- byte[] msg = (TIDY_MARK + messageText + TIDY_MARK).getBytes();
- Node comment = lexer.newNode(Node.COMMENT_TAG, msg, 0,
- msg.length);
- // TODO - detect style or script elements - not allow comment in
- // it.
- element.insertNodeAtEnd(comment);
- }
- }
- }
-
- /**
- * 'null' writer for discard errors - since processed in message listener
- *
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:59:17 $
- *
- */
- private static class ErrorWriter extends Writer {
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Writer#write(char[], int, int)
- */
- public void write(char[] cbuf, int off, int len) throws IOException {
- // do nothing
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Writer#flush()
- */
- public void flush() throws IOException {
- // do nothing
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Writer#close()
- */
- public void close() throws IOException {
- // do nothing
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setEncoding(java.lang.String)
- */
- public void setInputEncoding(String encoding) {
- if (null != encoding) {
- this._encoding = encoding;
- if (null != encoding) {
- this.tidy.setInputEncoding(encoding);
- }
- // this.tidy.setOutputEncoding(encoding);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setEncoding(java.lang.String)
- */
- public void setOutputEncoding(String encoding) {
- if (null != encoding) {
- this._outputEncoding = encoding;
- // this.tidy.setInputEncoding(encoding);
- if (null != encoding) {
- this.tidy.setOutputEncoding(encoding);
- }
- }
- }
-
- /**
- * Setup properly tidy output for given mime type. return {@link false } if
- * this type not supported by tidy.
- *
- * @param mimeType
- * @return
- */
- public boolean setMime(String mimeType) {
- if (null != mimeType) {
- for (int i = 0; i < _htmlTypes.length; i++) {
- String mime = _htmlTypes[i];
- if (mimeType.startsWith(mime)) {
- // setup html output
- tidy.setXHTML(false);
- tidy.setXmlOut(false);
- // TODO - auto doctype ?
- return true;
- }
- }
- for (int i = 0; i < _xhtmlTypes.length; i++) {
- String mime = _xhtmlTypes[i];
- if (mimeType.startsWith(mime)) {
- // setup xhtml output
- tidy.setXHTML(true);
- tidy.setXmlOut(false);
- return true;
- }
- }
- for (int i = 0; i < _xmlTypes.length; i++) {
- String mime = _xmlTypes[i];
- if (mimeType.startsWith(mime)) {
- // setup html output
- tidy.setXHTML(true);
- tidy.setXmlOut(true);
- tidy.setXmlPi(true);
- tidy.setEscapeCdata(false);
- tidy.setNumEntities(true);
- return true;
- }
- }
- }
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setMoveElements(boolean)
- */
- public void setMoveElements(boolean move) {
- tidy.setMoveElements(move);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setScripts(java.util.Set)
- */
- public void setScripts(Set scripts) {
- this._scripts = scripts;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setStyles(java.util.Set)
- */
- public void setStyles(Set styles) {
- this._styles = styles;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setDoctype(java.lang.String)
- */
- public void setDoctype(String doctype) {
- tidy.setDocType(doctype);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setViewState(java.lang.String)
- */
- public void setViewState(String viewState) {
- _viewState = viewState;
- }
-}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java (from
rev 1558,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/TidyParser.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyParser.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,406 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp.tidy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.application.AjaxViewHandler;
+import org.ajax4jsf.org.w3c.tidy.Lexer;
+import org.ajax4jsf.org.w3c.tidy.Node;
+import org.ajax4jsf.org.w3c.tidy.Tidy;
+import org.ajax4jsf.org.w3c.tidy.TidyMessage;
+import org.ajax4jsf.org.w3c.tidy.TidyMessageListener;
+import org.ajax4jsf.webapp.HtmlParser;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:59:17 $
+ *
+ */
+public class TidyParser implements TidyMessageListener, HtmlParser {
+
+ private static final Log log = LogFactory.getLog(TidyParser.class);
+
+ private Tidy tidy;
+
+ private Set _scripts;
+
+ private Set _styles;
+
+ private String _viewState;
+
+ private String _encoding;
+
+ private String _outputEncoding;
+
+ private static final String[] _htmlTypes = { "text/html" };
+
+ private static final String[] _xmlTypes = { "text/xml" };//
"text/xml"};
+
+ private static final String[] _xhtmlTypes = { "application/xhtml+xml" };
+
+ private static final String TIDY_MARK = "[TIDY_MESSAGE]";
+
+ /**
+ *
+ */
+ public TidyParser(Properties props) {
+ tidy = new Tidy();
+ tidy.setConfigurationFromProps(props);
+ // tidy.setConfigurationFromProps(getProperties("tidy.properties"));
+ PrintWriter errout = new PrintWriter(new ErrorWriter());
+ tidy.setErrout(errout);
+ tidy.setForceOutput(true);
+ tidy.setHideEndTags(false);
+ tidy.setMessageListener(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.HtmlParser#parseHtml(java.lang.Object,
+ * java.io.OutputStream)
+ */
+ public Document parseHtmlByTidy(Object input, Writer output)
+ throws IOException {
+ Document document = tidy.parseDOM(input, null);
+ if (null != document) {
+ Element documentElement = document.getDocumentElement();
+ if (null != documentElement) {
+ // Replace state elements with real stored.
+
+ NodeList inputs = documentElement.getElementsByTagName("span");
+ for (int i = 0; i < inputs.getLength(); i++) {
+ Element node = (Element) inputs.item(i);
+ if (AjaxViewHandler.STATE_MARKER_KEY.equals(node
+ .getAttribute("id"))
+ && AjaxViewHandler.STATE_MARKER_KEY.equals(node
+ .getAttribute("name"))) {
+ // State marker - replace with real.
+ org.w3c.dom.Node parentNode = node.getParentNode();
+ if (null != _viewState) {
+ parentNode.replaceChild(document
+ .createCDATASection(_viewState), node);
+ } else {
+ // Remove marker element, but keep it content.
+ if (node.hasChildNodes()) {
+ org.w3c.dom.Node nextSibling = node
+ .getNextSibling();
+ NodeList childNodes = node.getChildNodes();
+ // Copy all nodes by temporary array ( since
+ // moving nodes in iteration
+ // modify NodeList with side effects.
+ org.w3c.dom.Node[] childArray = new org.w3c.dom.Node[childNodes
+ .getLength()];
+ for (int j = 0; j < childArray.length; j++) {
+ childArray[j] = childNodes.item(j);
+ }
+ for (int j = 0; j < childArray.length; j++) {
+ parentNode.insertBefore(childArray[j],
+ nextSibling);
+ }
+ }
+ parentNode.removeChild(node);
+ }
+ }
+ }
+
+ // Inserts scripts and styles to head.
+ if (null != _scripts || null != _styles || null != _viewState) {
+ // find head
+ org.w3c.dom.Node head = documentElement
+ .getElementsByTagName("head").item(0);
+ // Insert empty if not found
+ if (null == head) {
+ head = document.createElement("head");
+ documentElement.insertBefore(head, documentElement
+ .getFirstChild());
+ }
+ NodeList headChildren = head.getChildNodes();
+ org.w3c.dom.Node child = null;
+ for (int i = 0; i < headChildren.getLength(); i++) {
+ child = headChildren.item(i);
+ if (child instanceof Element) {
+ String nodeName = ((Element) child).getNodeName();
+ if (!("title".equalsIgnoreCase(nodeName) || "base"
+ .equalsIgnoreCase(nodeName))) {
+ break;
+ }
+ }
+ child = null;
+ }
+ if (null != _styles) {
+ for (Iterator iter = _styles.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);
+ head.insertBefore(style, child);
+ }
+ }
+ // Scripts
+ if (null != _scripts) {
+ for (Iterator iter = _scripts.iterator(); iter
+ .hasNext();) {
+ String url = (String) iter.next();
+ Element script = document.createElement("script");
+
+ script.setAttribute("type", "text/javascript");
+ // script.setAttribute("defer", "defer");
+ script.setAttribute("src", url);
+ // script.appendChild(document.createTextNode(""));
+ head.insertBefore(script, child);
+ }
+ }
+ }
+ }
+ if (null != output) {
+ tidy.pprint(document, output);
+ }
+ }
+ return document;
+ }
+
+ public void parseHtml(InputStream input, Writer output) throws IOException {
+ this.parseHtmlByTidy(input, output);
+
+ }
+
+ public void parseHtml(Reader input, Writer output) throws IOException {
+ this.parseHtmlByTidy(input, output);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.w3c.tidy.TidyMessageListener#messageReceived(org.w3c.tidy.TidyMessage)
+ */
+ public void messageReceived(TidyMessage message) {
+ // TODO record messages for output.
+ // TODO change signature for receive current node and append message in
+ // tree.
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.MESSAGE_PARSING_INFO,
+ message.getMessage()));
+ }
+ // TODO - configurable output for reeors in page.
+ if (false) {
+ Lexer lexer = message.getLexer();
+ Node element = message.getElement();
+ if (null == element) {
+ element = lexer.getLastNode();
+ } else if ("style".equalsIgnoreCase(element.getElement())
+ || "script".equalsIgnoreCase(element.getElement())) {
+ element = lexer.getLastNode();
+ }
+ // Insert comment about error.
+ if (null != element) {
+ String messageText = message.getMessage();
+ byte[] msg = (TIDY_MARK + messageText + TIDY_MARK).getBytes();
+ Node comment = lexer.newNode(Node.COMMENT_TAG, msg, 0,
+ msg.length);
+ // TODO - detect style or script elements - not allow comment in
+ // it.
+ element.insertNodeAtEnd(comment);
+ }
+ }
+ }
+
+ /**
+ * 'null' writer for discard errors - since processed in message listener
+ *
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:59:17 $
+ *
+ */
+ private static class ErrorWriter extends Writer {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Writer#write(char[], int, int)
+ */
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ // do nothing
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Writer#flush()
+ */
+ public void flush() throws IOException {
+ // do nothing
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Writer#close()
+ */
+ public void close() throws IOException {
+ // do nothing
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.HtmlParser#setEncoding(java.lang.String)
+ */
+ public void setInputEncoding(String encoding) {
+ if (null != encoding) {
+ this._encoding = encoding;
+ if (null != encoding) {
+ this.tidy.setInputEncoding(encoding);
+ }
+ // this.tidy.setOutputEncoding(encoding);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.HtmlParser#setEncoding(java.lang.String)
+ */
+ public void setOutputEncoding(String encoding) {
+ if (null != encoding) {
+ this._outputEncoding = encoding;
+ // this.tidy.setInputEncoding(encoding);
+ if (null != encoding) {
+ this.tidy.setOutputEncoding(encoding);
+ }
+ }
+ }
+
+ /**
+ * Setup properly tidy output for given mime type. return {@link false } if
+ * this type not supported by tidy.
+ *
+ * @param mimeType
+ * @return
+ */
+ public boolean setMime(String mimeType) {
+ if (null != mimeType) {
+ for (int i = 0; i < _htmlTypes.length; i++) {
+ String mime = _htmlTypes[i];
+ if (mimeType.startsWith(mime)) {
+ // setup html output
+ tidy.setXHTML(false);
+ tidy.setXmlOut(false);
+ if (log.isDebugEnabled()) {
+ log.debug("Print output as ordinary HTML");
+ }
+ return true;
+ }
+ }
+ for (int i = 0; i < _xhtmlTypes.length; i++) {
+ String mime = _xhtmlTypes[i];
+ if (mimeType.startsWith(mime)) {
+ // setup xhtml output
+ tidy.setXHTML(true);
+ tidy.setXmlOut(false);
+ if (log.isDebugEnabled()) {
+ log.debug("Print output as XHTML");
+ }
+ return true;
+ }
+ }
+ for (int i = 0; i < _xmlTypes.length; i++) {
+ String mime = _xmlTypes[i];
+ if (mimeType.startsWith(mime)) {
+ // setup html output
+ tidy.setXHTML(true);
+ tidy.setXmlOut(true);
+ tidy.setXmlPi(true);
+ tidy.setEscapeCdata(false);
+ tidy.setNumEntities(true);
+ if (log.isDebugEnabled()) {
+ log.debug("Print output as XML");
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.HtmlParser#setMoveElements(boolean)
+ */
+ public void setMoveElements(boolean move) {
+ tidy.setMoveElements(move);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.HtmlParser#setScripts(java.util.Set)
+ */
+ public void setScripts(Set scripts) {
+ this._scripts = scripts;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.HtmlParser#setStyles(java.util.Set)
+ */
+ public void setStyles(Set styles) {
+ this._styles = styles;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.HtmlParser#setDoctype(java.lang.String)
+ */
+ public void setDoctype(String doctype) {
+ tidy.setDocType("omit");//doctype);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.HtmlParser#setViewState(java.lang.String)
+ */
+ public void setViewState(String viewState) {
+ _viewState = viewState;
+ }
+}
Deleted: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/TidyXMLFilter.java 2007-07-09
15:13:40 UTC (rev 1551)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -1,123 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.framework.ajax.xmlfilter.tidy;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter;
-import org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser;
-import org.ajax4jsf.io.parser.FastHtmlParser;
-import org.apache.commons.collections.ArrayStack;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class TidyXMLFilter extends BaseXMLFilter {
- static final Log log = LogFactory.getLog(TidyXMLFilter.class);
- private Properties _tidyProperties;
- private static final int STACK_SIZE = 100;
-
- /**
- * Stack for handle parsers pool - to avoid instantiane on each request.
- */
- private ArrayStack _parsersPool = new ArrayStack(STACK_SIZE);
-
- public TidyXMLFilter() {}
-
- /**
- * Peturn parser to pool
- * @param parser
- */
- protected void reuseParser(HtmlParser parser) {
-// synchronized (_parsersPool) {
-// if (_parsersPool.size()<STACK_SIZE) {
-// if (log.isDebugEnabled()) {
-// log.debug("Push JTidy parser to pool");
-// }
-// _parsersPool.push(parser);
-// }
-// }
- }
-
- /**
- * Factory method for create parsing object - contain chain of parsing,
- * transformation and serialization of response output
- * @param string Encodings for parser
- * @return
- */
- protected HtmlParser getParser(String mime, boolean isAjax) {
- // For non-ajax, parse only html types !
- if (isAjax || mime.startsWith("text/html") ||
mime.startsWith("application/xhtml+xml")) {
- if(isAjax || isForcexml()){
- TidyParser parser ;
- parser = new TidyParser(getTidyProperties());
- // If tidy not handle all requests, disable reorganising of html
- parser.setMoveElements(isForcexml());
- // Setup configuration.
- if (parser.setMime(mime)) {
- // parser.setEncoding(encoding);
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.CREATE_JTIDY_INFO));
- }
- return parser;
- }
- } else {
- return new FastHtmlParser();
- }
- }
- return null;
- }
-
- private Properties getTidyProperties() {
- if (null == _tidyProperties) {
- _tidyProperties = new Properties();
- InputStream props = null;
- try {
- props = TidyXMLFilter.class.getResourceAsStream("tidy.properties");
- if (null != props) {
- _tidyProperties.load(props);
- }
- // Second part - user-defined properties.
- props =
Thread.currentThread().getContextClassLoader().getResourceAsStream("tidy.properties");
- if (null != props) {
- _tidyProperties.load(props);
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- log.warn(Messages.getMessage(Messages.READING_TIDY_PROPERTIES_ERROR), e);
- } finally {
- if(null != props){
- try {
- props.close();
- } catch (IOException e) {
- // can be ignored
- }
- }
- }
- }
- return _tidyProperties;
-
- }
-
-}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java
(from rev 1558,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/TidyXMLFilter.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -0,0 +1,123 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.webapp.tidy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.io.parser.FastHtmlParser;
+import org.ajax4jsf.webapp.BaseXMLFilter;
+import org.ajax4jsf.webapp.HtmlParser;
+import org.apache.commons.collections.ArrayStack;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class TidyXMLFilter extends BaseXMLFilter {
+ static final Log log = LogFactory.getLog(TidyXMLFilter.class);
+ private Properties _tidyProperties;
+ private static final int STACK_SIZE = 100;
+
+ /**
+ * Stack for handle parsers pool - to avoid instantiane on each request.
+ */
+ private ArrayStack _parsersPool = new ArrayStack(STACK_SIZE);
+
+ public TidyXMLFilter() {}
+
+ /**
+ * Peturn parser to pool
+ * @param parser
+ */
+ protected void reuseParser(HtmlParser parser) {
+// synchronized (_parsersPool) {
+// if (_parsersPool.size()<STACK_SIZE) {
+// if (log.isDebugEnabled()) {
+// log.debug("Push JTidy parser to pool");
+// }
+// _parsersPool.push(parser);
+// }
+// }
+ }
+
+ /**
+ * Factory method for create parsing object - contain chain of parsing,
+ * transformation and serialization of response output
+ * @param string Encodings for parser
+ * @return
+ */
+ protected HtmlParser getParser(String mime, boolean isAjax, String viewId) {
+ // For non-ajax, parse only html types !
+ if (isAjax || mime.startsWith("text/html") ||
mime.startsWith("application/xhtml+xml")) {
+ if(isAjax || isForcexml()){
+ TidyParser parser ;
+ parser = new TidyParser(getTidyProperties());
+ // If tidy not handle all requests, disable reorganising of html
+ parser.setMoveElements(isForcexml());
+ // Setup configuration.
+ if (parser.setMime(mime)) {
+ // parser.setEncoding(encoding);
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.CREATE_JTIDY_INFO));
+ }
+ return parser;
+ }
+ } else {
+ return new FastHtmlParser();
+ }
+ }
+ return null;
+ }
+
+ private Properties getTidyProperties() {
+ if (null == _tidyProperties) {
+ _tidyProperties = new Properties();
+ InputStream props = null;
+ try {
+ props = TidyXMLFilter.class.getResourceAsStream("tidy.properties");
+ if (null != props) {
+ _tidyProperties.load(props);
+ }
+ // Second part - user-defined properties.
+ props =
Thread.currentThread().getContextClassLoader().getResourceAsStream("tidy.properties");
+ if (null != props) {
+ _tidyProperties.load(props);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ log.warn(Messages.getMessage(Messages.READING_TIDY_PROPERTIES_ERROR), e);
+ } finally {
+ if(null != props){
+ try {
+ props.close();
+ } catch (IOException e) {
+ // can be ignored
+ }
+ }
+ }
+ }
+ return _tidyProperties;
+
+ }
+
+}
Modified:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -20,9 +20,9 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
-import org.ajax4jsf.framework.ajax.xmlfilter.tidy.TidyParser;
-import org.ajax4jsf.framework.ajax.xmlfilter.tidy.TidyXMLFilter;
import org.ajax4jsf.framework.renderer.HeaderResourcesRendererBase;
+import org.ajax4jsf.webapp.tidy.TidyParser;
+import org.ajax4jsf.webapp.tidy.TidyXMLFilter;
import org.richfaces.json.JSContentHandler;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
Modified:
trunk/framework/impl/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/HtmlCorrectionFilterTestCase.java
===================================================================
---
trunk/framework/impl/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/HtmlCorrectionFilterTestCase.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/impl/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/HtmlCorrectionFilterTestCase.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -7,6 +7,7 @@
import java.util.Iterator;
import java.util.List;
+import org.ajax4jsf.webapp.nekko.HtmlCorrectionFilter;
import org.apache.xerces.util.XMLAttributesImpl;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.NamespaceContext;
@@ -102,7 +103,7 @@
}
}
/**
- * Test method for {@link
org.ajax4jsf.framework.ajax.xmlfilter.nekko.HtmlCorrectionFilter#endElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.Augmentations)}.
+ * Test method for {@link
org.ajax4jsf.webapp.nekko.HtmlCorrectionFilter#endElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.Augmentations)}.
*/
public void testEndElementQNameAugmentations() {
startElement("html");//0
@@ -289,7 +290,7 @@
assertSequence(expect);
}
/**
- * Test method for {@link
org.ajax4jsf.framework.ajax.xmlfilter.nekko.HtmlCorrectionFilter#startElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)}.
+ * Test method for {@link
org.ajax4jsf.webapp.nekko.HtmlCorrectionFilter#startElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)}.
*/
// public void testResVoid() {
// fail("Not yet implemented");
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/AllTests.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/AllTests.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/AllTests.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -28,7 +28,7 @@
public static Test suite() {
TestSuite suite = new TestSuite(
- "Test for org.ajax4jsf.framework.ajax.xmlfilter");
+ "Test for org.ajax4jsf.webapp");
//$JUnit-BEGIN$
suite.addTestSuite(CacheContentTest.class);
suite.addTestSuite(NekkoParserTest.class);
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContentTest.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContentTest.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/CacheContentTest.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -30,6 +30,7 @@
import java.io.PrintWriter;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.webapp.CacheContent;
import org.apache.shale.test.mock.MockPrintWriter;
import org.apache.shale.test.mock.MockServletOutputStream;
@@ -64,7 +65,7 @@
/**
- * Test method for {@link
org.ajax4jsf.framework.ajax.xmlfilter.CacheContent#getOutputStream(java.io.OutputStream)}.
+ * Test method for {@link
org.ajax4jsf.webapp.CacheContent#getOutputStream(java.io.OutputStream)}.
* @throws IOException
*/
public void testGetOutputStream() throws IOException {
@@ -93,7 +94,7 @@
}
/**
- * Test method for {@link
org.ajax4jsf.framework.ajax.xmlfilter.CacheContent#getWriter(java.io.Writer)}.
+ * Test method for {@link org.ajax4jsf.webapp.CacheContent#getWriter(java.io.Writer)}.
* @throws IOException
*/
public void testGetWriter() throws IOException {
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoParserTest.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoParserTest.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/NekkoParserTest.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -28,7 +28,7 @@
import junit.framework.TestCase;
-import org.ajax4jsf.framework.ajax.xmlfilter.nekko.NekkoParser;
+import org.ajax4jsf.webapp.nekko.NekkoParser;
public class NekkoParserTest extends TestCase {
@@ -47,7 +47,7 @@
}
/*
- * Test method for
'org.ajax4jsf.framework.ajax.xmlfilter.NekkoParser.parseHtml(Reader, Writer)'
+ * Test method for 'org.ajax4jsf.webapp.NekkoParser.parseHtml(Reader, Writer)'
*/
public void testParseHtmlReaderWriter() {
String html =
"<html><body><table><tr><td>xxx</td></tr></table></body></html>";
Modified:
trunk/framework/test/src/test/java/org/ajax4jsf/framework/renderer/BeforeRendererListenerTestCase.java
===================================================================
---
trunk/framework/test/src/test/java/org/ajax4jsf/framework/renderer/BeforeRendererListenerTestCase.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/framework/test/src/test/java/org/ajax4jsf/framework/renderer/BeforeRendererListenerTestCase.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -26,9 +26,9 @@
import javax.faces.event.PhaseListener;
import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter;
-import org.ajax4jsf.framework.ajax.xmlfilter.FilterServletResponseWrapper;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.webapp.BaseFilter;
+import org.ajax4jsf.webapp.FilterServletResponseWrapper;
/**
* @author asmirnov(a)exadel.com (latest modification by $Author: ishabalov $)
Modified: trunk/ui/core/src/main/java/org/ajax4jsf/component/UIPush.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/component/UIPush.java 2007-07-10 00:39:15 UTC
(rev 1558)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/component/UIPush.java 2007-07-10 00:58:39 UTC
(rev 1559)
@@ -29,7 +29,7 @@
import javax.servlet.http.HttpSession;
import org.ajax4jsf.ajax.PushEventsCounter;
-import org.ajax4jsf.framework.ajax.xmlfilter.PollEventsManager;
+import org.ajax4jsf.webapp.PollEventsManager;
/**
* Component for periodically call AJAX events on server ( poll actions )
Modified: trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/AjaxPageRenderer.java
===================================================================
---
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/AjaxPageRenderer.java 2007-07-10
00:39:15 UTC (rev 1558)
+++
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/AjaxPageRenderer.java 2007-07-10
00:58:39 UTC (rev 1559)
@@ -32,9 +32,9 @@
import org.ajax4jsf.component.AjaxContainer;
import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter;
import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
+import org.ajax4jsf.webapp.BaseFilter;
/**
* @author shura