Package de.innovationgate.wgpublisher.webtml.utils

Examples of de.innovationgate.wgpublisher.webtml.utils.HttpErrorException


        response.setContentType(contentType);

        // Create publishing file object, which will provide the data
        PublishingFile publishingFile = new PublishingFile(this, fileContainer, fileName);
        if (!publishingFile.isPublishable()) {
            throw new HttpErrorException(403, "Files from this container may not be published", path.getDatabaseKey());
        }
       
        // Optionally inject scaling information to file object
        String maxHeightStr = request.getParameter("maxheight");
        if (maxHeightStr != null) {
View Full Code Here


        else {
            file = new File(this.getServletContext().getRealPath("/"), path.getResourcePath());
        }

        if (file == null || !file.exists() || !file.isFile()) {
            throw new HttpErrorException(404, "File not found: " + path.getResourcePath(), null);
        }

        // / Set expiration time
        int fileExpirationMinutes = getCore().getWgaConfiguration().getCacheExpirationForStaticResources();
        if (fileExpirationMinutes > 0) {
            int fileExpirationSeconds = fileExpirationMinutes * 60;
            response.setHeader("Cache-Control", "max-age=" + fileExpirationSeconds + ", must-revalidate");
        }

        // determine lastModified
        // - last modified of binary response depends only on resource change
        // date
        // - last change date of textual response additionally depends on
        // character encoding change date
        long lastModified;
        if (isBinary(response)) {
            lastModified = file.lastModified();
        }
        else {
            lastModified = Math.max(file.lastModified(), _core.getCharacterEncodingLastModified());
        }
        if (browserCacheIsValid(request, lastModified)) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            return;
        }
        else {
            response.setDateHeader("Last-Modified", lastModified);
            response.setHeader("ETag", '"' + String.valueOf(lastModified) + '"');
        }

        if (mimeType.startsWith("application/")) {
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        }

        // Dispatch to file resource
        try {
            if (!"HEAD".equalsIgnoreCase(request.getMethod())) {
                DataSource in = null;
                int fileSize = 0;

                // We allow direct file dispatching only for temporary files. In
                // all other cases we use the servlet
                // context which will take care of file system security.
                if (isTemporaryDownload) {
                    response.setHeader("Content-Disposition", "attachment;filename=" + file.getName());
                    in = new URLDataSource(file.toURL());
                    fileSize = (int) file.length();
                }
                else {
                    in = new URLDataSource(this.getServletContext().getResource(resourcePath));
                }

                if (in == null) {
                    throw new HttpErrorException(404, "File not found: " + resourcePath, null);
                }

                // B000041DA
                // write data to response - use UTF-8 when reading characters -
                // WGA resources are UTF-8 encoded
View Full Code Here

    private void writeWholeData(DataSource data, HttpServletResponse response, String characterEncoding, String dbHint) throws IOException, HttpErrorException, UnsupportedEncodingException {

        Reader reader = null;
        InputStream in = data.getInputStream();
        if (in == null) {
            throw new HttpErrorException(404, "File not found: " + data.getName(), dbHint);
        }

        try {
            if (!isBinary(response)) {
                // this is a textual reponse
View Full Code Here

        ServletOutputStream out = response.getOutputStream();
        for (AcceptRange range : ranges) {
            InputStream in = data.getInputStream();
            if (in == null) {
                throw new HttpErrorException(404, "File not found: " + data.getName(), dbHint);
            }
           
            if (ranges.size() != 1) {
                out.println();
                out.println("--" + BYTERANGE_BOUNDARY);
View Full Code Here

            case WGPRequestPath.TYPE_JS:
                codeType = WGScriptModule.CODETYPE_JS;
                break;

            default:
                throw new HttpErrorException(500, "Invalid path type to dispatch a css/js request: " + path.getPathType(), path.getDatabaseKey());

        }

        WGCSSJSModule lib = database.getScriptModule(path.getCssjsKey(), codeType);
        if (lib == null) {
            throw new HttpErrorException(404, "No css/js resource of name " + path.getCssjsKey(), path.getDatabaseKey());
        }

        // determine mime type and encoding
        String mimeType;
        String libType = lib.getCodeType();
View Full Code Here

                if (content == null) {
                    if (request.getQueryString() != null && request.getQueryString().toLowerCase().indexOf("login") != -1) {
                        sendRedirect(response, getLoginURL(request, database, path.getCompleteURL()));
                    }
                    else {
                        throw new HttpErrorException(404, "No content of name/id " + contentKey, path.getDatabaseKey());
                    }
                    return;
                }
                if (!content.isVisible() && !isBrowserInterface(request.getSession())) {
                    throw new HttpErrorException(404, "No content of name/id " + contentKey, path.getDatabaseKey());
                }
            }
            else {
                WGLanguage lang = langBehaviour.requestSelectDatabaseLanguage(database, request);
                content = database.getDummyContent(lang.getName());
            }

            // Test browsability of content
            if (!content.isDummy() && getBrowsingSecurity(database) <= BrowsingSecurity.NO_BROWSING) {
                throw new HttpErrorException(java.net.HttpURLConnection.HTTP_FORBIDDEN, "Browsing not allowed in database '" + path.getDatabaseKey() + "'", path.getDatabaseKey());
            }

            request.setAttribute(WGACore.ATTRIB_MAINCONTEXT, content);
            request.setAttribute(WGACore.ATTRIB_MEDIAKEY, database.getAttribute(WGACore.DBATTRIB_DEFAULT_MEDIAKEY));

        }

        // Set context attributes for jsps
        String completeURL = path.getCompleteURL();
        request.setAttribute(WGACore.ATTRIB_WGPPATH, this.getPublisherURL(request));
        request.setAttribute(WGACore.ATTRIB_TAGIDS, WGUtils.createSynchronizedMap());
        request.setAttribute(WGACore.ATTRIB_TMLCONTEXTS, WGUtils.createSynchronizedMap());
        request.setAttribute(WGACore.ATTRIB_REQUESTURL, completeURL);
        request.setAttribute(WGACore.ATTRIB_REQUESTTYPE, REQUESTTYPE_STATICTML);

        String mimeType = null;
        if (contentKey != null) {
            mimeType = this.getServletContext().getMimeType(jspName);
        }
        else {
            mimeType = this.getServletContext().getMimeType(request.getRequestURI());
        }
        if (mimeType == null) {
            mimeType = "text/html";
        }

        request.setAttribute(WGACore.ATTRIB_MIMETYPE, mimeType);
        response.setContentType(mimeType);

        String targetJSP = jspName + ".jsp";

        if (targetJSP != null) {
            if (!"HEAD".equalsIgnoreCase(request.getMethod())) {
                this.getServletContext().getRequestDispatcher(targetJSP).include(request, response);
            }
        }
        else {
            throw new HttpErrorException(500, "no static tml page: " + targetJSP, path.getDatabaseKey());
        }

        // Eventually do redirect
        if (request.getAttribute(WGACore.ATTRIB_REDIRECT) != null) {
            response.reset();
View Full Code Here

     * @param dbHint
     * @deprecated instead throw HttpErrorException directly
     * @throws HttpErrorException
     */
    public void sendError(int code, String message, String dbHint) throws HttpErrorException {
        throw new HttpErrorException(code, message, dbHint);
    }
View Full Code Here

         * @throws ServletException
         */
        private void performDebugMode(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws HttpErrorException, ServletException, IOException {

            if (!getCore().isAdminLoggedIn(request)) {
                throw new HttpErrorException(HttpServletResponse.SC_FORBIDDEN, "You must be logged in to the wga admin page to use WebTML debugging", null);
            }

            String command = request.getParameter("command");
            Boolean debugModeEnabled = (Boolean) session.getAttribute(WGACore.ATTRIB_TMLDEBUG);
            if (debugModeEnabled == null) {
                debugModeEnabled = new Boolean(false);
            }
            Boolean resultTracingEnabled = (Boolean) session.getAttribute(WGACore.ATTRIB_TMLDEBUG_TRACE_RESULTS);
            if (resultTracingEnabled == null) {
                resultTracingEnabled = new Boolean(false);
            }

            Boolean optionsTracingEnabled = (Boolean) session.getAttribute(WGACore.ATTRIB_TMLDEBUG_TRACE_OPTIONS);
            if (optionsTracingEnabled == null) {
                optionsTracingEnabled = new Boolean(false);
            }

            Boolean tmlscriptOptimizationDisabled = (Boolean) session.getAttribute(WGACore.ATTRIB_TMLDEBUG_DISABLE_TMLSCRIPT_OPTIMIZATION);
            if (tmlscriptOptimizationDisabled == null) {
                tmlscriptOptimizationDisabled = new Boolean(false);
            }

            if (command == null) {
                request.getRequestDispatcher("/tmlDebugFrameset.jsp").include(request, response);
                return;
            }

            if (command.equalsIgnoreCase("toggledebug")) {
                debugModeEnabled = new Boolean(!debugModeEnabled.booleanValue());
                session.setAttribute(WGACore.ATTRIB_TMLDEBUG, debugModeEnabled);
                command = "status";
            }
            else if (command.equalsIgnoreCase("toggleresulttrace")) {
                resultTracingEnabled = new Boolean(!resultTracingEnabled.booleanValue());
                session.setAttribute(WGACore.ATTRIB_TMLDEBUG_TRACE_RESULTS, resultTracingEnabled);
                command = "status";
            }
            else if (command.equalsIgnoreCase("toggleoptionstrace")) {
                optionsTracingEnabled = new Boolean(!optionsTracingEnabled.booleanValue());
                session.setAttribute(WGACore.ATTRIB_TMLDEBUG_TRACE_OPTIONS, optionsTracingEnabled);
                command = "status";
            }
            else if (command.equalsIgnoreCase("toggletmlscriptoptimization")) {
                tmlscriptOptimizationDisabled = new Boolean(!tmlscriptOptimizationDisabled.booleanValue());
                session.setAttribute(WGACore.ATTRIB_TMLDEBUG_DISABLE_TMLSCRIPT_OPTIMIZATION, tmlscriptOptimizationDisabled);
                command = "status";
            }

            else if (command.equalsIgnoreCase("clearlist")) {
                List debugDocuments = WGACore.getDebugDocumentsList(session);
                debugDocuments.clear();
                command = "list";
            }

            if (command.equalsIgnoreCase("toolbar")) {
                request.getRequestDispatcher("/tmlDebugToolbar.jsp").include(request, response);
            }
            else if (command.equalsIgnoreCase("status")) {
                response.getWriter().write("TMLScript stack traces are switched " + (tmlscriptOptimizationDisabled.booleanValue() ? "ON" : "OFF") + "\n");
                if (debugModeEnabled.booleanValue() == true) {
                    response.getWriter().write("WebTML debug mode is switched ON\n");
                    response.getWriter().write("Result tracing is switched " + (resultTracingEnabled.booleanValue() ? "ON" : "OFF") + "\n");
                    response.getWriter().write("Options tracing is switched " + (optionsTracingEnabled.booleanValue() ? "ON" : "OFF") + "\n");
                }
                else {
                    response.getWriter().write("WebTML debug mode is switched OFF\n");
                }

            }
            else if (command.equalsIgnoreCase("list")) {
                if (debugModeEnabled.booleanValue() == true) {
                    sendDebugDocList(request, response, session);
                }
                else {
                    throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "WebTML debug mode is not enabled. First enable it via tmldebug?command=on", null);
                }
            }
            else if (command.equalsIgnoreCase("showModules")) {
                showTMLModules(request, response, session);
            }
            else if (command.equalsIgnoreCase("showTags")) {
                showTMLTags(request, response, session);
            }
            else if (command.equalsIgnoreCase("show")) {
                sendDebugDoc(request, response, session);
            }
            else {
                throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "Unknown debug command: " + command, null);
            }

        }
View Full Code Here

                List debugDocuments = WGACore.getDebugDocumentsList(session);
                if (index == -1) {
                    index = debugDocuments.size() - 1;
                }
                if (index >= debugDocuments.size()) {
                    throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "Index out of range: " + index + " where maximum index is " + (debugDocuments.size() - 1), null);
                }
                else {
                    Document doc = (Document) debugDocuments.get(index);
                    response.setContentType("text/xml");
                    XMLWriter writer = new XMLWriter(response.getWriter());
                    writer.write(doc);
                }
            }
            else {
                throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "You must include either parameter index or url to address the debug document to show", null);
            }
        }
