Source Code Cross Referenced for JspInspector.java in  » Code-Analyzer » hammurapi-3.20.0.3 » org » hammurapi » inspectors » metrics » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » hammurapi 3.20.0.3 » org.hammurapi.inspectors.metrics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on May 29, 2004
003:         * 
004:         * 
005:         * JSP invoke technique r Servlet response.redirect a HTML action L HTML HREF I
006:         * JSP include f JSP forward X JavaScript s HTML Frame Source
007:         *  
008:         */
009:        package org.hammurapi.inspectors.metrics;
010:
011:        import java.io.FileInputStream;
012:        import java.io.FileOutputStream;
013:        import java.util.Collection;
014:        import java.util.HashMap;
015:        import java.util.Iterator;
016:        import java.util.List;
017:        import java.util.Map;
018:        import java.util.Properties;
019:
020:        import org.hammurapi.InspectorBase;
021:        import org.hammurapi.HammurapiException;
022:        import org.hammurapi.results.AnnotationContext;
023:        import org.hammurapi.results.LinkedAnnotation;
024:        import org.w3c.dom.Document;
025:        import org.w3c.dom.Element;
026:
027:        import com.pavelvlasov.config.ConfigurationException;
028:        import com.pavelvlasov.jsel.JselException;
029:        import com.pavelvlasov.jsel.Repository;
030:        import com.pavelvlasov.jsel.TypeDefinition;
031:        import com.pavelvlasov.jsel.VariableDefinition;
032:        import com.pavelvlasov.jsel.expressions.MethodCall;
033:        import com.pavelvlasov.jsel.expressions.StringConstant;
034:        import com.pavelvlasov.render.RenderRequest;
035:        import com.pavelvlasov.render.RenderingException;
036:        import com.pavelvlasov.render.dom.AbstractRenderer;
037:        import com.pavelvlasov.review.SourceMarker;
038:
039:        /**
040:         * @author MUCBJ0
041:         * 
042:         * TODO parameter for JspBase Type, Jsp File Extractor,
043:         */
044:        public class JspInspector extends InspectorBase implements 
045:                com.pavelvlasov.config.Parameterizable {
046:
047:            private Map jspList = new HashMap();
048:            private boolean isJavaScriptStream = false;
049:            private JspDescriptor currentJspDescriptor = null;
050:            private String jspBaseClass = "";
051:
052:            public void visit(MethodCall methodCall) {
053:                // Pavel Vlasov - to avoid NPE
054:                if (currentJspDescriptor == null) {
055:                    return;
056:                }
057:                // System.out.println("*> " + methodCall.getName());
058:                if ("response.sendRedirect".equals(methodCall.getName()
059:                        .toString())) {
060:                    String referenceStr = methodCall.getParameters().get(0)
061:                            .toString();
062:                    JspXref jXref = new JspXref(currentJspDescriptor,
063:                            "response.sendRedirect", referenceStr);
064:                    currentJspDescriptor.listOfInvokedJsp.add(jXref);
065:                }
066:                if ("pageContext.forward".equals(methodCall.getName()
067:                        .toString())) {
068:                    String referenceStr = methodCall.getParameters().get(0)
069:                            .toString();
070:                    JspXref jXref = new JspXref(currentJspDescriptor,
071:                            "JSP Forward", referenceStr);
072:                    currentJspDescriptor.listOfInvokedJsp.add(jXref);
073:                }
074:                if ("out.print".equals(methodCall.getName().toString())
075:                        || "out.println"
076:                                .equals(methodCall.getName().toString())) {
077:                    this .currentJspDescriptor.numberOfOutPrintOps++;
078:                } else if ("out.write".equals(methodCall.getName().toString())) {
079:                    this .currentJspDescriptor.numberOfOutWriteOps++;
080:                    List parameterList = methodCall.getParameters();
081:                    for (int i = 0; i < parameterList.size(); i++) {
082:                        Object param = parameterList.get(i);
083:                        if (param instanceof  StringConstant) {
084:                            StringConstant strCnst = (StringConstant) param;
085:
086:                            if (!isJavaScriptStream
087:                                    && strCnst.toString().toLowerCase()
088:                                            .indexOf("<script".toLowerCase()) > -1) {
089:                                isJavaScriptStream = true;
090:                                this .currentJspDescriptor.numberOfJavaScriptSnippets++;
091:
092:                                currentJspDescriptor
093:                                        .analyseJavaScriptPortion(strCnst
094:                                                .toString());
095:                            } else if (isJavaScriptStream
096:                                    && strCnst.toString().toLowerCase()
097:                                            .indexOf("</script>".toLowerCase()) > -1) {
098:
099:                                currentJspDescriptor
100:                                        .analyseJavaScriptPortion(strCnst
101:                                                .toString());
102:
103:                                isJavaScriptStream = false;
104:                            } else if (isJavaScriptStream) {
105:
106:                                currentJspDescriptor
107:                                        .analyseJavaScriptPortion(strCnst
108:                                                .toString());
109:                            }
110:                            if (!isJavaScriptStream
111:                                    && strCnst.toString().toLowerCase()
112:                                            .indexOf("<form".toLowerCase()) > -1) {
113:                                currentJspDescriptor.analyseHtmlForm(strCnst
114:                                        .toString());
115:                            }
116:                        }
117:                    }
118:                }
119:            }
120:
121:            public void extractJavaScriptPortion(String jsStream) {
122:                // Pavel Vlasov: to avoid NPE
123:                if (currentJspDescriptor != null) {
124:                    currentJspDescriptor.analyseJavaScriptPortion(jsStream);
125:                }
126:            }
127:
128:            public void visit(VariableDefinition element) {
129:                //!! SQL Extractor
130:            }
131:
132:            public void visit(TypeDefinition typeDefinition) {
133:                try {
134:                    if (typeDefinition.isKindOf(jspBaseClass)) {
135:                        int start = typeDefinition.getAst().getFirstToken()
136:                                .getLine();
137:                        int end = typeDefinition.getAst().getLastToken()
138:                                .getLine();
139:                        JspDescriptor jspDescr = new JspDescriptor();
140:                        CodeMetric typeCodeMetric = new CodeMetric();
141:                        typeCodeMetric.setDescriptonEntity("Class");
142:                        typeCodeMetric.setName(typeDefinition.getFcn());
143:                        // packageName.replace('.','/')+compilationUnit.getName()
144:                        System.out.println("++ "
145:                                + typeDefinition.getCompilationUnit()
146:                                        .getPackage().getName().toString());
147:                        typeCodeMetric.source_url = ((SourceMarker) typeDefinition)
148:                                .getSourceURL();
149:                        typeCodeMetric.source_line = ((SourceMarker) typeDefinition)
150:                                .getLine();
151:                        typeCodeMetric.source_col = ((SourceMarker) typeDefinition)
152:                                .getColumn();
153:                        typeCodeMetric.setNcss(end - start);
154:                        jspDescr.codeMetric = typeCodeMetric;
155:                        //!! potential thread issue !!
156:                        this .currentJspDescriptor = jspDescr;
157:                        jspList.put((String) typeDefinition.getFcn(), jspDescr);
158:                    }
159:                } catch (JselException e) {
160:                    // TODO Auto-generated catch block
161:                    e.printStackTrace();
162:                }
163:            }
164:
165:            public void leave(Repository repository) {
166:                //aggregate();
167:                context.annotate(new LinkedAnnotation() {
168:                    private String path;
169:
170:                    public String getName() {
171:                        return getContext().getDescriptor().getName();
172:                    }
173:
174:                    public String getPath() {
175:                        return path;
176:                    }
177:
178:                    public void render(AnnotationContext context)
179:                            throws HammurapiException {
180:                        String errorCausingFile = "";
181:                        // Output images here. See AnnotationTest for details.
182:                        class JspInspectorRenderer extends AbstractRenderer {
183:                            JspInspectorRenderer() {
184:                                super (new RenderRequest(JspInspector.this ));
185:                            }
186:
187:                            public Element render(Document document)
188:                                    throws RenderingException {
189:                                Element entities = document
190:                                        .createElement("Entities");
191:                                Element jspMetricElement = document
192:                                        .createElement("JspMetric");
193:                                Collection values = jspList.values();
194:                                Iterator it = values.iterator();
195:                                System.out
196:                                        .println("Number of JspDescriptors - "
197:                                                + values.size());
198:                                while (it.hasNext()) {
199:                                    JspDescriptor jspD = (JspDescriptor) it
200:                                            .next();
201:                                    jspMetricElement.appendChild(jspD
202:                                            .toDom(document));
203:                                }
204:                                return jspMetricElement;
205:                            }
206:                        } //-- end class JspInspectorRenderer
207:                        /*
208:                         * locReport = new LocReporter( context, classMaxLoc,
209:                         * functionMaxLoc, ncssReport, chartDebugWindow );
210:                         * locReport.setNcssClassList( ncssClassList );
211:                         * locReport.setNcssFunctionList( ncssFunctionList );
212:                         * 
213:                         * locReport.doIt( projectMetric) ;
214:                         */
215:                        AnnotationContext.FileEntry fileEntry = context
216:                                .getNextFile(context.getExtension());
217:                        path = fileEntry.getPath();
218:                        System.out.println(".> " + this .getPath().toString());
219:                        AnnotationContext.FileEntry fileEntryXml = context
220:                                .getNextFile(".xml");
221:                        try {
222:                            JspInspectorRenderer renderer = new JspInspectorRenderer();
223:                            FileOutputStream out = new FileOutputStream(
224:                                    fileEntry.getFile());
225:                            renderer
226:                                    .setEmbeddedStyle(context.isEmbeddedStyle());
227:                            try {
228:                                errorCausingFile = fileEntry.getFile()
229:                                        .getAbsolutePath();
230:                                renderer
231:                                        .render(
232:                                                context.getParameter("style") == null ? null
233:                                                        : new FileInputStream(
234:                                                                context
235:                                                                        .getParameter(
236:                                                                                "style")
237:                                                                        .toString()),
238:                                                out);
239:                            } finally {
240:                                out.close();
241:                            }
242:                            //-- write a XML file for other XSL usage
243:                            FileOutputStream outXml = new FileOutputStream(
244:                                    fileEntryXml.getFile());
245:                            try {
246:                                errorCausingFile = fileEntryXml.getFile()
247:                                        .getAbsolutePath();
248:                                //-- write a XML file for other XSL usage
249:                                renderer.setEmbeddedStyle(false);
250:                                renderer.render(outXml);
251:                                //						renderer.setPrettyPrint( true );
252:                                //						InputStream
253:                                // inStream=getClass().getClassLoader().getResourceAsStream(xmlResourceName);
254:                                //						renderer.render(inStream, outXml);
255:                            } finally {
256:                                outXml.close();
257:                            }
258:                        } catch (Exception e) {
259:                            throw new HammurapiException("Can't save "
260:                                    + errorCausingFile + ". " + e.getMessage());
261:                        }
262:                    }
263:
264:                    public Properties getProperties() {
265:                        Properties ret = new Properties();
266:                        ret.setProperty("left-panel", "yes");
267:                        ret.setProperty("target", "JSP Metrics");
268:                        return ret;
269:                    }
270:                });
271:            }
272:
273:            public boolean setParameter(String name, Object value)
274:                    throws ConfigurationException {
275:                if ("jsp-base-class".equals(name)) {
276:                    jspBaseClass = value.toString();
277:                    return true;
278:                } else {
279:                    throw new ConfigurationException("Parameter '" + name
280:                            + "' is not supported");
281:                }
282:            }
283:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.