You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/04/14 19:48:28 UTC

svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Author: jakobk
Date: Wed Apr 14 17:48:28 2010
New Revision: 934048

URL: http://svn.apache.org/viewvc?rev=934048&view=rev
Log:
MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X) pages

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java   (with props)
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java   (contents, props changed)

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java Wed Apr 14 17:48:28 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.jsp;
+
+/**
+ * An Exception that indicates that the user uses a
+ * facelets-only feature on a JSP.
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * 
+ * @since 2.0
+ */
+public class FaceletsOnlyException extends Exception
+{
+
+    private static final long serialVersionUID = 4268633427284543647L;
+
+    public FaceletsOnlyException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+    
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java Wed Apr 14 17:48:28 2010
@@ -1,139 +1,222 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.view.jsp;
-
-import java.io.IOException;
-import java.util.Locale;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.faces.FacesException;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.jsp.jstl.core.Config;
-
-import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
-import org.apache.myfaces.context.servlet.ResponseSwitch;
-import org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
-import org.apache.myfaces.util.ExternalContextUtils;
-
-/**
- * @author Simon Lessard (latest modification by $Author: slessard $)
- * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400 (mer., 17 sept. 2008) $
- * 
- * @since 2.0
- */
-public class JspViewDeclarationLanguage extends JspViewDeclarationLanguageBase
-{
-    //private static final Log log = LogFactory.getLog(JspViewDeclarationLanguage.class);
-    public static final Logger log = Logger.getLogger(JspViewDeclarationLanguage.class.getName());
-    /**
-     * 
-     */
-    public JspViewDeclarationLanguage()
-    {
-        if (log.isLoggable(Level.FINEST))
-            log.finest("New JspViewDeclarationLanguage instance created");
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void buildView(FacesContext context, UIViewRoot view) throws IOException
-    {
-        ExternalContext externalContext = context.getExternalContext();
-
-        if (context.getPartialViewContext().isPartialRequest())
-        {
-            // try to get (or create) a ResponseSwitch and turn off the output
-            Object origResponse = context.getExternalContext().getResponse();
-            ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(origResponse);
-            if (responseSwitch == null)
-            {
-                // no ResponseSwitch installed yet - create one 
-                responseSwitch = ExternalContextUtils.createResponseSwitch(origResponse);
-                if (responseSwitch != null)
-                {
-                    // install the ResponseSwitch
-                    context.getExternalContext().setResponse(responseSwitch);
-                }
-            }
-            if (responseSwitch != null)
-            {
-                responseSwitch.setEnabled(context, false);
-            }
-        }
-        
-        ServletResponse response = (ServletResponse) externalContext.getResponse();
-        ServletRequest request = (ServletRequest) externalContext.getRequest();
-        
-        Locale locale = view.getLocale();
-        response.setLocale(locale);
-        Config.set(request, Config.FMT_LOCALE, context.getViewRoot().getLocale());
-
-        String viewId = view.getViewId();
-        ServletViewResponseWrapper wrappedResponse = new ServletViewResponseWrapper((HttpServletResponse) response);
-
-        externalContext.setResponse(wrappedResponse);
-        try
-        {
-            externalContext.dispatch(viewId);
-        }
-        finally
-        {
-            externalContext.setResponse(response);
-        }
-
-        boolean errorResponse = wrappedResponse.getStatus() < 200 || wrappedResponse.getStatus() > 299;
-        if (errorResponse)
-        {
-            wrappedResponse.flushToWrappedResponse();
-            return;
-        }
-
-        //Skip this step if we are rendering an ajax request, because no content outside
-        //f:view tag should be output.
-        if (!context.getPartialViewContext().isPartialRequest())
-        {
-            // store the wrapped response in the request, so it is thread-safe
-            setAfterViewTagResponseWrapper(externalContext, wrappedResponse);
-        }
-    }
-
-    @Override
-    protected void sendSourceNotFound(FacesContext context, String message)
-    {
-        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
-        try
-        {
-            context.responseComplete();
-            response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
-        }
-        catch (IOException ioe)
-        {
-            throw new FacesException(ioe);
-        }
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.view.jsp;
+
+import java.io.IOException;
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.jstl.core.Config;
+
+import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
+import org.apache.myfaces.context.servlet.ResponseSwitch;
+import org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
+import org.apache.myfaces.util.ExternalContextUtils;
+import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
+import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
+import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
+import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
+
+/**
+ * @author Simon Lessard (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * 
+ * @since 2.0
+ */
+public class JspViewDeclarationLanguage extends JspViewDeclarationLanguageBase
+{
+    //private static final Log log = LogFactory.getLog(JspViewDeclarationLanguage.class);
+    public static final Logger log = Logger.getLogger(JspViewDeclarationLanguage.class.getName());
+    
+    /**
+     * Tags that are only available on facelets and not on JSP.
+     * If a user uses one of these tags on a JSP, we will provide
+     * a more informative error message than the standard one.
+     */
+    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax", "event", "metadata"};
+    public static final String[] FACELETS_ONLY_H_TAGS = {"outputScript", "outputStylesheet",
+                                                         "head", "body", "button", "link"};
+    
+    /**
+     * 
+     */
+    public JspViewDeclarationLanguage()
+    {
+        if (log.isLoggable(Level.FINEST))
+            log.finest("New JspViewDeclarationLanguage instance created");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void buildView(FacesContext context, UIViewRoot view) throws IOException
+    {
+        ExternalContext externalContext = context.getExternalContext();
+
+        if (context.getPartialViewContext().isPartialRequest())
+        {
+            // try to get (or create) a ResponseSwitch and turn off the output
+            Object origResponse = context.getExternalContext().getResponse();
+            ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(origResponse);
+            if (responseSwitch == null)
+            {
+                // no ResponseSwitch installed yet - create one 
+                responseSwitch = ExternalContextUtils.createResponseSwitch(origResponse);
+                if (responseSwitch != null)
+                {
+                    // install the ResponseSwitch
+                    context.getExternalContext().setResponse(responseSwitch);
+                }
+            }
+            if (responseSwitch != null)
+            {
+                responseSwitch.setEnabled(context, false);
+            }
+        }
+        
+        ServletResponse response = (ServletResponse) externalContext.getResponse();
+        ServletRequest request = (ServletRequest) externalContext.getRequest();
+        
+        Locale locale = view.getLocale();
+        response.setLocale(locale);
+        Config.set(request, Config.FMT_LOCALE, context.getViewRoot().getLocale());
+
+        String viewId = view.getViewId();
+        ServletViewResponseWrapper wrappedResponse = new ServletViewResponseWrapper((HttpServletResponse) response);
+
+        externalContext.setResponse(wrappedResponse);
+        try
+        {
+            externalContext.dispatch(viewId);
+        }
+        catch (FacesException e)
+        {
+            // try to extract the most likely exceptions here
+            // and provide a better error message for them
+            
+            String message = e.getMessage(); 
+            
+            // errors related to using facelets-only tags on a JSP page
+            if (message != null)
+            {
+                // does the message contain "f" (prefix f of tags)
+                // or the related uri http://java.sun.com/jsf/core
+                if (message.contains("\"f\"") 
+                        || message.contains("\"" + CoreLibrary.Namespace + "\""))
+                {
+                    // check facelets-only f tags
+                    for (String tag : FACELETS_ONLY_F_TAGS)
+                    {
+                        if (message.contains("\"" + tag + "\""))
+                        {
+                            String exceptionMessage = "The tag f:" + tag + 
+                                    " is only available on facelets.";
+                            throw new FacesException(exceptionMessage, 
+                                    new FaceletsOnlyException(exceptionMessage, e.getCause()));
+                        }
+                    }
+                }  
+                else if (message.contains("\"h\"") 
+                        || message.contains("\"" + HtmlLibrary.Namespace + "\""))
+                {
+                    // check facelets-only h tags
+                    for (String tag : FACELETS_ONLY_H_TAGS)
+                    {
+                        if (message.contains("\"" + tag + "\""))
+                        {
+                            String exceptionMessage = "The tag h:" + tag + 
+                                    " is only available on facelets.";
+                            throw new FacesException(exceptionMessage, 
+                                    new FaceletsOnlyException(exceptionMessage, e.getCause()));
+                        }
+                    }
+                }
+                else 
+                {
+                    // check facelets-only namespaces
+                    String namespace = null;
+                    if (message.contains(UILibrary.Namespace))
+                    {
+                        namespace = UILibrary.Namespace;
+                    }
+                    else if (message.contains(CompositeLibrary.NAMESPACE))
+                    {
+                        namespace = CompositeLibrary.NAMESPACE;
+                    }
+                    
+                    if (namespace != null)
+                    {
+                        // the message contains a facelets-only namespace
+                        String exceptionMessage = "All tags with namespace " +
+                                namespace + " are only available on facelets.";
+                        throw new FacesException(exceptionMessage, 
+                                new FaceletsOnlyException(exceptionMessage, e.getCause()));
+                    }
+                }
+            }
+            
+            // no rule applied to this Exception - rethrow it
+            throw e;
+        }
+        finally
+        {
+            externalContext.setResponse(response);
+        }
+
+        boolean errorResponse = wrappedResponse.getStatus() < 200 || wrappedResponse.getStatus() > 299;
+        if (errorResponse)
+        {
+            wrappedResponse.flushToWrappedResponse();
+            return;
+        }
+
+        //Skip this step if we are rendering an ajax request, because no content outside
+        //f:view tag should be output.
+        if (!context.getPartialViewContext().isPartialRequest())
+        {
+            // store the wrapped response in the request, so it is thread-safe
+            setAfterViewTagResponseWrapper(externalContext, wrappedResponse);
+        }
+    }
+
+    @Override
+    protected void sendSourceNotFound(FacesContext context, String message)
+    {
+        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
+        try
+        {
+            context.responseComplete();
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+        }
+        catch (IOException ioe)
+        {
+            throw new FacesException(ioe);
+        }
+    }
+
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Matthias Wessendorf <ma...@apache.org>.
with a delay of 13 hours, it made it.

Some gave approval, I guess (it may ended up in the moderation queue)

-M

On Wed, Apr 14, 2010 at 8:09 PM, Jakob Korherr <ja...@apache.org> wrote:
> No I cannot, because then its message won't be displayed by the
> ExceptionHandler, because the ExceptionHandler "extracts" the Exception
> until it finds the first non-FacesException and then it handles this one.
>
> Thus if I would make it a FacesException, the message will be lost. This was
> the reason I created FaceletsOnlyException in the first place...
>
> Regards,
> Jakob
>
> 2010/4/14 Matthias Wessendorf <ma...@apache.org>
>>
>> public class FaceletsOnlyException extends Exception
>>
>>
>> ==> can you make that extending FacesException ?
>>
>> -Matthias
>>
>> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
>> > Author: jakobk
>> > Date: Wed Apr 14 17:48:28 2010
>> > New Revision: 934048
>> >
>> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
>> > Log:
>> > MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X)
>> > pages
>> >
>> > Added:
>> >
>> >  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >   (with props)
>> > Modified:
>> >
>> >  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >   (contents, props changed)
>> >
>> > Added:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> > URL:
>> > http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
>> >
>> > ==============================================================================
>> > ---
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> > (added)
>> > +++
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> > Wed Apr 14 17:48:28 2010
>> > @@ -0,0 +1,40 @@
>> > +/*
>> > + * Licensed to the Apache Software Foundation (ASF) under one
>> > + * or more contributor license agreements.  See the NOTICE file
>> > + * distributed with this work for additional information
>> > + * regarding copyright ownership.  The ASF licenses this file
>> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > + *
>> > + * Unless required by applicable law or agreed to in writing,
>> > + * software distributed under the License is distributed on an
>> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > + * KIND, either express or implied.  See the License for the
>> > + * specific language governing permissions and limitations
>> > + * under the License.
>> > + */
>> > +package org.apache.myfaces.view.jsp;
>> > +
>> > +/**
>> > + * An Exception that indicates that the user uses a
>> > + * facelets-only feature on a JSP.
>> > + *
>> > + * @author Jakob Korherr (latest modification by $Author$)
>> > + * @version $Revision$ $Date$
>> > + *
>> > + * @since 2.0
>> > + */
>> > +public class FaceletsOnlyException extends Exception
>> > +{
>> > +
>> > +    private static final long serialVersionUID = 4268633427284543647L;
>> > +
>> > +    public FaceletsOnlyException(String message, Throwable cause)
>> > +    {
>> > +        super(message, cause);
>> > +    }
>> > +
>> > +}
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:eol-style = native
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:keywords = Date Author Id Revision HeadURL
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:mime-type = text/plain
>> >
>> > Modified:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> > URL:
>> > http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
>> >
>> > ==============================================================================
>> > ---
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> > (original)
>> > +++
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> > Wed Apr 14 17:48:28 2010
>> > @@ -1,139 +1,222 @@
>> > -/*
>> > - * Licensed to the Apache Software Foundation (ASF) under one
>> > - * or more contributor license agreements.  See the NOTICE file
>> > - * distributed with this work for additional information
>> > - * regarding copyright ownership.  The ASF licenses this file
>> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > - *
>> > - * Unless required by applicable law or agreed to in writing,
>> > - * software distributed under the License is distributed on an
>> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > - * KIND, either express or implied.  See the License for the
>> > - * specific language governing permissions and limitations
>> > - * under the License.
>> > - */
>> > -package org.apache.myfaces.view.jsp;
>> > -
>> > -import java.io.IOException;
>> > -import java.util.Locale;
>> > -import java.util.logging.Level;
>> > -import java.util.logging.Logger;
>> > -
>> > -import javax.faces.FacesException;
>> > -import javax.faces.component.UIViewRoot;
>> > -import javax.faces.context.ExternalContext;
>> > -import javax.faces.context.FacesContext;
>> > -import javax.servlet.ServletRequest;
>> > -import javax.servlet.ServletResponse;
>> > -import javax.servlet.http.HttpServletResponse;
>> > -import javax.servlet.jsp.jstl.core.Config;
>> > -
>> > -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
>> > -import
>> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>> > -import org.apache.myfaces.util.ExternalContextUtils;
>> > -
>> > -/**
>> > - * @author Simon Lessard (latest modification by $Author: slessard $)
>> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400 (mer.,
>> > 17 sept. 2008) $
>> > - *
>> > - * @since 2.0
>> > - */
>> > -public class JspViewDeclarationLanguage extends
>> > JspViewDeclarationLanguageBase
>> > -{
>> > -    //private static final Log log =
>> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>> > -    public static final Logger log =
>> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>> > -    /**
>> > -     *
>> > -     */
>> > -    public JspViewDeclarationLanguage()
>> > -    {
>> > -        if (log.isLoggable(Level.FINEST))
>> > -            log.finest("New JspViewDeclarationLanguage instance
>> > created");
>> > -    }
>> > -
>> > -    /**
>> > -     * {@inheritDoc}
>> > -     */
>> > -    @Override
>> > -    public void buildView(FacesContext context, UIViewRoot view) throws
>> > IOException
>> > -    {
>> > -        ExternalContext externalContext = context.getExternalContext();
>> > -
>> > -        if (context.getPartialViewContext().isPartialRequest())
>> > -        {
>> > -            // try to get (or create) a ResponseSwitch and turn off the
>> > output
>> > -            Object origResponse =
>> > context.getExternalContext().getResponse();
>> > -            ResponseSwitch responseSwitch =
>> > ExternalContextUtils.getResponseSwitch(origResponse);
>> > -            if (responseSwitch == null)
>> > -            {
>> > -                // no ResponseSwitch installed yet - create one
>> > -                responseSwitch =
>> > ExternalContextUtils.createResponseSwitch(origResponse);
>> > -                if (responseSwitch != null)
>> > -                {
>> > -                    // install the ResponseSwitch
>> > -
>> >  context.getExternalContext().setResponse(responseSwitch);
>> > -                }
>> > -            }
>> > -            if (responseSwitch != null)
>> > -            {
>> > -                responseSwitch.setEnabled(context, false);
>> > -            }
>> > -        }
>> > -
>> > -        ServletResponse response = (ServletResponse)
>> > externalContext.getResponse();
>> > -        ServletRequest request = (ServletRequest)
>> > externalContext.getRequest();
>> > -
>> > -        Locale locale = view.getLocale();
>> > -        response.setLocale(locale);
>> > -        Config.set(request, Config.FMT_LOCALE,
>> > context.getViewRoot().getLocale());
>> > -
>> > -        String viewId = view.getViewId();
>> > -        ServletViewResponseWrapper wrappedResponse = new
>> > ServletViewResponseWrapper((HttpServletResponse) response);
>> > -
>> > -        externalContext.setResponse(wrappedResponse);
>> > -        try
>> > -        {
>> > -            externalContext.dispatch(viewId);
>> > -        }
>> > -        finally
>> > -        {
>> > -            externalContext.setResponse(response);
>> > -        }
>> > -
>> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>> > wrappedResponse.getStatus() > 299;
>> > -        if (errorResponse)
>> > -        {
>> > -            wrappedResponse.flushToWrappedResponse();
>> > -            return;
>> > -        }
>> > -
>> > -        //Skip this step if we are rendering an ajax request, because
>> > no content outside
>> > -        //f:view tag should be output.
>> > -        if (!context.getPartialViewContext().isPartialRequest())
>> > -        {
>> > -            // store the wrapped response in the request, so it is
>> > thread-safe
>> > -            setAfterViewTagResponseWrapper(externalContext,
>> > wrappedResponse);
>> > -        }
>> > -    }
>> > -
>> > -    @Override
>> > -    protected void sendSourceNotFound(FacesContext context, String
>> > message)
>> > -    {
>> > -        HttpServletResponse response = (HttpServletResponse)
>> > context.getExternalContext().getResponse();
>> > -        try
>> > -        {
>> > -            context.responseComplete();
>> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>> > message);
>> > -        }
>> > -        catch (IOException ioe)
>> > -        {
>> > -            throw new FacesException(ioe);
>> > -        }
>> > -    }
>> > -
>> > -}
>> > +/*
>> > + * Licensed to the Apache Software Foundation (ASF) under one
>> > + * or more contributor license agreements.  See the NOTICE file
>> > + * distributed with this work for additional information
>> > + * regarding copyright ownership.  The ASF licenses this file
>> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > + *
>> > + * Unless required by applicable law or agreed to in writing,
>> > + * software distributed under the License is distributed on an
>> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > + * KIND, either express or implied.  See the License for the
>> > + * specific language governing permissions and limitations
>> > + * under the License.
>> > + */
>> > +package org.apache.myfaces.view.jsp;
>> > +
>> > +import java.io.IOException;
>> > +import java.util.Locale;
>> > +import java.util.logging.Level;
>> > +import java.util.logging.Logger;
>> > +
>> > +import javax.faces.FacesException;
>> > +import javax.faces.component.UIViewRoot;
>> > +import javax.faces.context.ExternalContext;
>> > +import javax.faces.context.FacesContext;
>> > +import javax.servlet.ServletRequest;
>> > +import javax.servlet.ServletResponse;
>> > +import javax.servlet.http.HttpServletResponse;
>> > +import javax.servlet.jsp.jstl.core.Config;
>> > +
>> > +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
>> > +import
>> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>> > +import org.apache.myfaces.util.ExternalContextUtils;
>> > +import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
>> > +
>> > +/**
>> > + * @author Simon Lessard (latest modification by $Author$)
>> > + * @version $Revision$ $Date$
>> > + *
>> > + * @since 2.0
>> > + */
>> > +public class JspViewDeclarationLanguage extends
>> > JspViewDeclarationLanguageBase
>> > +{
>> > +    //private static final Log log =
>> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>> > +    public static final Logger log =
>> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>> > +
>> > +    /**
>> > +     * Tags that are only available on facelets and not on JSP.
>> > +     * If a user uses one of these tags on a JSP, we will provide
>> > +     * a more informative error message than the standard one.
>> > +     */
>> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
>> > "event", "metadata"};
>> > +    public static final String[] FACELETS_ONLY_H_TAGS =
>> > {"outputScript", "outputStylesheet",
>> > +                                                         "head",
>> > "body", "button", "link"};
>> > +
>> > +    /**
>> > +     *
>> > +     */
>> > +    public JspViewDeclarationLanguage()
>> > +    {
>> > +        if (log.isLoggable(Level.FINEST))
>> > +            log.finest("New JspViewDeclarationLanguage instance
>> > created");
>> > +    }
>> > +
>> > +    /**
>> > +     * {@inheritDoc}
>> > +     */
>> > +    @Override
>> > +    public void buildView(FacesContext context, UIViewRoot view) throws
>> > IOException
>> > +    {
>> > +        ExternalContext externalContext = context.getExternalContext();
>> > +
>> > +        if (context.getPartialViewContext().isPartialRequest())
>> > +        {
>> > +            // try to get (or create) a ResponseSwitch and turn off the
>> > output
>> > +            Object origResponse =
>> > context.getExternalContext().getResponse();
>> > +            ResponseSwitch responseSwitch =
>> > ExternalContextUtils.getResponseSwitch(origResponse);
>> > +            if (responseSwitch == null)
>> > +            {
>> > +                // no ResponseSwitch installed yet - create one
>> > +                responseSwitch =
>> > ExternalContextUtils.createResponseSwitch(origResponse);
>> > +                if (responseSwitch != null)
>> > +                {
>> > +                    // install the ResponseSwitch
>> > +
>> >  context.getExternalContext().setResponse(responseSwitch);
>> > +                }
>> > +            }
>> > +            if (responseSwitch != null)
>> > +            {
>> > +                responseSwitch.setEnabled(context, false);
>> > +            }
>> > +        }
>> > +
>> > +        ServletResponse response = (ServletResponse)
>> > externalContext.getResponse();
>> > +        ServletRequest request = (ServletRequest)
>> > externalContext.getRequest();
>> > +
>> > +        Locale locale = view.getLocale();
>> > +        response.setLocale(locale);
>> > +        Config.set(request, Config.FMT_LOCALE,
>> > context.getViewRoot().getLocale());
>> > +
>> > +        String viewId = view.getViewId();
>> > +        ServletViewResponseWrapper wrappedResponse = new
>> > ServletViewResponseWrapper((HttpServletResponse) response);
>> > +
>> > +        externalContext.setResponse(wrappedResponse);
>> > +        try
>> > +        {
>> > +            externalContext.dispatch(viewId);
>> > +        }
>> > +        catch (FacesException e)
>> > +        {
>> > +            // try to extract the most likely exceptions here
>> > +            // and provide a better error message for them
>> > +
>> > +            String message = e.getMessage();
>> > +
>> > +            // errors related to using facelets-only tags on a JSP page
>> > +            if (message != null)
>> > +            {
>> > +                // does the message contain "f" (prefix f of tags)
>> > +                // or the related uri http://java.sun.com/jsf/core
>> > +                if (message.contains("\"f\"")
>> > +                        || message.contains("\"" +
>> > CoreLibrary.Namespace + "\""))
>> > +                {
>> > +                    // check facelets-only f tags
>> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
>> > +                    {
>> > +                        if (message.contains("\"" + tag + "\""))
>> > +                        {
>> > +                            String exceptionMessage = "The tag f:" +
>> > tag +
>> > +                                    " is only available on facelets.";
>> > +                            throw new FacesException(exceptionMessage,
>> > +                                    new
>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                        }
>> > +                    }
>> > +                }
>> > +                else if (message.contains("\"h\"")
>> > +                        || message.contains("\"" +
>> > HtmlLibrary.Namespace + "\""))
>> > +                {
>> > +                    // check facelets-only h tags
>> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
>> > +                    {
>> > +                        if (message.contains("\"" + tag + "\""))
>> > +                        {
>> > +                            String exceptionMessage = "The tag h:" +
>> > tag +
>> > +                                    " is only available on facelets.";
>> > +                            throw new FacesException(exceptionMessage,
>> > +                                    new
>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                        }
>> > +                    }
>> > +                }
>> > +                else
>> > +                {
>> > +                    // check facelets-only namespaces
>> > +                    String namespace = null;
>> > +                    if (message.contains(UILibrary.Namespace))
>> > +                    {
>> > +                        namespace = UILibrary.Namespace;
>> > +                    }
>> > +                    else if
>> > (message.contains(CompositeLibrary.NAMESPACE))
>> > +                    {
>> > +                        namespace = CompositeLibrary.NAMESPACE;
>> > +                    }
>> > +
>> > +                    if (namespace != null)
>> > +                    {
>> > +                        // the message contains a facelets-only
>> > namespace
>> > +                        String exceptionMessage = "All tags with
>> > namespace " +
>> > +                                namespace + " are only available on
>> > facelets.";
>> > +                        throw new FacesException(exceptionMessage,
>> > +                                new
>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                    }
>> > +                }
>> > +            }
>> > +
>> > +            // no rule applied to this Exception - rethrow it
>> > +            throw e;
>> > +        }
>> > +        finally
>> > +        {
>> > +            externalContext.setResponse(response);
>> > +        }
>> > +
>> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>> > wrappedResponse.getStatus() > 299;
>> > +        if (errorResponse)
>> > +        {
>> > +            wrappedResponse.flushToWrappedResponse();
>> > +            return;
>> > +        }
>> > +
>> > +        //Skip this step if we are rendering an ajax request, because
>> > no content outside
>> > +        //f:view tag should be output.
>> > +        if (!context.getPartialViewContext().isPartialRequest())
>> > +        {
>> > +            // store the wrapped response in the request, so it is
>> > thread-safe
>> > +            setAfterViewTagResponseWrapper(externalContext,
>> > wrappedResponse);
>> > +        }
>> > +    }
>> > +
>> > +    @Override
>> > +    protected void sendSourceNotFound(FacesContext context, String
>> > message)
>> > +    {
>> > +        HttpServletResponse response = (HttpServletResponse)
>> > context.getExternalContext().getResponse();
>> > +        try
>> > +        {
>> > +            context.responseComplete();
>> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>> > message);
>> > +        }
>> > +        catch (IOException ioe)
>> > +        {
>> > +            throw new FacesException(ioe);
>> > +        }
>> > +    }
>> > +
>> > +}
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:eol-style = native
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:keywords = Date Author Id Revision HeadURL
>> >
>> >
>> >
>>
>>
>>
>> --
>> Matthias Wessendorf
>>
>> blog: http://matthiaswessendorf.wordpress.com/
>> sessions: http://www.slideshare.net/mwessendorf
>> twitter: http://twitter.com/mwessendorf
>
>
>
> --
> Jakob Korherr
>
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at
>



-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Jakob Korherr <ja...@gmail.com>.
This could be it.. The commit mail was sent by jakobk@apache.org and thus
gmail wanted to send my follow up mail also from this address, but this one
is not subscribed.

Thanks Leonardo for finding that out :)

2010/4/14 Leonardo Uribe <lu...@gmail.com>

> Hi
>
> The mail says from jakobk@apache.org, maybe that account is not suscribed
> to dev list.
>
> regards,
>
> Leonardo Uribe
>
> 2010/4/14 Jakob Korherr <ja...@gmail.com>
>
> Hi,
>>
>> I have no idea why this mail was lost, but fact is that it wasn't even
>> sent, because it's not in the mail archive.. However Gmail displayed it as
>> "sent correctly" and thus I was kinda annoyed - you understand...
>>
>> FYI: I just added some JavaDoc about it in r934200, so this should not
>> happen again (hopefully).
>>
>>
>> Regards,
>> Jakob
>>
>>
>> 2010/4/14 Matthias Wessendorf <ma...@apache.org>
>>
>>> ah! :-)
>>>
>>> no, this mail is not visible , or it was lost in Gmail (at least for me).
>>>
>>> Ok, so let's "revert" Leo's commit and add some JavaDoc on why it
>>> directly
>>> extends Exception to avoid similar "refactorings" in the future.
>>>
>>> Thanks,
>>> Matthias
>>>
>>> On Wed, Apr 14, 2010 at 10:48 PM, Jakob Korherr <ja...@gmail.com>
>>> wrote:
>>> > Forwarded my original mail to this topic since it obviously went wrong
>>> the
>>> > first time.
>>> >
>>> > ---------- Forwarded message ----------
>>> > From: Jakob Korherr <ja...@apache.org>
>>> > Date: 2010/4/14
>>> > Subject: Re: svn commit: r934048 - in
>>> > /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp:
>>> > FaceletsOnlyException.java JspViewDeclarationLanguage.java
>>> > To: MyFaces Development <de...@myfaces.apache.org>
>>> >
>>> >
>>> > No I cannot, because then its message won't be displayed by the
>>> > ExceptionHandler, because the ExceptionHandler "extracts" the Exception
>>> > until it finds the first non-FacesException and then it handles this
>>> one.
>>> >
>>> > Thus if I would make it a FacesException, the message will be lost.
>>> This was
>>> > the reason I created FaceletsOnlyException in the first place...
>>> >
>>> > Regards,
>>> > Jakob
>>> >
>>> > 2010/4/14 Matthias Wessendorf <ma...@apache.org>
>>> >>
>>> >> public class FaceletsOnlyException extends Exception
>>> >>
>>> >>
>>> >> ==> can you make that extending FacesException ?
>>> >>
>>> >> -Matthias
>>> >>
>>> >> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
>>> >> > Author: jakobk
>>> >> > Date: Wed Apr 14 17:48:28 2010
>>> >> > New Revision: 934048
>>> >> >
>>> >> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
>>> >> > Log:
>>> >> > MYFACES-2658 Indicate a better error when using Facelet TAGs on
>>> JSP(X)
>>> >> > pages
>>> >> >
>>> >> > Added:
>>> >> >
>>> >> >
>>>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >> >   (with props)
>>> >> > Modified:
>>> >> >
>>> >> >
>>>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >> >   (contents, props changed)
>>> >> >
>>> >> > Added:
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >> > URL:
>>> >> >
>>> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
>>> >> >
>>> >> >
>>> ==============================================================================
>>> >> > ---
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >> > (added)
>>> >> > +++
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >> > Wed Apr 14 17:48:28 2010
>>> >> > @@ -0,0 +1,40 @@
>>> >> > +/*
>>> >> > + * Licensed to the Apache Software Foundation (ASF) under one
>>> >> > + * or more contributor license agreements.  See the NOTICE file
>>> >> > + * distributed with this work for additional information
>>> >> > + * regarding copyright ownership.  The ASF licenses this file
>>> >> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>>> >> > + *
>>> >> > + * Unless required by applicable law or agreed to in writing,
>>> >> > + * software distributed under the License is distributed on an
>>> >> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> >> > + * KIND, either express or implied.  See the License for the
>>> >> > + * specific language governing permissions and limitations
>>> >> > + * under the License.
>>> >> > + */
>>> >> > +package org.apache.myfaces.view.jsp;
>>> >> > +
>>> >> > +/**
>>> >> > + * An Exception that indicates that the user uses a
>>> >> > + * facelets-only feature on a JSP.
>>> >> > + *
>>> >> > + * @author Jakob Korherr (latest modification by $Author$)
>>> >> > + * @version $Revision$ $Date$
>>> >> > + *
>>> >> > + * @since 2.0
>>> >> > + */
>>> >> > +public class FaceletsOnlyException extends Exception
>>> >> > +{
>>> >> > +
>>> >> > +    private static final long serialVersionUID =
>>> 4268633427284543647L;
>>> >> > +
>>> >> > +    public FaceletsOnlyException(String message, Throwable cause)
>>> >> > +    {
>>> >> > +        super(message, cause);
>>> >> > +    }
>>> >> > +
>>> >> > +}
>>> >> >
>>> >> > Propchange:
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >> >
>>> >> >
>>> ------------------------------------------------------------------------------
>>> >> >    svn:eol-style = native
>>> >> >
>>> >> > Propchange:
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >> >
>>> >> >
>>> ------------------------------------------------------------------------------
>>> >> >    svn:keywords = Date Author Id Revision HeadURL
>>> >> >
>>> >> > Propchange:
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >> >
>>> >> >
>>> ------------------------------------------------------------------------------
>>> >> >    svn:mime-type = text/plain
>>> >> >
>>> >> > Modified:
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >> > URL:
>>> >> >
>>> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
>>> >> >
>>> >> >
>>> ==============================================================================
>>> >> > ---
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >> > (original)
>>> >> > +++
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >> > Wed Apr 14 17:48:28 2010
>>> >> > @@ -1,139 +1,222 @@
>>> >> > -/*
>>> >> > - * Licensed to the Apache Software Foundation (ASF) under one
>>> >> > - * or more contributor license agreements.  See the NOTICE file
>>> >> > - * distributed with this work for additional information
>>> >> > - * regarding copyright ownership.  The ASF licenses this file
>>> >> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>>> >> > - *
>>> >> > - * Unless required by applicable law or agreed to in writing,
>>> >> > - * software distributed under the License is distributed on an
>>> >> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> >> > - * KIND, either express or implied.  See the License for the
>>> >> > - * specific language governing permissions and limitations
>>> >> > - * under the License.
>>> >> > - */
>>> >> > -package org.apache.myfaces.view.jsp;
>>> >> > -
>>> >> > -import java.io.IOException;
>>> >> > -import java.util.Locale;
>>> >> > -import java.util.logging.Level;
>>> >> > -import java.util.logging.Logger;
>>> >> > -
>>> >> > -import javax.faces.FacesException;
>>> >> > -import javax.faces.component.UIViewRoot;
>>> >> > -import javax.faces.context.ExternalContext;
>>> >> > -import javax.faces.context.FacesContext;
>>> >> > -import javax.servlet.ServletRequest;
>>> >> > -import javax.servlet.ServletResponse;
>>> >> > -import javax.servlet.http.HttpServletResponse;
>>> >> > -import javax.servlet.jsp.jstl.core.Config;
>>> >> > -
>>> >> > -import
>>> org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>>> >> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
>>> >> > -import
>>> >> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>>> >> > -import org.apache.myfaces.util.ExternalContextUtils;
>>> >> > -
>>> >> > -/**
>>> >> > - * @author Simon Lessard (latest modification by $Author: slessard
>>> $)
>>> >> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400
>>> (mer.,
>>> >> > 17 sept. 2008) $
>>> >> > - *
>>> >> > - * @since 2.0
>>> >> > - */
>>> >> > -public class JspViewDeclarationLanguage extends
>>> >> > JspViewDeclarationLanguageBase
>>> >> > -{
>>> >> > -    //private static final Log log =
>>> >> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>>> >> > -    public static final Logger log =
>>> >> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>>> >> > -    /**
>>> >> > -     *
>>> >> > -     */
>>> >> > -    public JspViewDeclarationLanguage()
>>> >> > -    {
>>> >> > -        if (log.isLoggable(Level.FINEST))
>>> >> > -            log.finest("New JspViewDeclarationLanguage instance
>>> >> > created");
>>> >> > -    }
>>> >> > -
>>> >> > -    /**
>>> >> > -     * {@inheritDoc}
>>> >> > -     */
>>> >> > -    @Override
>>> >> > -    public void buildView(FacesContext context, UIViewRoot view)
>>> throws
>>> >> > IOException
>>> >> > -    {
>>> >> > -        ExternalContext externalContext =
>>> context.getExternalContext();
>>> >> > -
>>> >> > -        if (context.getPartialViewContext().isPartialRequest())
>>> >> > -        {
>>> >> > -            // try to get (or create) a ResponseSwitch and turn off
>>> the
>>> >> > output
>>> >> > -            Object origResponse =
>>> >> > context.getExternalContext().getResponse();
>>> >> > -            ResponseSwitch responseSwitch =
>>> >> > ExternalContextUtils.getResponseSwitch(origResponse);
>>> >> > -            if (responseSwitch == null)
>>> >> > -            {
>>> >> > -                // no ResponseSwitch installed yet - create one
>>> >> > -                responseSwitch =
>>> >> > ExternalContextUtils.createResponseSwitch(origResponse);
>>> >> > -                if (responseSwitch != null)
>>> >> > -                {
>>> >> > -                    // install the ResponseSwitch
>>> >> > -
>>> >> >  context.getExternalContext().setResponse(responseSwitch);
>>> >> > -                }
>>> >> > -            }
>>> >> > -            if (responseSwitch != null)
>>> >> > -            {
>>> >> > -                responseSwitch.setEnabled(context, false);
>>> >> > -            }
>>> >> > -        }
>>> >> > -
>>> >> > -        ServletResponse response = (ServletResponse)
>>> >> > externalContext.getResponse();
>>> >> > -        ServletRequest request = (ServletRequest)
>>> >> > externalContext.getRequest();
>>> >> > -
>>> >> > -        Locale locale = view.getLocale();
>>> >> > -        response.setLocale(locale);
>>> >> > -        Config.set(request, Config.FMT_LOCALE,
>>> >> > context.getViewRoot().getLocale());
>>> >> > -
>>> >> > -        String viewId = view.getViewId();
>>> >> > -        ServletViewResponseWrapper wrappedResponse = new
>>> >> > ServletViewResponseWrapper((HttpServletResponse) response);
>>> >> > -
>>> >> > -        externalContext.setResponse(wrappedResponse);
>>> >> > -        try
>>> >> > -        {
>>> >> > -            externalContext.dispatch(viewId);
>>> >> > -        }
>>> >> > -        finally
>>> >> > -        {
>>> >> > -            externalContext.setResponse(response);
>>> >> > -        }
>>> >> > -
>>> >> > -        boolean errorResponse = wrappedResponse.getStatus() < 200
>>> ||
>>> >> > wrappedResponse.getStatus() > 299;
>>> >> > -        if (errorResponse)
>>> >> > -        {
>>> >> > -            wrappedResponse.flushToWrappedResponse();
>>> >> > -            return;
>>> >> > -        }
>>> >> > -
>>> >> > -        //Skip this step if we are rendering an ajax request,
>>> because
>>> >> > no content outside
>>> >> > -        //f:view tag should be output.
>>> >> > -        if (!context.getPartialViewContext().isPartialRequest())
>>> >> > -        {
>>> >> > -            // store the wrapped response in the request, so it is
>>> >> > thread-safe
>>> >> > -            setAfterViewTagResponseWrapper(externalContext,
>>> >> > wrappedResponse);
>>> >> > -        }
>>> >> > -    }
>>> >> > -
>>> >> > -    @Override
>>> >> > -    protected void sendSourceNotFound(FacesContext context, String
>>> >> > message)
>>> >> > -    {
>>> >> > -        HttpServletResponse response = (HttpServletResponse)
>>> >> > context.getExternalContext().getResponse();
>>> >> > -        try
>>> >> > -        {
>>> >> > -            context.responseComplete();
>>> >> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>>> >> > message);
>>> >> > -        }
>>> >> > -        catch (IOException ioe)
>>> >> > -        {
>>> >> > -            throw new FacesException(ioe);
>>> >> > -        }
>>> >> > -    }
>>> >> > -
>>> >> > -}
>>> >> > +/*
>>> >> > + * Licensed to the Apache Software Foundation (ASF) under one
>>> >> > + * or more contributor license agreements.  See the NOTICE file
>>> >> > + * distributed with this work for additional information
>>> >> > + * regarding copyright ownership.  The ASF licenses this file
>>> >> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>>> >> > + *
>>> >> > + * Unless required by applicable law or agreed to in writing,
>>> >> > + * software distributed under the License is distributed on an
>>> >> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> >> > + * KIND, either express or implied.  See the License for the
>>> >> > + * specific language governing permissions and limitations
>>> >> > + * under the License.
>>> >> > + */
>>> >> > +package org.apache.myfaces.view.jsp;
>>> >> > +
>>> >> > +import java.io.IOException;
>>> >> > +import java.util.Locale;
>>> >> > +import java.util.logging.Level;
>>> >> > +import java.util.logging.Logger;
>>> >> > +
>>> >> > +import javax.faces.FacesException;
>>> >> > +import javax.faces.component.UIViewRoot;
>>> >> > +import javax.faces.context.ExternalContext;
>>> >> > +import javax.faces.context.FacesContext;
>>> >> > +import javax.servlet.ServletRequest;
>>> >> > +import javax.servlet.ServletResponse;
>>> >> > +import javax.servlet.http.HttpServletResponse;
>>> >> > +import javax.servlet.jsp.jstl.core.Config;
>>> >> > +
>>> >> > +import
>>> org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>>> >> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
>>> >> > +import
>>> >> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>>> >> > +import org.apache.myfaces.util.ExternalContextUtils;
>>> >> > +import
>>> org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
>>> >> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
>>> >> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
>>> >> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
>>> >> > +
>>> >> > +/**
>>> >> > + * @author Simon Lessard (latest modification by $Author$)
>>> >> > + * @version $Revision$ $Date$
>>> >> > + *
>>> >> > + * @since 2.0
>>> >> > + */
>>> >> > +public class JspViewDeclarationLanguage extends
>>> >> > JspViewDeclarationLanguageBase
>>> >> > +{
>>> >> > +    //private static final Log log =
>>> >> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>>> >> > +    public static final Logger log =
>>> >> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>>> >> > +
>>> >> > +    /**
>>> >> > +     * Tags that are only available on facelets and not on JSP.
>>> >> > +     * If a user uses one of these tags on a JSP, we will provide
>>> >> > +     * a more informative error message than the standard one.
>>> >> > +     */
>>> >> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
>>> >> > "event", "metadata"};
>>> >> > +    public static final String[] FACELETS_ONLY_H_TAGS =
>>> >> > {"outputScript", "outputStylesheet",
>>> >> > +                                                         "head",
>>> >> > "body", "button", "link"};
>>> >> > +
>>> >> > +    /**
>>> >> > +     *
>>> >> > +     */
>>> >> > +    public JspViewDeclarationLanguage()
>>> >> > +    {
>>> >> > +        if (log.isLoggable(Level.FINEST))
>>> >> > +            log.finest("New JspViewDeclarationLanguage instance
>>> >> > created");
>>> >> > +    }
>>> >> > +
>>> >> > +    /**
>>> >> > +     * {@inheritDoc}
>>> >> > +     */
>>> >> > +    @Override
>>> >> > +    public void buildView(FacesContext context, UIViewRoot view)
>>> throws
>>> >> > IOException
>>> >> > +    {
>>> >> > +        ExternalContext externalContext =
>>> context.getExternalContext();
>>> >> > +
>>> >> > +        if (context.getPartialViewContext().isPartialRequest())
>>> >> > +        {
>>> >> > +            // try to get (or create) a ResponseSwitch and turn off
>>> the
>>> >> > output
>>> >> > +            Object origResponse =
>>> >> > context.getExternalContext().getResponse();
>>> >> > +            ResponseSwitch responseSwitch =
>>> >> > ExternalContextUtils.getResponseSwitch(origResponse);
>>> >> > +            if (responseSwitch == null)
>>> >> > +            {
>>> >> > +                // no ResponseSwitch installed yet - create one
>>> >> > +                responseSwitch =
>>> >> > ExternalContextUtils.createResponseSwitch(origResponse);
>>> >> > +                if (responseSwitch != null)
>>> >> > +                {
>>> >> > +                    // install the ResponseSwitch
>>> >> > +
>>> >> >  context.getExternalContext().setResponse(responseSwitch);
>>> >> > +                }
>>> >> > +            }
>>> >> > +            if (responseSwitch != null)
>>> >> > +            {
>>> >> > +                responseSwitch.setEnabled(context, false);
>>> >> > +            }
>>> >> > +        }
>>> >> > +
>>> >> > +        ServletResponse response = (ServletResponse)
>>> >> > externalContext.getResponse();
>>> >> > +        ServletRequest request = (ServletRequest)
>>> >> > externalContext.getRequest();
>>> >> > +
>>> >> > +        Locale locale = view.getLocale();
>>> >> > +        response.setLocale(locale);
>>> >> > +        Config.set(request, Config.FMT_LOCALE,
>>> >> > context.getViewRoot().getLocale());
>>> >> > +
>>> >> > +        String viewId = view.getViewId();
>>> >> > +        ServletViewResponseWrapper wrappedResponse = new
>>> >> > ServletViewResponseWrapper((HttpServletResponse) response);
>>> >> > +
>>> >> > +        externalContext.setResponse(wrappedResponse);
>>> >> > +        try
>>> >> > +        {
>>> >> > +            externalContext.dispatch(viewId);
>>> >> > +        }
>>> >> > +        catch (FacesException e)
>>> >> > +        {
>>> >> > +            // try to extract the most likely exceptions here
>>> >> > +            // and provide a better error message for them
>>> >> > +
>>> >> > +            String message = e.getMessage();
>>> >> > +
>>> >> > +            // errors related to using facelets-only tags on a JSP
>>> page
>>> >> > +            if (message != null)
>>> >> > +            {
>>> >> > +                // does the message contain "f" (prefix f of tags)
>>> >> > +                // or the related uri http://java.sun.com/jsf/core
>>> >> > +                if (message.contains("\"f\"")
>>> >> > +                        || message.contains("\"" +
>>> >> > CoreLibrary.Namespace + "\""))
>>> >> > +                {
>>> >> > +                    // check facelets-only f tags
>>> >> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
>>> >> > +                    {
>>> >> > +                        if (message.contains("\"" + tag + "\""))
>>> >> > +                        {
>>> >> > +                            String exceptionMessage = "The tag f:"
>>> +
>>> >> > tag +
>>> >> > +                                    " is only available on
>>> facelets.";
>>> >> > +                            throw new
>>> FacesException(exceptionMessage,
>>> >> > +                                    new
>>> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>>> >> > +                        }
>>> >> > +                    }
>>> >> > +                }
>>> >> > +                else if (message.contains("\"h\"")
>>> >> > +                        || message.contains("\"" +
>>> >> > HtmlLibrary.Namespace + "\""))
>>> >> > +                {
>>> >> > +                    // check facelets-only h tags
>>> >> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
>>> >> > +                    {
>>> >> > +                        if (message.contains("\"" + tag + "\""))
>>> >> > +                        {
>>> >> > +                            String exceptionMessage = "The tag h:"
>>> +
>>> >> > tag +
>>> >> > +                                    " is only available on
>>> facelets.";
>>> >> > +                            throw new
>>> FacesException(exceptionMessage,
>>> >> > +                                    new
>>> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>>> >> > +                        }
>>> >> > +                    }
>>> >> > +                }
>>> >> > +                else
>>> >> > +                {
>>> >> > +                    // check facelets-only namespaces
>>> >> > +                    String namespace = null;
>>> >> > +                    if (message.contains(UILibrary.Namespace))
>>> >> > +                    {
>>> >> > +                        namespace = UILibrary.Namespace;
>>> >> > +                    }
>>> >> > +                    else if
>>> >> > (message.contains(CompositeLibrary.NAMESPACE))
>>> >> > +                    {
>>> >> > +                        namespace = CompositeLibrary.NAMESPACE;
>>> >> > +                    }
>>> >> > +
>>> >> > +                    if (namespace != null)
>>> >> > +                    {
>>> >> > +                        // the message contains a facelets-only
>>> >> > namespace
>>> >> > +                        String exceptionMessage = "All tags with
>>> >> > namespace " +
>>> >> > +                                namespace + " are only available on
>>> >> > facelets.";
>>> >> > +                        throw new FacesException(exceptionMessage,
>>> >> > +                                new
>>> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>>> >> > +                    }
>>> >> > +                }
>>> >> > +            }
>>> >> > +
>>> >> > +            // no rule applied to this Exception - rethrow it
>>> >> > +            throw e;
>>> >> > +        }
>>> >> > +        finally
>>> >> > +        {
>>> >> > +            externalContext.setResponse(response);
>>> >> > +        }
>>> >> > +
>>> >> > +        boolean errorResponse = wrappedResponse.getStatus() < 200
>>> ||
>>> >> > wrappedResponse.getStatus() > 299;
>>> >> > +        if (errorResponse)
>>> >> > +        {
>>> >> > +            wrappedResponse.flushToWrappedResponse();
>>> >> > +            return;
>>> >> > +        }
>>> >> > +
>>> >> > +        //Skip this step if we are rendering an ajax request,
>>> because
>>> >> > no content outside
>>> >> > +        //f:view tag should be output.
>>> >> > +        if (!context.getPartialViewContext().isPartialRequest())
>>> >> > +        {
>>> >> > +            // store the wrapped response in the request, so it is
>>> >> > thread-safe
>>> >> > +            setAfterViewTagResponseWrapper(externalContext,
>>> >> > wrappedResponse);
>>> >> > +        }
>>> >> > +    }
>>> >> > +
>>> >> > +    @Override
>>> >> > +    protected void sendSourceNotFound(FacesContext context, String
>>> >> > message)
>>> >> > +    {
>>> >> > +        HttpServletResponse response = (HttpServletResponse)
>>> >> > context.getExternalContext().getResponse();
>>> >> > +        try
>>> >> > +        {
>>> >> > +            context.responseComplete();
>>> >> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>>> >> > message);
>>> >> > +        }
>>> >> > +        catch (IOException ioe)
>>> >> > +        {
>>> >> > +            throw new FacesException(ioe);
>>> >> > +        }
>>> >> > +    }
>>> >> > +
>>> >> > +}
>>> >> >
>>> >> > Propchange:
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >> >
>>> >> >
>>> ------------------------------------------------------------------------------
>>> >> >    svn:eol-style = native
>>> >> >
>>> >> > Propchange:
>>> >> >
>>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >> >
>>> >> >
>>> ------------------------------------------------------------------------------
>>> >> >    svn:keywords = Date Author Id Revision HeadURL
>>> >> >
>>> >> >
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Matthias Wessendorf
>>> >>
>>> >> blog: http://matthiaswessendorf.wordpress.com/
>>> >> sessions: http://www.slideshare.net/mwessendorf
>>> >> twitter: http://twitter.com/mwessendorf
>>> >
>>> >
>>> >
>>> > --
>>> > Jakob Korherr
>>> >
>>> > blog: http://www.jakobk.com
>>> > twitter: http://twitter.com/jakobkorherr
>>> > work: http://www.irian.at
>>> >
>>> >
>>> >
>>> > --
>>> > Jakob Korherr
>>> >
>>> > blog: http://www.jakobk.com
>>> > twitter: http://twitter.com/jakobkorherr
>>> > work: http://www.irian.at
>>> >
>>>
>>>
>>>
>>> --
>>> Matthias Wessendorf
>>>
>>> blog: http://matthiaswessendorf.wordpress.com/
>>> sessions: http://www.slideshare.net/mwessendorf
>>> twitter: http://twitter.com/mwessendorf
>>>
>>
>>
>>
>> --
>> Jakob Korherr
>>
>> blog: http://www.jakobk.com
>> twitter: http://twitter.com/jakobkorherr
>> work: http://www.irian.at
>>
>
>


-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Leonardo Uribe <lu...@gmail.com>.
Hi

The mail says from jakobk@apache.org, maybe that account is not suscribed to
dev list.

regards,

Leonardo Uribe

2010/4/14 Jakob Korherr <ja...@gmail.com>

> Hi,
>
> I have no idea why this mail was lost, but fact is that it wasn't even
> sent, because it's not in the mail archive.. However Gmail displayed it as
> "sent correctly" and thus I was kinda annoyed - you understand...
>
> FYI: I just added some JavaDoc about it in r934200, so this should not
> happen again (hopefully).
>
>
> Regards,
> Jakob
>
>
> 2010/4/14 Matthias Wessendorf <ma...@apache.org>
>
>> ah! :-)
>>
>> no, this mail is not visible , or it was lost in Gmail (at least for me).
>>
>> Ok, so let's "revert" Leo's commit and add some JavaDoc on why it directly
>> extends Exception to avoid similar "refactorings" in the future.
>>
>> Thanks,
>> Matthias
>>
>> On Wed, Apr 14, 2010 at 10:48 PM, Jakob Korherr <ja...@gmail.com>
>> wrote:
>> > Forwarded my original mail to this topic since it obviously went wrong
>> the
>> > first time.
>> >
>> > ---------- Forwarded message ----------
>> > From: Jakob Korherr <ja...@apache.org>
>> > Date: 2010/4/14
>> > Subject: Re: svn commit: r934048 - in
>> > /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp:
>> > FaceletsOnlyException.java JspViewDeclarationLanguage.java
>> > To: MyFaces Development <de...@myfaces.apache.org>
>> >
>> >
>> > No I cannot, because then its message won't be displayed by the
>> > ExceptionHandler, because the ExceptionHandler "extracts" the Exception
>> > until it finds the first non-FacesException and then it handles this
>> one.
>> >
>> > Thus if I would make it a FacesException, the message will be lost. This
>> was
>> > the reason I created FaceletsOnlyException in the first place...
>> >
>> > Regards,
>> > Jakob
>> >
>> > 2010/4/14 Matthias Wessendorf <ma...@apache.org>
>> >>
>> >> public class FaceletsOnlyException extends Exception
>> >>
>> >>
>> >> ==> can you make that extending FacesException ?
>> >>
>> >> -Matthias
>> >>
>> >> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
>> >> > Author: jakobk
>> >> > Date: Wed Apr 14 17:48:28 2010
>> >> > New Revision: 934048
>> >> >
>> >> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
>> >> > Log:
>> >> > MYFACES-2658 Indicate a better error when using Facelet TAGs on
>> JSP(X)
>> >> > pages
>> >> >
>> >> > Added:
>> >> >
>> >> >
>>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >> >   (with props)
>> >> > Modified:
>> >> >
>> >> >
>>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >> >   (contents, props changed)
>> >> >
>> >> > Added:
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >> > URL:
>> >> >
>> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
>> >> >
>> >> >
>> ==============================================================================
>> >> > ---
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >> > (added)
>> >> > +++
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >> > Wed Apr 14 17:48:28 2010
>> >> > @@ -0,0 +1,40 @@
>> >> > +/*
>> >> > + * Licensed to the Apache Software Foundation (ASF) under one
>> >> > + * or more contributor license agreements.  See the NOTICE file
>> >> > + * distributed with this work for additional information
>> >> > + * regarding copyright ownership.  The ASF licenses this file
>> >> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> >> > + *
>> >> > + * Unless required by applicable law or agreed to in writing,
>> >> > + * software distributed under the License is distributed on an
>> >> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> >> > + * KIND, either express or implied.  See the License for the
>> >> > + * specific language governing permissions and limitations
>> >> > + * under the License.
>> >> > + */
>> >> > +package org.apache.myfaces.view.jsp;
>> >> > +
>> >> > +/**
>> >> > + * An Exception that indicates that the user uses a
>> >> > + * facelets-only feature on a JSP.
>> >> > + *
>> >> > + * @author Jakob Korherr (latest modification by $Author$)
>> >> > + * @version $Revision$ $Date$
>> >> > + *
>> >> > + * @since 2.0
>> >> > + */
>> >> > +public class FaceletsOnlyException extends Exception
>> >> > +{
>> >> > +
>> >> > +    private static final long serialVersionUID =
>> 4268633427284543647L;
>> >> > +
>> >> > +    public FaceletsOnlyException(String message, Throwable cause)
>> >> > +    {
>> >> > +        super(message, cause);
>> >> > +    }
>> >> > +
>> >> > +}
>> >> >
>> >> > Propchange:
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >> >
>> >> >
>> ------------------------------------------------------------------------------
>> >> >    svn:eol-style = native
>> >> >
>> >> > Propchange:
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >> >
>> >> >
>> ------------------------------------------------------------------------------
>> >> >    svn:keywords = Date Author Id Revision HeadURL
>> >> >
>> >> > Propchange:
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >> >
>> >> >
>> ------------------------------------------------------------------------------
>> >> >    svn:mime-type = text/plain
>> >> >
>> >> > Modified:
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >> > URL:
>> >> >
>> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
>> >> >
>> >> >
>> ==============================================================================
>> >> > ---
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >> > (original)
>> >> > +++
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >> > Wed Apr 14 17:48:28 2010
>> >> > @@ -1,139 +1,222 @@
>> >> > -/*
>> >> > - * Licensed to the Apache Software Foundation (ASF) under one
>> >> > - * or more contributor license agreements.  See the NOTICE file
>> >> > - * distributed with this work for additional information
>> >> > - * regarding copyright ownership.  The ASF licenses this file
>> >> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> >> > - *
>> >> > - * Unless required by applicable law or agreed to in writing,
>> >> > - * software distributed under the License is distributed on an
>> >> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> >> > - * KIND, either express or implied.  See the License for the
>> >> > - * specific language governing permissions and limitations
>> >> > - * under the License.
>> >> > - */
>> >> > -package org.apache.myfaces.view.jsp;
>> >> > -
>> >> > -import java.io.IOException;
>> >> > -import java.util.Locale;
>> >> > -import java.util.logging.Level;
>> >> > -import java.util.logging.Logger;
>> >> > -
>> >> > -import javax.faces.FacesException;
>> >> > -import javax.faces.component.UIViewRoot;
>> >> > -import javax.faces.context.ExternalContext;
>> >> > -import javax.faces.context.FacesContext;
>> >> > -import javax.servlet.ServletRequest;
>> >> > -import javax.servlet.ServletResponse;
>> >> > -import javax.servlet.http.HttpServletResponse;
>> >> > -import javax.servlet.jsp.jstl.core.Config;
>> >> > -
>> >> > -import
>> org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>> >> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
>> >> > -import
>> >> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>> >> > -import org.apache.myfaces.util.ExternalContextUtils;
>> >> > -
>> >> > -/**
>> >> > - * @author Simon Lessard (latest modification by $Author: slessard
>> $)
>> >> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400
>> (mer.,
>> >> > 17 sept. 2008) $
>> >> > - *
>> >> > - * @since 2.0
>> >> > - */
>> >> > -public class JspViewDeclarationLanguage extends
>> >> > JspViewDeclarationLanguageBase
>> >> > -{
>> >> > -    //private static final Log log =
>> >> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>> >> > -    public static final Logger log =
>> >> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>> >> > -    /**
>> >> > -     *
>> >> > -     */
>> >> > -    public JspViewDeclarationLanguage()
>> >> > -    {
>> >> > -        if (log.isLoggable(Level.FINEST))
>> >> > -            log.finest("New JspViewDeclarationLanguage instance
>> >> > created");
>> >> > -    }
>> >> > -
>> >> > -    /**
>> >> > -     * {@inheritDoc}
>> >> > -     */
>> >> > -    @Override
>> >> > -    public void buildView(FacesContext context, UIViewRoot view)
>> throws
>> >> > IOException
>> >> > -    {
>> >> > -        ExternalContext externalContext =
>> context.getExternalContext();
>> >> > -
>> >> > -        if (context.getPartialViewContext().isPartialRequest())
>> >> > -        {
>> >> > -            // try to get (or create) a ResponseSwitch and turn off
>> the
>> >> > output
>> >> > -            Object origResponse =
>> >> > context.getExternalContext().getResponse();
>> >> > -            ResponseSwitch responseSwitch =
>> >> > ExternalContextUtils.getResponseSwitch(origResponse);
>> >> > -            if (responseSwitch == null)
>> >> > -            {
>> >> > -                // no ResponseSwitch installed yet - create one
>> >> > -                responseSwitch =
>> >> > ExternalContextUtils.createResponseSwitch(origResponse);
>> >> > -                if (responseSwitch != null)
>> >> > -                {
>> >> > -                    // install the ResponseSwitch
>> >> > -
>> >> >  context.getExternalContext().setResponse(responseSwitch);
>> >> > -                }
>> >> > -            }
>> >> > -            if (responseSwitch != null)
>> >> > -            {
>> >> > -                responseSwitch.setEnabled(context, false);
>> >> > -            }
>> >> > -        }
>> >> > -
>> >> > -        ServletResponse response = (ServletResponse)
>> >> > externalContext.getResponse();
>> >> > -        ServletRequest request = (ServletRequest)
>> >> > externalContext.getRequest();
>> >> > -
>> >> > -        Locale locale = view.getLocale();
>> >> > -        response.setLocale(locale);
>> >> > -        Config.set(request, Config.FMT_LOCALE,
>> >> > context.getViewRoot().getLocale());
>> >> > -
>> >> > -        String viewId = view.getViewId();
>> >> > -        ServletViewResponseWrapper wrappedResponse = new
>> >> > ServletViewResponseWrapper((HttpServletResponse) response);
>> >> > -
>> >> > -        externalContext.setResponse(wrappedResponse);
>> >> > -        try
>> >> > -        {
>> >> > -            externalContext.dispatch(viewId);
>> >> > -        }
>> >> > -        finally
>> >> > -        {
>> >> > -            externalContext.setResponse(response);
>> >> > -        }
>> >> > -
>> >> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>> >> > wrappedResponse.getStatus() > 299;
>> >> > -        if (errorResponse)
>> >> > -        {
>> >> > -            wrappedResponse.flushToWrappedResponse();
>> >> > -            return;
>> >> > -        }
>> >> > -
>> >> > -        //Skip this step if we are rendering an ajax request,
>> because
>> >> > no content outside
>> >> > -        //f:view tag should be output.
>> >> > -        if (!context.getPartialViewContext().isPartialRequest())
>> >> > -        {
>> >> > -            // store the wrapped response in the request, so it is
>> >> > thread-safe
>> >> > -            setAfterViewTagResponseWrapper(externalContext,
>> >> > wrappedResponse);
>> >> > -        }
>> >> > -    }
>> >> > -
>> >> > -    @Override
>> >> > -    protected void sendSourceNotFound(FacesContext context, String
>> >> > message)
>> >> > -    {
>> >> > -        HttpServletResponse response = (HttpServletResponse)
>> >> > context.getExternalContext().getResponse();
>> >> > -        try
>> >> > -        {
>> >> > -            context.responseComplete();
>> >> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>> >> > message);
>> >> > -        }
>> >> > -        catch (IOException ioe)
>> >> > -        {
>> >> > -            throw new FacesException(ioe);
>> >> > -        }
>> >> > -    }
>> >> > -
>> >> > -}
>> >> > +/*
>> >> > + * Licensed to the Apache Software Foundation (ASF) under one
>> >> > + * or more contributor license agreements.  See the NOTICE file
>> >> > + * distributed with this work for additional information
>> >> > + * regarding copyright ownership.  The ASF licenses this file
>> >> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> >> > + *
>> >> > + * Unless required by applicable law or agreed to in writing,
>> >> > + * software distributed under the License is distributed on an
>> >> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> >> > + * KIND, either express or implied.  See the License for the
>> >> > + * specific language governing permissions and limitations
>> >> > + * under the License.
>> >> > + */
>> >> > +package org.apache.myfaces.view.jsp;
>> >> > +
>> >> > +import java.io.IOException;
>> >> > +import java.util.Locale;
>> >> > +import java.util.logging.Level;
>> >> > +import java.util.logging.Logger;
>> >> > +
>> >> > +import javax.faces.FacesException;
>> >> > +import javax.faces.component.UIViewRoot;
>> >> > +import javax.faces.context.ExternalContext;
>> >> > +import javax.faces.context.FacesContext;
>> >> > +import javax.servlet.ServletRequest;
>> >> > +import javax.servlet.ServletResponse;
>> >> > +import javax.servlet.http.HttpServletResponse;
>> >> > +import javax.servlet.jsp.jstl.core.Config;
>> >> > +
>> >> > +import
>> org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>> >> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
>> >> > +import
>> >> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>> >> > +import org.apache.myfaces.util.ExternalContextUtils;
>> >> > +import
>> org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
>> >> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
>> >> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
>> >> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
>> >> > +
>> >> > +/**
>> >> > + * @author Simon Lessard (latest modification by $Author$)
>> >> > + * @version $Revision$ $Date$
>> >> > + *
>> >> > + * @since 2.0
>> >> > + */
>> >> > +public class JspViewDeclarationLanguage extends
>> >> > JspViewDeclarationLanguageBase
>> >> > +{
>> >> > +    //private static final Log log =
>> >> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>> >> > +    public static final Logger log =
>> >> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>> >> > +
>> >> > +    /**
>> >> > +     * Tags that are only available on facelets and not on JSP.
>> >> > +     * If a user uses one of these tags on a JSP, we will provide
>> >> > +     * a more informative error message than the standard one.
>> >> > +     */
>> >> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
>> >> > "event", "metadata"};
>> >> > +    public static final String[] FACELETS_ONLY_H_TAGS =
>> >> > {"outputScript", "outputStylesheet",
>> >> > +                                                         "head",
>> >> > "body", "button", "link"};
>> >> > +
>> >> > +    /**
>> >> > +     *
>> >> > +     */
>> >> > +    public JspViewDeclarationLanguage()
>> >> > +    {
>> >> > +        if (log.isLoggable(Level.FINEST))
>> >> > +            log.finest("New JspViewDeclarationLanguage instance
>> >> > created");
>> >> > +    }
>> >> > +
>> >> > +    /**
>> >> > +     * {@inheritDoc}
>> >> > +     */
>> >> > +    @Override
>> >> > +    public void buildView(FacesContext context, UIViewRoot view)
>> throws
>> >> > IOException
>> >> > +    {
>> >> > +        ExternalContext externalContext =
>> context.getExternalContext();
>> >> > +
>> >> > +        if (context.getPartialViewContext().isPartialRequest())
>> >> > +        {
>> >> > +            // try to get (or create) a ResponseSwitch and turn off
>> the
>> >> > output
>> >> > +            Object origResponse =
>> >> > context.getExternalContext().getResponse();
>> >> > +            ResponseSwitch responseSwitch =
>> >> > ExternalContextUtils.getResponseSwitch(origResponse);
>> >> > +            if (responseSwitch == null)
>> >> > +            {
>> >> > +                // no ResponseSwitch installed yet - create one
>> >> > +                responseSwitch =
>> >> > ExternalContextUtils.createResponseSwitch(origResponse);
>> >> > +                if (responseSwitch != null)
>> >> > +                {
>> >> > +                    // install the ResponseSwitch
>> >> > +
>> >> >  context.getExternalContext().setResponse(responseSwitch);
>> >> > +                }
>> >> > +            }
>> >> > +            if (responseSwitch != null)
>> >> > +            {
>> >> > +                responseSwitch.setEnabled(context, false);
>> >> > +            }
>> >> > +        }
>> >> > +
>> >> > +        ServletResponse response = (ServletResponse)
>> >> > externalContext.getResponse();
>> >> > +        ServletRequest request = (ServletRequest)
>> >> > externalContext.getRequest();
>> >> > +
>> >> > +        Locale locale = view.getLocale();
>> >> > +        response.setLocale(locale);
>> >> > +        Config.set(request, Config.FMT_LOCALE,
>> >> > context.getViewRoot().getLocale());
>> >> > +
>> >> > +        String viewId = view.getViewId();
>> >> > +        ServletViewResponseWrapper wrappedResponse = new
>> >> > ServletViewResponseWrapper((HttpServletResponse) response);
>> >> > +
>> >> > +        externalContext.setResponse(wrappedResponse);
>> >> > +        try
>> >> > +        {
>> >> > +            externalContext.dispatch(viewId);
>> >> > +        }
>> >> > +        catch (FacesException e)
>> >> > +        {
>> >> > +            // try to extract the most likely exceptions here
>> >> > +            // and provide a better error message for them
>> >> > +
>> >> > +            String message = e.getMessage();
>> >> > +
>> >> > +            // errors related to using facelets-only tags on a JSP
>> page
>> >> > +            if (message != null)
>> >> > +            {
>> >> > +                // does the message contain "f" (prefix f of tags)
>> >> > +                // or the related uri http://java.sun.com/jsf/core
>> >> > +                if (message.contains("\"f\"")
>> >> > +                        || message.contains("\"" +
>> >> > CoreLibrary.Namespace + "\""))
>> >> > +                {
>> >> > +                    // check facelets-only f tags
>> >> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
>> >> > +                    {
>> >> > +                        if (message.contains("\"" + tag + "\""))
>> >> > +                        {
>> >> > +                            String exceptionMessage = "The tag f:" +
>> >> > tag +
>> >> > +                                    " is only available on
>> facelets.";
>> >> > +                            throw new
>> FacesException(exceptionMessage,
>> >> > +                                    new
>> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> >> > +                        }
>> >> > +                    }
>> >> > +                }
>> >> > +                else if (message.contains("\"h\"")
>> >> > +                        || message.contains("\"" +
>> >> > HtmlLibrary.Namespace + "\""))
>> >> > +                {
>> >> > +                    // check facelets-only h tags
>> >> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
>> >> > +                    {
>> >> > +                        if (message.contains("\"" + tag + "\""))
>> >> > +                        {
>> >> > +                            String exceptionMessage = "The tag h:" +
>> >> > tag +
>> >> > +                                    " is only available on
>> facelets.";
>> >> > +                            throw new
>> FacesException(exceptionMessage,
>> >> > +                                    new
>> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> >> > +                        }
>> >> > +                    }
>> >> > +                }
>> >> > +                else
>> >> > +                {
>> >> > +                    // check facelets-only namespaces
>> >> > +                    String namespace = null;
>> >> > +                    if (message.contains(UILibrary.Namespace))
>> >> > +                    {
>> >> > +                        namespace = UILibrary.Namespace;
>> >> > +                    }
>> >> > +                    else if
>> >> > (message.contains(CompositeLibrary.NAMESPACE))
>> >> > +                    {
>> >> > +                        namespace = CompositeLibrary.NAMESPACE;
>> >> > +                    }
>> >> > +
>> >> > +                    if (namespace != null)
>> >> > +                    {
>> >> > +                        // the message contains a facelets-only
>> >> > namespace
>> >> > +                        String exceptionMessage = "All tags with
>> >> > namespace " +
>> >> > +                                namespace + " are only available on
>> >> > facelets.";
>> >> > +                        throw new FacesException(exceptionMessage,
>> >> > +                                new
>> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> >> > +                    }
>> >> > +                }
>> >> > +            }
>> >> > +
>> >> > +            // no rule applied to this Exception - rethrow it
>> >> > +            throw e;
>> >> > +        }
>> >> > +        finally
>> >> > +        {
>> >> > +            externalContext.setResponse(response);
>> >> > +        }
>> >> > +
>> >> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>> >> > wrappedResponse.getStatus() > 299;
>> >> > +        if (errorResponse)
>> >> > +        {
>> >> > +            wrappedResponse.flushToWrappedResponse();
>> >> > +            return;
>> >> > +        }
>> >> > +
>> >> > +        //Skip this step if we are rendering an ajax request,
>> because
>> >> > no content outside
>> >> > +        //f:view tag should be output.
>> >> > +        if (!context.getPartialViewContext().isPartialRequest())
>> >> > +        {
>> >> > +            // store the wrapped response in the request, so it is
>> >> > thread-safe
>> >> > +            setAfterViewTagResponseWrapper(externalContext,
>> >> > wrappedResponse);
>> >> > +        }
>> >> > +    }
>> >> > +
>> >> > +    @Override
>> >> > +    protected void sendSourceNotFound(FacesContext context, String
>> >> > message)
>> >> > +    {
>> >> > +        HttpServletResponse response = (HttpServletResponse)
>> >> > context.getExternalContext().getResponse();
>> >> > +        try
>> >> > +        {
>> >> > +            context.responseComplete();
>> >> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>> >> > message);
>> >> > +        }
>> >> > +        catch (IOException ioe)
>> >> > +        {
>> >> > +            throw new FacesException(ioe);
>> >> > +        }
>> >> > +    }
>> >> > +
>> >> > +}
>> >> >
>> >> > Propchange:
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >> >
>> >> >
>> ------------------------------------------------------------------------------
>> >> >    svn:eol-style = native
>> >> >
>> >> > Propchange:
>> >> >
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >> >
>> >> >
>> ------------------------------------------------------------------------------
>> >> >    svn:keywords = Date Author Id Revision HeadURL
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Matthias Wessendorf
>> >>
>> >> blog: http://matthiaswessendorf.wordpress.com/
>> >> sessions: http://www.slideshare.net/mwessendorf
>> >> twitter: http://twitter.com/mwessendorf
>> >
>> >
>> >
>> > --
>> > Jakob Korherr
>> >
>> > blog: http://www.jakobk.com
>> > twitter: http://twitter.com/jakobkorherr
>> > work: http://www.irian.at
>> >
>> >
>> >
>> > --
>> > Jakob Korherr
>> >
>> > blog: http://www.jakobk.com
>> > twitter: http://twitter.com/jakobkorherr
>> > work: http://www.irian.at
>> >
>>
>>
>>
>> --
>> Matthias Wessendorf
>>
>> blog: http://matthiaswessendorf.wordpress.com/
>> sessions: http://www.slideshare.net/mwessendorf
>> twitter: http://twitter.com/mwessendorf
>>
>
>
>
> --
> Jakob Korherr
>
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at
>

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Jakob Korherr <ja...@gmail.com>.
Hi,

I have no idea why this mail was lost, but fact is that it wasn't even sent,
because it's not in the mail archive.. However Gmail displayed it as "sent
correctly" and thus I was kinda annoyed - you understand...

FYI: I just added some JavaDoc about it in r934200, so this should not
happen again (hopefully).

Regards,
Jakob


2010/4/14 Matthias Wessendorf <ma...@apache.org>

> ah! :-)
>
> no, this mail is not visible , or it was lost in Gmail (at least for me).
>
> Ok, so let's "revert" Leo's commit and add some JavaDoc on why it directly
> extends Exception to avoid similar "refactorings" in the future.
>
> Thanks,
> Matthias
>
> On Wed, Apr 14, 2010 at 10:48 PM, Jakob Korherr <ja...@gmail.com>
> wrote:
> > Forwarded my original mail to this topic since it obviously went wrong
> the
> > first time.
> >
> > ---------- Forwarded message ----------
> > From: Jakob Korherr <ja...@apache.org>
> > Date: 2010/4/14
> > Subject: Re: svn commit: r934048 - in
> > /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp:
> > FaceletsOnlyException.java JspViewDeclarationLanguage.java
> > To: MyFaces Development <de...@myfaces.apache.org>
> >
> >
> > No I cannot, because then its message won't be displayed by the
> > ExceptionHandler, because the ExceptionHandler "extracts" the Exception
> > until it finds the first non-FacesException and then it handles this one.
> >
> > Thus if I would make it a FacesException, the message will be lost. This
> was
> > the reason I created FaceletsOnlyException in the first place...
> >
> > Regards,
> > Jakob
> >
> > 2010/4/14 Matthias Wessendorf <ma...@apache.org>
> >>
> >> public class FaceletsOnlyException extends Exception
> >>
> >>
> >> ==> can you make that extending FacesException ?
> >>
> >> -Matthias
> >>
> >> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
> >> > Author: jakobk
> >> > Date: Wed Apr 14 17:48:28 2010
> >> > New Revision: 934048
> >> >
> >> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
> >> > Log:
> >> > MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X)
> >> > pages
> >> >
> >> > Added:
> >> >
> >> >
>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >> >   (with props)
> >> > Modified:
> >> >
> >> >
>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >> >   (contents, props changed)
> >> >
> >> > Added:
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >> > URL:
> >> >
> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
> >> >
> >> >
> ==============================================================================
> >> > ---
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >> > (added)
> >> > +++
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >> > Wed Apr 14 17:48:28 2010
> >> > @@ -0,0 +1,40 @@
> >> > +/*
> >> > + * Licensed to the Apache Software Foundation (ASF) under one
> >> > + * or more contributor license agreements.  See the NOTICE file
> >> > + * distributed with this work for additional information
> >> > + * regarding copyright ownership.  The ASF licenses this file
> >> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> >> > + *
> >> > + * Unless required by applicable law or agreed to in writing,
> >> > + * software distributed under the License is distributed on an
> >> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> >> > + * KIND, either express or implied.  See the License for the
> >> > + * specific language governing permissions and limitations
> >> > + * under the License.
> >> > + */
> >> > +package org.apache.myfaces.view.jsp;
> >> > +
> >> > +/**
> >> > + * An Exception that indicates that the user uses a
> >> > + * facelets-only feature on a JSP.
> >> > + *
> >> > + * @author Jakob Korherr (latest modification by $Author$)
> >> > + * @version $Revision$ $Date$
> >> > + *
> >> > + * @since 2.0
> >> > + */
> >> > +public class FaceletsOnlyException extends Exception
> >> > +{
> >> > +
> >> > +    private static final long serialVersionUID =
> 4268633427284543647L;
> >> > +
> >> > +    public FaceletsOnlyException(String message, Throwable cause)
> >> > +    {
> >> > +        super(message, cause);
> >> > +    }
> >> > +
> >> > +}
> >> >
> >> > Propchange:
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >> >
> >> >
> ------------------------------------------------------------------------------
> >> >    svn:eol-style = native
> >> >
> >> > Propchange:
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >> >
> >> >
> ------------------------------------------------------------------------------
> >> >    svn:keywords = Date Author Id Revision HeadURL
> >> >
> >> > Propchange:
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >> >
> >> >
> ------------------------------------------------------------------------------
> >> >    svn:mime-type = text/plain
> >> >
> >> > Modified:
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >> > URL:
> >> >
> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
> >> >
> >> >
> ==============================================================================
> >> > ---
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >> > (original)
> >> > +++
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >> > Wed Apr 14 17:48:28 2010
> >> > @@ -1,139 +1,222 @@
> >> > -/*
> >> > - * Licensed to the Apache Software Foundation (ASF) under one
> >> > - * or more contributor license agreements.  See the NOTICE file
> >> > - * distributed with this work for additional information
> >> > - * regarding copyright ownership.  The ASF licenses this file
> >> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> >> > - *
> >> > - * Unless required by applicable law or agreed to in writing,
> >> > - * software distributed under the License is distributed on an
> >> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> >> > - * KIND, either express or implied.  See the License for the
> >> > - * specific language governing permissions and limitations
> >> > - * under the License.
> >> > - */
> >> > -package org.apache.myfaces.view.jsp;
> >> > -
> >> > -import java.io.IOException;
> >> > -import java.util.Locale;
> >> > -import java.util.logging.Level;
> >> > -import java.util.logging.Logger;
> >> > -
> >> > -import javax.faces.FacesException;
> >> > -import javax.faces.component.UIViewRoot;
> >> > -import javax.faces.context.ExternalContext;
> >> > -import javax.faces.context.FacesContext;
> >> > -import javax.servlet.ServletRequest;
> >> > -import javax.servlet.ServletResponse;
> >> > -import javax.servlet.http.HttpServletResponse;
> >> > -import javax.servlet.jsp.jstl.core.Config;
> >> > -
> >> > -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> >> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
> >> > -import
> >> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> >> > -import org.apache.myfaces.util.ExternalContextUtils;
> >> > -
> >> > -/**
> >> > - * @author Simon Lessard (latest modification by $Author: slessard $)
> >> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400
> (mer.,
> >> > 17 sept. 2008) $
> >> > - *
> >> > - * @since 2.0
> >> > - */
> >> > -public class JspViewDeclarationLanguage extends
> >> > JspViewDeclarationLanguageBase
> >> > -{
> >> > -    //private static final Log log =
> >> > LogFactory.getLog(JspViewDeclarationLanguage.class);
> >> > -    public static final Logger log =
> >> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> >> > -    /**
> >> > -     *
> >> > -     */
> >> > -    public JspViewDeclarationLanguage()
> >> > -    {
> >> > -        if (log.isLoggable(Level.FINEST))
> >> > -            log.finest("New JspViewDeclarationLanguage instance
> >> > created");
> >> > -    }
> >> > -
> >> > -    /**
> >> > -     * {@inheritDoc}
> >> > -     */
> >> > -    @Override
> >> > -    public void buildView(FacesContext context, UIViewRoot view)
> throws
> >> > IOException
> >> > -    {
> >> > -        ExternalContext externalContext =
> context.getExternalContext();
> >> > -
> >> > -        if (context.getPartialViewContext().isPartialRequest())
> >> > -        {
> >> > -            // try to get (or create) a ResponseSwitch and turn off
> the
> >> > output
> >> > -            Object origResponse =
> >> > context.getExternalContext().getResponse();
> >> > -            ResponseSwitch responseSwitch =
> >> > ExternalContextUtils.getResponseSwitch(origResponse);
> >> > -            if (responseSwitch == null)
> >> > -            {
> >> > -                // no ResponseSwitch installed yet - create one
> >> > -                responseSwitch =
> >> > ExternalContextUtils.createResponseSwitch(origResponse);
> >> > -                if (responseSwitch != null)
> >> > -                {
> >> > -                    // install the ResponseSwitch
> >> > -
> >> >  context.getExternalContext().setResponse(responseSwitch);
> >> > -                }
> >> > -            }
> >> > -            if (responseSwitch != null)
> >> > -            {
> >> > -                responseSwitch.setEnabled(context, false);
> >> > -            }
> >> > -        }
> >> > -
> >> > -        ServletResponse response = (ServletResponse)
> >> > externalContext.getResponse();
> >> > -        ServletRequest request = (ServletRequest)
> >> > externalContext.getRequest();
> >> > -
> >> > -        Locale locale = view.getLocale();
> >> > -        response.setLocale(locale);
> >> > -        Config.set(request, Config.FMT_LOCALE,
> >> > context.getViewRoot().getLocale());
> >> > -
> >> > -        String viewId = view.getViewId();
> >> > -        ServletViewResponseWrapper wrappedResponse = new
> >> > ServletViewResponseWrapper((HttpServletResponse) response);
> >> > -
> >> > -        externalContext.setResponse(wrappedResponse);
> >> > -        try
> >> > -        {
> >> > -            externalContext.dispatch(viewId);
> >> > -        }
> >> > -        finally
> >> > -        {
> >> > -            externalContext.setResponse(response);
> >> > -        }
> >> > -
> >> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
> >> > wrappedResponse.getStatus() > 299;
> >> > -        if (errorResponse)
> >> > -        {
> >> > -            wrappedResponse.flushToWrappedResponse();
> >> > -            return;
> >> > -        }
> >> > -
> >> > -        //Skip this step if we are rendering an ajax request, because
> >> > no content outside
> >> > -        //f:view tag should be output.
> >> > -        if (!context.getPartialViewContext().isPartialRequest())
> >> > -        {
> >> > -            // store the wrapped response in the request, so it is
> >> > thread-safe
> >> > -            setAfterViewTagResponseWrapper(externalContext,
> >> > wrappedResponse);
> >> > -        }
> >> > -    }
> >> > -
> >> > -    @Override
> >> > -    protected void sendSourceNotFound(FacesContext context, String
> >> > message)
> >> > -    {
> >> > -        HttpServletResponse response = (HttpServletResponse)
> >> > context.getExternalContext().getResponse();
> >> > -        try
> >> > -        {
> >> > -            context.responseComplete();
> >> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> >> > message);
> >> > -        }
> >> > -        catch (IOException ioe)
> >> > -        {
> >> > -            throw new FacesException(ioe);
> >> > -        }
> >> > -    }
> >> > -
> >> > -}
> >> > +/*
> >> > + * Licensed to the Apache Software Foundation (ASF) under one
> >> > + * or more contributor license agreements.  See the NOTICE file
> >> > + * distributed with this work for additional information
> >> > + * regarding copyright ownership.  The ASF licenses this file
> >> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> >> > + *
> >> > + * Unless required by applicable law or agreed to in writing,
> >> > + * software distributed under the License is distributed on an
> >> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> >> > + * KIND, either express or implied.  See the License for the
> >> > + * specific language governing permissions and limitations
> >> > + * under the License.
> >> > + */
> >> > +package org.apache.myfaces.view.jsp;
> >> > +
> >> > +import java.io.IOException;
> >> > +import java.util.Locale;
> >> > +import java.util.logging.Level;
> >> > +import java.util.logging.Logger;
> >> > +
> >> > +import javax.faces.FacesException;
> >> > +import javax.faces.component.UIViewRoot;
> >> > +import javax.faces.context.ExternalContext;
> >> > +import javax.faces.context.FacesContext;
> >> > +import javax.servlet.ServletRequest;
> >> > +import javax.servlet.ServletResponse;
> >> > +import javax.servlet.http.HttpServletResponse;
> >> > +import javax.servlet.jsp.jstl.core.Config;
> >> > +
> >> > +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> >> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
> >> > +import
> >> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> >> > +import org.apache.myfaces.util.ExternalContextUtils;
> >> > +import
> org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
> >> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
> >> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
> >> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
> >> > +
> >> > +/**
> >> > + * @author Simon Lessard (latest modification by $Author$)
> >> > + * @version $Revision$ $Date$
> >> > + *
> >> > + * @since 2.0
> >> > + */
> >> > +public class JspViewDeclarationLanguage extends
> >> > JspViewDeclarationLanguageBase
> >> > +{
> >> > +    //private static final Log log =
> >> > LogFactory.getLog(JspViewDeclarationLanguage.class);
> >> > +    public static final Logger log =
> >> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> >> > +
> >> > +    /**
> >> > +     * Tags that are only available on facelets and not on JSP.
> >> > +     * If a user uses one of these tags on a JSP, we will provide
> >> > +     * a more informative error message than the standard one.
> >> > +     */
> >> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
> >> > "event", "metadata"};
> >> > +    public static final String[] FACELETS_ONLY_H_TAGS =
> >> > {"outputScript", "outputStylesheet",
> >> > +                                                         "head",
> >> > "body", "button", "link"};
> >> > +
> >> > +    /**
> >> > +     *
> >> > +     */
> >> > +    public JspViewDeclarationLanguage()
> >> > +    {
> >> > +        if (log.isLoggable(Level.FINEST))
> >> > +            log.finest("New JspViewDeclarationLanguage instance
> >> > created");
> >> > +    }
> >> > +
> >> > +    /**
> >> > +     * {@inheritDoc}
> >> > +     */
> >> > +    @Override
> >> > +    public void buildView(FacesContext context, UIViewRoot view)
> throws
> >> > IOException
> >> > +    {
> >> > +        ExternalContext externalContext =
> context.getExternalContext();
> >> > +
> >> > +        if (context.getPartialViewContext().isPartialRequest())
> >> > +        {
> >> > +            // try to get (or create) a ResponseSwitch and turn off
> the
> >> > output
> >> > +            Object origResponse =
> >> > context.getExternalContext().getResponse();
> >> > +            ResponseSwitch responseSwitch =
> >> > ExternalContextUtils.getResponseSwitch(origResponse);
> >> > +            if (responseSwitch == null)
> >> > +            {
> >> > +                // no ResponseSwitch installed yet - create one
> >> > +                responseSwitch =
> >> > ExternalContextUtils.createResponseSwitch(origResponse);
> >> > +                if (responseSwitch != null)
> >> > +                {
> >> > +                    // install the ResponseSwitch
> >> > +
> >> >  context.getExternalContext().setResponse(responseSwitch);
> >> > +                }
> >> > +            }
> >> > +            if (responseSwitch != null)
> >> > +            {
> >> > +                responseSwitch.setEnabled(context, false);
> >> > +            }
> >> > +        }
> >> > +
> >> > +        ServletResponse response = (ServletResponse)
> >> > externalContext.getResponse();
> >> > +        ServletRequest request = (ServletRequest)
> >> > externalContext.getRequest();
> >> > +
> >> > +        Locale locale = view.getLocale();
> >> > +        response.setLocale(locale);
> >> > +        Config.set(request, Config.FMT_LOCALE,
> >> > context.getViewRoot().getLocale());
> >> > +
> >> > +        String viewId = view.getViewId();
> >> > +        ServletViewResponseWrapper wrappedResponse = new
> >> > ServletViewResponseWrapper((HttpServletResponse) response);
> >> > +
> >> > +        externalContext.setResponse(wrappedResponse);
> >> > +        try
> >> > +        {
> >> > +            externalContext.dispatch(viewId);
> >> > +        }
> >> > +        catch (FacesException e)
> >> > +        {
> >> > +            // try to extract the most likely exceptions here
> >> > +            // and provide a better error message for them
> >> > +
> >> > +            String message = e.getMessage();
> >> > +
> >> > +            // errors related to using facelets-only tags on a JSP
> page
> >> > +            if (message != null)
> >> > +            {
> >> > +                // does the message contain "f" (prefix f of tags)
> >> > +                // or the related uri http://java.sun.com/jsf/core
> >> > +                if (message.contains("\"f\"")
> >> > +                        || message.contains("\"" +
> >> > CoreLibrary.Namespace + "\""))
> >> > +                {
> >> > +                    // check facelets-only f tags
> >> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
> >> > +                    {
> >> > +                        if (message.contains("\"" + tag + "\""))
> >> > +                        {
> >> > +                            String exceptionMessage = "The tag f:" +
> >> > tag +
> >> > +                                    " is only available on
> facelets.";
> >> > +                            throw new
> FacesException(exceptionMessage,
> >> > +                                    new
> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
> >> > +                        }
> >> > +                    }
> >> > +                }
> >> > +                else if (message.contains("\"h\"")
> >> > +                        || message.contains("\"" +
> >> > HtmlLibrary.Namespace + "\""))
> >> > +                {
> >> > +                    // check facelets-only h tags
> >> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
> >> > +                    {
> >> > +                        if (message.contains("\"" + tag + "\""))
> >> > +                        {
> >> > +                            String exceptionMessage = "The tag h:" +
> >> > tag +
> >> > +                                    " is only available on
> facelets.";
> >> > +                            throw new
> FacesException(exceptionMessage,
> >> > +                                    new
> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
> >> > +                        }
> >> > +                    }
> >> > +                }
> >> > +                else
> >> > +                {
> >> > +                    // check facelets-only namespaces
> >> > +                    String namespace = null;
> >> > +                    if (message.contains(UILibrary.Namespace))
> >> > +                    {
> >> > +                        namespace = UILibrary.Namespace;
> >> > +                    }
> >> > +                    else if
> >> > (message.contains(CompositeLibrary.NAMESPACE))
> >> > +                    {
> >> > +                        namespace = CompositeLibrary.NAMESPACE;
> >> > +                    }
> >> > +
> >> > +                    if (namespace != null)
> >> > +                    {
> >> > +                        // the message contains a facelets-only
> >> > namespace
> >> > +                        String exceptionMessage = "All tags with
> >> > namespace " +
> >> > +                                namespace + " are only available on
> >> > facelets.";
> >> > +                        throw new FacesException(exceptionMessage,
> >> > +                                new
> >> > FaceletsOnlyException(exceptionMessage, e.getCause()));
> >> > +                    }
> >> > +                }
> >> > +            }
> >> > +
> >> > +            // no rule applied to this Exception - rethrow it
> >> > +            throw e;
> >> > +        }
> >> > +        finally
> >> > +        {
> >> > +            externalContext.setResponse(response);
> >> > +        }
> >> > +
> >> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
> >> > wrappedResponse.getStatus() > 299;
> >> > +        if (errorResponse)
> >> > +        {
> >> > +            wrappedResponse.flushToWrappedResponse();
> >> > +            return;
> >> > +        }
> >> > +
> >> > +        //Skip this step if we are rendering an ajax request, because
> >> > no content outside
> >> > +        //f:view tag should be output.
> >> > +        if (!context.getPartialViewContext().isPartialRequest())
> >> > +        {
> >> > +            // store the wrapped response in the request, so it is
> >> > thread-safe
> >> > +            setAfterViewTagResponseWrapper(externalContext,
> >> > wrappedResponse);
> >> > +        }
> >> > +    }
> >> > +
> >> > +    @Override
> >> > +    protected void sendSourceNotFound(FacesContext context, String
> >> > message)
> >> > +    {
> >> > +        HttpServletResponse response = (HttpServletResponse)
> >> > context.getExternalContext().getResponse();
> >> > +        try
> >> > +        {
> >> > +            context.responseComplete();
> >> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> >> > message);
> >> > +        }
> >> > +        catch (IOException ioe)
> >> > +        {
> >> > +            throw new FacesException(ioe);
> >> > +        }
> >> > +    }
> >> > +
> >> > +}
> >> >
> >> > Propchange:
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >> >
> >> >
> ------------------------------------------------------------------------------
> >> >    svn:eol-style = native
> >> >
> >> > Propchange:
> >> >
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >> >
> >> >
> ------------------------------------------------------------------------------
> >> >    svn:keywords = Date Author Id Revision HeadURL
> >> >
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> Matthias Wessendorf
> >>
> >> blog: http://matthiaswessendorf.wordpress.com/
> >> sessions: http://www.slideshare.net/mwessendorf
> >> twitter: http://twitter.com/mwessendorf
> >
> >
> >
> > --
> > Jakob Korherr
> >
> > blog: http://www.jakobk.com
> > twitter: http://twitter.com/jakobkorherr
> > work: http://www.irian.at
> >
> >
> >
> > --
> > Jakob Korherr
> >
> > blog: http://www.jakobk.com
> > twitter: http://twitter.com/jakobkorherr
> > work: http://www.irian.at
> >
>
>
>
> --
> Matthias Wessendorf
>
> blog: http://matthiaswessendorf.wordpress.com/
> sessions: http://www.slideshare.net/mwessendorf
> twitter: http://twitter.com/mwessendorf
>



-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Matthias Wessendorf <ma...@apache.org>.
ah! :-)

no, this mail is not visible , or it was lost in Gmail (at least for me).

Ok, so let's "revert" Leo's commit and add some JavaDoc on why it directly
extends Exception to avoid similar "refactorings" in the future.

Thanks,
Matthias

On Wed, Apr 14, 2010 at 10:48 PM, Jakob Korherr <ja...@gmail.com> wrote:
> Forwarded my original mail to this topic since it obviously went wrong the
> first time.
>
> ---------- Forwarded message ----------
> From: Jakob Korherr <ja...@apache.org>
> Date: 2010/4/14
> Subject: Re: svn commit: r934048 - in
> /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp:
> FaceletsOnlyException.java JspViewDeclarationLanguage.java
> To: MyFaces Development <de...@myfaces.apache.org>
>
>
> No I cannot, because then its message won't be displayed by the
> ExceptionHandler, because the ExceptionHandler "extracts" the Exception
> until it finds the first non-FacesException and then it handles this one.
>
> Thus if I would make it a FacesException, the message will be lost. This was
> the reason I created FaceletsOnlyException in the first place...
>
> Regards,
> Jakob
>
> 2010/4/14 Matthias Wessendorf <ma...@apache.org>
>>
>> public class FaceletsOnlyException extends Exception
>>
>>
>> ==> can you make that extending FacesException ?
>>
>> -Matthias
>>
>> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
>> > Author: jakobk
>> > Date: Wed Apr 14 17:48:28 2010
>> > New Revision: 934048
>> >
>> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
>> > Log:
>> > MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X)
>> > pages
>> >
>> > Added:
>> >
>> >  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >   (with props)
>> > Modified:
>> >
>> >  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >   (contents, props changed)
>> >
>> > Added:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> > URL:
>> > http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
>> >
>> > ==============================================================================
>> > ---
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> > (added)
>> > +++
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> > Wed Apr 14 17:48:28 2010
>> > @@ -0,0 +1,40 @@
>> > +/*
>> > + * Licensed to the Apache Software Foundation (ASF) under one
>> > + * or more contributor license agreements.  See the NOTICE file
>> > + * distributed with this work for additional information
>> > + * regarding copyright ownership.  The ASF licenses this file
>> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > + *
>> > + * Unless required by applicable law or agreed to in writing,
>> > + * software distributed under the License is distributed on an
>> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > + * KIND, either express or implied.  See the License for the
>> > + * specific language governing permissions and limitations
>> > + * under the License.
>> > + */
>> > +package org.apache.myfaces.view.jsp;
>> > +
>> > +/**
>> > + * An Exception that indicates that the user uses a
>> > + * facelets-only feature on a JSP.
>> > + *
>> > + * @author Jakob Korherr (latest modification by $Author$)
>> > + * @version $Revision$ $Date$
>> > + *
>> > + * @since 2.0
>> > + */
>> > +public class FaceletsOnlyException extends Exception
>> > +{
>> > +
>> > +    private static final long serialVersionUID = 4268633427284543647L;
>> > +
>> > +    public FaceletsOnlyException(String message, Throwable cause)
>> > +    {
>> > +        super(message, cause);
>> > +    }
>> > +
>> > +}
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:eol-style = native
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:keywords = Date Author Id Revision HeadURL
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:mime-type = text/plain
>> >
>> > Modified:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> > URL:
>> > http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
>> >
>> > ==============================================================================
>> > ---
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> > (original)
>> > +++
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> > Wed Apr 14 17:48:28 2010
>> > @@ -1,139 +1,222 @@
>> > -/*
>> > - * Licensed to the Apache Software Foundation (ASF) under one
>> > - * or more contributor license agreements.  See the NOTICE file
>> > - * distributed with this work for additional information
>> > - * regarding copyright ownership.  The ASF licenses this file
>> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > - *
>> > - * Unless required by applicable law or agreed to in writing,
>> > - * software distributed under the License is distributed on an
>> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > - * KIND, either express or implied.  See the License for the
>> > - * specific language governing permissions and limitations
>> > - * under the License.
>> > - */
>> > -package org.apache.myfaces.view.jsp;
>> > -
>> > -import java.io.IOException;
>> > -import java.util.Locale;
>> > -import java.util.logging.Level;
>> > -import java.util.logging.Logger;
>> > -
>> > -import javax.faces.FacesException;
>> > -import javax.faces.component.UIViewRoot;
>> > -import javax.faces.context.ExternalContext;
>> > -import javax.faces.context.FacesContext;
>> > -import javax.servlet.ServletRequest;
>> > -import javax.servlet.ServletResponse;
>> > -import javax.servlet.http.HttpServletResponse;
>> > -import javax.servlet.jsp.jstl.core.Config;
>> > -
>> > -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
>> > -import
>> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>> > -import org.apache.myfaces.util.ExternalContextUtils;
>> > -
>> > -/**
>> > - * @author Simon Lessard (latest modification by $Author: slessard $)
>> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400 (mer.,
>> > 17 sept. 2008) $
>> > - *
>> > - * @since 2.0
>> > - */
>> > -public class JspViewDeclarationLanguage extends
>> > JspViewDeclarationLanguageBase
>> > -{
>> > -    //private static final Log log =
>> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>> > -    public static final Logger log =
>> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>> > -    /**
>> > -     *
>> > -     */
>> > -    public JspViewDeclarationLanguage()
>> > -    {
>> > -        if (log.isLoggable(Level.FINEST))
>> > -            log.finest("New JspViewDeclarationLanguage instance
>> > created");
>> > -    }
>> > -
>> > -    /**
>> > -     * {@inheritDoc}
>> > -     */
>> > -    @Override
>> > -    public void buildView(FacesContext context, UIViewRoot view) throws
>> > IOException
>> > -    {
>> > -        ExternalContext externalContext = context.getExternalContext();
>> > -
>> > -        if (context.getPartialViewContext().isPartialRequest())
>> > -        {
>> > -            // try to get (or create) a ResponseSwitch and turn off the
>> > output
>> > -            Object origResponse =
>> > context.getExternalContext().getResponse();
>> > -            ResponseSwitch responseSwitch =
>> > ExternalContextUtils.getResponseSwitch(origResponse);
>> > -            if (responseSwitch == null)
>> > -            {
>> > -                // no ResponseSwitch installed yet - create one
>> > -                responseSwitch =
>> > ExternalContextUtils.createResponseSwitch(origResponse);
>> > -                if (responseSwitch != null)
>> > -                {
>> > -                    // install the ResponseSwitch
>> > -
>> >  context.getExternalContext().setResponse(responseSwitch);
>> > -                }
>> > -            }
>> > -            if (responseSwitch != null)
>> > -            {
>> > -                responseSwitch.setEnabled(context, false);
>> > -            }
>> > -        }
>> > -
>> > -        ServletResponse response = (ServletResponse)
>> > externalContext.getResponse();
>> > -        ServletRequest request = (ServletRequest)
>> > externalContext.getRequest();
>> > -
>> > -        Locale locale = view.getLocale();
>> > -        response.setLocale(locale);
>> > -        Config.set(request, Config.FMT_LOCALE,
>> > context.getViewRoot().getLocale());
>> > -
>> > -        String viewId = view.getViewId();
>> > -        ServletViewResponseWrapper wrappedResponse = new
>> > ServletViewResponseWrapper((HttpServletResponse) response);
>> > -
>> > -        externalContext.setResponse(wrappedResponse);
>> > -        try
>> > -        {
>> > -            externalContext.dispatch(viewId);
>> > -        }
>> > -        finally
>> > -        {
>> > -            externalContext.setResponse(response);
>> > -        }
>> > -
>> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>> > wrappedResponse.getStatus() > 299;
>> > -        if (errorResponse)
>> > -        {
>> > -            wrappedResponse.flushToWrappedResponse();
>> > -            return;
>> > -        }
>> > -
>> > -        //Skip this step if we are rendering an ajax request, because
>> > no content outside
>> > -        //f:view tag should be output.
>> > -        if (!context.getPartialViewContext().isPartialRequest())
>> > -        {
>> > -            // store the wrapped response in the request, so it is
>> > thread-safe
>> > -            setAfterViewTagResponseWrapper(externalContext,
>> > wrappedResponse);
>> > -        }
>> > -    }
>> > -
>> > -    @Override
>> > -    protected void sendSourceNotFound(FacesContext context, String
>> > message)
>> > -    {
>> > -        HttpServletResponse response = (HttpServletResponse)
>> > context.getExternalContext().getResponse();
>> > -        try
>> > -        {
>> > -            context.responseComplete();
>> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>> > message);
>> > -        }
>> > -        catch (IOException ioe)
>> > -        {
>> > -            throw new FacesException(ioe);
>> > -        }
>> > -    }
>> > -
>> > -}
>> > +/*
>> > + * Licensed to the Apache Software Foundation (ASF) under one
>> > + * or more contributor license agreements.  See the NOTICE file
>> > + * distributed with this work for additional information
>> > + * regarding copyright ownership.  The ASF licenses this file
>> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > + *
>> > + * Unless required by applicable law or agreed to in writing,
>> > + * software distributed under the License is distributed on an
>> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > + * KIND, either express or implied.  See the License for the
>> > + * specific language governing permissions and limitations
>> > + * under the License.
>> > + */
>> > +package org.apache.myfaces.view.jsp;
>> > +
>> > +import java.io.IOException;
>> > +import java.util.Locale;
>> > +import java.util.logging.Level;
>> > +import java.util.logging.Logger;
>> > +
>> > +import javax.faces.FacesException;
>> > +import javax.faces.component.UIViewRoot;
>> > +import javax.faces.context.ExternalContext;
>> > +import javax.faces.context.FacesContext;
>> > +import javax.servlet.ServletRequest;
>> > +import javax.servlet.ServletResponse;
>> > +import javax.servlet.http.HttpServletResponse;
>> > +import javax.servlet.jsp.jstl.core.Config;
>> > +
>> > +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
>> > +import
>> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>> > +import org.apache.myfaces.util.ExternalContextUtils;
>> > +import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
>> > +
>> > +/**
>> > + * @author Simon Lessard (latest modification by $Author$)
>> > + * @version $Revision$ $Date$
>> > + *
>> > + * @since 2.0
>> > + */
>> > +public class JspViewDeclarationLanguage extends
>> > JspViewDeclarationLanguageBase
>> > +{
>> > +    //private static final Log log =
>> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>> > +    public static final Logger log =
>> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>> > +
>> > +    /**
>> > +     * Tags that are only available on facelets and not on JSP.
>> > +     * If a user uses one of these tags on a JSP, we will provide
>> > +     * a more informative error message than the standard one.
>> > +     */
>> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
>> > "event", "metadata"};
>> > +    public static final String[] FACELETS_ONLY_H_TAGS =
>> > {"outputScript", "outputStylesheet",
>> > +                                                         "head",
>> > "body", "button", "link"};
>> > +
>> > +    /**
>> > +     *
>> > +     */
>> > +    public JspViewDeclarationLanguage()
>> > +    {
>> > +        if (log.isLoggable(Level.FINEST))
>> > +            log.finest("New JspViewDeclarationLanguage instance
>> > created");
>> > +    }
>> > +
>> > +    /**
>> > +     * {@inheritDoc}
>> > +     */
>> > +    @Override
>> > +    public void buildView(FacesContext context, UIViewRoot view) throws
>> > IOException
>> > +    {
>> > +        ExternalContext externalContext = context.getExternalContext();
>> > +
>> > +        if (context.getPartialViewContext().isPartialRequest())
>> > +        {
>> > +            // try to get (or create) a ResponseSwitch and turn off the
>> > output
>> > +            Object origResponse =
>> > context.getExternalContext().getResponse();
>> > +            ResponseSwitch responseSwitch =
>> > ExternalContextUtils.getResponseSwitch(origResponse);
>> > +            if (responseSwitch == null)
>> > +            {
>> > +                // no ResponseSwitch installed yet - create one
>> > +                responseSwitch =
>> > ExternalContextUtils.createResponseSwitch(origResponse);
>> > +                if (responseSwitch != null)
>> > +                {
>> > +                    // install the ResponseSwitch
>> > +
>> >  context.getExternalContext().setResponse(responseSwitch);
>> > +                }
>> > +            }
>> > +            if (responseSwitch != null)
>> > +            {
>> > +                responseSwitch.setEnabled(context, false);
>> > +            }
>> > +        }
>> > +
>> > +        ServletResponse response = (ServletResponse)
>> > externalContext.getResponse();
>> > +        ServletRequest request = (ServletRequest)
>> > externalContext.getRequest();
>> > +
>> > +        Locale locale = view.getLocale();
>> > +        response.setLocale(locale);
>> > +        Config.set(request, Config.FMT_LOCALE,
>> > context.getViewRoot().getLocale());
>> > +
>> > +        String viewId = view.getViewId();
>> > +        ServletViewResponseWrapper wrappedResponse = new
>> > ServletViewResponseWrapper((HttpServletResponse) response);
>> > +
>> > +        externalContext.setResponse(wrappedResponse);
>> > +        try
>> > +        {
>> > +            externalContext.dispatch(viewId);
>> > +        }
>> > +        catch (FacesException e)
>> > +        {
>> > +            // try to extract the most likely exceptions here
>> > +            // and provide a better error message for them
>> > +
>> > +            String message = e.getMessage();
>> > +
>> > +            // errors related to using facelets-only tags on a JSP page
>> > +            if (message != null)
>> > +            {
>> > +                // does the message contain "f" (prefix f of tags)
>> > +                // or the related uri http://java.sun.com/jsf/core
>> > +                if (message.contains("\"f\"")
>> > +                        || message.contains("\"" +
>> > CoreLibrary.Namespace + "\""))
>> > +                {
>> > +                    // check facelets-only f tags
>> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
>> > +                    {
>> > +                        if (message.contains("\"" + tag + "\""))
>> > +                        {
>> > +                            String exceptionMessage = "The tag f:" +
>> > tag +
>> > +                                    " is only available on facelets.";
>> > +                            throw new FacesException(exceptionMessage,
>> > +                                    new
>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                        }
>> > +                    }
>> > +                }
>> > +                else if (message.contains("\"h\"")
>> > +                        || message.contains("\"" +
>> > HtmlLibrary.Namespace + "\""))
>> > +                {
>> > +                    // check facelets-only h tags
>> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
>> > +                    {
>> > +                        if (message.contains("\"" + tag + "\""))
>> > +                        {
>> > +                            String exceptionMessage = "The tag h:" +
>> > tag +
>> > +                                    " is only available on facelets.";
>> > +                            throw new FacesException(exceptionMessage,
>> > +                                    new
>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                        }
>> > +                    }
>> > +                }
>> > +                else
>> > +                {
>> > +                    // check facelets-only namespaces
>> > +                    String namespace = null;
>> > +                    if (message.contains(UILibrary.Namespace))
>> > +                    {
>> > +                        namespace = UILibrary.Namespace;
>> > +                    }
>> > +                    else if
>> > (message.contains(CompositeLibrary.NAMESPACE))
>> > +                    {
>> > +                        namespace = CompositeLibrary.NAMESPACE;
>> > +                    }
>> > +
>> > +                    if (namespace != null)
>> > +                    {
>> > +                        // the message contains a facelets-only
>> > namespace
>> > +                        String exceptionMessage = "All tags with
>> > namespace " +
>> > +                                namespace + " are only available on
>> > facelets.";
>> > +                        throw new FacesException(exceptionMessage,
>> > +                                new
>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                    }
>> > +                }
>> > +            }
>> > +
>> > +            // no rule applied to this Exception - rethrow it
>> > +            throw e;
>> > +        }
>> > +        finally
>> > +        {
>> > +            externalContext.setResponse(response);
>> > +        }
>> > +
>> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>> > wrappedResponse.getStatus() > 299;
>> > +        if (errorResponse)
>> > +        {
>> > +            wrappedResponse.flushToWrappedResponse();
>> > +            return;
>> > +        }
>> > +
>> > +        //Skip this step if we are rendering an ajax request, because
>> > no content outside
>> > +        //f:view tag should be output.
>> > +        if (!context.getPartialViewContext().isPartialRequest())
>> > +        {
>> > +            // store the wrapped response in the request, so it is
>> > thread-safe
>> > +            setAfterViewTagResponseWrapper(externalContext,
>> > wrappedResponse);
>> > +        }
>> > +    }
>> > +
>> > +    @Override
>> > +    protected void sendSourceNotFound(FacesContext context, String
>> > message)
>> > +    {
>> > +        HttpServletResponse response = (HttpServletResponse)
>> > context.getExternalContext().getResponse();
>> > +        try
>> > +        {
>> > +            context.responseComplete();
>> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>> > message);
>> > +        }
>> > +        catch (IOException ioe)
>> > +        {
>> > +            throw new FacesException(ioe);
>> > +        }
>> > +    }
>> > +
>> > +}
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:eol-style = native
>> >
>> > Propchange:
>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >
>> > ------------------------------------------------------------------------------
>> >    svn:keywords = Date Author Id Revision HeadURL
>> >
>> >
>> >
>>
>>
>>
>> --
>> Matthias Wessendorf
>>
>> blog: http://matthiaswessendorf.wordpress.com/
>> sessions: http://www.slideshare.net/mwessendorf
>> twitter: http://twitter.com/mwessendorf
>
>
>
> --
> Jakob Korherr
>
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at
>
>
>
> --
> Jakob Korherr
>
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at
>



-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Jakob Korherr <ja...@gmail.com>.
Forwarded my original mail to this topic since it obviously went wrong the
first time.

---------- Forwarded message ----------
From: Jakob Korherr <ja...@apache.org>
Date: 2010/4/14
Subject: Re: svn commit: r934048 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp:
FaceletsOnlyException.java JspViewDeclarationLanguage.java
To: MyFaces Development <de...@myfaces.apache.org>


No I cannot, because then its message won't be displayed by the
ExceptionHandler, because the ExceptionHandler "extracts" the Exception
until it finds the first non-FacesException and then it handles this one.

Thus if I would make it a FacesException, the message will be lost. This was
the reason I created FaceletsOnlyException in the first place...

Regards,
Jakob

2010/4/14 Matthias Wessendorf <ma...@apache.org>

public class FaceletsOnlyException extends Exception
>
>
> ==> can you make that extending FacesException ?
>
> -Matthias
>
> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
> > Author: jakobk
> > Date: Wed Apr 14 17:48:28 2010
> > New Revision: 934048
> >
> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
> > Log:
> > MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X)
> pages
> >
> > Added:
> >
>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>   (with props)
> > Modified:
> >
>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>   (contents, props changed)
> >
> > Added:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
> >
> ==============================================================================
> > ---
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> (added)
> > +++
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> Wed Apr 14 17:48:28 2010
> > @@ -0,0 +1,40 @@
> > +/*
> > + * Licensed to the Apache Software Foundation (ASF) under one
> > + * or more contributor license agreements.  See the NOTICE file
> > + * distributed with this work for additional information
> > + * regarding copyright ownership.  The ASF licenses this file
> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > + *
> > + * Unless required by applicable law or agreed to in writing,
> > + * software distributed under the License is distributed on an
> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > + * KIND, either express or implied.  See the License for the
> > + * specific language governing permissions and limitations
> > + * under the License.
> > + */
> > +package org.apache.myfaces.view.jsp;
> > +
> > +/**
> > + * An Exception that indicates that the user uses a
> > + * facelets-only feature on a JSP.
> > + *
> > + * @author Jakob Korherr (latest modification by $Author$)
> > + * @version $Revision$ $Date$
> > + *
> > + * @since 2.0
> > + */
> > +public class FaceletsOnlyException extends Exception
> > +{
> > +
> > +    private static final long serialVersionUID = 4268633427284543647L;
> > +
> > +    public FaceletsOnlyException(String message, Throwable cause)
> > +    {
> > +        super(message, cause);
> > +    }
> > +
> > +}
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:eol-style = native
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:keywords = Date Author Id Revision HeadURL
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:mime-type = text/plain
> >
> > Modified:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
> >
> ==============================================================================
> > ---
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> (original)
> > +++
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> Wed Apr 14 17:48:28 2010
> > @@ -1,139 +1,222 @@
> > -/*
> > - * Licensed to the Apache Software Foundation (ASF) under one
> > - * or more contributor license agreements.  See the NOTICE file
> > - * distributed with this work for additional information
> > - * regarding copyright ownership.  The ASF licenses this file
> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > - *
> > - * Unless required by applicable law or agreed to in writing,
> > - * software distributed under the License is distributed on an
> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > - * KIND, either express or implied.  See the License for the
> > - * specific language governing permissions and limitations
> > - * under the License.
> > - */
> > -package org.apache.myfaces.view.jsp;
> > -
> > -import java.io.IOException;
> > -import java.util.Locale;
> > -import java.util.logging.Level;
> > -import java.util.logging.Logger;
> > -
> > -import javax.faces.FacesException;
> > -import javax.faces.component.UIViewRoot;
> > -import javax.faces.context.ExternalContext;
> > -import javax.faces.context.FacesContext;
> > -import javax.servlet.ServletRequest;
> > -import javax.servlet.ServletResponse;
> > -import javax.servlet.http.HttpServletResponse;
> > -import javax.servlet.jsp.jstl.core.Config;
> > -
> > -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
> > -import
> org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> > -import org.apache.myfaces.util.ExternalContextUtils;
> > -
> > -/**
> > - * @author Simon Lessard (latest modification by $Author: slessard $)
> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400 (mer.,
> 17 sept. 2008) $
> > - *
> > - * @since 2.0
> > - */
> > -public class JspViewDeclarationLanguage extends
> JspViewDeclarationLanguageBase
> > -{
> > -    //private static final Log log =
> LogFactory.getLog(JspViewDeclarationLanguage.class);
> > -    public static final Logger log =
> Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> > -    /**
> > -     *
> > -     */
> > -    public JspViewDeclarationLanguage()
> > -    {
> > -        if (log.isLoggable(Level.FINEST))
> > -            log.finest("New JspViewDeclarationLanguage instance
> created");
> > -    }
> > -
> > -    /**
> > -     * {@inheritDoc}
> > -     */
> > -    @Override
> > -    public void buildView(FacesContext context, UIViewRoot view) throws
> IOException
> > -    {
> > -        ExternalContext externalContext = context.getExternalContext();
> > -
> > -        if (context.getPartialViewContext().isPartialRequest())
> > -        {
> > -            // try to get (or create) a ResponseSwitch and turn off the
> output
> > -            Object origResponse =
> context.getExternalContext().getResponse();
> > -            ResponseSwitch responseSwitch =
> ExternalContextUtils.getResponseSwitch(origResponse);
> > -            if (responseSwitch == null)
> > -            {
> > -                // no ResponseSwitch installed yet - create one
> > -                responseSwitch =
> ExternalContextUtils.createResponseSwitch(origResponse);
> > -                if (responseSwitch != null)
> > -                {
> > -                    // install the ResponseSwitch
> > -
>  context.getExternalContext().setResponse(responseSwitch);
> > -                }
> > -            }
> > -            if (responseSwitch != null)
> > -            {
> > -                responseSwitch.setEnabled(context, false);
> > -            }
> > -        }
> > -
> > -        ServletResponse response = (ServletResponse)
> externalContext.getResponse();
> > -        ServletRequest request = (ServletRequest)
> externalContext.getRequest();
> > -
> > -        Locale locale = view.getLocale();
> > -        response.setLocale(locale);
> > -        Config.set(request, Config.FMT_LOCALE,
> context.getViewRoot().getLocale());
> > -
> > -        String viewId = view.getViewId();
> > -        ServletViewResponseWrapper wrappedResponse = new
> ServletViewResponseWrapper((HttpServletResponse) response);
> > -
> > -        externalContext.setResponse(wrappedResponse);
> > -        try
> > -        {
> > -            externalContext.dispatch(viewId);
> > -        }
> > -        finally
> > -        {
> > -            externalContext.setResponse(response);
> > -        }
> > -
> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
> wrappedResponse.getStatus() > 299;
> > -        if (errorResponse)
> > -        {
> > -            wrappedResponse.flushToWrappedResponse();
> > -            return;
> > -        }
> > -
> > -        //Skip this step if we are rendering an ajax request, because no
> content outside
> > -        //f:view tag should be output.
> > -        if (!context.getPartialViewContext().isPartialRequest())
> > -        {
> > -            // store the wrapped response in the request, so it is
> thread-safe
> > -            setAfterViewTagResponseWrapper(externalContext,
> wrappedResponse);
> > -        }
> > -    }
> > -
> > -    @Override
> > -    protected void sendSourceNotFound(FacesContext context, String
> message)
> > -    {
> > -        HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
> > -        try
> > -        {
> > -            context.responseComplete();
> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> message);
> > -        }
> > -        catch (IOException ioe)
> > -        {
> > -            throw new FacesException(ioe);
> > -        }
> > -    }
> > -
> > -}
> > +/*
> > + * Licensed to the Apache Software Foundation (ASF) under one
> > + * or more contributor license agreements.  See the NOTICE file
> > + * distributed with this work for additional information
> > + * regarding copyright ownership.  The ASF licenses this file
> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > + *
> > + * Unless required by applicable law or agreed to in writing,
> > + * software distributed under the License is distributed on an
> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > + * KIND, either express or implied.  See the License for the
> > + * specific language governing permissions and limitations
> > + * under the License.
> > + */
> > +package org.apache.myfaces.view.jsp;
> > +
> > +import java.io.IOException;
> > +import java.util.Locale;
> > +import java.util.logging.Level;
> > +import java.util.logging.Logger;
> > +
> > +import javax.faces.FacesException;
> > +import javax.faces.component.UIViewRoot;
> > +import javax.faces.context.ExternalContext;
> > +import javax.faces.context.FacesContext;
> > +import javax.servlet.ServletRequest;
> > +import javax.servlet.ServletResponse;
> > +import javax.servlet.http.HttpServletResponse;
> > +import javax.servlet.jsp.jstl.core.Config;
> > +
> > +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
> > +import
> org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> > +import org.apache.myfaces.util.ExternalContextUtils;
> > +import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
> > +
> > +/**
> > + * @author Simon Lessard (latest modification by $Author$)
> > + * @version $Revision$ $Date$
> > + *
> > + * @since 2.0
> > + */
> > +public class JspViewDeclarationLanguage extends
> JspViewDeclarationLanguageBase
> > +{
> > +    //private static final Log log =
> LogFactory.getLog(JspViewDeclarationLanguage.class);
> > +    public static final Logger log =
> Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> > +
> > +    /**
> > +     * Tags that are only available on facelets and not on JSP.
> > +     * If a user uses one of these tags on a JSP, we will provide
> > +     * a more informative error message than the standard one.
> > +     */
> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
> "event", "metadata"};
> > +    public static final String[] FACELETS_ONLY_H_TAGS = {"outputScript",
> "outputStylesheet",
> > +                                                         "head", "body",
> "button", "link"};
> > +
> > +    /**
> > +     *
> > +     */
> > +    public JspViewDeclarationLanguage()
> > +    {
> > +        if (log.isLoggable(Level.FINEST))
> > +            log.finest("New JspViewDeclarationLanguage instance
> created");
> > +    }
> > +
> > +    /**
> > +     * {@inheritDoc}
> > +     */
> > +    @Override
> > +    public void buildView(FacesContext context, UIViewRoot view) throws
> IOException
> > +    {
> > +        ExternalContext externalContext = context.getExternalContext();
> > +
> > +        if (context.getPartialViewContext().isPartialRequest())
> > +        {
> > +            // try to get (or create) a ResponseSwitch and turn off the
> output
> > +            Object origResponse =
> context.getExternalContext().getResponse();
> > +            ResponseSwitch responseSwitch =
> ExternalContextUtils.getResponseSwitch(origResponse);
> > +            if (responseSwitch == null)
> > +            {
> > +                // no ResponseSwitch installed yet - create one
> > +                responseSwitch =
> ExternalContextUtils.createResponseSwitch(origResponse);
> > +                if (responseSwitch != null)
> > +                {
> > +                    // install the ResponseSwitch
> > +
>  context.getExternalContext().setResponse(responseSwitch);
> > +                }
> > +            }
> > +            if (responseSwitch != null)
> > +            {
> > +                responseSwitch.setEnabled(context, false);
> > +            }
> > +        }
> > +
> > +        ServletResponse response = (ServletResponse)
> externalContext.getResponse();
> > +        ServletRequest request = (ServletRequest)
> externalContext.getRequest();
> > +
> > +        Locale locale = view.getLocale();
> > +        response.setLocale(locale);
> > +        Config.set(request, Config.FMT_LOCALE,
> context.getViewRoot().getLocale());
> > +
> > +        String viewId = view.getViewId();
> > +        ServletViewResponseWrapper wrappedResponse = new
> ServletViewResponseWrapper((HttpServletResponse) response);
> > +
> > +        externalContext.setResponse(wrappedResponse);
> > +        try
> > +        {
> > +            externalContext.dispatch(viewId);
> > +        }
> > +        catch (FacesException e)
> > +        {
> > +            // try to extract the most likely exceptions here
> > +            // and provide a better error message for them
> > +
> > +            String message = e.getMessage();
> > +
> > +            // errors related to using facelets-only tags on a JSP page
> > +            if (message != null)
> > +            {
> > +                // does the message contain "f" (prefix f of tags)
> > +                // or the related uri http://java.sun.com/jsf/core
> > +                if (message.contains("\"f\"")
> > +                        || message.contains("\"" + CoreLibrary.Namespace
> + "\""))
> > +                {
> > +                    // check facelets-only f tags
> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
> > +                    {
> > +                        if (message.contains("\"" + tag + "\""))
> > +                        {
> > +                            String exceptionMessage = "The tag f:" + tag
> +
> > +                                    " is only available on facelets.";
> > +                            throw new FacesException(exceptionMessage,
> > +                                    new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                        }
> > +                    }
> > +                }
> > +                else if (message.contains("\"h\"")
> > +                        || message.contains("\"" + HtmlLibrary.Namespace
> + "\""))
> > +                {
> > +                    // check facelets-only h tags
> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
> > +                    {
> > +                        if (message.contains("\"" + tag + "\""))
> > +                        {
> > +                            String exceptionMessage = "The tag h:" + tag
> +
> > +                                    " is only available on facelets.";
> > +                            throw new FacesException(exceptionMessage,
> > +                                    new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                        }
> > +                    }
> > +                }
> > +                else
> > +                {
> > +                    // check facelets-only namespaces
> > +                    String namespace = null;
> > +                    if (message.contains(UILibrary.Namespace))
> > +                    {
> > +                        namespace = UILibrary.Namespace;
> > +                    }
> > +                    else if
> (message.contains(CompositeLibrary.NAMESPACE))
> > +                    {
> > +                        namespace = CompositeLibrary.NAMESPACE;
> > +                    }
> > +
> > +                    if (namespace != null)
> > +                    {
> > +                        // the message contains a facelets-only
> namespace
> > +                        String exceptionMessage = "All tags with
> namespace " +
> > +                                namespace + " are only available on
> facelets.";
> > +                        throw new FacesException(exceptionMessage,
> > +                                new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                    }
> > +                }
> > +            }
> > +
> > +            // no rule applied to this Exception - rethrow it
> > +            throw e;
> > +        }
> > +        finally
> > +        {
> > +            externalContext.setResponse(response);
> > +        }
> > +
> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
> wrappedResponse.getStatus() > 299;
> > +        if (errorResponse)
> > +        {
> > +            wrappedResponse.flushToWrappedResponse();
> > +            return;
> > +        }
> > +
> > +        //Skip this step if we are rendering an ajax request, because no
> content outside
> > +        //f:view tag should be output.
> > +        if (!context.getPartialViewContext().isPartialRequest())
> > +        {
> > +            // store the wrapped response in the request, so it is
> thread-safe
> > +            setAfterViewTagResponseWrapper(externalContext,
> wrappedResponse);
> > +        }
> > +    }
> > +
> > +    @Override
> > +    protected void sendSourceNotFound(FacesContext context, String
> message)
> > +    {
> > +        HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
> > +        try
> > +        {
> > +            context.responseComplete();
> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> message);
> > +        }
> > +        catch (IOException ioe)
> > +        {
> > +            throw new FacesException(ioe);
> > +        }
> > +    }
> > +
> > +}
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >
> ------------------------------------------------------------------------------
> >    svn:eol-style = native
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >
> ------------------------------------------------------------------------------
> >    svn:keywords = Date Author Id Revision HeadURL
> >
> >
> >
>
>
>
> --
> Matthias Wessendorf
>
> blog: http://matthiaswessendorf.wordpress.com/
> sessions: http://www.slideshare.net/mwessendorf
> twitter: http://twitter.com/mwessendorf
>



-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at



-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Jakob Korherr <ja...@apache.org>.
No I cannot, because then its message won't be displayed by the
ExceptionHandler, because the ExceptionHandler "extracts" the Exception
until it finds the first non-FacesException and then it handles this one.

Thus if I would make it a FacesException, the message will be lost. This was
the reason I created FaceletsOnlyException in the first place...

Regards,
Jakob

2010/4/14 Matthias Wessendorf <ma...@apache.org>

> public class FaceletsOnlyException extends Exception
>
>
> ==> can you make that extending FacesException ?
>
> -Matthias
>
> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
> > Author: jakobk
> > Date: Wed Apr 14 17:48:28 2010
> > New Revision: 934048
> >
> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
> > Log:
> > MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X)
> pages
> >
> > Added:
> >
>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>   (with props)
> > Modified:
> >
>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>   (contents, props changed)
> >
> > Added:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
> >
> ==============================================================================
> > ---
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> (added)
> > +++
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> Wed Apr 14 17:48:28 2010
> > @@ -0,0 +1,40 @@
> > +/*
> > + * Licensed to the Apache Software Foundation (ASF) under one
> > + * or more contributor license agreements.  See the NOTICE file
> > + * distributed with this work for additional information
> > + * regarding copyright ownership.  The ASF licenses this file
> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > + *
> > + * Unless required by applicable law or agreed to in writing,
> > + * software distributed under the License is distributed on an
> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > + * KIND, either express or implied.  See the License for the
> > + * specific language governing permissions and limitations
> > + * under the License.
> > + */
> > +package org.apache.myfaces.view.jsp;
> > +
> > +/**
> > + * An Exception that indicates that the user uses a
> > + * facelets-only feature on a JSP.
> > + *
> > + * @author Jakob Korherr (latest modification by $Author$)
> > + * @version $Revision$ $Date$
> > + *
> > + * @since 2.0
> > + */
> > +public class FaceletsOnlyException extends Exception
> > +{
> > +
> > +    private static final long serialVersionUID = 4268633427284543647L;
> > +
> > +    public FaceletsOnlyException(String message, Throwable cause)
> > +    {
> > +        super(message, cause);
> > +    }
> > +
> > +}
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:eol-style = native
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:keywords = Date Author Id Revision HeadURL
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:mime-type = text/plain
> >
> > Modified:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
> >
> ==============================================================================
> > ---
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> (original)
> > +++
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> Wed Apr 14 17:48:28 2010
> > @@ -1,139 +1,222 @@
> > -/*
> > - * Licensed to the Apache Software Foundation (ASF) under one
> > - * or more contributor license agreements.  See the NOTICE file
> > - * distributed with this work for additional information
> > - * regarding copyright ownership.  The ASF licenses this file
> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > - *
> > - * Unless required by applicable law or agreed to in writing,
> > - * software distributed under the License is distributed on an
> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > - * KIND, either express or implied.  See the License for the
> > - * specific language governing permissions and limitations
> > - * under the License.
> > - */
> > -package org.apache.myfaces.view.jsp;
> > -
> > -import java.io.IOException;
> > -import java.util.Locale;
> > -import java.util.logging.Level;
> > -import java.util.logging.Logger;
> > -
> > -import javax.faces.FacesException;
> > -import javax.faces.component.UIViewRoot;
> > -import javax.faces.context.ExternalContext;
> > -import javax.faces.context.FacesContext;
> > -import javax.servlet.ServletRequest;
> > -import javax.servlet.ServletResponse;
> > -import javax.servlet.http.HttpServletResponse;
> > -import javax.servlet.jsp.jstl.core.Config;
> > -
> > -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
> > -import
> org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> > -import org.apache.myfaces.util.ExternalContextUtils;
> > -
> > -/**
> > - * @author Simon Lessard (latest modification by $Author: slessard $)
> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400 (mer.,
> 17 sept. 2008) $
> > - *
> > - * @since 2.0
> > - */
> > -public class JspViewDeclarationLanguage extends
> JspViewDeclarationLanguageBase
> > -{
> > -    //private static final Log log =
> LogFactory.getLog(JspViewDeclarationLanguage.class);
> > -    public static final Logger log =
> Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> > -    /**
> > -     *
> > -     */
> > -    public JspViewDeclarationLanguage()
> > -    {
> > -        if (log.isLoggable(Level.FINEST))
> > -            log.finest("New JspViewDeclarationLanguage instance
> created");
> > -    }
> > -
> > -    /**
> > -     * {@inheritDoc}
> > -     */
> > -    @Override
> > -    public void buildView(FacesContext context, UIViewRoot view) throws
> IOException
> > -    {
> > -        ExternalContext externalContext = context.getExternalContext();
> > -
> > -        if (context.getPartialViewContext().isPartialRequest())
> > -        {
> > -            // try to get (or create) a ResponseSwitch and turn off the
> output
> > -            Object origResponse =
> context.getExternalContext().getResponse();
> > -            ResponseSwitch responseSwitch =
> ExternalContextUtils.getResponseSwitch(origResponse);
> > -            if (responseSwitch == null)
> > -            {
> > -                // no ResponseSwitch installed yet - create one
> > -                responseSwitch =
> ExternalContextUtils.createResponseSwitch(origResponse);
> > -                if (responseSwitch != null)
> > -                {
> > -                    // install the ResponseSwitch
> > -
>  context.getExternalContext().setResponse(responseSwitch);
> > -                }
> > -            }
> > -            if (responseSwitch != null)
> > -            {
> > -                responseSwitch.setEnabled(context, false);
> > -            }
> > -        }
> > -
> > -        ServletResponse response = (ServletResponse)
> externalContext.getResponse();
> > -        ServletRequest request = (ServletRequest)
> externalContext.getRequest();
> > -
> > -        Locale locale = view.getLocale();
> > -        response.setLocale(locale);
> > -        Config.set(request, Config.FMT_LOCALE,
> context.getViewRoot().getLocale());
> > -
> > -        String viewId = view.getViewId();
> > -        ServletViewResponseWrapper wrappedResponse = new
> ServletViewResponseWrapper((HttpServletResponse) response);
> > -
> > -        externalContext.setResponse(wrappedResponse);
> > -        try
> > -        {
> > -            externalContext.dispatch(viewId);
> > -        }
> > -        finally
> > -        {
> > -            externalContext.setResponse(response);
> > -        }
> > -
> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
> wrappedResponse.getStatus() > 299;
> > -        if (errorResponse)
> > -        {
> > -            wrappedResponse.flushToWrappedResponse();
> > -            return;
> > -        }
> > -
> > -        //Skip this step if we are rendering an ajax request, because no
> content outside
> > -        //f:view tag should be output.
> > -        if (!context.getPartialViewContext().isPartialRequest())
> > -        {
> > -            // store the wrapped response in the request, so it is
> thread-safe
> > -            setAfterViewTagResponseWrapper(externalContext,
> wrappedResponse);
> > -        }
> > -    }
> > -
> > -    @Override
> > -    protected void sendSourceNotFound(FacesContext context, String
> message)
> > -    {
> > -        HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
> > -        try
> > -        {
> > -            context.responseComplete();
> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> message);
> > -        }
> > -        catch (IOException ioe)
> > -        {
> > -            throw new FacesException(ioe);
> > -        }
> > -    }
> > -
> > -}
> > +/*
> > + * Licensed to the Apache Software Foundation (ASF) under one
> > + * or more contributor license agreements.  See the NOTICE file
> > + * distributed with this work for additional information
> > + * regarding copyright ownership.  The ASF licenses this file
> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > + *
> > + * Unless required by applicable law or agreed to in writing,
> > + * software distributed under the License is distributed on an
> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > + * KIND, either express or implied.  See the License for the
> > + * specific language governing permissions and limitations
> > + * under the License.
> > + */
> > +package org.apache.myfaces.view.jsp;
> > +
> > +import java.io.IOException;
> > +import java.util.Locale;
> > +import java.util.logging.Level;
> > +import java.util.logging.Logger;
> > +
> > +import javax.faces.FacesException;
> > +import javax.faces.component.UIViewRoot;
> > +import javax.faces.context.ExternalContext;
> > +import javax.faces.context.FacesContext;
> > +import javax.servlet.ServletRequest;
> > +import javax.servlet.ServletResponse;
> > +import javax.servlet.http.HttpServletResponse;
> > +import javax.servlet.jsp.jstl.core.Config;
> > +
> > +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
> > +import
> org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> > +import org.apache.myfaces.util.ExternalContextUtils;
> > +import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
> > +
> > +/**
> > + * @author Simon Lessard (latest modification by $Author$)
> > + * @version $Revision$ $Date$
> > + *
> > + * @since 2.0
> > + */
> > +public class JspViewDeclarationLanguage extends
> JspViewDeclarationLanguageBase
> > +{
> > +    //private static final Log log =
> LogFactory.getLog(JspViewDeclarationLanguage.class);
> > +    public static final Logger log =
> Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> > +
> > +    /**
> > +     * Tags that are only available on facelets and not on JSP.
> > +     * If a user uses one of these tags on a JSP, we will provide
> > +     * a more informative error message than the standard one.
> > +     */
> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
> "event", "metadata"};
> > +    public static final String[] FACELETS_ONLY_H_TAGS = {"outputScript",
> "outputStylesheet",
> > +                                                         "head", "body",
> "button", "link"};
> > +
> > +    /**
> > +     *
> > +     */
> > +    public JspViewDeclarationLanguage()
> > +    {
> > +        if (log.isLoggable(Level.FINEST))
> > +            log.finest("New JspViewDeclarationLanguage instance
> created");
> > +    }
> > +
> > +    /**
> > +     * {@inheritDoc}
> > +     */
> > +    @Override
> > +    public void buildView(FacesContext context, UIViewRoot view) throws
> IOException
> > +    {
> > +        ExternalContext externalContext = context.getExternalContext();
> > +
> > +        if (context.getPartialViewContext().isPartialRequest())
> > +        {
> > +            // try to get (or create) a ResponseSwitch and turn off the
> output
> > +            Object origResponse =
> context.getExternalContext().getResponse();
> > +            ResponseSwitch responseSwitch =
> ExternalContextUtils.getResponseSwitch(origResponse);
> > +            if (responseSwitch == null)
> > +            {
> > +                // no ResponseSwitch installed yet - create one
> > +                responseSwitch =
> ExternalContextUtils.createResponseSwitch(origResponse);
> > +                if (responseSwitch != null)
> > +                {
> > +                    // install the ResponseSwitch
> > +
>  context.getExternalContext().setResponse(responseSwitch);
> > +                }
> > +            }
> > +            if (responseSwitch != null)
> > +            {
> > +                responseSwitch.setEnabled(context, false);
> > +            }
> > +        }
> > +
> > +        ServletResponse response = (ServletResponse)
> externalContext.getResponse();
> > +        ServletRequest request = (ServletRequest)
> externalContext.getRequest();
> > +
> > +        Locale locale = view.getLocale();
> > +        response.setLocale(locale);
> > +        Config.set(request, Config.FMT_LOCALE,
> context.getViewRoot().getLocale());
> > +
> > +        String viewId = view.getViewId();
> > +        ServletViewResponseWrapper wrappedResponse = new
> ServletViewResponseWrapper((HttpServletResponse) response);
> > +
> > +        externalContext.setResponse(wrappedResponse);
> > +        try
> > +        {
> > +            externalContext.dispatch(viewId);
> > +        }
> > +        catch (FacesException e)
> > +        {
> > +            // try to extract the most likely exceptions here
> > +            // and provide a better error message for them
> > +
> > +            String message = e.getMessage();
> > +
> > +            // errors related to using facelets-only tags on a JSP page
> > +            if (message != null)
> > +            {
> > +                // does the message contain "f" (prefix f of tags)
> > +                // or the related uri http://java.sun.com/jsf/core
> > +                if (message.contains("\"f\"")
> > +                        || message.contains("\"" + CoreLibrary.Namespace
> + "\""))
> > +                {
> > +                    // check facelets-only f tags
> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
> > +                    {
> > +                        if (message.contains("\"" + tag + "\""))
> > +                        {
> > +                            String exceptionMessage = "The tag f:" + tag
> +
> > +                                    " is only available on facelets.";
> > +                            throw new FacesException(exceptionMessage,
> > +                                    new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                        }
> > +                    }
> > +                }
> > +                else if (message.contains("\"h\"")
> > +                        || message.contains("\"" + HtmlLibrary.Namespace
> + "\""))
> > +                {
> > +                    // check facelets-only h tags
> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
> > +                    {
> > +                        if (message.contains("\"" + tag + "\""))
> > +                        {
> > +                            String exceptionMessage = "The tag h:" + tag
> +
> > +                                    " is only available on facelets.";
> > +                            throw new FacesException(exceptionMessage,
> > +                                    new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                        }
> > +                    }
> > +                }
> > +                else
> > +                {
> > +                    // check facelets-only namespaces
> > +                    String namespace = null;
> > +                    if (message.contains(UILibrary.Namespace))
> > +                    {
> > +                        namespace = UILibrary.Namespace;
> > +                    }
> > +                    else if
> (message.contains(CompositeLibrary.NAMESPACE))
> > +                    {
> > +                        namespace = CompositeLibrary.NAMESPACE;
> > +                    }
> > +
> > +                    if (namespace != null)
> > +                    {
> > +                        // the message contains a facelets-only
> namespace
> > +                        String exceptionMessage = "All tags with
> namespace " +
> > +                                namespace + " are only available on
> facelets.";
> > +                        throw new FacesException(exceptionMessage,
> > +                                new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                    }
> > +                }
> > +            }
> > +
> > +            // no rule applied to this Exception - rethrow it
> > +            throw e;
> > +        }
> > +        finally
> > +        {
> > +            externalContext.setResponse(response);
> > +        }
> > +
> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
> wrappedResponse.getStatus() > 299;
> > +        if (errorResponse)
> > +        {
> > +            wrappedResponse.flushToWrappedResponse();
> > +            return;
> > +        }
> > +
> > +        //Skip this step if we are rendering an ajax request, because no
> content outside
> > +        //f:view tag should be output.
> > +        if (!context.getPartialViewContext().isPartialRequest())
> > +        {
> > +            // store the wrapped response in the request, so it is
> thread-safe
> > +            setAfterViewTagResponseWrapper(externalContext,
> wrappedResponse);
> > +        }
> > +    }
> > +
> > +    @Override
> > +    protected void sendSourceNotFound(FacesContext context, String
> message)
> > +    {
> > +        HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
> > +        try
> > +        {
> > +            context.responseComplete();
> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> message);
> > +        }
> > +        catch (IOException ioe)
> > +        {
> > +            throw new FacesException(ioe);
> > +        }
> > +    }
> > +
> > +}
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >
> ------------------------------------------------------------------------------
> >    svn:eol-style = native
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >
> ------------------------------------------------------------------------------
> >    svn:keywords = Date Author Id Revision HeadURL
> >
> >
> >
>
>
>
> --
> Matthias Wessendorf
>
> blog: http://matthiaswessendorf.wordpress.com/
> sessions: http://www.slideshare.net/mwessendorf
> twitter: http://twitter.com/mwessendorf
>



-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Matthias Wessendorf <ma...@apache.org>.
On Wed, Apr 14, 2010 at 10:09 PM, Jakob Korherr <ja...@gmail.com> wrote:
> WTF?

no appropriate wording, here

> Did anyone read my mail on that?

nope, where did you sent it ?

> It cannot be a FacesException, because
> then the message would be lost!

that's fine, we can change that back to original code.

-Matthias

>
>
> 2010/4/14 Leonardo Uribe <lu...@gmail.com>
>>
>>
>> 2010/4/14 Matthias Wessendorf <ma...@apache.org>
>>>
>>> public class FaceletsOnlyException extends Exception
>>>
>>>
>>> ==> can you make that extending FacesException ?
>>>
>>
>> Yes, no problem. It is done.
>>
>>>
>>> -Matthias
>>>
>>> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
>>> > Author: jakobk
>>> > Date: Wed Apr 14 17:48:28 2010
>>> > New Revision: 934048
>>> >
>>> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
>>> > Log:
>>> > MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X)
>>> > pages
>>> >
>>> > Added:
>>> >
>>> >  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >   (with props)
>>> > Modified:
>>> >
>>> >  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >   (contents, props changed)
>>> >
>>> > Added:
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> > URL:
>>> > http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
>>> >
>>> > ==============================================================================
>>> > ---
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> > (added)
>>> > +++
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> > Wed Apr 14 17:48:28 2010
>>> > @@ -0,0 +1,40 @@
>>> > +/*
>>> > + * Licensed to the Apache Software Foundation (ASF) under one
>>> > + * or more contributor license agreements.  See the NOTICE file
>>> > + * distributed with this work for additional information
>>> > + * regarding copyright ownership.  The ASF licenses this file
>>> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>>> > + *
>>> > + * Unless required by applicable law or agreed to in writing,
>>> > + * software distributed under the License is distributed on an
>>> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> > + * KIND, either express or implied.  See the License for the
>>> > + * specific language governing permissions and limitations
>>> > + * under the License.
>>> > + */
>>> > +package org.apache.myfaces.view.jsp;
>>> > +
>>> > +/**
>>> > + * An Exception that indicates that the user uses a
>>> > + * facelets-only feature on a JSP.
>>> > + *
>>> > + * @author Jakob Korherr (latest modification by $Author$)
>>> > + * @version $Revision$ $Date$
>>> > + *
>>> > + * @since 2.0
>>> > + */
>>> > +public class FaceletsOnlyException extends Exception
>>> > +{
>>> > +
>>> > +    private static final long serialVersionUID = 4268633427284543647L;
>>> > +
>>> > +    public FaceletsOnlyException(String message, Throwable cause)
>>> > +    {
>>> > +        super(message, cause);
>>> > +    }
>>> > +
>>> > +}
>>> >
>>> > Propchange:
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >
>>> > ------------------------------------------------------------------------------
>>> >    svn:eol-style = native
>>> >
>>> > Propchange:
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >
>>> > ------------------------------------------------------------------------------
>>> >    svn:keywords = Date Author Id Revision HeadURL
>>> >
>>> > Propchange:
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>> >
>>> > ------------------------------------------------------------------------------
>>> >    svn:mime-type = text/plain
>>> >
>>> > Modified:
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> > URL:
>>> > http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
>>> >
>>> > ==============================================================================
>>> > ---
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> > (original)
>>> > +++
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> > Wed Apr 14 17:48:28 2010
>>> > @@ -1,139 +1,222 @@
>>> > -/*
>>> > - * Licensed to the Apache Software Foundation (ASF) under one
>>> > - * or more contributor license agreements.  See the NOTICE file
>>> > - * distributed with this work for additional information
>>> > - * regarding copyright ownership.  The ASF licenses this file
>>> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>>> > - *
>>> > - * Unless required by applicable law or agreed to in writing,
>>> > - * software distributed under the License is distributed on an
>>> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> > - * KIND, either express or implied.  See the License for the
>>> > - * specific language governing permissions and limitations
>>> > - * under the License.
>>> > - */
>>> > -package org.apache.myfaces.view.jsp;
>>> > -
>>> > -import java.io.IOException;
>>> > -import java.util.Locale;
>>> > -import java.util.logging.Level;
>>> > -import java.util.logging.Logger;
>>> > -
>>> > -import javax.faces.FacesException;
>>> > -import javax.faces.component.UIViewRoot;
>>> > -import javax.faces.context.ExternalContext;
>>> > -import javax.faces.context.FacesContext;
>>> > -import javax.servlet.ServletRequest;
>>> > -import javax.servlet.ServletResponse;
>>> > -import javax.servlet.http.HttpServletResponse;
>>> > -import javax.servlet.jsp.jstl.core.Config;
>>> > -
>>> > -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>>> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
>>> > -import
>>> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>>> > -import org.apache.myfaces.util.ExternalContextUtils;
>>> > -
>>> > -/**
>>> > - * @author Simon Lessard (latest modification by $Author: slessard $)
>>> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400
>>> > (mer., 17 sept. 2008) $
>>> > - *
>>> > - * @since 2.0
>>> > - */
>>> > -public class JspViewDeclarationLanguage extends
>>> > JspViewDeclarationLanguageBase
>>> > -{
>>> > -    //private static final Log log =
>>> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>>> > -    public static final Logger log =
>>> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>>> > -    /**
>>> > -     *
>>> > -     */
>>> > -    public JspViewDeclarationLanguage()
>>> > -    {
>>> > -        if (log.isLoggable(Level.FINEST))
>>> > -            log.finest("New JspViewDeclarationLanguage instance
>>> > created");
>>> > -    }
>>> > -
>>> > -    /**
>>> > -     * {@inheritDoc}
>>> > -     */
>>> > -    @Override
>>> > -    public void buildView(FacesContext context, UIViewRoot view)
>>> > throws IOException
>>> > -    {
>>> > -        ExternalContext externalContext =
>>> > context.getExternalContext();
>>> > -
>>> > -        if (context.getPartialViewContext().isPartialRequest())
>>> > -        {
>>> > -            // try to get (or create) a ResponseSwitch and turn off
>>> > the output
>>> > -            Object origResponse =
>>> > context.getExternalContext().getResponse();
>>> > -            ResponseSwitch responseSwitch =
>>> > ExternalContextUtils.getResponseSwitch(origResponse);
>>> > -            if (responseSwitch == null)
>>> > -            {
>>> > -                // no ResponseSwitch installed yet - create one
>>> > -                responseSwitch =
>>> > ExternalContextUtils.createResponseSwitch(origResponse);
>>> > -                if (responseSwitch != null)
>>> > -                {
>>> > -                    // install the ResponseSwitch
>>> > -
>>> >  context.getExternalContext().setResponse(responseSwitch);
>>> > -                }
>>> > -            }
>>> > -            if (responseSwitch != null)
>>> > -            {
>>> > -                responseSwitch.setEnabled(context, false);
>>> > -            }
>>> > -        }
>>> > -
>>> > -        ServletResponse response = (ServletResponse)
>>> > externalContext.getResponse();
>>> > -        ServletRequest request = (ServletRequest)
>>> > externalContext.getRequest();
>>> > -
>>> > -        Locale locale = view.getLocale();
>>> > -        response.setLocale(locale);
>>> > -        Config.set(request, Config.FMT_LOCALE,
>>> > context.getViewRoot().getLocale());
>>> > -
>>> > -        String viewId = view.getViewId();
>>> > -        ServletViewResponseWrapper wrappedResponse = new
>>> > ServletViewResponseWrapper((HttpServletResponse) response);
>>> > -
>>> > -        externalContext.setResponse(wrappedResponse);
>>> > -        try
>>> > -        {
>>> > -            externalContext.dispatch(viewId);
>>> > -        }
>>> > -        finally
>>> > -        {
>>> > -            externalContext.setResponse(response);
>>> > -        }
>>> > -
>>> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>>> > wrappedResponse.getStatus() > 299;
>>> > -        if (errorResponse)
>>> > -        {
>>> > -            wrappedResponse.flushToWrappedResponse();
>>> > -            return;
>>> > -        }
>>> > -
>>> > -        //Skip this step if we are rendering an ajax request, because
>>> > no content outside
>>> > -        //f:view tag should be output.
>>> > -        if (!context.getPartialViewContext().isPartialRequest())
>>> > -        {
>>> > -            // store the wrapped response in the request, so it is
>>> > thread-safe
>>> > -            setAfterViewTagResponseWrapper(externalContext,
>>> > wrappedResponse);
>>> > -        }
>>> > -    }
>>> > -
>>> > -    @Override
>>> > -    protected void sendSourceNotFound(FacesContext context, String
>>> > message)
>>> > -    {
>>> > -        HttpServletResponse response = (HttpServletResponse)
>>> > context.getExternalContext().getResponse();
>>> > -        try
>>> > -        {
>>> > -            context.responseComplete();
>>> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>>> > message);
>>> > -        }
>>> > -        catch (IOException ioe)
>>> > -        {
>>> > -            throw new FacesException(ioe);
>>> > -        }
>>> > -    }
>>> > -
>>> > -}
>>> > +/*
>>> > + * Licensed to the Apache Software Foundation (ASF) under one
>>> > + * or more contributor license agreements.  See the NOTICE file
>>> > + * distributed with this work for additional information
>>> > + * regarding copyright ownership.  The ASF licenses this file
>>> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>>> > + *
>>> > + * Unless required by applicable law or agreed to in writing,
>>> > + * software distributed under the License is distributed on an
>>> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> > + * KIND, either express or implied.  See the License for the
>>> > + * specific language governing permissions and limitations
>>> > + * under the License.
>>> > + */
>>> > +package org.apache.myfaces.view.jsp;
>>> > +
>>> > +import java.io.IOException;
>>> > +import java.util.Locale;
>>> > +import java.util.logging.Level;
>>> > +import java.util.logging.Logger;
>>> > +
>>> > +import javax.faces.FacesException;
>>> > +import javax.faces.component.UIViewRoot;
>>> > +import javax.faces.context.ExternalContext;
>>> > +import javax.faces.context.FacesContext;
>>> > +import javax.servlet.ServletRequest;
>>> > +import javax.servlet.ServletResponse;
>>> > +import javax.servlet.http.HttpServletResponse;
>>> > +import javax.servlet.jsp.jstl.core.Config;
>>> > +
>>> > +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>>> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
>>> > +import
>>> > org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>>> > +import org.apache.myfaces.util.ExternalContextUtils;
>>> > +import
>>> > org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
>>> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
>>> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
>>> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
>>> > +
>>> > +/**
>>> > + * @author Simon Lessard (latest modification by $Author$)
>>> > + * @version $Revision$ $Date$
>>> > + *
>>> > + * @since 2.0
>>> > + */
>>> > +public class JspViewDeclarationLanguage extends
>>> > JspViewDeclarationLanguageBase
>>> > +{
>>> > +    //private static final Log log =
>>> > LogFactory.getLog(JspViewDeclarationLanguage.class);
>>> > +    public static final Logger log =
>>> > Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>>> > +
>>> > +    /**
>>> > +     * Tags that are only available on facelets and not on JSP.
>>> > +     * If a user uses one of these tags on a JSP, we will provide
>>> > +     * a more informative error message than the standard one.
>>> > +     */
>>> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
>>> > "event", "metadata"};
>>> > +    public static final String[] FACELETS_ONLY_H_TAGS =
>>> > {"outputScript", "outputStylesheet",
>>> > +                                                         "head",
>>> > "body", "button", "link"};
>>> > +
>>> > +    /**
>>> > +     *
>>> > +     */
>>> > +    public JspViewDeclarationLanguage()
>>> > +    {
>>> > +        if (log.isLoggable(Level.FINEST))
>>> > +            log.finest("New JspViewDeclarationLanguage instance
>>> > created");
>>> > +    }
>>> > +
>>> > +    /**
>>> > +     * {@inheritDoc}
>>> > +     */
>>> > +    @Override
>>> > +    public void buildView(FacesContext context, UIViewRoot view)
>>> > throws IOException
>>> > +    {
>>> > +        ExternalContext externalContext =
>>> > context.getExternalContext();
>>> > +
>>> > +        if (context.getPartialViewContext().isPartialRequest())
>>> > +        {
>>> > +            // try to get (or create) a ResponseSwitch and turn off
>>> > the output
>>> > +            Object origResponse =
>>> > context.getExternalContext().getResponse();
>>> > +            ResponseSwitch responseSwitch =
>>> > ExternalContextUtils.getResponseSwitch(origResponse);
>>> > +            if (responseSwitch == null)
>>> > +            {
>>> > +                // no ResponseSwitch installed yet - create one
>>> > +                responseSwitch =
>>> > ExternalContextUtils.createResponseSwitch(origResponse);
>>> > +                if (responseSwitch != null)
>>> > +                {
>>> > +                    // install the ResponseSwitch
>>> > +
>>> >  context.getExternalContext().setResponse(responseSwitch);
>>> > +                }
>>> > +            }
>>> > +            if (responseSwitch != null)
>>> > +            {
>>> > +                responseSwitch.setEnabled(context, false);
>>> > +            }
>>> > +        }
>>> > +
>>> > +        ServletResponse response = (ServletResponse)
>>> > externalContext.getResponse();
>>> > +        ServletRequest request = (ServletRequest)
>>> > externalContext.getRequest();
>>> > +
>>> > +        Locale locale = view.getLocale();
>>> > +        response.setLocale(locale);
>>> > +        Config.set(request, Config.FMT_LOCALE,
>>> > context.getViewRoot().getLocale());
>>> > +
>>> > +        String viewId = view.getViewId();
>>> > +        ServletViewResponseWrapper wrappedResponse = new
>>> > ServletViewResponseWrapper((HttpServletResponse) response);
>>> > +
>>> > +        externalContext.setResponse(wrappedResponse);
>>> > +        try
>>> > +        {
>>> > +            externalContext.dispatch(viewId);
>>> > +        }
>>> > +        catch (FacesException e)
>>> > +        {
>>> > +            // try to extract the most likely exceptions here
>>> > +            // and provide a better error message for them
>>> > +
>>> > +            String message = e.getMessage();
>>> > +
>>> > +            // errors related to using facelets-only tags on a JSP
>>> > page
>>> > +            if (message != null)
>>> > +            {
>>> > +                // does the message contain "f" (prefix f of tags)
>>> > +                // or the related uri http://java.sun.com/jsf/core
>>> > +                if (message.contains("\"f\"")
>>> > +                        || message.contains("\"" +
>>> > CoreLibrary.Namespace + "\""))
>>> > +                {
>>> > +                    // check facelets-only f tags
>>> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
>>> > +                    {
>>> > +                        if (message.contains("\"" + tag + "\""))
>>> > +                        {
>>> > +                            String exceptionMessage = "The tag f:" +
>>> > tag +
>>> > +                                    " is only available on facelets.";
>>> > +                            throw new FacesException(exceptionMessage,
>>> > +                                    new
>>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>>> > +                        }
>>> > +                    }
>>> > +                }
>>> > +                else if (message.contains("\"h\"")
>>> > +                        || message.contains("\"" +
>>> > HtmlLibrary.Namespace + "\""))
>>> > +                {
>>> > +                    // check facelets-only h tags
>>> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
>>> > +                    {
>>> > +                        if (message.contains("\"" + tag + "\""))
>>> > +                        {
>>> > +                            String exceptionMessage = "The tag h:" +
>>> > tag +
>>> > +                                    " is only available on facelets.";
>>> > +                            throw new FacesException(exceptionMessage,
>>> > +                                    new
>>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>>> > +                        }
>>> > +                    }
>>> > +                }
>>> > +                else
>>> > +                {
>>> > +                    // check facelets-only namespaces
>>> > +                    String namespace = null;
>>> > +                    if (message.contains(UILibrary.Namespace))
>>> > +                    {
>>> > +                        namespace = UILibrary.Namespace;
>>> > +                    }
>>> > +                    else if
>>> > (message.contains(CompositeLibrary.NAMESPACE))
>>> > +                    {
>>> > +                        namespace = CompositeLibrary.NAMESPACE;
>>> > +                    }
>>> > +
>>> > +                    if (namespace != null)
>>> > +                    {
>>> > +                        // the message contains a facelets-only
>>> > namespace
>>> > +                        String exceptionMessage = "All tags with
>>> > namespace " +
>>> > +                                namespace + " are only available on
>>> > facelets.";
>>> > +                        throw new FacesException(exceptionMessage,
>>> > +                                new
>>> > FaceletsOnlyException(exceptionMessage, e.getCause()));
>>> > +                    }
>>> > +                }
>>> > +            }
>>> > +
>>> > +            // no rule applied to this Exception - rethrow it
>>> > +            throw e;
>>> > +        }
>>> > +        finally
>>> > +        {
>>> > +            externalContext.setResponse(response);
>>> > +        }
>>> > +
>>> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>>> > wrappedResponse.getStatus() > 299;
>>> > +        if (errorResponse)
>>> > +        {
>>> > +            wrappedResponse.flushToWrappedResponse();
>>> > +            return;
>>> > +        }
>>> > +
>>> > +        //Skip this step if we are rendering an ajax request, because
>>> > no content outside
>>> > +        //f:view tag should be output.
>>> > +        if (!context.getPartialViewContext().isPartialRequest())
>>> > +        {
>>> > +            // store the wrapped response in the request, so it is
>>> > thread-safe
>>> > +            setAfterViewTagResponseWrapper(externalContext,
>>> > wrappedResponse);
>>> > +        }
>>> > +    }
>>> > +
>>> > +    @Override
>>> > +    protected void sendSourceNotFound(FacesContext context, String
>>> > message)
>>> > +    {
>>> > +        HttpServletResponse response = (HttpServletResponse)
>>> > context.getExternalContext().getResponse();
>>> > +        try
>>> > +        {
>>> > +            context.responseComplete();
>>> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>>> > message);
>>> > +        }
>>> > +        catch (IOException ioe)
>>> > +        {
>>> > +            throw new FacesException(ioe);
>>> > +        }
>>> > +    }
>>> > +
>>> > +}
>>> >
>>> > Propchange:
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >
>>> > ------------------------------------------------------------------------------
>>> >    svn:eol-style = native
>>> >
>>> > Propchange:
>>> > myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>> >
>>> > ------------------------------------------------------------------------------
>>> >    svn:keywords = Date Author Id Revision HeadURL
>>> >
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Matthias Wessendorf
>>>
>>> blog: http://matthiaswessendorf.wordpress.com/
>>> sessions: http://www.slideshare.net/mwessendorf
>>> twitter: http://twitter.com/mwessendorf
>>
>
>
>
> --
> Jakob Korherr
>
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at
>



-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Jakob Korherr <ja...@gmail.com>.
WTF? Did anyone read my mail on that? It cannot be a FacesException, because
then the message would be lost!


2010/4/14 Leonardo Uribe <lu...@gmail.com>

>
>
> 2010/4/14 Matthias Wessendorf <ma...@apache.org>
>
>> public class FaceletsOnlyException extends Exception
>>
>>
>>
>> ==> can you make that extending FacesException ?
>>
>>
> Yes, no problem. It is done.
>
>
>> -Matthias
>>
>> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
>> > Author: jakobk
>> > Date: Wed Apr 14 17:48:28 2010
>> > New Revision: 934048
>> >
>> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
>> > Log:
>> > MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X)
>> pages
>> >
>> > Added:
>> >
>>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>>   (with props)
>> > Modified:
>> >
>>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>>   (contents, props changed)
>> >
>> > Added:
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> > URL:
>> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
>> >
>> ==============================================================================
>> > ---
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> (added)
>> > +++
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> Wed Apr 14 17:48:28 2010
>> > @@ -0,0 +1,40 @@
>> > +/*
>> > + * Licensed to the Apache Software Foundation (ASF) under one
>> > + * or more contributor license agreements.  See the NOTICE file
>> > + * distributed with this work for additional information
>> > + * regarding copyright ownership.  The ASF licenses this file
>> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > + *
>> > + * Unless required by applicable law or agreed to in writing,
>> > + * software distributed under the License is distributed on an
>> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > + * KIND, either express or implied.  See the License for the
>> > + * specific language governing permissions and limitations
>> > + * under the License.
>> > + */
>> > +package org.apache.myfaces.view.jsp;
>> > +
>> > +/**
>> > + * An Exception that indicates that the user uses a
>> > + * facelets-only feature on a JSP.
>> > + *
>> > + * @author Jakob Korherr (latest modification by $Author$)
>> > + * @version $Revision$ $Date$
>> > + *
>> > + * @since 2.0
>> > + */
>> > +public class FaceletsOnlyException extends Exception
>> > +{
>> > +
>> > +    private static final long serialVersionUID = 4268633427284543647L;
>> > +
>> > +    public FaceletsOnlyException(String message, Throwable cause)
>> > +    {
>> > +        super(message, cause);
>> > +    }
>> > +
>> > +}
>> >
>> > Propchange:
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> ------------------------------------------------------------------------------
>> >    svn:eol-style = native
>> >
>> > Propchange:
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> ------------------------------------------------------------------------------
>> >    svn:keywords = Date Author Id Revision HeadURL
>> >
>> > Propchange:
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>> >
>> ------------------------------------------------------------------------------
>> >    svn:mime-type = text/plain
>> >
>> > Modified:
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> > URL:
>> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
>> >
>> ==============================================================================
>> > ---
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> (original)
>> > +++
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> Wed Apr 14 17:48:28 2010
>> > @@ -1,139 +1,222 @@
>> > -/*
>> > - * Licensed to the Apache Software Foundation (ASF) under one
>> > - * or more contributor license agreements.  See the NOTICE file
>> > - * distributed with this work for additional information
>> > - * regarding copyright ownership.  The ASF licenses this file
>> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > - *
>> > - * Unless required by applicable law or agreed to in writing,
>> > - * software distributed under the License is distributed on an
>> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > - * KIND, either express or implied.  See the License for the
>> > - * specific language governing permissions and limitations
>> > - * under the License.
>> > - */
>> > -package org.apache.myfaces.view.jsp;
>> > -
>> > -import java.io.IOException;
>> > -import java.util.Locale;
>> > -import java.util.logging.Level;
>> > -import java.util.logging.Logger;
>> > -
>> > -import javax.faces.FacesException;
>> > -import javax.faces.component.UIViewRoot;
>> > -import javax.faces.context.ExternalContext;
>> > -import javax.faces.context.FacesContext;
>> > -import javax.servlet.ServletRequest;
>> > -import javax.servlet.ServletResponse;
>> > -import javax.servlet.http.HttpServletResponse;
>> > -import javax.servlet.jsp.jstl.core.Config;
>> > -
>> > -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
>> > -import
>> org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>> > -import org.apache.myfaces.util.ExternalContextUtils;
>> > -
>> > -/**
>> > - * @author Simon Lessard (latest modification by $Author: slessard $)
>> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400 (mer.,
>> 17 sept. 2008) $
>> > - *
>> > - * @since 2.0
>> > - */
>> > -public class JspViewDeclarationLanguage extends
>> JspViewDeclarationLanguageBase
>> > -{
>> > -    //private static final Log log =
>> LogFactory.getLog(JspViewDeclarationLanguage.class);
>> > -    public static final Logger log =
>> Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>> > -    /**
>> > -     *
>> > -     */
>> > -    public JspViewDeclarationLanguage()
>> > -    {
>> > -        if (log.isLoggable(Level.FINEST))
>> > -            log.finest("New JspViewDeclarationLanguage instance
>> created");
>> > -    }
>> > -
>> > -    /**
>> > -     * {@inheritDoc}
>> > -     */
>> > -    @Override
>> > -    public void buildView(FacesContext context, UIViewRoot view) throws
>> IOException
>> > -    {
>> > -        ExternalContext externalContext = context.getExternalContext();
>> > -
>> > -        if (context.getPartialViewContext().isPartialRequest())
>> > -        {
>> > -            // try to get (or create) a ResponseSwitch and turn off the
>> output
>> > -            Object origResponse =
>> context.getExternalContext().getResponse();
>> > -            ResponseSwitch responseSwitch =
>> ExternalContextUtils.getResponseSwitch(origResponse);
>> > -            if (responseSwitch == null)
>> > -            {
>> > -                // no ResponseSwitch installed yet - create one
>> > -                responseSwitch =
>> ExternalContextUtils.createResponseSwitch(origResponse);
>> > -                if (responseSwitch != null)
>> > -                {
>> > -                    // install the ResponseSwitch
>> > -
>>  context.getExternalContext().setResponse(responseSwitch);
>> > -                }
>> > -            }
>> > -            if (responseSwitch != null)
>> > -            {
>> > -                responseSwitch.setEnabled(context, false);
>> > -            }
>> > -        }
>> > -
>> > -        ServletResponse response = (ServletResponse)
>> externalContext.getResponse();
>> > -        ServletRequest request = (ServletRequest)
>> externalContext.getRequest();
>> > -
>> > -        Locale locale = view.getLocale();
>> > -        response.setLocale(locale);
>> > -        Config.set(request, Config.FMT_LOCALE,
>> context.getViewRoot().getLocale());
>> > -
>> > -        String viewId = view.getViewId();
>> > -        ServletViewResponseWrapper wrappedResponse = new
>> ServletViewResponseWrapper((HttpServletResponse) response);
>> > -
>> > -        externalContext.setResponse(wrappedResponse);
>> > -        try
>> > -        {
>> > -            externalContext.dispatch(viewId);
>> > -        }
>> > -        finally
>> > -        {
>> > -            externalContext.setResponse(response);
>> > -        }
>> > -
>> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>> wrappedResponse.getStatus() > 299;
>> > -        if (errorResponse)
>> > -        {
>> > -            wrappedResponse.flushToWrappedResponse();
>> > -            return;
>> > -        }
>> > -
>> > -        //Skip this step if we are rendering an ajax request, because
>> no content outside
>> > -        //f:view tag should be output.
>> > -        if (!context.getPartialViewContext().isPartialRequest())
>> > -        {
>> > -            // store the wrapped response in the request, so it is
>> thread-safe
>> > -            setAfterViewTagResponseWrapper(externalContext,
>> wrappedResponse);
>> > -        }
>> > -    }
>> > -
>> > -    @Override
>> > -    protected void sendSourceNotFound(FacesContext context, String
>> message)
>> > -    {
>> > -        HttpServletResponse response = (HttpServletResponse)
>> context.getExternalContext().getResponse();
>> > -        try
>> > -        {
>> > -            context.responseComplete();
>> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>> message);
>> > -        }
>> > -        catch (IOException ioe)
>> > -        {
>> > -            throw new FacesException(ioe);
>> > -        }
>> > -    }
>> > -
>> > -}
>> > +/*
>> > + * Licensed to the Apache Software Foundation (ASF) under one
>> > + * or more contributor license agreements.  See the NOTICE file
>> > + * distributed with this work for additional information
>> > + * regarding copyright ownership.  The ASF licenses this file
>> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
>> > + *
>> > + * Unless required by applicable law or agreed to in writing,
>> > + * software distributed under the License is distributed on an
>> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> > + * KIND, either express or implied.  See the License for the
>> > + * specific language governing permissions and limitations
>> > + * under the License.
>> > + */
>> > +package org.apache.myfaces.view.jsp;
>> > +
>> > +import java.io.IOException;
>> > +import java.util.Locale;
>> > +import java.util.logging.Level;
>> > +import java.util.logging.Logger;
>> > +
>> > +import javax.faces.FacesException;
>> > +import javax.faces.component.UIViewRoot;
>> > +import javax.faces.context.ExternalContext;
>> > +import javax.faces.context.FacesContext;
>> > +import javax.servlet.ServletRequest;
>> > +import javax.servlet.ServletResponse;
>> > +import javax.servlet.http.HttpServletResponse;
>> > +import javax.servlet.jsp.jstl.core.Config;
>> > +
>> > +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
>> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
>> > +import
>> org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
>> > +import org.apache.myfaces.util.ExternalContextUtils;
>> > +import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
>> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
>> > +
>> > +/**
>> > + * @author Simon Lessard (latest modification by $Author$)
>> > + * @version $Revision$ $Date$
>> > + *
>> > + * @since 2.0
>> > + */
>> > +public class JspViewDeclarationLanguage extends
>> JspViewDeclarationLanguageBase
>> > +{
>> > +    //private static final Log log =
>> LogFactory.getLog(JspViewDeclarationLanguage.class);
>> > +    public static final Logger log =
>> Logger.getLogger(JspViewDeclarationLanguage.class.getName());
>> > +
>> > +    /**
>> > +     * Tags that are only available on facelets and not on JSP.
>> > +     * If a user uses one of these tags on a JSP, we will provide
>> > +     * a more informative error message than the standard one.
>> > +     */
>> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
>> "event", "metadata"};
>> > +    public static final String[] FACELETS_ONLY_H_TAGS =
>> {"outputScript", "outputStylesheet",
>> > +                                                         "head",
>> "body", "button", "link"};
>> > +
>> > +    /**
>> > +     *
>> > +     */
>> > +    public JspViewDeclarationLanguage()
>> > +    {
>> > +        if (log.isLoggable(Level.FINEST))
>> > +            log.finest("New JspViewDeclarationLanguage instance
>> created");
>> > +    }
>> > +
>> > +    /**
>> > +     * {@inheritDoc}
>> > +     */
>> > +    @Override
>> > +    public void buildView(FacesContext context, UIViewRoot view) throws
>> IOException
>> > +    {
>> > +        ExternalContext externalContext = context.getExternalContext();
>> > +
>> > +        if (context.getPartialViewContext().isPartialRequest())
>> > +        {
>> > +            // try to get (or create) a ResponseSwitch and turn off the
>> output
>> > +            Object origResponse =
>> context.getExternalContext().getResponse();
>> > +            ResponseSwitch responseSwitch =
>> ExternalContextUtils.getResponseSwitch(origResponse);
>> > +            if (responseSwitch == null)
>> > +            {
>> > +                // no ResponseSwitch installed yet - create one
>> > +                responseSwitch =
>> ExternalContextUtils.createResponseSwitch(origResponse);
>> > +                if (responseSwitch != null)
>> > +                {
>> > +                    // install the ResponseSwitch
>> > +
>>  context.getExternalContext().setResponse(responseSwitch);
>> > +                }
>> > +            }
>> > +            if (responseSwitch != null)
>> > +            {
>> > +                responseSwitch.setEnabled(context, false);
>> > +            }
>> > +        }
>> > +
>> > +        ServletResponse response = (ServletResponse)
>> externalContext.getResponse();
>> > +        ServletRequest request = (ServletRequest)
>> externalContext.getRequest();
>> > +
>> > +        Locale locale = view.getLocale();
>> > +        response.setLocale(locale);
>> > +        Config.set(request, Config.FMT_LOCALE,
>> context.getViewRoot().getLocale());
>> > +
>> > +        String viewId = view.getViewId();
>> > +        ServletViewResponseWrapper wrappedResponse = new
>> ServletViewResponseWrapper((HttpServletResponse) response);
>> > +
>> > +        externalContext.setResponse(wrappedResponse);
>> > +        try
>> > +        {
>> > +            externalContext.dispatch(viewId);
>> > +        }
>> > +        catch (FacesException e)
>> > +        {
>> > +            // try to extract the most likely exceptions here
>> > +            // and provide a better error message for them
>> > +
>> > +            String message = e.getMessage();
>> > +
>> > +            // errors related to using facelets-only tags on a JSP page
>> > +            if (message != null)
>> > +            {
>> > +                // does the message contain "f" (prefix f of tags)
>> > +                // or the related uri http://java.sun.com/jsf/core
>> > +                if (message.contains("\"f\"")
>> > +                        || message.contains("\"" +
>> CoreLibrary.Namespace + "\""))
>> > +                {
>> > +                    // check facelets-only f tags
>> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
>> > +                    {
>> > +                        if (message.contains("\"" + tag + "\""))
>> > +                        {
>> > +                            String exceptionMessage = "The tag f:" +
>> tag +
>> > +                                    " is only available on facelets.";
>> > +                            throw new FacesException(exceptionMessage,
>> > +                                    new
>> FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                        }
>> > +                    }
>> > +                }
>> > +                else if (message.contains("\"h\"")
>> > +                        || message.contains("\"" +
>> HtmlLibrary.Namespace + "\""))
>> > +                {
>> > +                    // check facelets-only h tags
>> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
>> > +                    {
>> > +                        if (message.contains("\"" + tag + "\""))
>> > +                        {
>> > +                            String exceptionMessage = "The tag h:" +
>> tag +
>> > +                                    " is only available on facelets.";
>> > +                            throw new FacesException(exceptionMessage,
>> > +                                    new
>> FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                        }
>> > +                    }
>> > +                }
>> > +                else
>> > +                {
>> > +                    // check facelets-only namespaces
>> > +                    String namespace = null;
>> > +                    if (message.contains(UILibrary.Namespace))
>> > +                    {
>> > +                        namespace = UILibrary.Namespace;
>> > +                    }
>> > +                    else if
>> (message.contains(CompositeLibrary.NAMESPACE))
>> > +                    {
>> > +                        namespace = CompositeLibrary.NAMESPACE;
>> > +                    }
>> > +
>> > +                    if (namespace != null)
>> > +                    {
>> > +                        // the message contains a facelets-only
>> namespace
>> > +                        String exceptionMessage = "All tags with
>> namespace " +
>> > +                                namespace + " are only available on
>> facelets.";
>> > +                        throw new FacesException(exceptionMessage,
>> > +                                new
>> FaceletsOnlyException(exceptionMessage, e.getCause()));
>> > +                    }
>> > +                }
>> > +            }
>> > +
>> > +            // no rule applied to this Exception - rethrow it
>> > +            throw e;
>> > +        }
>> > +        finally
>> > +        {
>> > +            externalContext.setResponse(response);
>> > +        }
>> > +
>> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
>> wrappedResponse.getStatus() > 299;
>> > +        if (errorResponse)
>> > +        {
>> > +            wrappedResponse.flushToWrappedResponse();
>> > +            return;
>> > +        }
>> > +
>> > +        //Skip this step if we are rendering an ajax request, because
>> no content outside
>> > +        //f:view tag should be output.
>> > +        if (!context.getPartialViewContext().isPartialRequest())
>> > +        {
>> > +            // store the wrapped response in the request, so it is
>> thread-safe
>> > +            setAfterViewTagResponseWrapper(externalContext,
>> wrappedResponse);
>> > +        }
>> > +    }
>> > +
>> > +    @Override
>> > +    protected void sendSourceNotFound(FacesContext context, String
>> message)
>> > +    {
>> > +        HttpServletResponse response = (HttpServletResponse)
>> context.getExternalContext().getResponse();
>> > +        try
>> > +        {
>> > +            context.responseComplete();
>> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
>> message);
>> > +        }
>> > +        catch (IOException ioe)
>> > +        {
>> > +            throw new FacesException(ioe);
>> > +        }
>> > +    }
>> > +
>> > +}
>> >
>> > Propchange:
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >
>> ------------------------------------------------------------------------------
>> >    svn:eol-style = native
>> >
>> > Propchange:
>> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>> >
>> ------------------------------------------------------------------------------
>> >    svn:keywords = Date Author Id Revision HeadURL
>> >
>> >
>> >
>>
>>
>>
>> --
>> Matthias Wessendorf
>>
>> blog: http://matthiaswessendorf.wordpress.com/
>> sessions: http://www.slideshare.net/mwessendorf
>> twitter: http://twitter.com/mwessendorf
>>
>
>


-- 
Jakob Korherr

blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Leonardo Uribe <lu...@gmail.com>.
2010/4/14 Matthias Wessendorf <ma...@apache.org>

> public class FaceletsOnlyException extends Exception
>
>
> ==> can you make that extending FacesException ?
>
>
Yes, no problem. It is done.


> -Matthias
>
> On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
> > Author: jakobk
> > Date: Wed Apr 14 17:48:28 2010
> > New Revision: 934048
> >
> > URL: http://svn.apache.org/viewvc?rev=934048&view=rev
> > Log:
> > MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X)
> pages
> >
> > Added:
> >
>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
>   (with props)
> > Modified:
> >
>  myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
>   (contents, props changed)
> >
> > Added:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
> >
> ==============================================================================
> > ---
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> (added)
> > +++
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> Wed Apr 14 17:48:28 2010
> > @@ -0,0 +1,40 @@
> > +/*
> > + * Licensed to the Apache Software Foundation (ASF) under one
> > + * or more contributor license agreements.  See the NOTICE file
> > + * distributed with this work for additional information
> > + * regarding copyright ownership.  The ASF licenses this file
> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > + *
> > + * Unless required by applicable law or agreed to in writing,
> > + * software distributed under the License is distributed on an
> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > + * KIND, either express or implied.  See the License for the
> > + * specific language governing permissions and limitations
> > + * under the License.
> > + */
> > +package org.apache.myfaces.view.jsp;
> > +
> > +/**
> > + * An Exception that indicates that the user uses a
> > + * facelets-only feature on a JSP.
> > + *
> > + * @author Jakob Korherr (latest modification by $Author$)
> > + * @version $Revision$ $Date$
> > + *
> > + * @since 2.0
> > + */
> > +public class FaceletsOnlyException extends Exception
> > +{
> > +
> > +    private static final long serialVersionUID = 4268633427284543647L;
> > +
> > +    public FaceletsOnlyException(String message, Throwable cause)
> > +    {
> > +        super(message, cause);
> > +    }
> > +
> > +}
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:eol-style = native
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:keywords = Date Author Id Revision HeadURL
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> >
> ------------------------------------------------------------------------------
> >    svn:mime-type = text/plain
> >
> > Modified:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> > URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
> >
> ==============================================================================
> > ---
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> (original)
> > +++
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> Wed Apr 14 17:48:28 2010
> > @@ -1,139 +1,222 @@
> > -/*
> > - * Licensed to the Apache Software Foundation (ASF) under one
> > - * or more contributor license agreements.  See the NOTICE file
> > - * distributed with this work for additional information
> > - * regarding copyright ownership.  The ASF licenses this file
> > - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > - *
> > - * Unless required by applicable law or agreed to in writing,
> > - * software distributed under the License is distributed on an
> > - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > - * KIND, either express or implied.  See the License for the
> > - * specific language governing permissions and limitations
> > - * under the License.
> > - */
> > -package org.apache.myfaces.view.jsp;
> > -
> > -import java.io.IOException;
> > -import java.util.Locale;
> > -import java.util.logging.Level;
> > -import java.util.logging.Logger;
> > -
> > -import javax.faces.FacesException;
> > -import javax.faces.component.UIViewRoot;
> > -import javax.faces.context.ExternalContext;
> > -import javax.faces.context.FacesContext;
> > -import javax.servlet.ServletRequest;
> > -import javax.servlet.ServletResponse;
> > -import javax.servlet.http.HttpServletResponse;
> > -import javax.servlet.jsp.jstl.core.Config;
> > -
> > -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> > -import org.apache.myfaces.context.servlet.ResponseSwitch;
> > -import
> org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> > -import org.apache.myfaces.util.ExternalContextUtils;
> > -
> > -/**
> > - * @author Simon Lessard (latest modification by $Author: slessard $)
> > - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400 (mer.,
> 17 sept. 2008) $
> > - *
> > - * @since 2.0
> > - */
> > -public class JspViewDeclarationLanguage extends
> JspViewDeclarationLanguageBase
> > -{
> > -    //private static final Log log =
> LogFactory.getLog(JspViewDeclarationLanguage.class);
> > -    public static final Logger log =
> Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> > -    /**
> > -     *
> > -     */
> > -    public JspViewDeclarationLanguage()
> > -    {
> > -        if (log.isLoggable(Level.FINEST))
> > -            log.finest("New JspViewDeclarationLanguage instance
> created");
> > -    }
> > -
> > -    /**
> > -     * {@inheritDoc}
> > -     */
> > -    @Override
> > -    public void buildView(FacesContext context, UIViewRoot view) throws
> IOException
> > -    {
> > -        ExternalContext externalContext = context.getExternalContext();
> > -
> > -        if (context.getPartialViewContext().isPartialRequest())
> > -        {
> > -            // try to get (or create) a ResponseSwitch and turn off the
> output
> > -            Object origResponse =
> context.getExternalContext().getResponse();
> > -            ResponseSwitch responseSwitch =
> ExternalContextUtils.getResponseSwitch(origResponse);
> > -            if (responseSwitch == null)
> > -            {
> > -                // no ResponseSwitch installed yet - create one
> > -                responseSwitch =
> ExternalContextUtils.createResponseSwitch(origResponse);
> > -                if (responseSwitch != null)
> > -                {
> > -                    // install the ResponseSwitch
> > -
>  context.getExternalContext().setResponse(responseSwitch);
> > -                }
> > -            }
> > -            if (responseSwitch != null)
> > -            {
> > -                responseSwitch.setEnabled(context, false);
> > -            }
> > -        }
> > -
> > -        ServletResponse response = (ServletResponse)
> externalContext.getResponse();
> > -        ServletRequest request = (ServletRequest)
> externalContext.getRequest();
> > -
> > -        Locale locale = view.getLocale();
> > -        response.setLocale(locale);
> > -        Config.set(request, Config.FMT_LOCALE,
> context.getViewRoot().getLocale());
> > -
> > -        String viewId = view.getViewId();
> > -        ServletViewResponseWrapper wrappedResponse = new
> ServletViewResponseWrapper((HttpServletResponse) response);
> > -
> > -        externalContext.setResponse(wrappedResponse);
> > -        try
> > -        {
> > -            externalContext.dispatch(viewId);
> > -        }
> > -        finally
> > -        {
> > -            externalContext.setResponse(response);
> > -        }
> > -
> > -        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
> wrappedResponse.getStatus() > 299;
> > -        if (errorResponse)
> > -        {
> > -            wrappedResponse.flushToWrappedResponse();
> > -            return;
> > -        }
> > -
> > -        //Skip this step if we are rendering an ajax request, because no
> content outside
> > -        //f:view tag should be output.
> > -        if (!context.getPartialViewContext().isPartialRequest())
> > -        {
> > -            // store the wrapped response in the request, so it is
> thread-safe
> > -            setAfterViewTagResponseWrapper(externalContext,
> wrappedResponse);
> > -        }
> > -    }
> > -
> > -    @Override
> > -    protected void sendSourceNotFound(FacesContext context, String
> message)
> > -    {
> > -        HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
> > -        try
> > -        {
> > -            context.responseComplete();
> > -            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> message);
> > -        }
> > -        catch (IOException ioe)
> > -        {
> > -            throw new FacesException(ioe);
> > -        }
> > -    }
> > -
> > -}
> > +/*
> > + * Licensed to the Apache Software Foundation (ASF) under one
> > + * or more contributor license agreements.  See the NOTICE file
> > + * distributed with this work for additional information
> > + * regarding copyright ownership.  The ASF licenses this file
> > + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> > + *
> > + * Unless required by applicable law or agreed to in writing,
> > + * software distributed under the License is distributed on an
> > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> > + * KIND, either express or implied.  See the License for the
> > + * specific language governing permissions and limitations
> > + * under the License.
> > + */
> > +package org.apache.myfaces.view.jsp;
> > +
> > +import java.io.IOException;
> > +import java.util.Locale;
> > +import java.util.logging.Level;
> > +import java.util.logging.Logger;
> > +
> > +import javax.faces.FacesException;
> > +import javax.faces.component.UIViewRoot;
> > +import javax.faces.context.ExternalContext;
> > +import javax.faces.context.FacesContext;
> > +import javax.servlet.ServletRequest;
> > +import javax.servlet.ServletResponse;
> > +import javax.servlet.http.HttpServletResponse;
> > +import javax.servlet.jsp.jstl.core.Config;
> > +
> > +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> > +import org.apache.myfaces.context.servlet.ResponseSwitch;
> > +import
> org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> > +import org.apache.myfaces.util.ExternalContextUtils;
> > +import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
> > +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
> > +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
> > +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
> > +
> > +/**
> > + * @author Simon Lessard (latest modification by $Author$)
> > + * @version $Revision$ $Date$
> > + *
> > + * @since 2.0
> > + */
> > +public class JspViewDeclarationLanguage extends
> JspViewDeclarationLanguageBase
> > +{
> > +    //private static final Log log =
> LogFactory.getLog(JspViewDeclarationLanguage.class);
> > +    public static final Logger log =
> Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> > +
> > +    /**
> > +     * Tags that are only available on facelets and not on JSP.
> > +     * If a user uses one of these tags on a JSP, we will provide
> > +     * a more informative error message than the standard one.
> > +     */
> > +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax",
> "event", "metadata"};
> > +    public static final String[] FACELETS_ONLY_H_TAGS = {"outputScript",
> "outputStylesheet",
> > +                                                         "head", "body",
> "button", "link"};
> > +
> > +    /**
> > +     *
> > +     */
> > +    public JspViewDeclarationLanguage()
> > +    {
> > +        if (log.isLoggable(Level.FINEST))
> > +            log.finest("New JspViewDeclarationLanguage instance
> created");
> > +    }
> > +
> > +    /**
> > +     * {@inheritDoc}
> > +     */
> > +    @Override
> > +    public void buildView(FacesContext context, UIViewRoot view) throws
> IOException
> > +    {
> > +        ExternalContext externalContext = context.getExternalContext();
> > +
> > +        if (context.getPartialViewContext().isPartialRequest())
> > +        {
> > +            // try to get (or create) a ResponseSwitch and turn off the
> output
> > +            Object origResponse =
> context.getExternalContext().getResponse();
> > +            ResponseSwitch responseSwitch =
> ExternalContextUtils.getResponseSwitch(origResponse);
> > +            if (responseSwitch == null)
> > +            {
> > +                // no ResponseSwitch installed yet - create one
> > +                responseSwitch =
> ExternalContextUtils.createResponseSwitch(origResponse);
> > +                if (responseSwitch != null)
> > +                {
> > +                    // install the ResponseSwitch
> > +
>  context.getExternalContext().setResponse(responseSwitch);
> > +                }
> > +            }
> > +            if (responseSwitch != null)
> > +            {
> > +                responseSwitch.setEnabled(context, false);
> > +            }
> > +        }
> > +
> > +        ServletResponse response = (ServletResponse)
> externalContext.getResponse();
> > +        ServletRequest request = (ServletRequest)
> externalContext.getRequest();
> > +
> > +        Locale locale = view.getLocale();
> > +        response.setLocale(locale);
> > +        Config.set(request, Config.FMT_LOCALE,
> context.getViewRoot().getLocale());
> > +
> > +        String viewId = view.getViewId();
> > +        ServletViewResponseWrapper wrappedResponse = new
> ServletViewResponseWrapper((HttpServletResponse) response);
> > +
> > +        externalContext.setResponse(wrappedResponse);
> > +        try
> > +        {
> > +            externalContext.dispatch(viewId);
> > +        }
> > +        catch (FacesException e)
> > +        {
> > +            // try to extract the most likely exceptions here
> > +            // and provide a better error message for them
> > +
> > +            String message = e.getMessage();
> > +
> > +            // errors related to using facelets-only tags on a JSP page
> > +            if (message != null)
> > +            {
> > +                // does the message contain "f" (prefix f of tags)
> > +                // or the related uri http://java.sun.com/jsf/core
> > +                if (message.contains("\"f\"")
> > +                        || message.contains("\"" + CoreLibrary.Namespace
> + "\""))
> > +                {
> > +                    // check facelets-only f tags
> > +                    for (String tag : FACELETS_ONLY_F_TAGS)
> > +                    {
> > +                        if (message.contains("\"" + tag + "\""))
> > +                        {
> > +                            String exceptionMessage = "The tag f:" + tag
> +
> > +                                    " is only available on facelets.";
> > +                            throw new FacesException(exceptionMessage,
> > +                                    new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                        }
> > +                    }
> > +                }
> > +                else if (message.contains("\"h\"")
> > +                        || message.contains("\"" + HtmlLibrary.Namespace
> + "\""))
> > +                {
> > +                    // check facelets-only h tags
> > +                    for (String tag : FACELETS_ONLY_H_TAGS)
> > +                    {
> > +                        if (message.contains("\"" + tag + "\""))
> > +                        {
> > +                            String exceptionMessage = "The tag h:" + tag
> +
> > +                                    " is only available on facelets.";
> > +                            throw new FacesException(exceptionMessage,
> > +                                    new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                        }
> > +                    }
> > +                }
> > +                else
> > +                {
> > +                    // check facelets-only namespaces
> > +                    String namespace = null;
> > +                    if (message.contains(UILibrary.Namespace))
> > +                    {
> > +                        namespace = UILibrary.Namespace;
> > +                    }
> > +                    else if
> (message.contains(CompositeLibrary.NAMESPACE))
> > +                    {
> > +                        namespace = CompositeLibrary.NAMESPACE;
> > +                    }
> > +
> > +                    if (namespace != null)
> > +                    {
> > +                        // the message contains a facelets-only
> namespace
> > +                        String exceptionMessage = "All tags with
> namespace " +
> > +                                namespace + " are only available on
> facelets.";
> > +                        throw new FacesException(exceptionMessage,
> > +                                new
> FaceletsOnlyException(exceptionMessage, e.getCause()));
> > +                    }
> > +                }
> > +            }
> > +
> > +            // no rule applied to this Exception - rethrow it
> > +            throw e;
> > +        }
> > +        finally
> > +        {
> > +            externalContext.setResponse(response);
> > +        }
> > +
> > +        boolean errorResponse = wrappedResponse.getStatus() < 200 ||
> wrappedResponse.getStatus() > 299;
> > +        if (errorResponse)
> > +        {
> > +            wrappedResponse.flushToWrappedResponse();
> > +            return;
> > +        }
> > +
> > +        //Skip this step if we are rendering an ajax request, because no
> content outside
> > +        //f:view tag should be output.
> > +        if (!context.getPartialViewContext().isPartialRequest())
> > +        {
> > +            // store the wrapped response in the request, so it is
> thread-safe
> > +            setAfterViewTagResponseWrapper(externalContext,
> wrappedResponse);
> > +        }
> > +    }
> > +
> > +    @Override
> > +    protected void sendSourceNotFound(FacesContext context, String
> message)
> > +    {
> > +        HttpServletResponse response = (HttpServletResponse)
> context.getExternalContext().getResponse();
> > +        try
> > +        {
> > +            context.responseComplete();
> > +            response.sendError(HttpServletResponse.SC_NOT_FOUND,
> message);
> > +        }
> > +        catch (IOException ioe)
> > +        {
> > +            throw new FacesException(ioe);
> > +        }
> > +    }
> > +
> > +}
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >
> ------------------------------------------------------------------------------
> >    svn:eol-style = native
> >
> > Propchange:
> myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> >
> ------------------------------------------------------------------------------
> >    svn:keywords = Date Author Id Revision HeadURL
> >
> >
> >
>
>
>
> --
> Matthias Wessendorf
>
> blog: http://matthiaswessendorf.wordpress.com/
> sessions: http://www.slideshare.net/mwessendorf
> twitter: http://twitter.com/mwessendorf
>

Re: svn commit: r934048 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp: FaceletsOnlyException.java JspViewDeclarationLanguage.java

Posted by Matthias Wessendorf <ma...@apache.org>.
public class FaceletsOnlyException extends Exception


==> can you make that extending FacesException ?

-Matthias

On Wed, Apr 14, 2010 at 7:48 PM,  <ja...@apache.org> wrote:
> Author: jakobk
> Date: Wed Apr 14 17:48:28 2010
> New Revision: 934048
>
> URL: http://svn.apache.org/viewvc?rev=934048&view=rev
> Log:
> MYFACES-2658 Indicate a better error when using Facelet TAGs on JSP(X) pages
>
> Added:
>    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java   (with props)
> Modified:
>    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java   (contents, props changed)
>
> Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java?rev=934048&view=auto
> ==============================================================================
> --- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java (added)
> +++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java Wed Apr 14 17:48:28 2010
> @@ -0,0 +1,40 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.myfaces.view.jsp;
> +
> +/**
> + * An Exception that indicates that the user uses a
> + * facelets-only feature on a JSP.
> + *
> + * @author Jakob Korherr (latest modification by $Author$)
> + * @version $Revision$ $Date$
> + *
> + * @since 2.0
> + */
> +public class FaceletsOnlyException extends Exception
> +{
> +
> +    private static final long serialVersionUID = 4268633427284543647L;
> +
> +    public FaceletsOnlyException(String message, Throwable cause)
> +    {
> +        super(message, cause);
> +    }
> +
> +}
>
> Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> ------------------------------------------------------------------------------
>    svn:keywords = Date Author Id Revision HeadURL
>
> Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/FaceletsOnlyException.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=934048&r1=934047&r2=934048&view=diff
> ==============================================================================
> --- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java (original)
> +++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java Wed Apr 14 17:48:28 2010
> @@ -1,139 +1,222 @@
> -/*
> - * Licensed to the Apache Software Foundation (ASF) under one
> - * or more contributor license agreements.  See the NOTICE file
> - * distributed with this work for additional information
> - * regarding copyright ownership.  The ASF licenses this file
> - * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> - *
> - * Unless required by applicable law or agreed to in writing,
> - * software distributed under the License is distributed on an
> - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> - * KIND, either express or implied.  See the License for the
> - * specific language governing permissions and limitations
> - * under the License.
> - */
> -package org.apache.myfaces.view.jsp;
> -
> -import java.io.IOException;
> -import java.util.Locale;
> -import java.util.logging.Level;
> -import java.util.logging.Logger;
> -
> -import javax.faces.FacesException;
> -import javax.faces.component.UIViewRoot;
> -import javax.faces.context.ExternalContext;
> -import javax.faces.context.FacesContext;
> -import javax.servlet.ServletRequest;
> -import javax.servlet.ServletResponse;
> -import javax.servlet.http.HttpServletResponse;
> -import javax.servlet.jsp.jstl.core.Config;
> -
> -import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> -import org.apache.myfaces.context.servlet.ResponseSwitch;
> -import org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> -import org.apache.myfaces.util.ExternalContextUtils;
> -
> -/**
> - * @author Simon Lessard (latest modification by $Author: slessard $)
> - * @version $Revision: 696523 $ $Date: 2009-03-22 13:55:12 -0400 (mer., 17 sept. 2008) $
> - *
> - * @since 2.0
> - */
> -public class JspViewDeclarationLanguage extends JspViewDeclarationLanguageBase
> -{
> -    //private static final Log log = LogFactory.getLog(JspViewDeclarationLanguage.class);
> -    public static final Logger log = Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> -    /**
> -     *
> -     */
> -    public JspViewDeclarationLanguage()
> -    {
> -        if (log.isLoggable(Level.FINEST))
> -            log.finest("New JspViewDeclarationLanguage instance created");
> -    }
> -
> -    /**
> -     * {@inheritDoc}
> -     */
> -    @Override
> -    public void buildView(FacesContext context, UIViewRoot view) throws IOException
> -    {
> -        ExternalContext externalContext = context.getExternalContext();
> -
> -        if (context.getPartialViewContext().isPartialRequest())
> -        {
> -            // try to get (or create) a ResponseSwitch and turn off the output
> -            Object origResponse = context.getExternalContext().getResponse();
> -            ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(origResponse);
> -            if (responseSwitch == null)
> -            {
> -                // no ResponseSwitch installed yet - create one
> -                responseSwitch = ExternalContextUtils.createResponseSwitch(origResponse);
> -                if (responseSwitch != null)
> -                {
> -                    // install the ResponseSwitch
> -                    context.getExternalContext().setResponse(responseSwitch);
> -                }
> -            }
> -            if (responseSwitch != null)
> -            {
> -                responseSwitch.setEnabled(context, false);
> -            }
> -        }
> -
> -        ServletResponse response = (ServletResponse) externalContext.getResponse();
> -        ServletRequest request = (ServletRequest) externalContext.getRequest();
> -
> -        Locale locale = view.getLocale();
> -        response.setLocale(locale);
> -        Config.set(request, Config.FMT_LOCALE, context.getViewRoot().getLocale());
> -
> -        String viewId = view.getViewId();
> -        ServletViewResponseWrapper wrappedResponse = new ServletViewResponseWrapper((HttpServletResponse) response);
> -
> -        externalContext.setResponse(wrappedResponse);
> -        try
> -        {
> -            externalContext.dispatch(viewId);
> -        }
> -        finally
> -        {
> -            externalContext.setResponse(response);
> -        }
> -
> -        boolean errorResponse = wrappedResponse.getStatus() < 200 || wrappedResponse.getStatus() > 299;
> -        if (errorResponse)
> -        {
> -            wrappedResponse.flushToWrappedResponse();
> -            return;
> -        }
> -
> -        //Skip this step if we are rendering an ajax request, because no content outside
> -        //f:view tag should be output.
> -        if (!context.getPartialViewContext().isPartialRequest())
> -        {
> -            // store the wrapped response in the request, so it is thread-safe
> -            setAfterViewTagResponseWrapper(externalContext, wrappedResponse);
> -        }
> -    }
> -
> -    @Override
> -    protected void sendSourceNotFound(FacesContext context, String message)
> -    {
> -        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
> -        try
> -        {
> -            context.responseComplete();
> -            response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
> -        }
> -        catch (IOException ioe)
> -        {
> -            throw new FacesException(ioe);
> -        }
> -    }
> -
> -}
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.myfaces.view.jsp;
> +
> +import java.io.IOException;
> +import java.util.Locale;
> +import java.util.logging.Level;
> +import java.util.logging.Logger;
> +
> +import javax.faces.FacesException;
> +import javax.faces.component.UIViewRoot;
> +import javax.faces.context.ExternalContext;
> +import javax.faces.context.FacesContext;
> +import javax.servlet.ServletRequest;
> +import javax.servlet.ServletResponse;
> +import javax.servlet.http.HttpServletResponse;
> +import javax.servlet.jsp.jstl.core.Config;
> +
> +import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
> +import org.apache.myfaces.context.servlet.ResponseSwitch;
> +import org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
> +import org.apache.myfaces.util.ExternalContextUtils;
> +import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
> +import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
> +import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
> +import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
> +
> +/**
> + * @author Simon Lessard (latest modification by $Author$)
> + * @version $Revision$ $Date$
> + *
> + * @since 2.0
> + */
> +public class JspViewDeclarationLanguage extends JspViewDeclarationLanguageBase
> +{
> +    //private static final Log log = LogFactory.getLog(JspViewDeclarationLanguage.class);
> +    public static final Logger log = Logger.getLogger(JspViewDeclarationLanguage.class.getName());
> +
> +    /**
> +     * Tags that are only available on facelets and not on JSP.
> +     * If a user uses one of these tags on a JSP, we will provide
> +     * a more informative error message than the standard one.
> +     */
> +    public static final String[] FACELETS_ONLY_F_TAGS = {"ajax", "event", "metadata"};
> +    public static final String[] FACELETS_ONLY_H_TAGS = {"outputScript", "outputStylesheet",
> +                                                         "head", "body", "button", "link"};
> +
> +    /**
> +     *
> +     */
> +    public JspViewDeclarationLanguage()
> +    {
> +        if (log.isLoggable(Level.FINEST))
> +            log.finest("New JspViewDeclarationLanguage instance created");
> +    }
> +
> +    /**
> +     * {@inheritDoc}
> +     */
> +    @Override
> +    public void buildView(FacesContext context, UIViewRoot view) throws IOException
> +    {
> +        ExternalContext externalContext = context.getExternalContext();
> +
> +        if (context.getPartialViewContext().isPartialRequest())
> +        {
> +            // try to get (or create) a ResponseSwitch and turn off the output
> +            Object origResponse = context.getExternalContext().getResponse();
> +            ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(origResponse);
> +            if (responseSwitch == null)
> +            {
> +                // no ResponseSwitch installed yet - create one
> +                responseSwitch = ExternalContextUtils.createResponseSwitch(origResponse);
> +                if (responseSwitch != null)
> +                {
> +                    // install the ResponseSwitch
> +                    context.getExternalContext().setResponse(responseSwitch);
> +                }
> +            }
> +            if (responseSwitch != null)
> +            {
> +                responseSwitch.setEnabled(context, false);
> +            }
> +        }
> +
> +        ServletResponse response = (ServletResponse) externalContext.getResponse();
> +        ServletRequest request = (ServletRequest) externalContext.getRequest();
> +
> +        Locale locale = view.getLocale();
> +        response.setLocale(locale);
> +        Config.set(request, Config.FMT_LOCALE, context.getViewRoot().getLocale());
> +
> +        String viewId = view.getViewId();
> +        ServletViewResponseWrapper wrappedResponse = new ServletViewResponseWrapper((HttpServletResponse) response);
> +
> +        externalContext.setResponse(wrappedResponse);
> +        try
> +        {
> +            externalContext.dispatch(viewId);
> +        }
> +        catch (FacesException e)
> +        {
> +            // try to extract the most likely exceptions here
> +            // and provide a better error message for them
> +
> +            String message = e.getMessage();
> +
> +            // errors related to using facelets-only tags on a JSP page
> +            if (message != null)
> +            {
> +                // does the message contain "f" (prefix f of tags)
> +                // or the related uri http://java.sun.com/jsf/core
> +                if (message.contains("\"f\"")
> +                        || message.contains("\"" + CoreLibrary.Namespace + "\""))
> +                {
> +                    // check facelets-only f tags
> +                    for (String tag : FACELETS_ONLY_F_TAGS)
> +                    {
> +                        if (message.contains("\"" + tag + "\""))
> +                        {
> +                            String exceptionMessage = "The tag f:" + tag +
> +                                    " is only available on facelets.";
> +                            throw new FacesException(exceptionMessage,
> +                                    new FaceletsOnlyException(exceptionMessage, e.getCause()));
> +                        }
> +                    }
> +                }
> +                else if (message.contains("\"h\"")
> +                        || message.contains("\"" + HtmlLibrary.Namespace + "\""))
> +                {
> +                    // check facelets-only h tags
> +                    for (String tag : FACELETS_ONLY_H_TAGS)
> +                    {
> +                        if (message.contains("\"" + tag + "\""))
> +                        {
> +                            String exceptionMessage = "The tag h:" + tag +
> +                                    " is only available on facelets.";
> +                            throw new FacesException(exceptionMessage,
> +                                    new FaceletsOnlyException(exceptionMessage, e.getCause()));
> +                        }
> +                    }
> +                }
> +                else
> +                {
> +                    // check facelets-only namespaces
> +                    String namespace = null;
> +                    if (message.contains(UILibrary.Namespace))
> +                    {
> +                        namespace = UILibrary.Namespace;
> +                    }
> +                    else if (message.contains(CompositeLibrary.NAMESPACE))
> +                    {
> +                        namespace = CompositeLibrary.NAMESPACE;
> +                    }
> +
> +                    if (namespace != null)
> +                    {
> +                        // the message contains a facelets-only namespace
> +                        String exceptionMessage = "All tags with namespace " +
> +                                namespace + " are only available on facelets.";
> +                        throw new FacesException(exceptionMessage,
> +                                new FaceletsOnlyException(exceptionMessage, e.getCause()));
> +                    }
> +                }
> +            }
> +
> +            // no rule applied to this Exception - rethrow it
> +            throw e;
> +        }
> +        finally
> +        {
> +            externalContext.setResponse(response);
> +        }
> +
> +        boolean errorResponse = wrappedResponse.getStatus() < 200 || wrappedResponse.getStatus() > 299;
> +        if (errorResponse)
> +        {
> +            wrappedResponse.flushToWrappedResponse();
> +            return;
> +        }
> +
> +        //Skip this step if we are rendering an ajax request, because no content outside
> +        //f:view tag should be output.
> +        if (!context.getPartialViewContext().isPartialRequest())
> +        {
> +            // store the wrapped response in the request, so it is thread-safe
> +            setAfterViewTagResponseWrapper(externalContext, wrappedResponse);
> +        }
> +    }
> +
> +    @Override
> +    protected void sendSourceNotFound(FacesContext context, String message)
> +    {
> +        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
> +        try
> +        {
> +            context.responseComplete();
> +            response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
> +        }
> +        catch (IOException ioe)
> +        {
> +            throw new FacesException(ioe);
> +        }
> +    }
> +
> +}
>
> Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
> ------------------------------------------------------------------------------
>    svn:keywords = Date Author Id Revision HeadURL
>
>
>



-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf