myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sless...@apache.org
Subject svn commit: r740940 [9/9] - in /myfaces/core/branches/2_0_0: api/src/main/java/javax/faces/webapp/pdl/facelets/ api/src/main/resources/META-INF/ impl/src/main/java/com/ impl/src/main/java/com/sun/ impl/src/main/java/com/sun/facelets/ impl/src/main/java...
Date Wed, 04 Feb 2009 23:55:29 GMT
Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/UIDebug.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/UIDebug.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/UIDebug.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/UIDebug.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,180 @@
+/**
+ * Licensed 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 com.sun.facelets.tag.ui;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.servlet.http.HttpServletResponse;
+
+import com.sun.facelets.util.DevTools;
+import com.sun.facelets.util.FastWriter;
+
+/**
+ * @author Jacob Hookom
+ * @version $Id: UIDebug.java,v 1.6 2008/07/13 19:01:41 rlubke Exp $
+ */
+public final class UIDebug extends UIComponentBase
+{
+
+    public final static String COMPONENT_TYPE = "facelets.ui.Debug";
+    public final static String COMPONENT_FAMILY = "facelets";
+    private static long nextId = System.currentTimeMillis();
+    private final static String KEY = "facelets.ui.DebugOutput";
+    public final static String DEFAULT_HOTKEY = "D";
+    private String hotkey = DEFAULT_HOTKEY;
+
+    public UIDebug()
+    {
+        super();
+        this.setTransient(true);
+        this.setRendered(true);
+        this.setRendererType(null);
+    }
+
+    public String getFamily()
+    {
+        return COMPONENT_FAMILY;
+    }
+
+    public List getChildren()
+    {
+        return new ArrayList()
+        {
+            public boolean add(Object o)
+            {
+                throw new IllegalStateException("<ui:debug> does not support children");
+            }
+
+            public void add(int index, Object o)
+            {
+                throw new IllegalStateException("<ui:debug> does not support children");
+            }
+        };
+    }
+
+    public void encodeBegin(FacesContext faces) throws IOException
+    {
+
+        String actionId = faces.getApplication().getViewHandler().getActionURL(faces, faces.getViewRoot().getViewId());
+
+        StringBuffer sb = new StringBuffer(512);
+        sb.append("<script language=\"javascript\" type=\"text/javascript\">\n");
+        sb.append("//<![CDATA[\n");
+        sb
+                .append("function faceletsDebug(URL) { day = new Date(); id = day.getTime(); eval(\"page\" + id + \" = window.open(URL, '\" + id + \"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 240,top = 212');\"); };");
+        sb
+                .append("var faceletsOrigKeyup = document.onkeyup; document.onkeyup = function(e) { if (window.event) e = window.event; if (String.fromCharCode(e.keyCode) == '"
+                        + this.getHotkey() + "' & e.shiftKey & e.ctrlKey) faceletsDebug('");
+        sb.append(actionId);
+        sb.append('?');
+        sb.append(KEY);
+        sb.append('=');
+        sb.append(writeDebugOutput(faces));
+        sb.append("'); else if (faceletsOrigKeyup) faceletsOrigKeyup(e); };\n");
+        sb.append("//]]>\n");
+        sb.append("</script>\n");
+
+        ResponseWriter writer = faces.getResponseWriter();
+        writer.write(sb.toString());
+    }
+
+    private static String writeDebugOutput(FacesContext faces) throws IOException
+    {
+        FastWriter fw = new FastWriter();
+        DevTools.debugHtml(fw, faces);
+
+        Map session = faces.getExternalContext().getSessionMap();
+        Map debugs = (Map) session.get(KEY);
+        if (debugs == null)
+        {
+            debugs = new LinkedHashMap()
+            {
+                protected boolean removeEldestEntry(Entry eldest)
+                {
+                    return (this.size() > 5);
+                }
+            };
+            session.put(KEY, debugs);
+        }
+        String id = "" + nextId++;
+        debugs.put(id, fw.toString());
+        return id;
+    }
+
+    private static String fetchDebugOutput(FacesContext faces, String id)
+    {
+        Map session = faces.getExternalContext().getSessionMap();
+        Map debugs = (Map) session.get(KEY);
+        if (debugs != null)
+        {
+            return (String) debugs.get(id);
+        }
+        return null;
+    }
+
+    public static boolean debugRequest(FacesContext faces)
+    {
+        String id = (String) faces.getExternalContext().getRequestParameterMap().get(KEY);
+        if (id != null)
+        {
+            Object resp = faces.getExternalContext().getResponse();
+            if (!faces.getResponseComplete() && resp instanceof HttpServletResponse)
+            {
+                try
+                {
+                    HttpServletResponse httpResp = (HttpServletResponse) resp;
+                    String page = fetchDebugOutput(faces, id);
+                    if (page != null)
+                    {
+                        httpResp.setContentType("text/html");
+                        httpResp.getWriter().write(page);
+                    }
+                    else
+                    {
+                        httpResp.setContentType("text/plain");
+                        httpResp.getWriter().write("No Debug Output Available");
+                    }
+                    httpResp.flushBuffer();
+                    faces.responseComplete();
+                }
+                catch (IOException e)
+                {
+                    return false;
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public String getHotkey()
+    {
+        return this.hotkey;
+    }
+
+    public void setHotkey(String hotkey)
+    {
+        this.hotkey = (hotkey != null) ? hotkey.toUpperCase() : "";
+    }
+
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/UILibrary.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/UILibrary.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/UILibrary.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/UILibrary.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,55 @@
+/**
+ * Licensed 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 com.sun.facelets.tag.ui;
+
+import com.sun.facelets.component.UIRepeat;
+import com.sun.facelets.tag.AbstractTagLibrary;
+
+/**
+ * @author Jacob Hookom
+ * @version $Id: UILibrary.java,v 1.8 2008/07/13 19:01:42 rlubke Exp $
+ */
+public final class UILibrary extends AbstractTagLibrary
+{
+
+    public final static String Namespace = "http://java.sun.com/jsf/facelets";
+
+    public final static UILibrary Instance = new UILibrary();
+
+    public UILibrary()
+    {
+        super(Namespace);
+
+        this.addTagHandler("include", IncludeHandler.class);
+
+        this.addTagHandler("composition", CompositionHandler.class);
+
+        this.addComponent("component", ComponentRef.COMPONENT_TYPE, null, ComponentRefHandler.class);
+
+        this.addComponent("fragment", ComponentRef.COMPONENT_TYPE, null, ComponentRefHandler.class);
+
+        this.addTagHandler("define", DefineHandler.class);
+
+        this.addTagHandler("insert", InsertHandler.class);
+
+        this.addTagHandler("param", ParamHandler.class);
+
+        this.addTagHandler("decorate", DecorateHandler.class);
+
+        this.addComponent("repeat", UIRepeat.COMPONENT_TYPE, null, RepeatHandler.class);
+
+        this.addComponent("debug", UIDebug.COMPONENT_TYPE, null);
+    }
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/package.html
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/package.html?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/package.html (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/tag/ui/package.html Wed Feb  4 23:55:25 2009
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+ Licensed 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.
+
+ $Id: package.html,v 1.3 2008/07/13 19:01:41 rlubke Exp $
+-->
+</head>
+<body bgcolor="white">
+Tag Library for <b>http://java.sun.com/jsf/ui</b>.
+See JSF Core Tag Javadocs for attributes/functionality.
+</body>
+</html>
\ No newline at end of file

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Classpath.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Classpath.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Classpath.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Classpath.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,281 @@
+/**
+ * Licensed 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 com.sun.facelets.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLDecoder;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * @author Jacob Hookom
+ * @author Roland Huss
+ * @author Ales Justin (ales.justin@jboss.org)
+ * @version $Id: Classpath.java,v 1.10 2008/07/13 19:01:34 rlubke Exp $
+ */
+public final class Classpath
+{
+
+    /**
+	 * 
+	 */
+    public Classpath()
+    {
+        super();
+    }
+
+    public static URL[] search(String prefix, String suffix) throws IOException
+    {
+        return search(Thread.currentThread().getContextClassLoader(), prefix, suffix);
+    }
+
+    public static URL[] search(ClassLoader cl, String prefix, String suffix) throws IOException
+    {
+        Enumeration[] e = new Enumeration[] { cl.getResources(prefix), cl.getResources(prefix + "MANIFEST.MF") };
+        Set all = new LinkedHashSet();
+        URL url;
+        URLConnection conn;
+        JarFile jarFile;
+        for (int i = 0, s = e.length; i < s; ++i)
+        {
+            while (e[i].hasMoreElements())
+            {
+                url = (URL) e[i].nextElement();
+                conn = url.openConnection();
+                conn.setUseCaches(false);
+                conn.setDefaultUseCaches(false);
+                if (conn instanceof JarURLConnection)
+                {
+                    jarFile = ((JarURLConnection) conn).getJarFile();
+                }
+                else
+                {
+                    jarFile = getAlternativeJarFile(url);
+                }
+                if (jarFile != null)
+                {
+                    searchJar(cl, all, jarFile, prefix, suffix);
+                }
+                else
+                {
+                    boolean searchDone = searchDir(all, new File(URLDecoder.decode(url.getFile(), "UTF-8")), suffix);
+                    if (!searchDone)
+                    {
+                        searchFromURL(all, prefix, suffix, url);
+                    }
+                }
+            }
+        }
+        URL[] urlArray = (URL[]) all.toArray(new URL[all.size()]);
+        return urlArray;
+    }
+
+    private static boolean searchDir(Set result, File file, String suffix) throws IOException
+    {
+        if (file.exists() && file.isDirectory())
+        {
+            File[] fc = file.listFiles();
+            String path;
+            URL src;
+            for (int i = 0; i < fc.length; i++)
+            {
+                path = fc[i].getAbsolutePath();
+                if (fc[i].isDirectory())
+                {
+                    searchDir(result, fc[i], suffix);
+                }
+                else if (path.endsWith(suffix))
+                {
+                    // result.add(new URL("file:/" + path));
+                    result.add(fc[i].toURL());
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Search from URL. Fall back on prefix tokens if not able to read from original url param.
+     * 
+     * @param result
+     *            the result urls
+     * @param prefix
+     *            the current prefix
+     * @param suffix
+     *            the suffix to match
+     * @param url
+     *            the current url to start search
+     * @throws IOException
+     *             for any error
+     */
+    private static void searchFromURL(Set result, String prefix, String suffix, URL url) throws IOException
+    {
+        boolean done = false;
+        InputStream is = getInputStream(url);
+        if (is != null)
+        {
+            try
+            {
+                ZipInputStream zis;
+                if (is instanceof ZipInputStream)
+                    zis = (ZipInputStream) is;
+                else
+                    zis = new ZipInputStream(is);
+                try
+                {
+                    ZipEntry entry = zis.getNextEntry();
+                    // initial entry should not be null
+                    // if we assume this is some inner jar
+                    done = (entry != null);
+                    while (entry != null)
+                    {
+                        String entryName = entry.getName();
+                        if (entryName.endsWith(suffix))
+                        {
+                            String urlString = url.toExternalForm();
+                            result.add(new URL(urlString + entryName));
+                        }
+                        entry = zis.getNextEntry();
+                    }
+                }
+                finally
+                {
+                    zis.close();
+                }
+            }
+            catch (Exception ignore)
+            {
+            }
+        }
+        if (done == false && prefix.length() > 0)
+        {
+            // we add '/' at the end since join adds it as well
+            String urlString = url.toExternalForm() + "/";
+            String[] split = prefix.split("/");
+            prefix = join(split, true);
+            String end = join(split, false);
+            int p = urlString.lastIndexOf(end);
+            url = new URL(urlString.substring(0, p));
+            searchFromURL(result, prefix, suffix, url);
+        }
+    }
+
+    /**
+     * Join tokens, exlude last if param equals true.
+     * 
+     * @param tokens
+     *            the tokens
+     * @param excludeLast
+     *            do we exclude last token
+     * @return joined tokens
+     */
+    private static String join(String[] tokens, boolean excludeLast)
+    {
+        StringBuffer join = new StringBuffer();
+        for (int i = 0; i < tokens.length - (excludeLast ? 1 : 0); i++)
+            join.append(tokens[i]).append("/");
+        return join.toString();
+    }
+
+    /**
+     * Open input stream from url. Ignore any errors.
+     * 
+     * @param url
+     *            the url to open
+     * @return input stream or null if not possible
+     */
+    private static InputStream getInputStream(URL url)
+    {
+        try
+        {
+            return url.openStream();
+        }
+        catch (Throwable t)
+        {
+            return null;
+        }
+    }
+
+    /**
+     * For URLs to JARs that do not use JarURLConnection - allowed by the servlet spec - attempt to produce a JarFile
+     * object all the same. Known servlet engines that function like this include Weblogic and OC4J. This is not a full
+     * solution, since an unpacked WAR or EAR will not have JAR "files" as such.
+     */
+    private static JarFile getAlternativeJarFile(URL url) throws IOException
+    {
+        String urlFile = url.getFile();
+        // Trim off any suffix - which is prefixed by "!/" on Weblogic
+        int separatorIndex = urlFile.indexOf("!/");
+
+        // OK, didn't find that. Try the less safe "!", used on OC4J
+        if (separatorIndex == -1)
+        {
+            separatorIndex = urlFile.indexOf('!');
+        }
+
+        if (separatorIndex != -1)
+        {
+            String jarFileUrl = urlFile.substring(0, separatorIndex);
+            // And trim off any "file:" prefix.
+            if (jarFileUrl.startsWith("file:"))
+            {
+                jarFileUrl = jarFileUrl.substring("file:".length());
+            }
+            return new JarFile(jarFileUrl);
+        }
+        return null;
+    }
+
+    private static void searchJar(ClassLoader cl, Set result, JarFile file, String prefix, String suffix)
+            throws IOException
+    {
+        Enumeration e = file.entries();
+        JarEntry entry;
+        String name;
+        while (e.hasMoreElements())
+        {
+            try
+            {
+                entry = (JarEntry) e.nextElement();
+            }
+            catch (Throwable t)
+            {
+                continue;
+            }
+            name = entry.getName();
+            if (name.startsWith(prefix) && name.endsWith(suffix))
+            {
+                Enumeration e2 = cl.getResources(name);
+                while (e2.hasMoreElements())
+                {
+                    result.add(e2.nextElement());
+                }
+            }
+        }
+    }
+
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/DevTools.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/DevTools.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/DevTools.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/DevTools.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,384 @@
+/**
+ * Licensed 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 com.sun.facelets.util;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.lang.reflect.Method;
+import java.text.DateFormat;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.logging.Logger;
+
+import javax.el.Expression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.ValueBinding;
+
+public final class DevTools
+{
+
+    private final static String TS = "&lt;";
+
+    private static final String ERROR_TEMPLATE = "META-INF/rsc/facelet-dev-error.xml";
+
+    private static String[] ERROR_PARTS;
+
+    private static final String DEBUG_TEMPLATE = "META-INF/rsc/facelet-dev-debug.xml";
+
+    private static String[] DEBUG_PARTS;
+
+    public DevTools()
+    {
+        super();
+    }
+
+    public static void main(String[] argv) throws Exception
+    {
+        DevTools.init();
+    }
+
+    private static void init() throws IOException
+    {
+        if (ERROR_PARTS == null)
+        {
+            ERROR_PARTS = splitTemplate(ERROR_TEMPLATE);
+        }
+
+        if (DEBUG_PARTS == null)
+        {
+            DEBUG_PARTS = splitTemplate(DEBUG_TEMPLATE);
+        }
+    }
+
+    private static String[] splitTemplate(String rsc) throws IOException
+    {
+        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(rsc);
+        if (is == null)
+        {
+            throw new FileNotFoundException(rsc);
+        }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] buff = new byte[512];
+        int read;
+        while ((read = is.read(buff)) != -1)
+        {
+            baos.write(buff, 0, read);
+        }
+        String str = baos.toString();
+        return str.split("@@");
+    }
+
+    public static void debugHtml(Writer writer, FacesContext faces, Exception e) throws IOException
+    {
+        init();
+        Date now = new Date();
+        for (int i = 0; i < ERROR_PARTS.length; i++)
+        {
+            if ("message".equals(ERROR_PARTS[i]))
+            {
+                String msg = e.getMessage();
+                if (msg != null)
+                {
+                    writer.write(msg.replaceAll("<", TS));
+                }
+                else
+                {
+                    writer.write(e.getClass().getName());
+                }
+            }
+            else if ("trace".equals(ERROR_PARTS[i]))
+            {
+                writeException(writer, e);
+            }
+            else if ("now".equals(ERROR_PARTS[i]))
+            {
+                writer.write(DateFormat.getDateTimeInstance().format(now));
+            }
+            else if ("tree".equals(ERROR_PARTS[i]))
+            {
+                writeComponent(writer, faces.getViewRoot());
+            }
+            else if ("vars".equals(ERROR_PARTS[i]))
+            {
+                writeVariables(writer, faces);
+            }
+            else
+            {
+                writer.write(ERROR_PARTS[i]);
+            }
+        }
+    }
+
+    private static void writeException(Writer writer, Exception e) throws IOException
+    {
+        StringWriter str = new StringWriter(256);
+        PrintWriter pstr = new PrintWriter(str);
+        e.printStackTrace(pstr);
+        pstr.close();
+        writer.write(str.toString().replaceAll("<", TS));
+    }
+
+    public static void debugHtml(Writer writer, FacesContext faces) throws IOException
+    {
+        init();
+        Date now = new Date();
+        for (int i = 0; i < DEBUG_PARTS.length; i++)
+        {
+            if ("message".equals(DEBUG_PARTS[i]))
+            {
+                writer.write(faces.getViewRoot().getViewId());
+            }
+            else if ("now".equals(DEBUG_PARTS[i]))
+            {
+                writer.write(DateFormat.getDateTimeInstance().format(now));
+            }
+            else if ("tree".equals(DEBUG_PARTS[i]))
+            {
+                writeComponent(writer, faces.getViewRoot());
+            }
+            else if ("vars".equals(DEBUG_PARTS[i]))
+            {
+                writeVariables(writer, faces);
+            }
+            else
+            {
+                writer.write(DEBUG_PARTS[i]);
+            }
+        }
+    }
+
+    private static void writeVariables(Writer writer, FacesContext faces) throws IOException
+    {
+        ExternalContext ctx = faces.getExternalContext();
+        writeVariables(writer, ctx.getRequestParameterMap(), "Request Parameters");
+        writeVariables(writer, ctx.getRequestMap(), "Request Attributes");
+        if (ctx.getSession(false) != null)
+        {
+            writeVariables(writer, ctx.getSessionMap(), "Session Attributes");
+        }
+        writeVariables(writer, ctx.getApplicationMap(), "Application Attributes");
+    }
+
+    private static void writeVariables(Writer writer, Map vars, String caption) throws IOException
+    {
+        writer.write("<table><caption>");
+        writer.write(caption);
+        writer
+                .write("</caption><thead><tr><th style=\"width: 10%; \">Name</th><th style=\"width: 90%; \">Value</th></tr></thead><tbody>");
+        boolean written = false;
+        if (!vars.isEmpty())
+        {
+            SortedMap map = new TreeMap(vars);
+            Map.Entry entry = null;
+            String key = null;
+            for (Iterator itr = map.entrySet().iterator(); itr.hasNext();)
+            {
+                entry = (Map.Entry) itr.next();
+                key = entry.getKey().toString();
+                if (key.indexOf('.') == -1)
+                {
+                    writer.write("<tr><td>");
+                    writer.write(key.replaceAll("<", TS));
+                    writer.write("</td><td>");
+                    writer.write(entry.getValue() == null ? "null" : entry.getValue().toString().replaceAll("<", TS));
+                    writer.write("</td></tr>");
+                    written = true;
+                }
+            }
+        }
+        if (!written)
+        {
+            writer.write("<tr><td colspan=\"2\"><em>None</em></td></tr>");
+        }
+        writer.write("</tbody></table>");
+    }
+
+    private static void writeComponent(Writer writer, UIComponent c) throws IOException
+    {
+        writer.write("<dl><dt");
+        if (isText(c))
+        {
+            writer.write(" class=\"uicText\"");
+        }
+        writer.write(">");
+
+        boolean hasChildren = c.getChildCount() > 0 || c.getFacets().size() > 0;
+
+        writeStart(writer, c, hasChildren);
+        writer.write("</dt>");
+        if (hasChildren)
+        {
+            if (c.getFacets().size() > 0)
+            {
+                Map.Entry entry;
+                for (Iterator itr = c.getFacets().entrySet().iterator(); itr.hasNext();)
+                {
+                    entry = (Map.Entry) itr.next();
+                    writer.write("<dd class=\"uicFacet\">");
+                    writer.write("<span>");
+                    writer.write((String) entry.getKey());
+                    writer.write("</span>");
+                    writeComponent(writer, (UIComponent) entry.getValue());
+                    writer.write("</dd>");
+                }
+            }
+            if (c.getChildCount() > 0)
+            {
+                for (Iterator itr = c.getChildren().iterator(); itr.hasNext();)
+                {
+                    writer.write("<dd>");
+                    writeComponent(writer, (UIComponent) itr.next());
+                    writer.write("</dd>");
+                }
+            }
+            writer.write("<dt>");
+            writeEnd(writer, c);
+            writer.write("</dt>");
+        }
+        writer.write("</dl>");
+    }
+
+    private static void writeEnd(Writer writer, UIComponent c) throws IOException
+    {
+        if (!isText(c))
+        {
+            writer.write(TS);
+            writer.write('/');
+            writer.write(getName(c));
+            writer.write('>');
+        }
+    }
+
+    private final static String[] IGNORE = new String[] { "parent", "rendererType" };
+
+    private static void writeAttributes(Writer writer, UIComponent c)
+    {
+        try
+        {
+            BeanInfo info = Introspector.getBeanInfo(c.getClass());
+            PropertyDescriptor[] pd = info.getPropertyDescriptors();
+            Method m = null;
+            Object v = null;
+            String str = null;
+            for (int i = 0; i < pd.length; i++)
+            {
+                if (pd[i].getWriteMethod() != null && Arrays.binarySearch(IGNORE, pd[i].getName()) < 0)
+                {
+                    m = pd[i].getReadMethod();
+                    try
+                    {
+                        v = m.invoke(c, null);
+                        if (v != null)
+                        {
+                            if (v instanceof Collection || v instanceof Map || v instanceof Iterator)
+                            {
+                                continue;
+                            }
+                            writer.write(" ");
+                            writer.write(pd[i].getName());
+                            writer.write("=\"");
+                            if (v instanceof Expression)
+                            {
+                                str = ((Expression) v).getExpressionString();
+                            }
+                            else if (v instanceof ValueBinding)
+                            {
+                                str = ((ValueBinding) v).getExpressionString();
+                            }
+                            else if (v instanceof MethodBinding)
+                            {
+                                str = ((MethodBinding) v).getExpressionString();
+                            }
+                            else
+                            {
+                                str = v.toString();
+                            }
+                            writer.write(str.replaceAll("<", TS));
+                            writer.write("\"");
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        // do nothing
+                    }
+                }
+            }
+
+            ValueBinding binding = c.getValueBinding("binding");
+            if (binding != null)
+            {
+                writer.write(" binding=\"");
+                writer.write(binding.getExpressionString().replaceAll("<", TS));
+                writer.write("\"");
+            }
+        }
+        catch (Exception e)
+        {
+            // do nothing
+        }
+    }
+
+    private static void writeStart(Writer writer, UIComponent c, boolean children) throws IOException
+    {
+        if (isText(c))
+        {
+            String str = c.toString().trim();
+            writer.write(str.replaceAll("<", TS));
+        }
+        else
+        {
+            writer.write(TS);
+            writer.write(getName(c));
+            writeAttributes(writer, c);
+            if (children)
+            {
+                writer.write('>');
+            }
+            else
+            {
+                writer.write("/>");
+            }
+        }
+    }
+
+    private static String getName(UIComponent c)
+    {
+        String nm = c.getClass().getName();
+        return nm.substring(nm.lastIndexOf('.') + 1);
+    }
+
+    private static boolean isText(UIComponent c)
+    {
+        return (c.getClass().getName().startsWith("com.sun.facelets.compiler"));
+    }
+
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/FacesAPI.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/FacesAPI.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/FacesAPI.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/FacesAPI.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,59 @@
+/**
+ * Licensed 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 com.sun.facelets.util;
+
+import javax.faces.application.Application;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+
+public final class FacesAPI
+{
+
+    private static final int version = specifyVersion();
+    private static final Class[] UIC_SIG = new Class[] { String.class };
+
+    private FacesAPI()
+    {
+        super();
+    }
+
+    private final static int specifyVersion()
+    {
+        try
+        {
+            Application.class.getMethod("getExpressionFactory", null);
+        }
+        catch (NoSuchMethodException e)
+        {
+            return 11;
+        }
+        return 12;
+    }
+
+    public final static int getVersion()
+    {
+        return version;
+    }
+
+    public final static int getComponentVersion(UIComponent c)
+    {
+        return version;
+    }
+
+    public final static int getComponentVersion(Class c)
+    {
+        return version;
+    }
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/FastWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/FastWriter.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/FastWriter.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/FastWriter.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,102 @@
+/**
+ * Licensed 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 com.sun.facelets.util;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author Jacob Hookom
+ * @version $Id: FastWriter.java,v 1.4 2008/07/13 19:01:34 rlubke Exp $
+ */
+public final class FastWriter extends Writer
+{
+
+    private char[] buff;
+    private int size;
+
+    public FastWriter()
+    {
+        this(1024);
+    }
+
+    public FastWriter(int initialSize)
+    {
+        if (initialSize < 0)
+        {
+            throw new IllegalArgumentException("Initial Size cannot be less than 0");
+        }
+        this.buff = new char[initialSize];
+    }
+
+    public void close() throws IOException
+    {
+        // do nothing
+    }
+
+    public void flush() throws IOException
+    {
+        // do nothing
+    }
+
+    private final void overflow(int len)
+    {
+        if (this.size + len > this.buff.length)
+        {
+            char[] next = new char[(this.size + len) * 2];
+            System.arraycopy(this.buff, 0, next, 0, this.size);
+            this.buff = next;
+        }
+    }
+
+    public void write(char[] cbuf, int off, int len) throws IOException
+    {
+        overflow(len);
+        System.arraycopy(cbuf, off, this.buff, this.size, len);
+        this.size += len;
+    }
+
+    public void write(char[] cbuf) throws IOException
+    {
+        this.write(cbuf, 0, cbuf.length);
+    }
+
+    public void write(int c) throws IOException
+    {
+        this.overflow(1);
+        this.buff[this.size] = (char) c;
+        this.size++;
+    }
+
+    public void write(String str, int off, int len) throws IOException
+    {
+        this.write(str.toCharArray(), off, len);
+    }
+
+    public void write(String str) throws IOException
+    {
+        this.write(str.toCharArray(), 0, str.length());
+    }
+
+    public void reset()
+    {
+        this.size = 0;
+    }
+
+    public String toString()
+    {
+        return new String(this.buff, 0, this.size);
+    }
+}
\ No newline at end of file

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/ParameterCheck.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/ParameterCheck.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/ParameterCheck.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/ParameterCheck.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,32 @@
+/**
+ * Licensed 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 com.sun.facelets.util;
+
+/**
+ * @author Jacob Hookom
+ * @version $Id: ParameterCheck.java,v 1.3 2008/07/13 19:01:34 rlubke Exp $
+ */
+public final class ParameterCheck
+{
+
+    public final static void notNull(String name, Object value) throws NullPointerException
+    {
+        if (value == null)
+        {
+            throw new NullPointerException("Parameter '" + name + "' cannot be null");
+        }
+    }
+
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Path.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Path.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Path.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Path.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,103 @@
+/**
+ * Licensed 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 com.sun.facelets.util;
+
+/**
+ * @author Jacob Hookom
+ * @version $Id: Path.java,v 1.3 2008/07/13 19:01:34 rlubke Exp $
+ */
+public final class Path
+{
+
+    public static final String normalize(String path)
+    {
+        if (path.length() == 0)
+            return path;
+        String n = path;
+        boolean abs = false;
+        while (n.indexOf('\\') >= 0)
+        {
+            n = n.replace('\\', '/');
+        }
+        if (n.charAt(0) != '/')
+        {
+            n = '/' + n;
+            abs = true;
+        }
+        int idx = 0;
+        while (true)
+        {
+            idx = n.indexOf("%20");
+            if (idx == -1)
+            {
+                break;
+            }
+            n = n.substring(0, idx) + " " + n.substring(idx + 3);
+        }
+        while (true)
+        {
+            idx = n.indexOf("/./");
+            if (idx == -1)
+            {
+                break;
+            }
+            n = n.substring(0, idx) + n.substring(idx + 2);
+        }
+        if (abs)
+        {
+            n = n.substring(1);
+        }
+        return n;
+    }
+
+    public static final String relative(String ctx, String path)
+    {
+        if (path.length() == 0)
+        {
+            return context(ctx);
+        }
+        String c = context(normalize(ctx));
+        String p = normalize(path);
+        p = c + p;
+
+        int idx = 0;
+        while (true)
+        {
+            idx = p.indexOf("/../");
+            if (idx == -1)
+            {
+                break;
+            }
+            int s = p.lastIndexOf('/', idx - 3);
+            if (s == -1)
+            {
+                break;
+            }
+            p = p.substring(0, s) + p.substring(idx + 3);
+        }
+        return p;
+    }
+
+    public static final String context(String path)
+    {
+        int idx = path.lastIndexOf('/');
+        if (idx == -1)
+        {
+            return "/";
+        }
+        return path.substring(0, idx + 1);
+    }
+
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/ReflectionUtil.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/ReflectionUtil.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/ReflectionUtil.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/ReflectionUtil.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,176 @@
+/**
+ * Licensed 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 com.sun.facelets.util;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+
+public class ReflectionUtil
+{
+    protected static final String[] EMPTY_STRING = new String[0];
+
+    protected static final String[] PRIMITIVE_NAMES = new String[] { "boolean", "byte", "char", "double", "float",
+                                                                    "int", "long", "short", "void" };
+
+    protected static final Class[] PRIMITIVES = new Class[] { boolean.class, byte.class, char.class, double.class,
+                                                             float.class, int.class, long.class, short.class, Void.TYPE };
+
+    /**
+     * 
+     */
+    private ReflectionUtil()
+    {
+        super();
+    }
+
+    public static Class forName(String name) throws ClassNotFoundException
+    {
+        if (null == name || "".equals(name))
+        {
+            return null;
+        }
+        Class c = forNamePrimitive(name);
+        if (c == null)
+        {
+            if (name.endsWith("[]"))
+            {
+                String nc = name.substring(0, name.length() - 2);
+                c = Class.forName(nc, false, Thread.currentThread().getContextClassLoader());
+                c = Array.newInstance(c, 0).getClass();
+            }
+            else
+            {
+                c = Class.forName(name, false, Thread.currentThread().getContextClassLoader());
+            }
+        }
+        return c;
+    }
+
+    protected static Class forNamePrimitive(String name)
+    {
+        if (name.length() <= 8)
+        {
+            int p = Arrays.binarySearch(PRIMITIVE_NAMES, name);
+            if (p >= 0)
+            {
+                return PRIMITIVES[p];
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Converts an array of Class names to Class types
+     * 
+     * @param s
+     * @return
+     * @throws ClassNotFoundException
+     */
+    public static Class[] toTypeArray(String[] s) throws ClassNotFoundException
+    {
+        if (s == null)
+            return null;
+        Class[] c = new Class[s.length];
+        for (int i = 0; i < s.length; i++)
+        {
+            c[i] = forName(s[i]);
+        }
+        return c;
+    }
+
+    /**
+     * Converts an array of Class types to Class names
+     * 
+     * @param c
+     * @return
+     */
+    public static String[] toTypeNameArray(Class[] c)
+    {
+        if (c == null)
+            return null;
+        String[] s = new String[c.length];
+        for (int i = 0; i < c.length; i++)
+        {
+            s[i] = c[i].getName();
+        }
+        return s;
+    }
+
+    /*
+     * Get a public method form a public class or interface of a given method. Note that if the base is an instance of a
+     * non-public class that implements a public interface, calling Class.getMethod() with the base will not find the
+     * method. To correct this, a version of the same method must be found in a superclass or interface.
+     */
+
+    static private Method getMethod(Class cl, String methodName, Class[] paramTypes)
+    {
+
+        Method m = null;
+        try
+        {
+            m = cl.getMethod(methodName, paramTypes);
+        }
+        catch (NoSuchMethodException ex)
+        {
+            return null;
+        }
+
+        Class dclass = m.getDeclaringClass();
+        if (Modifier.isPublic(dclass.getModifiers()))
+        {
+            return m;
+        }
+
+        Class[] intf = dclass.getInterfaces();
+        for (int i = 0; i < intf.length; i++)
+        {
+            m = getMethod(intf[i], methodName, paramTypes);
+            if (m != null)
+            {
+                return m;
+            }
+        }
+        Class c = dclass.getSuperclass();
+        if (c != null)
+        {
+            m = getMethod(c, methodName, paramTypes);
+            if (m != null)
+            {
+                return m;
+            }
+        }
+        return null;
+    }
+
+    protected static final String paramString(Class[] types)
+    {
+        if (types != null)
+        {
+            StringBuffer sb = new StringBuffer();
+            for (int i = 0; i < types.length; i++)
+            {
+                sb.append(types[i].getName()).append(", ");
+            }
+            if (sb.length() > 2)
+            {
+                sb.setLength(sb.length() - 2);
+            }
+            return sb.toString();
+        }
+        return null;
+    }
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Resource.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Resource.java?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Resource.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/Resource.java Wed Feb  4 23:55:25 2009
@@ -0,0 +1,160 @@
+/**
+ * Licensed 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 com.sun.facelets.util;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletContext;
+
+/**
+ * @author Roland Huss
+ * 
+ */
+public final class Resource
+{
+
+    protected final static Logger log = Logger.getLogger("facelets.factory");
+
+    /**
+     * Get an URL of an internal resource. First, {@link javax.faces.context.ExternalContext#getResource(String)} is
+     * checked for an non-null URL return value. In the case of a null return value (as it is the case for Weblogic 8.1
+     * for a packed war), a URL with a special URL handler is constructed, which can be used for <em>opening</em> a
+     * serlvet resource later. Internally, this special URL handler will call
+     * {@link ServletContext#getResourceAsStream(String)} when an inputstream is requested. This works even on Weblogic
+     * 8.1
+     * 
+     * @param ctx
+     *            the faces context from which to retrieve the resource
+     * @param path
+     *            an URL path
+     * 
+     * @return an url representing the URL and on which getInputStream() can be called to get the resource
+     * @throws MalformedURLException
+     */
+    public static URL getResourceUrl(FacesContext ctx, String path) throws MalformedURLException
+    {
+        final ExternalContext externalContext = ctx.getExternalContext();
+        URL url = externalContext.getResource(path);
+        if (log.isLoggable(Level.FINE))
+        {
+            log.fine("Resource-Url from external context: " + url);
+        }
+        if (url == null)
+        {
+            // This might happen on Servlet container which doesnot return
+            // anything
+            // for getResource() (like weblogic 8.1 for packaged wars) we
+            // are trying
+            // to use an own URL protocol in order to use
+            // ServletContext.getResourceAsStream()
+            // when opening the url
+            if (resourceExist(externalContext, path))
+            {
+                url = getUrlForResourceAsStream(externalContext, path);
+            }
+        }
+        return url;
+    }
+
+    // This method could be used above to provide a 'fail fast' if a
+    // resource
+    // doesnt exist. Otherwise, the URL will fail on the first access.
+    private static boolean resourceExist(ExternalContext externalContext, String path)
+    {
+        if ("/".equals(path))
+        {
+            // The root context exists always
+            return true;
+        }
+        Object ctx = externalContext.getContext();
+        if (ctx instanceof ServletContext)
+        {
+            ServletContext servletContext = (ServletContext) ctx;
+            InputStream stream = servletContext.getResourceAsStream(path);
+            if (stream != null)
+            {
+                try
+                {
+                    stream.close();
+                }
+                catch (IOException e)
+                {
+                    // Ignore here, since we donnot wanted to read from this
+                    // resource anyway
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    // Construct URL with special URLStreamHandler for proxying
+    // ServletContext.getResourceAsStream()
+    private static URL getUrlForResourceAsStream(final ExternalContext externalContext, String path)
+            throws MalformedURLException
+    {
+        URLStreamHandler handler = new URLStreamHandler()
+        {
+            protected URLConnection openConnection(URL u) throws IOException
+            {
+                final String file = u.getFile();
+                return new URLConnection(u)
+                {
+                    public void connect() throws IOException
+                    {
+                    }
+
+                    public InputStream getInputStream() throws IOException
+                    {
+                        if (log.isLoggable(Level.FINE))
+                        {
+                            log.fine("Opening internal url to " + file);
+                        }
+                        Object ctx = externalContext.getContext();
+                        // Or maybe fetch the external context afresh ?
+                        // Object ctx =
+                        // FacesContext.getCurrentInstance().getExternalContext().getContext();
+
+                        if (ctx instanceof ServletContext)
+                        {
+                            ServletContext servletContext = (ServletContext) ctx;
+                            InputStream stream = servletContext.getResourceAsStream(file);
+                            if (stream == null)
+                            {
+                                throw new FileNotFoundException("Cannot open resource " + file);
+                            }
+                            return stream;
+                        }
+                        else
+                        {
+                            throw new IOException("Cannot open resource for an context of "
+                                    + (ctx != null ? ctx.getClass() : null));
+                        }
+                    }
+                };
+            }
+        };
+        return new URL("internal", null, 0, path, handler);
+    }
+}

Added: myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/package.html
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/package.html?rev=740940&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/package.html (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/com/sun/facelets/util/package.html Wed Feb  4 23:55:25 2009
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+ Licensed 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.
+
+ $Id: package.html,v 1.3 2008/07/13 19:01:34 rlubke Exp $
+-->
+</head>
+<body bgcolor="white">
+Utility classes for implementation
+</body>
+</html>
\ No newline at end of file

Modified: myfaces/core/branches/2_0_0/impl/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/resources/META-INF/NOTICE.txt?rev=740940&r1=740939&r2=740940&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/resources/META-INF/NOTICE.txt (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/resources/META-INF/NOTICE.txt Wed Feb  4 23:55:25 2009
@@ -6,5 +6,5 @@
 See licenses for accompanying products in the "/licenses" subdirectory.
 ------------------------------------------------------------------------
 
-This sowftware includes code from Facelets (https://facelets.dev.java.net/)
-for the purpose of implementing Facelets PDL for JSF 2.0 support.
\ No newline at end of file
+This software also includes code from Facelets (https://facelets.dev.java.net/)
+for the purpose of implementing Facelets PDL for JSF 2.0 support.



Mime
View raw message