Package org.apache.cocoon.environment.http

Examples of org.apache.cocoon.environment.http.HttpRequest


        Map objectModel,
        String source,
        Parameters parameters)
        throws Exception {

        HttpRequest request = (HttpRequest)ObjectModelHelper.getRequest(objectModel);

        // Get namespaces
        String namespaces = removeRedundantNamespaces(request.getParameter("namespaces"));
        log.debug(namespaces);

        // Aggregate content
        String encoding = request.getCharacterEncoding();
        String content =
            "<?xml version=\"1.0\" encoding=\""
                + encoding
                + "\"?>\n"
                + addNamespaces(namespaces, request.getParameter("content"));

        // Save file temporarily
        File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile());
        File file =
            new File(
View Full Code Here


        getLogger().debug(".act(): Absolute XSL Root Directory: " + sitemapPath + xslRoot);
        getLogger().debug(".act(): Absolute XSD Root Directory: " + sitemapPath + xsdRoot);
        getLogger().debug(".act(): Absolute Temp Root Directory: " + sitemapPath + tempRoot);

        // Get request object
        HttpRequest httpReq = (HttpRequest) objectModel.get(ObjectModelHelper.REQUEST_OBJECT);

        if (httpReq == null) {
            getLogger().error("Could not get HTTP_REQUEST_OBJECT from objectModel");

            return null;
        }

        int length = httpReq.getContentLength();
        PostInputStream reqContent = new PostInputStream(httpReq.getInputStream(), length);

        // construct DOM document from the request contents
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        InputSource saxSource = new InputSource(reqContent);
        Document requestDoc = parser.parseDocument(saxSource);

        // get the root element (should be "request") and its attributes ---> FixMe: Add error handling
        Element root = requestDoc.getDocumentElement();
        getLogger().debug(".act(): Root element (should be 'request'): " + root.getTagName());

        String reqId = root.getAttribute("id");
        getLogger().debug(".act(): Request ID: " + reqId);

        String reqType = root.getAttribute("type");
        getLogger().debug(".act(): Request Type: " + reqType);

        // get the first child element for root element (should be "data") and its attributes ---> FixMe: Add error handling
        Element data = (Element) root.getFirstChild();
        getLogger().debug(".act(): first child element (should be 'data'): " + data.getTagName());

        String reqFile = data.getAttribute("id");
        getLogger().debug(".act(): Requested File: " + reqFile);

        String fileType = data.getAttribute("type");
        getLogger().debug(".act(): Requested File's Type: " + fileType);

        // close the input stream
        reqContent.close();

        // Define Files
        File tempFileDir =
            new File(sitemapPath + relRootDirs.get("temp") + "/" + relRootDirs.get(fileType));

        if (!(tempFileDir.exists())) {
            tempFileDir.mkdir();
        }

        File tempFile = IOUtils.createFile(tempFileDir, reqFile);
        File permFile = new File(sitemapPath + relRootDirs.get(fileType) + "/" + reqFile);

        if (!permFile.exists()) {
            getLogger().error(".act(): No such file: " + permFile.getAbsolutePath());
            getLogger().error(
                ".act(): No such file: "
                    + sitemapPath
                    + "::"
                    + relRootDirs.get(fileType)
                    + "::"
                    + reqFile);

            return null;
        }

        // make a temporary copy of the file to be edited
        if ("xml".equals(fileType) && "open".equals(reqType)) {
            FileUtils.copyFile(permFile, tempFile);
            getLogger().debug(".act(): PERMANENT FILE: " + permFile.getAbsolutePath());
            getLogger().debug(".act(): TEMPORARY FILE: " + tempFile.getAbsolutePath());
        }

        // set sitemap params for response routing
        Map sitemapParams = new HashMap();
        sitemapParams.put("reqId", reqId);
        sitemapParams.put("reqType", reqType);
        sitemapParams.put("reqFile", reqFile);
        sitemapParams.put("fileType", fileType);

        if ("xml".equals(fileType) && ("open".equals(reqType) || "save".equals(reqType))) {
            sitemapParams.put(
                "reqFilePath",
                (String) relRootDirs.get("temp")
                    + "/"
                    + (String) relRootDirs.get(fileType)
                    + "/"
                    + reqFile);
            getLogger().debug(
                ".act(): File to be edited (in temp dir): " + sitemapParams.get("reqFilePath"));
        } else {
            sitemapParams.put("reqFilePath", (String) relRootDirs.get(fileType) + "/" + reqFile);
        }

        // The xopus sitemap will return the XML
        if ("open".equals(reqType)) {
            return sitemapParams;
        }

        // save to temporary file, if needed
        if ("save".equals(reqType) || "checkin".equals(reqType)) {
            getLogger().debug(".act(): Write to temp file: " + tempFile);

            try {
                Element contentNode = (Element) data.getFirstChild();
                DOMParserFactory dpf = new DOMParserFactory();

                // Create a new document, where the actual content starts at the root element, which is the inner part of requestDoc
                Document contentDocument = dpf.getDocument();
                contentDocument.appendChild(
                    dpf.cloneNode(contentDocument, contentNode, true));
                new DOMWriter(new FileOutputStream(tempFile)).printWithoutFormatting(
                    contentDocument);
            } catch (Exception e) {
                getLogger().error(".act(): Exception during writing to temp file", e);
            }
        }

        // save to permanent file, if needed
        if ("checkin".equals(reqType)) {
            getLogger().debug(".act(): Save to permanent file: " + permFile);

            RevisionController rc =
                new RevisionController(
                    sitemapPath + rcmlDirectory,
                    sitemapPath + backupDirectory,
                    sitemapPath);

            try {
                Session session = httpReq.getSession(false);

                if (session == null) {
                    throw new Exception("No session");
                }
View Full Code Here

        getLogger().debug("Absolute XSL Root Directory: " + sitemapPath + xslRoot);
        getLogger().debug("Absolute XSD Root Directory: " + sitemapPath + xsdRoot);
        getLogger().debug("Absolute Temp Root Directory: " + sitemapPath + tempRoot);

        // Get request object
        HttpRequest httpReq = (HttpRequest) objectModel.get(ObjectModelHelper.REQUEST_OBJECT);

        if (httpReq == null) {
            getLogger().error("Could not get HTTP_REQUEST_OBJECT from objectModel");

            return null;
        }

        int length = httpReq.getContentLength();
        PostInputStream reqContent = new PostInputStream(httpReq.getInputStream(), length);

        // construct DOM document from the request contents
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        InputSource saxSource = new InputSource(reqContent);
        Document requestDoc = parser.parseDocument(saxSource);

        // get the root element (should be "request") and its attributes ---> FixMe: Add error handling
        Element root = requestDoc.getDocumentElement();
        getLogger().debug("root element (should be 'request'): " + root.getTagName());

        String reqType = root.getAttribute("type");
        getLogger().debug("Request Type: " + reqType);

        // get the first child element for root element (should be "data") and its attributes ---> FixMe: Add error handling
        Element data = (Element) root.getFirstChild();
        getLogger().debug("first child element (should be 'data'): " + data.getTagName());

        String fileType = data.getAttribute("type");
        getLogger().debug("Requested File's Type: " + fileType);

        // close the input stream
        reqContent.close();

        // Define temp dir
        File tempFileDir =
            new File(sitemapPath + relRootDirs.get("temp") + "/" + relRootDirs.get(fileType));

        if (!(tempFileDir.exists())) {
            tempFileDir.mkdir();
        }

        // Define Filenames
        File tempFile = IOUtils.createFile(tempFileDir, relativeFilename);
        File permFile = new File(sitemapPath + relRootDirs.get(fileType) + "/" + relativeFilename);
        getLogger().debug("PERMANENT FILE: " + permFile.getAbsolutePath());
        getLogger().debug("TEMPORARY FILE: " + tempFile.getAbsolutePath());

        // make a temporary copy of the file to be edited
        if ("xml".equals(fileType) && "open".equals(reqType)) {
            FileUtil.copyFile(permFile, tempFile);
        }

        Map sitemapParams = new HashMap();

        // save to temporary file, if needed
        if ("save".equals(reqType) || "checkin".equals(reqType)) {
            //FIXME(): remove hard coding
            final OutputStream os = new FileOutputStream(tempFile);
            ComponentSelector selector =
                (ComponentSelector) super.manager.lookup(Serializer.ROLE + "Selector");

            //FIXME: remove hardcoding stuff
            Serializer serializer = (Serializer) selector.select("xml");
            serializer.setOutputStream(os);
            serializer.startDocument();

            DOMStreamer domStreamer = new DOMStreamer(serializer);
            Element contentNode = (Element) data.getFirstChild();
            domStreamer.stream(contentNode);
            serializer.endDocument();
            getLogger().debug("NODE IS: \n" + contentNode.toString());
            selector.release(serializer);
            super.manager.release(selector);
            os.flush();
            os.close();
        }

        // save to permanent file, if needed
        if ("checkin".equals(reqType)) {
            getLogger().debug(".act(): Save to permanent file: " + permFile);

            RevisionController rc =
                new RevisionController(
                    sitemapPath + rcmlDirectory,
                    sitemapPath + backupDirectory,
                    sitemapPath);

            try {
                Session session = httpReq.getSession(false);

                if (session == null) {
                    throw new Exception("No session");
                }
View Full Code Here

        getLogger().debug(".act(): Absolute XSL Root Directory: " + sitemapPath + xslRoot);
        getLogger().debug(".act(): Absolute XSD Root Directory: " + sitemapPath + xsdRoot);
        getLogger().debug(".act(): Absolute Temp Root Directory: " + sitemapPath + tempRoot);

        // Get request object
        HttpRequest httpReq = (HttpRequest) objectModel.get(ObjectModelHelper.REQUEST_OBJECT);

        if (httpReq == null) {
            getLogger().error("Could not get HTTP_REQUEST_OBJECT from objectModel");

            return null;
        }

        int length = httpReq.getContentLength();
        PostInputStream reqContent = new PostInputStream(httpReq.getInputStream(), length);

        // construct DOM document from the request contents
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        InputSource saxSource = new InputSource(reqContent);
        Document requestDoc = parser.parseDocument(saxSource);

        // get the root element (should be "request") and its attributes ---> FixMe: Add error handling
        Element root = requestDoc.getDocumentElement();
        getLogger().debug(".act(): Root element (should be 'request'): " + root.getTagName());

        String reqId = root.getAttribute("id");
        getLogger().debug(".act(): Request ID: " + reqId);

        String reqType = root.getAttribute("type");
        getLogger().debug(".act(): Request Type: " + reqType);

        // get the first child element for root element (should be "data") and its attributes ---> FixMe: Add error handling
        Element data = (Element) root.getFirstChild();
        getLogger().debug(".act(): first child element (should be 'data'): " + data.getTagName());

        String reqFile = data.getAttribute("id");
        getLogger().debug(".act(): Requested File: " + reqFile);

        String fileType = data.getAttribute("type");
        getLogger().debug(".act(): Requested File's Type: " + fileType);

        // close the input stream
        reqContent.close();

        // Define Files
        File tempFileDir =
            new File(sitemapPath + relRootDirs.get("temp") + "/" + relRootDirs.get(fileType));

        if (!(tempFileDir.exists())) {
            tempFileDir.mkdir();
        }

        File tempFile = IOUtils.createFile(tempFileDir, reqFile);
        File permFile = new File(sitemapPath + relRootDirs.get(fileType) + "/" + reqFile);

        if (!permFile.exists()) {
            getLogger().error(".act(): No such file: " + permFile.getAbsolutePath());
            getLogger().error(
                ".act(): No such file: "
                    + sitemapPath
                    + "::"
                    + relRootDirs.get(fileType)
                    + "::"
                    + reqFile);

            return null;
        }

        // make a temporary copy of the file to be edited
        if ("xml".equals(fileType) && "open".equals(reqType)) {
            FileUtil.copyFile(permFile, tempFile);
            getLogger().debug(".act(): PERMANENT FILE: " + permFile.getAbsolutePath());
            getLogger().debug(".act(): TEMPORARY FILE: " + tempFile.getAbsolutePath());
        }

        // set sitemap params for response routing
        Map sitemapParams = new HashMap();
        sitemapParams.put("reqId", reqId);
        sitemapParams.put("reqType", reqType);
        sitemapParams.put("reqFile", reqFile);
        sitemapParams.put("fileType", fileType);

        if ("xml".equals(fileType) && ("open".equals(reqType) || "save".equals(reqType))) {
            sitemapParams.put(
                "reqFilePath",
                (String) relRootDirs.get("temp")
                    + "/"
                    + (String) relRootDirs.get(fileType)
                    + "/"
                    + reqFile);
            getLogger().debug(
                ".act(): File to be edited (in temp dir): " + sitemapParams.get("reqFilePath"));
        } else {
            sitemapParams.put("reqFilePath", (String) relRootDirs.get(fileType) + "/" + reqFile);
        }

        // The xopus sitemap will return the XML
        if ("open".equals(reqType)) {
            return sitemapParams;
        }

        // save to temporary file, if needed
        if ("save".equals(reqType) || "checkin".equals(reqType)) {
            getLogger().debug(".act(): Write to temp file: " + tempFile);

            try {
                Element contentNode = (Element) data.getFirstChild();
                DOMParserFactory dpf = new DOMParserFactory();

                // Create a new document, where the actual content starts at the root element, which is the inner part of requestDoc
                Document contentDocument = dpf.getDocument();
                contentDocument.appendChild(
                    (Element) dpf.cloneNode(contentDocument, contentNode, true));
                new DOMWriter(new FileOutputStream(tempFile)).printWithoutFormatting(
                    contentDocument);
            } catch (Exception e) {
                getLogger().error(".act(): Exception during writing to temp file", e);
            }
        }

        // save to permanent file, if needed
        if ("checkin".equals(reqType)) {
            getLogger().debug(".act(): Save to permanent file: " + permFile);

            RevisionController rc =
                new RevisionController(
                    sitemapPath + rcmlDirectory,
                    sitemapPath + backupDirectory,
                    sitemapPath);

            try {
                Session session = httpReq.getSession(false);

                if (session == null) {
                    throw new Exception("No session");
                }
View Full Code Here

        Map objectModel,
        String source,
        Parameters parameters)
        throws Exception {

        HttpRequest request = (HttpRequest)ObjectModelHelper.getRequest(objectModel);

        // Get namespaces
        String namespaces = removeRedundantNamespaces(request.getParameter("namespaces"));
        log.debug(namespaces);

        // Aggregate content
        String encoding = request.getCharacterEncoding();
        String content =
            "<?xml version=\"1.0\" encoding=\""
                + encoding
                + "\"?>\n"
                + addNamespaces(namespaces, request.getParameter("content"));

        // Save file temporarily
        File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile());
        File file =
            new File(
View Full Code Here

        getLogger().debug("Absolute XSL Root Directory: " + sitemapPath + xslRoot);
        getLogger().debug("Absolute XSD Root Directory: " + sitemapPath + xsdRoot);
        getLogger().debug("Absolute Temp Root Directory: " + sitemapPath + tempRoot);

        // Get request object
        HttpRequest httpReq = (HttpRequest) objectModel.get(ObjectModelHelper.REQUEST_OBJECT);

        if (httpReq == null) {
            getLogger().error("Could not get HTTP_REQUEST_OBJECT from objectModel");

            return null;
        }

        int length = httpReq.getContentLength();
        PostInputStream reqContent = new PostInputStream(httpReq.getInputStream(), length);

        // construct DOM document from the request contents
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        InputSource saxSource = new InputSource(reqContent);
        Document requestDoc = parser.parseDocument(saxSource);

        // get the root element (should be "request") and its attributes ---> FixMe: Add error handling
        Element root = requestDoc.getDocumentElement();
        getLogger().debug("root element (should be 'request'): " + root.getTagName());

        String reqType = root.getAttribute("type");
        getLogger().debug("Request Type: " + reqType);

        // get the first child element for root element (should be "data") and its attributes ---> FixMe: Add error handling
        Element data = (Element) root.getFirstChild();
        getLogger().debug("first child element (should be 'data'): " + data.getTagName());

        String reqFile = data.getAttribute("id");
        String fileType = data.getAttribute("type");
        getLogger().debug("Requested File's Type: " + fileType);

        // close the input stream
        reqContent.close();

        // Define temp dir
        File tempFileDir = new File(sitemapPath + relRootDirs.get("temp") + "/" +
                relRootDirs.get(fileType));

        if (!(tempFileDir.exists())) {
            tempFileDir.mkdir();
        }

        // Define Filenames
        File tempFile = IOUtils.createFile(tempFileDir, relativeFilename);
        File permFile = new File(sitemapPath + relRootDirs.get(fileType) + "/" + relativeFilename);
        getLogger().debug("PERMANENT FILE: " + permFile.getAbsolutePath());
        getLogger().debug("TEMPORARY FILE: " + tempFile.getAbsolutePath());

        // make a temporary copy of the file to be edited
        if ("xml".equals(fileType) && "open".equals(reqType)) {
            FileUtil.copyFile(permFile, tempFile);
        }

        Map sitemapParams = new HashMap();

        // save to temporary file, if needed
        if ("save".equals(reqType) || "checkin".equals(reqType)) {
            //FIXME(): remove hard coding
            final OutputStream os = new FileOutputStream(tempFile);
            ComponentSelector selector = (ComponentSelector) super.manager.lookup(Serializer.ROLE +
                    "Selector");

            //FIXME: remove hardcoding stuff
            Serializer serializer = (Serializer) selector.select("xml");
            serializer.setOutputStream(os);
            serializer.startDocument();

            DOMStreamer domStreamer = new DOMStreamer(serializer);
            Element contentNode = (Element) data.getFirstChild();
            domStreamer.stream(contentNode);
            serializer.endDocument();
            getLogger().debug("NODE IS: \n" + contentNode.toString());
            selector.release(serializer);
            super.manager.release(selector);
            os.flush();
            os.close();
        }

        // save to permanent file, if needed
        if ("checkin".equals(reqType)) {
            getLogger().debug(".act(): Save to permanent file: " + permFile);

            RevisionController rc = new RevisionController(sitemapPath + rcmlDirectory,
                    sitemapPath + backupDirectory, sitemapPath);

            try {
                Session session = httpReq.getSession(false);

                if (session == null) {
                    throw new Exception("No session");
                }
View Full Code Here




        // Get request object
        HttpRequest httpReq = (HttpRequest) objectModel.get(ObjectModelHelper.REQUEST_OBJECT);

        if (httpReq == null) {
            getLogger().error("Could not get HTTP_REQUEST_OBJECT from objectModel");

            return null;
        }

        int length = httpReq.getContentLength();
        PostInputStream reqContent = new PostInputStream(httpReq.getInputStream(), length);

        // construct DOM document from the request contents
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        InputSource saxSource = new InputSource(reqContent);
        Document requestDoc = parser.parseDocument(saxSource);

        // get the root element (should be "request") and its attributes ---> FixMe: Add error handling
        Element root = requestDoc.getDocumentElement();
        getLogger().debug(".act(): Root element (should be 'request'): " + root.getTagName());

        String reqId = root.getAttribute("id");
        getLogger().debug(".act(): Request ID: " + reqId);

        String reqType = root.getAttribute("type");
        getLogger().debug(".act(): Request Type: " + reqType);

        // get the first child element for root element (should be "data") and its attributes ---> FixMe: Add error handling
        Element data = (Element) root.getFirstChild();
        getLogger().debug(".act(): first child element (should be 'data'): " + data.getTagName());

        String reqFile = data.getAttribute("id");
        getLogger().debug(".act(): Requested File: " + reqFile);

        String fileType = data.getAttribute("type");
        getLogger().debug(".act(): Requested File's Type: " + fileType);

        // close the input stream
        reqContent.close();








        // Define Files
        File tempFileDir = new File(sitemapPath + relRootDirs.get("temp") + "/" + relRootDirs.get(fileType));

        if (!(tempFileDir.exists())) {
            tempFileDir.mkdir();
        }

        File tempFile = IOUtils.createFile(tempFileDir, reqFile);
        File permFile = new File(sitemapPath + relRootDirs.get(fileType) + "/" + reqFile);


        if(!permFile.exists()) {
            getLogger().error(".act(): No such file: " + permFile.getAbsolutePath());
            getLogger().error(".act(): No such file: " + sitemapPath + "::" + relRootDirs.get(fileType) + "::" + reqFile);
            return null;
        }

        // make a temporary copy of the file to be edited
        if ("xml".equals(fileType) && "open".equals(reqType)) {
            FileUtil.copyFile(permFile, tempFile);
            getLogger().debug(".act(): PERMANENT FILE: " + permFile.getAbsolutePath());
            getLogger().debug(".act(): TEMPORARY FILE: " + tempFile.getAbsolutePath());
        }

        // set sitemap params for response routing
        Map sitemapParams = new HashMap();
        sitemapParams.put("reqId", reqId);
        sitemapParams.put("reqType", reqType);
        sitemapParams.put("reqFile", reqFile);
        sitemapParams.put("fileType", fileType);

        if ("xml".equals(fileType) && ("open".equals(reqType) || "save".equals(reqType))) {
            sitemapParams.put("reqFilePath", (String) relRootDirs.get("temp") + "/" + (String) relRootDirs.get(fileType) + "/" + reqFile);
            getLogger().debug(".act(): File to be edited (in temp dir): " + sitemapParams.get("reqFilePath"));
        } else {
            sitemapParams.put("reqFilePath", (String) relRootDirs.get(fileType) + "/" + reqFile);
        }


        // The xopus sitemap will return the XML
        if ("open".equals(reqType)) {
            return sitemapParams;
        }




        // save to temporary file, if needed
        if ("save".equals(reqType) || "checkin".equals(reqType)) {
            getLogger().debug(".act(): Write to temp file: " + tempFile);
            try {
                Element contentNode = (Element) data.getFirstChild();
                DOMParserFactory dpf = new DOMParserFactory();

                // Create a new document, where the actual content starts at the root element, which is the inner part of requestDoc
                Document contentDocument = dpf.getDocument();
                contentDocument.appendChild((Element) dpf.cloneNode(contentDocument, contentNode, true));
                new DOMWriter(new FileOutputStream(tempFile)).printWithoutFormatting(contentDocument);
            } catch (Exception e) {
                getLogger().error(".act(): Exception during writing to temp file: " + e);
            }
        }

        // save to permanent file, if needed
        if ("checkin".equals(reqType)) {
            getLogger().debug(".act(): Save to permanent file: " + permFile);

            RevisionController rc = new RevisionController(sitemapPath + rcmlDirectory,
                    sitemapPath + backupDirectory, sitemapPath);

            try {
                Session session = httpReq.getSession(false);

                if (session == null) {
                    throw new Exception("No session");
                }
View Full Code Here

        Map objectModel,
        String source,
        Parameters parameters)
        throws Exception {

        HttpRequest request = (HttpRequest)ObjectModelHelper.getRequest(objectModel);

        // Get namespaces
        String namespaces = removeRedundantNamespaces(request.getParameter("namespaces"));
        log.debug(namespaces);

        // Aggregate content
        String encoding = request.getCharacterEncoding();
        String content =
            "<?xml version=\"1.0\" encoding=\""
                + encoding
                + "\"?>\n"
                + addNamespaces(namespaces, request.getParameter("content"));

        // Save file temporarily
        File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile());
        File file =
            new File(
View Full Code Here

        getLogger().debug(".act(): Absolute XSL Root Directory: " + sitemapPath + xslRoot);
        getLogger().debug(".act(): Absolute XSD Root Directory: " + sitemapPath + xsdRoot);
        getLogger().debug(".act(): Absolute Temp Root Directory: " + sitemapPath + tempRoot);

        // Get request object
        HttpRequest httpReq = (HttpRequest) objectModel.get(ObjectModelHelper.REQUEST_OBJECT);

        if (httpReq == null) {
            getLogger().error("Could not get HTTP_REQUEST_OBJECT from objectModel");

            return null;
        }

        int length = httpReq.getContentLength();
        PostInputStream reqContent = new PostInputStream(httpReq.getInputStream(), length);

        // construct DOM document from the request contents
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        InputSource saxSource = new InputSource(reqContent);
        Document requestDoc = parser.parseDocument(saxSource);

        // get the root element (should be "request") and its attributes ---> FixMe: Add error handling
        Element root = requestDoc.getDocumentElement();
        getLogger().debug(".act(): Root element (should be 'request'): " + root.getTagName());

        String reqId = root.getAttribute("id");
        getLogger().debug(".act(): Request ID: " + reqId);

        String reqType = root.getAttribute("type");
        getLogger().debug(".act(): Request Type: " + reqType);

        // get the first child element for root element (should be "data") and its attributes ---> FixMe: Add error handling
        Element data = (Element) root.getFirstChild();
        getLogger().debug(".act(): first child element (should be 'data'): " + data.getTagName());

        String reqFile = data.getAttribute("id");
        getLogger().debug(".act(): Requested File: " + reqFile);

        String fileType = data.getAttribute("type");
        getLogger().debug(".act(): Requested File's Type: " + fileType);

        // close the input stream
        reqContent.close();

        // Define Files
        File tempFileDir =
            new File(sitemapPath + relRootDirs.get("temp") + "/" + relRootDirs.get(fileType));

        if (!(tempFileDir.exists())) {
            tempFileDir.mkdir();
        }

        File tempFile = IOUtils.createFile(tempFileDir, reqFile);
        File permFile = new File(sitemapPath + relRootDirs.get(fileType) + "/" + reqFile);

        if (!permFile.exists()) {
            getLogger().error(".act(): No such file: " + permFile.getAbsolutePath());
            getLogger().error(
                ".act(): No such file: "
                    + sitemapPath
                    + "::"
                    + relRootDirs.get(fileType)
                    + "::"
                    + reqFile);

            return null;
        }

        // make a temporary copy of the file to be edited
        if ("xml".equals(fileType) && "open".equals(reqType)) {
            FileUtil.copyFile(permFile, tempFile);
            getLogger().debug(".act(): PERMANENT FILE: " + permFile.getAbsolutePath());
            getLogger().debug(".act(): TEMPORARY FILE: " + tempFile.getAbsolutePath());
        }

        // set sitemap params for response routing
        Map sitemapParams = new HashMap();
        sitemapParams.put("reqId", reqId);
        sitemapParams.put("reqType", reqType);
        sitemapParams.put("reqFile", reqFile);
        sitemapParams.put("fileType", fileType);

        if ("xml".equals(fileType) && ("open".equals(reqType) || "save".equals(reqType))) {
            sitemapParams.put(
                "reqFilePath",
                (String) relRootDirs.get("temp")
                    + "/"
                    + (String) relRootDirs.get(fileType)
                    + "/"
                    + reqFile);
            getLogger().debug(
                ".act(): File to be edited (in temp dir): " + sitemapParams.get("reqFilePath"));
        } else {
            sitemapParams.put("reqFilePath", (String) relRootDirs.get(fileType) + "/" + reqFile);
        }

        // The xopus sitemap will return the XML
        if ("open".equals(reqType)) {
            return sitemapParams;
        }

        // save to temporary file, if needed
        if ("save".equals(reqType) || "checkin".equals(reqType)) {
            getLogger().debug(".act(): Write to temp file: " + tempFile);

            try {
                Element contentNode = (Element) data.getFirstChild();
                DOMParserFactory dpf = new DOMParserFactory();

                // Create a new document, where the actual content starts at the root element, which is the inner part of requestDoc
                Document contentDocument = dpf.getDocument();
                contentDocument.appendChild(
                    dpf.cloneNode(contentDocument, contentNode, true));
                new DOMWriter(new FileOutputStream(tempFile)).printWithoutFormatting(
                    contentDocument);
            } catch (Exception e) {
                getLogger().error(".act(): Exception during writing to temp file", e);
            }
        }

        // save to permanent file, if needed
        if ("checkin".equals(reqType)) {
            getLogger().debug(".act(): Save to permanent file: " + permFile);

            RevisionController rc =
                new RevisionController(
                    sitemapPath + rcmlDirectory,
                    sitemapPath + backupDirectory,
                    sitemapPath);

            try {
                Session session = httpReq.getSession(false);

                if (session == null) {
                    throw new Exception("No session");
                }
View Full Code Here

        getLogger().debug(".act(): Absolute XSL Root Directory: " + sitemapPath + xslRoot);
        getLogger().debug(".act(): Absolute XSD Root Directory: " + sitemapPath + xsdRoot);
        getLogger().debug(".act(): Absolute Temp Root Directory: " + sitemapPath + tempRoot);

        // Get request object
        HttpRequest httpReq = (HttpRequest) objectModel.get(ObjectModelHelper.REQUEST_OBJECT);

        if (httpReq == null) {
            getLogger().error("Could not get HTTP_REQUEST_OBJECT from objectModel");

            return null;
        }

        int length = httpReq.getContentLength();
        PostInputStream reqContent = new PostInputStream(httpReq.getInputStream(), length);

        // construct DOM document from the request contents
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        InputSource saxSource = new InputSource(reqContent);
        Document requestDoc = parser.parseDocument(saxSource);

        // get the root element (should be "request") and its attributes ---> FixMe: Add error handling
        Element root = requestDoc.getDocumentElement();
        getLogger().debug(".act(): Root element (should be 'request'): " + root.getTagName());

        String reqId = root.getAttribute("id");
        getLogger().debug(".act(): Request ID: " + reqId);

        String reqType = root.getAttribute("type");
        getLogger().debug(".act(): Request Type: " + reqType);

        // get the first child element for root element (should be "data") and its attributes ---> FixMe: Add error handling
        Element data = (Element) root.getFirstChild();
        getLogger().debug(".act(): first child element (should be 'data'): " + data.getTagName());

        String reqFile = data.getAttribute("id");
        getLogger().debug(".act(): Requested File: " + reqFile);

        String fileType = data.getAttribute("type");
        getLogger().debug(".act(): Requested File's Type: " + fileType);

        // close the input stream
        reqContent.close();

        // Define Files
        File tempFileDir =
            new File(sitemapPath + relRootDirs.get("temp") + "/" + relRootDirs.get(fileType));

        if (!(tempFileDir.exists())) {
            tempFileDir.mkdir();
        }

        File tempFile = IOUtils.createFile(tempFileDir, reqFile);
        File permFile = new File(sitemapPath + relRootDirs.get(fileType) + "/" + reqFile);

        if (!permFile.exists()) {
            getLogger().error(".act(): No such file: " + permFile.getAbsolutePath());
            getLogger().error(
                ".act(): No such file: "
                    + sitemapPath
                    + "::"
                    + relRootDirs.get(fileType)
                    + "::"
                    + reqFile);

            return null;
        }

        // make a temporary copy of the file to be edited
        if ("xml".equals(fileType) && "open".equals(reqType)) {
            FileUtil.copyFile(permFile, tempFile);
            getLogger().debug(".act(): PERMANENT FILE: " + permFile.getAbsolutePath());
            getLogger().debug(".act(): TEMPORARY FILE: " + tempFile.getAbsolutePath());
        }

        // set sitemap params for response routing
        Map sitemapParams = new HashMap();
        sitemapParams.put("reqId", reqId);
        sitemapParams.put("reqType", reqType);
        sitemapParams.put("reqFile", reqFile);
        sitemapParams.put("fileType", fileType);

        if ("xml".equals(fileType) && ("open".equals(reqType) || "save".equals(reqType))) {
            sitemapParams.put(
                "reqFilePath",
                (String) relRootDirs.get("temp")
                    + "/"
                    + (String) relRootDirs.get(fileType)
                    + "/"
                    + reqFile);
            getLogger().debug(
                ".act(): File to be edited (in temp dir): " + sitemapParams.get("reqFilePath"));
        } else {
            sitemapParams.put("reqFilePath", (String) relRootDirs.get(fileType) + "/" + reqFile);
        }

        // The xopus sitemap will return the XML
        if ("open".equals(reqType)) {
            return sitemapParams;
        }

        // save to temporary file, if needed
        if ("save".equals(reqType) || "checkin".equals(reqType)) {
            getLogger().debug(".act(): Write to temp file: " + tempFile);

            try {
                Element contentNode = (Element) data.getFirstChild();
                DOMParserFactory dpf = new DOMParserFactory();

                // Create a new document, where the actual content starts at the root element, which is the inner part of requestDoc
                Document contentDocument = dpf.getDocument();
                contentDocument.appendChild(
                    dpf.cloneNode(contentDocument, contentNode, true));
                new DOMWriter(new FileOutputStream(tempFile)).printWithoutFormatting(
                    contentDocument);
            } catch (Exception e) {
                getLogger().error(".act(): Exception during writing to temp file", e);
            }
        }

        // save to permanent file, if needed
        if ("checkin".equals(reqType)) {
            getLogger().debug(".act(): Save to permanent file: " + permFile);

            RevisionController rc =
                new RevisionController(
                    sitemapPath + rcmlDirectory,
                    sitemapPath + backupDirectory,
                    sitemapPath);

            try {
                Session session = httpReq.getSession(false);

                if (session == null) {
                    throw new Exception("No session");
                }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.environment.http.HttpRequest

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.