Package com.googlecode.psiprobe.model.jsp

Examples of com.googlecode.psiprobe.model.jsp.Item


                    //
                    // mark all items as missing
                    //
                    for (Iterator it = summary.getItems().keySet().iterator(); it.hasNext();) {
                        Item item = (Item) summary.getItems().get(it.next());
                        item.setMissing(true);
                    }

                    //
                    // we need to pass context classloader here, so the jsps can reference /WEB-INF/classes and
                    // /WEB-INF/lib. JspCompilationContext would only take URLClassLoader, so we fake it
                    //
                    compileItem("/", opt, context, jrctx, summary,
                            new URLClassLoader(new URL[]{}, context.getLoader().getClassLoader()), 0, compile);
                } finally {
                    jrctx.destroy();
                }
            }

            //
            // delete "missing" items by keeping "not missing" ones
            //
            Map hashMap = new HashMap();
            for (Iterator it = summary.getItems().keySet().iterator(); it.hasNext();) {
                Object key = it.next();
                Item item = (Item) summary.getItems().get(key);
                if (!item.isMissing()) {
                    hashMap.put(key, item);
                }
            }

            summary.setItems(hashMap);
View Full Code Here


                if (isJsp) {
                    JspCompilationContext jcctx = createJspCompilationContext(name, false, opt, sctx, jrctx, classLoader);
                    ClassLoader prevCl = ClassUtils.overrideThreadContextClassLoader(classLoader);
                    try {
                        Item item = (Item) summary.getItems().get(name);

                        if (item == null) {
                            item = new Item();
                            item.setName(name);
                        }

                        item.setLevel(level);
                        item.setCompileTime(-1);
                        try {
                            ResourceAttributes jspAttributes = (ResourceAttributes) ctx.getResources().getAttributes(name);
                            item.setSize(jspAttributes.getContentLength());
                            item.setLastModified(jspAttributes.getLastModified());
                        } catch (NamingException e) {
                            logger.error("Cannot lookup attributes for " + name);
                        }


                        long time = System.currentTimeMillis();
                        try {
                            org.apache.jasper.compiler.Compiler c = jcctx.createCompiler();
                            if (compile) {
                                c.compile();
                                item.setState(Item.STATE_READY);
                                item.setException(null);
                            } else {
                                if (!c.isOutDated()) {
                                    item.setState(Item.STATE_READY);
                                    item.setException(null);
                                } else if (item.getState() != Item.STATE_FAILED) {
                                    item.setState(Item.STATE_OOD);
                                    item.setException(null);
                                }
                            }
                            logger.info("Compiled " + name + ": OK");
                        } catch (Exception e) {
                            item.setState(Item.STATE_FAILED);
                            item.setException(e);
                            logger.info("Compiled " + name + ": FAILED", e);
                        }
                        if (compile) {
                            item.setCompileTime(System.currentTimeMillis() - time);
                        }
                        item.setMissing(false);
                        summary.getItems().put(name, item);
                    } finally {
                        ClassUtils.overrideThreadContextClassLoader(prevCl);
                    }
                } else {
View Full Code Here

                            String name = (String) it.next();
                            long time = System.currentTimeMillis();
                            JspCompilationContext jcctx = createJspCompilationContext(name, false, opt, sctx, jrctx, classLoader);
                            ClassLoader prevCl = ClassUtils.overrideThreadContextClassLoader(classLoader);
                            try {
                                Item item = (Item) summary.getItems().get(name);
                                if (item != null) {
                                    try {
                                        org.apache.jasper.compiler.Compiler c = jcctx.createCompiler();
                                        c.compile();
                                        item.setState(Item.STATE_READY);
                                        item.setException(null);
                                        logger.info("Compiled " + name + ": OK");
                                    } catch (Exception e) {
                                        item.setState(Item.STATE_FAILED);
                                        item.setException(e);
                                        logger.info("Compiled " + name + ": FAILED", e);
                                    }
                                    item.setCompileTime(System.currentTimeMillis() - time);
                                } else {
                                    logger.error(name + " is not on the summary list, ignored");
                                }
                            } finally {
                                ClassUtils.overrideThreadContextClassLoader(prevCl);
View Full Code Here

        Summary summary = (Summary) (request.getSession() != null ?
                request.getSession().getAttribute(DisplayJspController.SUMMARY_ATTRIBUTE) : null);

        if (jspName != null && summary != null && contextName.equals(summary.getName())) {

            Item item = (Item) summary.getItems().get(jspName);

            if (item != null) {
                //
                // replace "\" with "/"
                //
                jspName = jspName.replaceAll("\\\\", "/");

                //
                // remove cheeky "../" from the path to avoid exploits
                //
                while (jspName.indexOf("../") != -1) {
                    jspName = jspName.replaceAll("\\.\\./", "");
                }

                Resource jsp = (Resource) context.getResources().lookup(jspName);

                if (jsp != null) {

                    ServletContext sctx = context.getServletContext();
                    ServletConfig scfg = (ServletConfig) context.findChild("jsp");
                    Options opt = new EmbeddedServletOptions(scfg, sctx);
                    String descriptorPageEncoding = opt.getJspConfig().findJspProperty(jspName).getPageEncoding();

                    if (descriptorPageEncoding != null && descriptorPageEncoding.length() > 0) {
                        item.setEncoding(descriptorPageEncoding);
                    } else {

                        //
                        // we have to read the JSP twice, once to figure out the content encoding
                        // the second time to read the actual content using the correct encoding
                        //
                        item.setEncoding(Utils.getJSPEncoding(jsp.streamContent()));
                    }
                    if (highlight) {
                        request.setAttribute("highlightedContent", Utils.highlightStream(jspName, jsp.streamContent(),
                                "xhtml", item.getEncoding()));
                    } else {
                        request.setAttribute("content", Utils.readStream(jsp.streamContent(), item.getEncoding()));
                    }

                } else {
                    logger.error(jspName + " does not exist");
                }
View Full Code Here

TOP

Related Classes of com.googlecode.psiprobe.model.jsp.Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.