| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.interceptor; |
| 17 | |
|
| 18 | |
import java.io.PrintWriter; |
| 19 | |
import java.util.Iterator; |
| 20 | |
|
| 21 | |
import javax.faces.component.UIComponent; |
| 22 | |
import javax.faces.component.UIViewRoot; |
| 23 | |
import javax.faces.component.html.HtmlCommandLink; |
| 24 | |
import javax.faces.component.html.HtmlOutputText; |
| 25 | |
import javax.faces.context.FacesContext; |
| 26 | |
|
| 27 | |
import org.aopalliance.intercept.MethodInvocation; |
| 28 | |
import org.seasar.framework.aop.interceptors.AbstractInterceptor; |
| 29 | |
import org.seasar.framework.log.Logger; |
| 30 | |
import org.seasar.framework.util.SPrintWriter; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 0 | public class DumpComponentTreeInterceptor extends AbstractInterceptor { |
| 36 | |
|
| 37 | 0 | private static final Logger logger_ = Logger |
| 38 | 0 | .getLogger(DumpComponentTreeInterceptor.class); |
| 39 | |
|
| 40 | |
private static final long serialVersionUID = 1L; |
| 41 | |
|
| 42 | |
public Object invoke(MethodInvocation invocation) throws Throwable { |
| 43 | 0 | FacesContext context = FacesContext.getCurrentInstance(); |
| 44 | 0 | printBefore(context); |
| 45 | |
try { |
| 46 | 0 | return invocation.proceed(); |
| 47 | |
} finally { |
| 48 | 0 | printAfter(context); |
| 49 | |
} |
| 50 | |
} |
| 51 | |
|
| 52 | |
private void printAfter(FacesContext context) { |
| 53 | 0 | SPrintWriter writer = new SPrintWriter(); |
| 54 | 0 | writer.println(getClass().getName() + " after"); |
| 55 | 0 | dumpTree(writer, context); |
| 56 | 0 | logger_.debug(writer.toString()); |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
private void printBefore(FacesContext context) { |
| 60 | 0 | SPrintWriter writer = new SPrintWriter(); |
| 61 | 0 | writer.println(getClass().getName() + " before"); |
| 62 | 0 | dumpTree(writer, context); |
| 63 | 0 | logger_.debug(writer.toString()); |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
protected void dumpTree(PrintWriter writer, FacesContext context) { |
| 67 | 0 | UIViewRoot viewRoot = context.getViewRoot(); |
| 68 | 0 | writer |
| 69 | |
.println("[tree] " + viewRoot + " viewId=" |
| 70 | |
+ viewRoot.getViewId()); |
| 71 | 0 | dumpTree(writer, viewRoot, 1); |
| 72 | 0 | } |
| 73 | |
|
| 74 | |
protected void dumpTree(PrintWriter writer, UIComponent component, int depth) { |
| 75 | 0 | for (Iterator it = component.getFacetsAndChildren(); it.hasNext();) { |
| 76 | 0 | UIComponent child = (UIComponent) it.next(); |
| 77 | 0 | writer.print("[tree] "); |
| 78 | 0 | for (int i = 0; i < depth; i++) { |
| 79 | 0 | writer.print(" "); |
| 80 | |
} |
| 81 | 0 | printComponent(writer, child); |
| 82 | 0 | writer.println(); |
| 83 | 0 | dumpTree(writer, child, depth + 1); |
| 84 | |
} |
| 85 | 0 | } |
| 86 | |
|
| 87 | |
protected void printComponent(PrintWriter writer, UIComponent child) { |
| 88 | 0 | if (child instanceof HtmlCommandLink) { |
| 89 | 0 | HtmlCommandLink commandLink = (HtmlCommandLink) child; |
| 90 | 0 | writer.print(commandLink); |
| 91 | 0 | writer.print(" " + commandLink.getValue()); |
| 92 | 0 | } else if (child instanceof HtmlOutputText) { |
| 93 | 0 | HtmlOutputText outputText = (HtmlOutputText) child; |
| 94 | 0 | writer.print(outputText); |
| 95 | 0 | writer.print(" " + outputText.getValue()); |
| 96 | |
} else { |
| 97 | 0 | writer.print(child); |
| 98 | |
} |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
} |