Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Request


        sitemapParentPath = sitemapParentPath.substring(5); // Remove "file:" protocol

        getLogger().debug(".act(): PARENT PATH OF SITEMAP: " + sitemapParentPath);

        // Get request object
        Request request = ObjectModelHelper.getRequest(objectModel);

        if (request == null) {
            getLogger().error("No request object");

            return null;
        }

        // Get parameters
        String parentid = request.getParameter("parentid");
        if (parentid == null) {
            getLogger().warn("No parentid parameter defined! It might be necessary to specify a parentid request parameter.");
        }
        String childid = request.getParameter("childid");
        if (childid == null) {
            getLogger().error("No childid parameter defined! Please specify childid as request parameter.");
            throw new Exception("No childname defined!");
        }
        String childname = request.getParameter("childname");
        if (childname == null) {
            getLogger().error("No childname defined! Please specify childname as request parameter which is being used as label within a sitetree or topic map.");
            throw new Exception("No childname defined!");
        }
        String childtype = request.getParameter("childtype");
        if (childtype == null) {
            getLogger().error("No childtype defined! Please specify childtype as request parameter with value either \"branch\" or \"leaf\".");
            throw new Exception("No childname defined!");
        }
        short childType;

        if (childtype.equals("branch")) {
            childType = ParentChildCreatorInterface.BRANCH_NODE;
        } else if (childtype.equals("leaf")) {
            childType = ParentChildCreatorInterface.LEAF_NODE;
        } else {
            getLogger().error("No such child type: " + childtype);
            return null;
        }

        String doctype = request.getParameter("doctype");
        if (doctype == null) {
            getLogger().warn("No doctype defined! Please specify doctype as request parameter, which is being used to resolve the creator within doctypes.xconf. Otherwise the DefaultCreator class is being used (see below)!");
        }
        String language = request.getParameter("language");

        if (!validate(parentid, childid, childname, childtype, doctype)) {
            getLogger().error("Exception: Validation of parameters failed");

            return null;
        }

        // Get session
        Session session = request.getSession(true);

        if (session == null) {
            getLogger().error("No session object");

            return null;
        }

        // Get creator
        ParentChildCreatorInterface creator = null;
        String absoluteDoctypesPath = sitemapParentPath + doctypesPath;
        Document doctypesDoc = new SAXReader().read("file:" + absoluteDoctypesPath +
                "doctypes.xconf");
        Attribute creator_src = (Attribute) doctypesDoc.selectSingleNode("/doctypes/doc[@type='" +
                doctype + "']/creator/@src");

        if (creator_src != null) {
            getLogger().info(".act(): Creator found for \"" + doctype + "\": " +
                creator_src.getName() + " " + creator_src.getPath() + " " + creator_src.getValue());

            // now get the constructor that accepts the configuration
            Class creatorClass = Class.forName(creator_src.getValue());
            creator = (ParentChildCreatorInterface) creatorClass.newInstance();
        } else {
            getLogger().warn("No creator found for \"" + doctype +
                "\". DefaultBranchCreator will be taken.");
            creator = new org.apache.lenya.cms.authoring.DefaultBranchCreator();
        }

        getLogger().debug(".act(): Creator : " + creator.getClass().getName());

        // Init creator
        // "Read" the configuration from the DOM node
        DefaultConfigurationBuilder defaultConfigBuilder = new DefaultConfigurationBuilder();
        Configuration[] docTypeConfigs = defaultConfigBuilder.buildFromFile(absoluteDoctypesPath +
                "doctypes.xconf").getChildren();

        Configuration doctypeConf = null;

        for (int i = 0; i < docTypeConfigs.length; i++) {
            String typeName = docTypeConfigs[i].getAttribute("type");

            if (typeName.equals(doctype)) {
                doctypeConf = docTypeConfigs[i].getChild("creator", false);
            }
        }

        creator.init(doctypeConf);

        // Transaction should actually be started here!
        String treefilename = sitemapParentPath + treeAuthoringPath;
        getLogger().debug(".act(): Filename of tree: " + treefilename);

        if (!new File(treefilename).exists()) {
            getLogger().warn("No sitetree or topic map: " + treefilename);
        } else {
            if (!updateTree(childtype, childType, childid, childname, parentid, doctype, creator, treefilename)) return null;
        }
        // Transaction should actually be finished here!


        // Create actual document
        // grab all the parameters from session, request params and
        // sitemap params
        HashMap allParameters = new HashMap();
        String[] names = parameters.getNames();

        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            String value = null;

            try {
                value = parameters.getParameter(name);
            } catch (ParameterException pe) {
                value = null;
            }

            allParameters.put(name, value);
        }

        Enumeration requestParameters = request.getParameterNames();

        while (requestParameters.hasMoreElements()) {
            String requestParameterName = (String) requestParameters.nextElement();

            if (allParameters.containsKey(requestParameterName)) {
                // we do not allow name clashes
                throw new ProcessingException("Name clash in request parameter " +
                    "and sitemap parameter: " + requestParameterName);
            }

            allParameters.put(requestParameterName, request.getParameter(requestParameterName));
        }

        Enumeration sessionAttributeNames = session.getAttributeNames();

        while (sessionAttributeNames.hasMoreElements()) {
View Full Code Here


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

        Request request = ObjectModelHelper.getRequest(objectModel);
        String uri = request.getRequestURI();

        URIParameterizer parameterizer = null;
        Map map = null;
        try {
            parameterizer = (URIParameterizer) manager.lookup(URIParameterizer.ROLE);
View Full Code Here

     * @param objectModel The object model.
     * @return A workflow situation.
     * @throws WorkflowException when something went wrong.
     */
    public static Situation buildSituation(Map objectModel) throws WorkflowException {
        Request request = ObjectModelHelper.getRequest(objectModel);
        return buildSituation(request);
    }
View Full Code Here

     * @param cocoon The FOM_Cocoon object.
     * @return A situation.
     * @throws AccessControlException when something went wrong.
     */
    public Situation getSituation(FOM_Cocoon cocoon) throws AccessControlException {
        Request request = ObjectModelHelper.getRequest(cocoon.getObjectModel());
        Session session = request.getSession();
        Identity identity = (Identity) session.getAttribute(Identity.class.getName());

        String userId = "";
        String ipAddress = "";

View Full Code Here

     */
    public String getImageParameterValue(FOM_Cocoon cocoon, String parameterName) {

        log.debug("Resolving parameter value for name [" + parameterName + "]");

        Request request = cocoon.getRequest();
        String value = request.getParameter(parameterName);

        if (value == null) {
            String prefix = parameterName + SEPARATOR;
            Enumeration e = request.getParameterNames();
            while (e.hasMoreElements() && value == null) {
                String name = (String) e.nextElement();
                if (name.startsWith(prefix)) {
                    log.debug("Complete parameter name: [" + name + "]");
                    value = name.substring(prefix.length(), name.length() - 2);
View Full Code Here

    try {
      publication = PublicationFactory.getPublication(objectModel);
    } catch (PublicationException e) {
      throw new ExecutionException(e);
    }
    Request request = ObjectModelHelper.getRequest(objectModel);

        initialize(parameters, publication, request);
  }
View Full Code Here

            if (documentId == null) {
                documentId = envelope.getDocument().getId();
            }

            Request request = ObjectModelHelper.getRequest(objectModel);

            if (documentArea == null) {
                String webappUrl = ServletHelper.getWebappURI(request);
                URLInformation info = new URLInformation(webappUrl);
                String completeArea = info.getCompleteArea();
                documentArea = completeArea;
            }

            if (language == null) {
                language = envelope.getDocument().getLanguage();
            }

            Publication publication = envelope.getPublication();
            DocumentBuilder builder = publication.getDocumentBuilder();

            url = builder.buildCanonicalUrl(publication, documentArea, documentId, language);

            String contextPath = request.getContextPath();
            if (contextPath == null) {
                contextPath = "";
            }

            url = contextPath + url;
View Full Code Here

        }

        Document document = envelope.getDocument();
        Publication publication = envelope.getPublication();

        Request request = ObjectModelHelper.getRequest(objectModel);
        String webappUrl = ServletHelper.getWebappURI(request);
        URLInformation info = new URLInformation(webappUrl);
        String completeArea = info.getCompleteArea();
        DocumentBuilder builder = publication.getDocumentBuilder();

        String parentId;

        int lastSlashIndex = document.getId().lastIndexOf("/");
        if (lastSlashIndex > 0) {
            parentId = document.getId().substring(0, lastSlashIndex);
        } else {
            parentId = "/index";
        }

        String parentUrl = builder.buildCanonicalUrl(publication, completeArea, parentId);
        Document parentDocument;

        try {
            parentDocument = builder.buildDocument(publication, parentUrl);
            parentDocument = getExistingLanguageVersion(parentDocument, document.getLanguage());
        } catch (Exception e) {
            throw new ProcessingException(e);
        }
        parentUrl =
            builder.buildCanonicalUrl(
                publication,
                completeArea,
                parentDocument.getId(),
                parentDocument.getLanguage());

        String contextPath = request.getContextPath();
        if (contextPath == null) {
            contextPath = "";
        }

        return contextPath + parentUrl;
View Full Code Here

        super.setup(resolver, objectModel, src, par);

        PageEnvelope envelope = null;

        if (getLogger().isDebugEnabled()) {
            Request request = ObjectModelHelper.getRequest(objectModel);
            getLogger().debug(
                    "Resolving page envelope for URL ["
                            + request.getRequestURI() + "]");
        }

        this.area = par.getParameter(PARAM_AREA, null);
        this.documentid = par.getParameter(PARAM_DOCUMENTID, null);
View Full Code Here

     * @throws Exception DOCUMENT ME!
     */
    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src,
        Parameters parameters) throws Exception {
        // Get request object
        Request req = ObjectModelHelper.getRequest(objectModel);

        if (req == null) {
            getLogger().error("No request object");

            return null;
        }

        Session session = req.getSession(true);

        if (session == null) {
            getLogger().error("No session object");

            return null;
        }

        // Get uri
        String request_uri = req.getRequestURI();
        String sitemap_uri = req.getSitemapURI();

        if (getLogger().isDebugEnabled()) {
            getLogger().debug("request-uri=" + request_uri);
            getLogger().debug("sitemap-uri=" + sitemap_uri);
        }

        // Set history
        Stack history = (Stack) session.getAttribute("org.apache.lenya.cms.cocoon.acting.History");

        if (history == null) {
            history = new Stack(10);
            session.setAttribute("org.apache.lenya.cms.cocoon.acting.History", history);
        }

        history.push(sitemap_uri);

        // Check public uris from configuration above. Should only be used during development before the implementation of a concrete authorizer.
        for (int i = 0; i < public_matchers.length; i++) {
            if (preparedMatch(public_matchers[i], sitemap_uri)) {
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Permission granted for free: " + request_uri);
                }

                HashMap actionMap = new HashMap();

                return actionMap;
            }
        }

        String query_string = req.getQueryString();

        if (query_string != null) {
            session.setAttribute("protected_destination", request_uri + "?" + req.getQueryString());
        } else {
            session.setAttribute("protected_destination", request_uri);
        }

        // FIXME: Can't be here. Please see comment within PMLAuthorizerAction
View Full Code Here

TOP

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

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.