Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Context


        final Map objectModel = ContextHelper.getObjectModel(this.context);

        Request request = ObjectModelHelper.getRequest(objectModel);
        JXPathContext context = (JXPathContext) request.getAttribute(Constants.JXPATH_CONTEXT);
        if (context == null) {
            Context envContext = ObjectModelHelper.getContext(objectModel);
            JXPathContext parentContext = null;

            Session session = request.getSession(false);
            if (session != null) {
                parentContext = getSessionContext(session, envContext);
View Full Code Here


    /**
     * Returns the mime-type of the resource in process.
     */
    public String getMimeType() {
        Context ctx = ObjectModelHelper.getContext(objectModel);
        if (ctx != null) {
            final String mimeType = ctx.getMimeType(source);
            if (mimeType != null) {
                return mimeType;
            }
        }

View Full Code Here

        // We get this parameter from the sitemap through the params object.
        // The filename is relative to the WEB-INF directory.
        //
        String flagFileRelativePath = params.getParameter("flagfilerelativepath",
                "new_installation_flag");
        Context context = ObjectModelHelper.getContext(objectModel);
        String flagFileAbsolutePath = context.getRealPath("/") + "/" + flagFileRelativePath;
        getLogger().error("DetectNewInstallationAction: flagFileAbsolutePath = " +
            flagFileAbsolutePath);

        if (!new File(flagFileAbsolutePath).exists()) {
            getLogger().error("DetectNewInstallationAction: does not exist, skipping first-time setup!");
View Full Code Here

        if (session != null) {
            o = session.getAttribute(name);
            if (o != null)
                return o;
        }
        Context context = ObjectModelHelper.getContext(objectModel);
        return context.getAttribute(name);
    }
View Full Code Here

     * @param location The location
     * @return The URL pointed to by the location
     * @exception MalformedURLException If the location is malformed
     */
    public URL getURL(String location) throws MalformedURLException {
        Context envContext = null;
        try {
            envContext = (Context)this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
        } catch (ContextException e){
            getLogger().error("ContextException in getURL",e);
        }
        if (envContext == null) {
            getLogger().warn("no environment-context in application context (making an absolute URL)");
            return new URL(location);
        }
        URL u = envContext.getResource("/" + location);
        if (u != null)
            return u;
        else {
            getLogger().info(location + " could not be found. (possible context problem)");
            throw new MalformedURLException(location + " could not be found. (possible context problem)");
View Full Code Here

     */
    public static Publication getPublication(Map objectModel) throws PublicationException {

        assert objectModel != null;
        Request request = ObjectModelHelper.getRequest(objectModel);
        Context context = ObjectModelHelper.getContext(objectModel);
        return getPublication(request, context);
    }
View Full Code Here

            return null;
        }

        // Get request object
        Context context = ObjectModelHelper.getContext(objectModel);

        // the absolute path where Cocoon resides
        //     String xxx = context.getRealPath("/");
        //     getLogger().error("=======> context real path ="+xxx);
        //getLogger().error("=======> editfilename ="+parameters.getParameter("editfilename"));
        // Get uri
        String request_uri = request.getRequestURI();
        String sitemap_uri = request.getSitemapURI();
        String action = request.getParameter("action");
        String save = request.getParameter("save");
        getLogger().debug("**** request-uri=" + request_uri);
        getLogger().debug("**** sitemap-uri=" + sitemap_uri);
        getLogger().debug("**** action=" + action);

        // prepare the return params
        String xmlErrorFlag = "";
        String xmlErrorMessage = "";

        if ((save != null) && save.equals("Save")) {
            // get the Document and copy it to the temporary file
            getLogger().debug("**** saving ****");

            Source source = resolver.resolve("cocoon:/saveedit");
            getLogger().debug("======= URL:" + source.getSystemId());

            String editFile = (String) session.getAttribute(
                    "org.apache.lenya.cms.editor.HTMLForm.editFile");
            getLogger().debug("======= Saving to :" + editFile);

            BufferedReader in = new BufferedReader(new InputStreamReader(source.getInputStream()));

            // first, copy to a temporary string buffer (so we can get it back later, and more than once!)
            StringBuffer trans = new StringBuffer();
            String line;

            while ((line = in.readLine()) != null) {
                // we need this in order to let EditOnPro save the XHTML markup:
                line = org.apache.lenya.util.StringUtil.replace(line, "&lt;", "<");
                line = org.apache.lenya.util.StringUtil.replace(line, "&gt;", ">");
                trans.append(line + "\n");
            }

            getLogger().debug("----- Contents of the StringBuffer (trans): " + trans.toString());

            // check well-formedness
            SAXParser parser = (SAXParser) this.manager.lookup(SAXParser.ROLE); // get the cocoon parser

            try {
                InputSource iS = new InputSource(new CharArrayReader(trans.toString().toCharArray()));

                if (iS == null) {
                    getLogger().error("----- InputStream is null!");
                } else {
                    //parser.setContentHandler(new AbstractXMLConsumer() { }); // the parser must have a content handler, it will not be used
                    parser.parse(iS, new org.xml.sax.helpers.DefaultHandler());
                }
            } catch (SAXException saxE) { // this is the exception we want to catch
                xmlErrorFlag = "X"; // set the flag for signalling to the page's stylesheet (body.xsl)
                xmlErrorMessage = saxE.getMessage(); // this will also be sent to the stylesheet
                getLogger().debug("----- SAX-Exception (message): " + saxE.getMessage());
                getLogger().debug("----- SAX-Exception (stacktrace): ", saxE.getException());

                String tempFile = (String) session.getAttribute(
                        "org.apache.lenya.cms.editor.HTMLForm.tempFile");

                if (tempFile != null) {
                    in.close();

                    HashMap actionMap = new HashMap();
                    actionMap.put("tempFile", tempFile);
                    actionMap.put("xmlErrorFlag", xmlErrorFlag);
                    actionMap.put("xmlErrorMessage", xmlErrorMessage);

                    return actionMap;
                }

                return null;
            }catch (Exception e) { // something went wrong
                getLogger().error("----- Exception occured: ", e);

                return null;
            }

            // then, copy the string buffer to the temporary file 
            StringReader in2 = new StringReader(trans.toString());
            BufferedWriter out = new BufferedWriter(new FileWriter(editFile));
            int c;

            while ((c = in2.read()) != -1) {
                out.write((char) c);
            }

            in.close();
            in2.close();
            out.close();

            return null;
        } else if ((action != null) && action.equals("request")) {
            getLogger().debug("**** request (do nothing) ****");

            HashMap actionMap = new HashMap();

            return actionMap;
        } else { // we are not saving

            // here comes the checkout, revision control aso.
            boolean checkout = true;

            if (checkout) {
                String formeditorPath = context.getRealPath("formeditor");
                String tempFile = formeditorPath + request.getRequestURI();

                String lenyaPath = "lenya/pubs/ethz-mat/docs/ethz/mat/";
                String editFile = context.getRealPath("/") + lenyaPath + request.getSitemapURI();

                getLogger().debug("**** tempfile=" + tempFile);
                getLogger().debug("**** editfile=" + editFile);

                File tf = new File(tempFile);
View Full Code Here

     */
    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source,
        Parameters parameters) throws Exception {
        HashMap results = new HashMap();
        Request request = ObjectModelHelper.getRequest(objectModel);
        Context context = ObjectModelHelper.getContext(objectModel);

        // find the absolute path (so we know where to put images and
        // meta data)
        Source inputSource = resolver.resolve("");
        String sitemapPath = inputSource.getSystemId();
View Full Code Here

        Object bean = FlowHelper.getContextObject(objectModel);
        WebContinuation kont = FlowHelper.getWebContinuation(objectModel);
        Map map = new HashMap();
        Request request = ObjectModelHelper.getRequest(objectModel);
        Response response = ObjectModelHelper.getResponse(objectModel);
        Context context = ObjectModelHelper.getContext(objectModel);
        if (bean != null) {
            fillContext(bean, map);
            map.put("flowContext", bean);
            map.put("continuation", kont);
        }
View Full Code Here

                if (session != null) {
                    bean = session.getAttribute(name);
                }
            }
            if (bean == null) {
                Context context = ObjectModelHelper.getContext(objectModel);
                if (context != null) {
                    bean = context.getAttribute(name);
                }
            }
        } else if (SCOPE_SITEMAP.equals(scope)) {
            bean = objectModel.get(name);
        } else if (SCOPE_REQUEST.equals(scope)) {
            bean = request.getAttribute(name);
        } if (SCOPE_SESSION.equals(scope)) {
            Session session = request.getSession(false);
            if (session != null) {
                bean = session.getAttribute(name);
            }
        } else if (SCOPE_CONTEXT.equals(scope)) {
            Context context = ObjectModelHelper.getContext(objectModel);
            if (context != null) {
                bean = context.getAttribute(name);
            }
        }

        return bean;
    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.environment.Context

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.