View Full Code Here

                List debugDocuments = WGACore.getDebugDocumentsList(session);
                if (index == -1) {
                    index = debugDocuments.size() - 1;
                }
                if (index >= debugDocuments.size()) {
                    throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "Index out of range: " + index + " where maximum index is " + (debugDocuments.size() - 1), null);
                }
                else {
                    Document doc = (Document) debugDocuments.get(index);
                    doc.getRootElement().addAttribute("index", String.valueOf(index));

                    try {
                        DOMWriter domWriter = new DOMWriter();
                        org.w3c.dom.Document domDocument = domWriter.write(doc);

                        Transformer trans = getDebugModulesTransformer(request.getParameter("throwAway") != null);
                        trans.transform(new DOMSource(domDocument), new StreamResult(response.getOutputStream()));
                    }
                    catch (TransformerConfigurationException e) {
                        response.sendError(500, e.getMessageAndLocation());
                        e.printStackTrace();
                    }
                    catch (TransformerFactoryConfigurationError e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                    catch (TransformerException e) {
                        response.sendError(500, e.getMessageAndLocation());
                        e.printStackTrace();
                    }
                    catch (IOException e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                    catch (DocumentException e) {
                        response.sendError(500, e.getMessage());
                        e.printStackTrace();
                    }
                }
            }
            else {
                throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "You must include either parameter index or url to address the debug document to show", null);
            }
        }
View Full Code Here

TOP

Related Classes of de.innovationgate.wgpublisher.webtml.utils.HttpErrorException

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.