Package org.apache.avalon.excalibur.source

Examples of org.apache.avalon.excalibur.source.SourceParameters


    public SourceParameters createParameters(SourceParameters parameters,
                                               String             myHandler,
                                               String             path,
                                               String             appName)
    throws ProcessingException {
        if (parameters == null) parameters = new SourceParameters();

        // add all elements from inside the handler data
        this.addParametersFromAuthenticationXML(myHandler,
                                                "/data",
                                                parameters);
View Full Code Here


     * Process one sunlet
     */
    public void run() {
        XMLSerializer compiler = null;
        Element sunletConf = (Element)this.loadedSunlet[1];
        SourceParameters p = (SourceParameters)loadedSunlet[2];

        try {
            // Determine the resource to load
            // If the sunLet is customizable and has no customization info
            // the customization resource is loaded, otherwise the resource
            Resource resource = null;
            boolean showCustomizePage = p.getParameterAsBoolean(Constants.PARAMETER_CUSTOMIZE, false);
            if (showCustomizePage == true) {
                final String value = XMLUtil.getValueOf(sunletConf, "customization/@uri", null);
                if (value == null) {
                    this.logger.error("The sunLet '"+this.sunletID+"' is customizable but has no customization info.");
                }
                resource = new Resource(this.resolver, value);
            }
            if (resource == null) {
                resource = new Resource(this.resolver, XMLUtil.getValueOf(sunletConf, "resource/@uri"));
            }
            boolean handlesSizable = XMLUtil.getValueAsBooleanOf(sunletConf, "configuration/handlesSizable", false);

            if (handlesSizable == false && p.getParameter("size", "max").equals("max") == false) {
                // do nothing here
                loadedSunlet[0] = new byte[0];
            } else {

                compiler = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
                compiler.startDocument();

                XMLConsumer nextConsumer = compiler;
                NodeList transformations = XMLUtil.selectNodeList(sunletConf,
                                                        "transformation/stylesheet");
                Transformer xslT = null;
                ArrayList transformers = new ArrayList();
                ComponentSelector selector = null;
                Request request = ObjectModelHelper.getRequest(this.objectModel);

                try {
                    if (transformations != null && transformations.getLength() > 0) {
                        selector = (ComponentSelector) this.manager.lookup(Transformer.ROLE + "Selector");
                        nextConsumer = new IncludeXMLConsumer(nextConsumer);
                        for(int k = transformations.getLength()-1; k >=0; k--) {
                            xslT = (Transformer)selector.select("xslt");
                            transformers.add(xslT);
                            xslT.setup(resolver,
                                       objectModel,
                                       XMLUtil.getValueOfNode(transformations.item(k)),
                                       new Parameters());
                            xslT.setConsumer(nextConsumer);
                            nextConsumer = xslT;
                        }
                        nextConsumer.startDocument();
                    }
                    switch (resource.getResourceType()) {
                        case ResourceConnector.RESOURCE_TYPE_CLASS: {
                             Sunlet theSunlet;
                             try {
                                 Class loaderClass = Class.forName(resource.getResourceIdentifier());
                                 theSunlet = (Sunlet)loaderClass.newInstance();
                             } catch (ClassNotFoundException cnfException) {
                                 throw new ProcessingException("getSunlet: Class not found: " + resource.getResourceIdentifier(), cnfException);
                             } catch (IllegalAccessException iaException) {
                                 throw new ProcessingException("getSunlet: Illegal Access: " + resource.getResourceIdentifier(), iaException);
                             } catch (InstantiationException iException) {
                                 throw new ProcessingException("getSunlet: Instantion exception: " + resource.getResourceIdentifier(), iException);
                             }
                             theSunlet.init(objectModel, p);
                             theSunlet.execute(nextConsumer, nextConsumer, objectModel, p);
                             break;
                        }
                        default: {
                            boolean includeFragment = true;
                            boolean handlesParameters = XMLUtil.getValueAsBooleanOf(sunletConf, "configuration/handlesParameters", true);
                            String size = p.getParameter("size", "max");
                            if (resource.getResourceType() == ResourceConnector.RESOURCE_TYPE_FILE) {
                                // files have no possibility to evaluate minimized, so if they are not maximized
                                // they will be neglected
                                includeFragment = size.equals("max");

View Full Code Here

                        XMLUtil.setValueOfNode(XMLUtil.selectSingleNode(sunlet, "status/visible"), "true");
                        XMLUtil.setValueOfNode(XMLUtil.selectSingleNode(sunlet, "status/size"), "max");
                        XMLUtil.getSingleNode(sunletsFragment, "sunlets-profile/sunlets").appendChild(sunlet);
                    } else if (command.equals("save") == true) {

                        SourceParameters pars = new SourceParameters();
                        pars.setSingleParameterValue("profile", "sunlet-base");
                        pars.setSingleParameterValue("application", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME));
                        pars.setSingleParameterValue("handler", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_HANDLER_NAME));

                        Resource saveResource = (Resource)configuration.get(Constants.CONF_SUNLETBASE_SAVE_RESOURCE);

                        if (saveResource == null) {
                            throw new ProcessingException("sunSpot: No save resource defined for type sunlet-base.");
                        } else {

                            this.getResourceConnector().saveXML(saveResource.getResourceType(),null,
                                 saveResource.getResourceIdentifier(),pars,
                                 sunletsFragment);

                            // now the hardest part, clean up the whole cache
                            this.cleanUpCache(null, null, configuration);
                        }
                    }
                } finally {
                    this.getSunShineComponent().stopWritingTransaction(context);
                }
            }

            // general commands
            if (command != null && command.equals("cleancache") == true) {
                this.cleanUpCache(null, null, configuration);
            }

            String state = this.request.getParameter(SunSpot.REQ_PARAMETER_STATE);
            if (state == null) {
                state = (String)context.getAttribute(ATTRIBUTE_ADMIN_STATE, Constants.STATE_MAIN);
            }

            // now start producing xml:
            AttributesImpl attr = new AttributesImpl();
            consumer.startElement("", Constants.ELEMENT_ADMINCONF, Constants.ELEMENT_ADMINCONF, attr);

            context.setAttribute(ATTRIBUTE_ADMIN_STATE, state);
            consumer.startElement("", Constants.ELEMENT_STATE, Constants.ELEMENT_STATE, attr);
            consumer.characters(state.toCharArray(), 0, state.length());
            consumer.endElement("", Constants.ELEMENT_STATE, Constants.ELEMENT_STATE);

            if (state.equals(Constants.STATE_MAIN) == true) {

                DocumentFragment rolesDF = this.getSunRise().getRoles();
                Node             roles   = null;
                if (rolesDF != null) roles = XMLUtil.getSingleNode(rolesDF, "roles");
                IncludeXMLConsumer.includeNode(roles, consumer, consumer);
            }

            if (state.equals(Constants.STATE_MAIN_ROLE) == true) {

                DocumentFragment rolesDF = this.getSunRise().getRoles();
                Node             roles   = null;
                if (rolesDF != null) roles = XMLUtil.getSingleNode(rolesDF, "roles");
                IncludeXMLConsumer.includeNode(roles, consumer, consumer);

                String role = this.request.getParameter(SunSpot.REQ_PARAMETER_ROLE);
                if (role == null) {
                    role = (String)context.getAttribute(ATTRIBUTE_ADMIN_ROLE);
                }
                context.setAttribute(ATTRIBUTE_ADMIN_ROLE, role);
                if (role != null) {
                    this.sendStartElementEvent(consumer, "roleusers");
                    this.sendStartElementEvent(consumer, "name");
                    this.sendTextEvent(consumer, role);
                    this.sendEndElementEvent(consumer, "name");
                    DocumentFragment userDF = this.getSunRise().getUsers(role, null);
                    Node             users = null;
                    if (userDF != null) users = XMLUtil.getSingleNode(userDF, "users");
                    IncludeXMLConsumer.includeNode(users, consumer, consumer);
                    this.sendEndElementEvent(consumer, "roleusers");
                }
            }

            if (state.equals(Constants.STATE_GLOBAL) == true) {
                profileID = this.getProfileID(SunSpot.BUILDTYPE_VALUE_GLOBAL, null, null, true);
                Map profile = this.retrieveProfile(profileID);
                if (profile == null) {
                    this.createProfile(context, SunSpot.BUILDTYPE_VALUE_GLOBAL, null, null, true);
                    profile = this.retrieveProfile(profileID);
                }
                this.showPortal(consumer, true, context, profile, profileID);
            }

            if (state.equals(Constants.STATE_ROLE) == true) {
                String role = this.request.getParameter(SunSpot.REQ_PARAMETER_ROLE);
                if (role == null) {
                    role = (String)context.getAttribute(ATTRIBUTE_ADMIN_ROLE);
                }
                context.setAttribute(ATTRIBUTE_ADMIN_ROLE, role);
                if (role != null) {
                    consumer.startElement("", Constants.ELEMENT_ROLE, Constants.ELEMENT_ROLE, attr);
                    consumer.characters(role.toCharArray(), 0, role.length());
                    consumer.endElement("", Constants.ELEMENT_ROLE, Constants.ELEMENT_ROLE);
                    profileID = this.getProfileID(SunSpot.BUILDTYPE_VALUE_ROLE, role, null, true);
                    Map profile = this.retrieveProfile(profileID);
                    if (profile == null) {
                        this.createProfile(context, SunSpot.BUILDTYPE_VALUE_ROLE, role, null, true);
                        profile = this.retrieveProfile(profileID);
                    }
                    this.showPortal(consumer, true, context, profile, profileID);
                }
            }
            if (state.equals(Constants.STATE_USER) == true) {
                String role = this.request.getParameter(SunSpot.REQ_PARAMETER_ROLE);
                String id   = this.request.getParameter(SunSpot.REQ_PARAMETER_ID);
                if (role == null) {
                    role = (String)context.getAttribute(ATTRIBUTE_ADMIN_ROLE);
                }
                if (id == null) {
                    id = (String)context.getAttribute(ATTRIBUTE_ADMIN_ID);
                }
                context.setAttribute(ATTRIBUTE_ADMIN_ID, id);
                context.setAttribute(ATTRIBUTE_ADMIN_ROLE, role);
                if (role != null && id != null) {
                    consumer.startElement("", Constants.ELEMENT_ROLE, Constants.ELEMENT_ROLE, attr);
                    consumer.characters(role.toCharArray(), 0, role.length());
                    consumer.endElement("", Constants.ELEMENT_ROLE, Constants.ELEMENT_ROLE);
                    consumer.startElement("", Constants.ELEMENT_ID, Constants.ELEMENT_ID, attr);
                    consumer.characters(id.toCharArray(), 0, id.length());
                    consumer.endElement("", Constants.ELEMENT_ID, Constants.ELEMENT_ID);

                    profileID = this.getProfileID(SunSpot.BUILDTYPE_VALUE_ID, role, id, true);
                    Map profile = this.retrieveProfile(profileID);
                    if (profile == null) {
                        this.createProfile(context, SunSpot.BUILDTYPE_VALUE_ID, role, id, true);
                        profile = this.retrieveProfile(profileID);
                    }
                    this.showPortal(consumer, true, context, profile, profileID);
                }
            }
            // one sunlet
            if (state.equals(Constants.STATE_SUNLET) == true) {
                if (sunletsFragment != null && sunletID != null) {
                    Node sunlet = XMLUtil.getSingleNode(sunletsFragment, "sunlets-profile/sunlets/sunlet[@id='"+sunletID+"']");
                    if (sunlet != null) {
                        IncludeXMLConsumer.includeNode(sunlet, consumer, consumer);
                    }
                } else {
                    state = Constants.STATE_SUNLETS;
                }
            }
            if (state.equals(Constants.STATE_SUNLETS) == true) {
                consumer.startElement("", Constants.ELEMENT_SUNLETS, Constants.ELEMENT_SUNLETS, attr);

                // load the base sunlets profile
                if (sunletsFragment == null) {
                    SourceParameters pars = new SourceParameters();
                    pars.setSingleParameterValue("application", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME));
                    Resource res = (Resource)configuration.get(Constants.CONF_SUNLETBASE_RESOURCE);
                    if (res == null) {
                        throw new ProcessingException("No configuration for sunSpot-sunlet base profile found.");
                    }
                    sunletsFragment = this.loadXML(res.getResourceType(), null,
View Full Code Here

                }

                // Create the parameters for the sunLet:
                //   The <status> part is mapped to parameters
                //   id, number and media are added
                SourceParameters p = XMLUtil.createParameters(XMLUtil.getFirstNodeFromPath(element, new String[] {"status"}, false), null);
                p.setSingleParameterValue(Constants.PARAMETER_ID, sunletID);
                p.setSingleParameterValue(Constants.PARAMETER_NUMBER, element.getAttributeNS(null, "number"));
                p.setSingleParameterValue(Constants.PARAMETER_MEDIA, media);
                String isPersistent = XMLUtil.getValueOf(sunletConf, "configuration/persistent", "false");
                p.setSingleParameterValue(Constants.PARAMETER_PERSISTENT, isPersistent);

                // the sunLet loading is a tricky part:
                // we create an object array containing all information
                // for later processing of the sunlet
                // so the processSunlet() method needs no lookup for information
View Full Code Here

                    }
                }
            }

            // now the status parameter
            SourceParameters p = XMLUtil.createParameters(XMLUtil.getFirstNodeFromPath(element, new String[] {"status"}, false), null);
            consumer.startElement("", "status", "status", attr);
            children = XMLUtil.selectNodeList(element, "status/*");
            if (children != null && children.getLength() > 0) {
                int l = children.getLength();
                for(int i = 0; i < l; i++) {
View Full Code Here

                                   ", type="+type+
                                   ", role="+role+
                                   ", id="+id);
        }

        SourceParameters pars = this.getSunRise().createParameters(null);
        pars.setSingleParameterValue("type", type);
        pars.setSingleParameterValue("admin", (adminProfile == true ? "true" : "false"));

        if (type.equals(SunSpot.BUILDTYPE_VALUE_ID) == false ||
            role != null) {
            pars.setSingleParameterValue("ID", id);
            pars.setSingleParameterValue("role", role);
        } else {
            id = pars.getParameter("ID", null);
            role = pars.getParameter("role", null);
        }

        Map map = this.getConfiguration();
        if (map == null) {
            throw new ProcessingException("sunSpot Configuration not found.");
View Full Code Here

        DocumentFragment profile;
        Document         profileDoc;
        Element          profileRoot;
        Resource         res;

        SourceParameters pars = new SourceParameters();
        pars.setSingleParameterValue("application", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME));
        pars.setSingleParameterValue("handler", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_HANDLER_NAME));
        pars.setSingleParameterValue("profile", "sunlet-base");

        // First load the base profiles: sunletProfile + layoutProfile
        res = (Resource)config.get(Constants.CONF_SUNLETBASE_RESOURCE);
        if (res == null) {
            throw new ProcessingException("No configuration for sunSpot-sunlet base profile found.");
        }
        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("Loading sunLet base profile");
        }
        sunletsFragment = this.loadXML(res.getResourceType(), null,
                                       res.getResourceIdentifier(), pars,
                                       "Error loading sunLet base profile." + res.getResourceIdentifier());
        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("sunLet base profile loaded");
        }
        res = (Resource)config.get(Constants.CONF_LAYOUTBASE_RESOURCE);
        if (res == null) {
            throw new ProcessingException("No configuration for sunSpot-layout base profile found.");
        }
        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("loading layout base profile");
        }
        pars.setSingleParameterValue("profile", "layout-base");
        layoutFragment = this.loadXML(res.getResourceType(), null,
                                      res.getResourceIdentifier(), pars,
                                      "Error loading layout base profile " + res.getResourceIdentifier());
        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("layout base profile loaded");
        }
        // now create the base profile containing the above profiles
        profileDoc = XMLUtil.createDocument();
        profile = profileDoc.createDocumentFragment();
        profileRoot = profileDoc.createElementNS(null, "profile");
        profile.appendChild(profileRoot);
        profileRoot.appendChild(profileDoc.importNode(XMLUtil.selectSingleNode(layoutFragment,
                                                                  "layout-profile"), true));
        profileRoot.appendChild(profileDoc.importNode(XMLUtil.selectSingleNode(sunletsFragment,
                                                                  "sunlets-profile"), true));

        // if avalailable append the type profile
        if (adminProfile == true) {
            res = (Resource)config.get(Constants.CONF_ADMIN_TYPE_BASE);
            pars.setSingleParameterValue("profile", "admin-type-base");
        } else {
            res = (Resource)config.get(Constants.CONF_TYPEBASE_RESOURCE);
            pars.setSingleParameterValue("profile", "type-base");
        }
        if (res != null) {
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("loading type base profile");
            }
View Full Code Here

        DocumentFragment globalFragment;
        Resource res = (Resource)config.get(Constants.CONF_GLOBALDELTA_LOADRESOURCE);
        if (res == null) {
            throw new ProcessingException("No configuration for sunSpot-role delta profile found.");
        }
        SourceParameters pars = new SourceParameters();
        pars.setSingleParameterValue("application", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME));
        pars.setSingleParameterValue("handler", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_HANDLER_NAME));
        pars.setSingleParameterValue("profile", "global-delta");

        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("loading global profile");
        }
        globalFragment = this.loadXML(res.getResourceType(), null,
                                      res.getResourceIdentifier(), pars,
                                      "Error loading global profile " + res.getResourceIdentifier());
        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("global profile loaded");
        }
        this.importProfileDelta(profileRoot, globalFragment, "global-delta", "layout-delta");
        this.importProfileDelta(profileRoot, globalFragment, "global-delta", "sunlets-delta");
        this.addProfilePart(profileRoot, globalFragment, "global-delta", "portal-profile");
        this.addProfilePart(profileRoot, globalFragment, "global-delta", "personal-profile");

        // types
        res = (Resource)config.get(Constants.CONF_GLOBALDELTA_TYPERESOURCE);
        if (adminProfile == false && res != null) {
            pars.setSingleParameterValue("profile", "global-type-delta");
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("loading global type profile");
            }
            globalFragment = this.loadXML(res.getResourceType(), null,
                                          res.getResourceIdentifier(), pars,
View Full Code Here

                                            boolean adminProfile)
    throws ProcessingException, SAXException, javax.xml.transform.TransformerException {
        // calling method is synced

        DocumentFragment roleFragment;
        SourceParameters pars;
        pars = new SourceParameters();
        pars.setSingleParameterValue("role", role);
        pars.setSingleParameterValue("application", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME));
        pars.setSingleParameterValue("handler", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_HANDLER_NAME));
        pars.setSingleParameterValue("profile", "role-delta");

        Resource res = (Resource)config.get(Constants.CONF_ROLEDELTA_LOADRESOURCE);
        if (res != null) {
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("loading role profile");
            }
            roleFragment = this.loadXML(res.getResourceType(), null,
                                        res.getResourceIdentifier(), pars,
                                        "Error loading role profile "  + res.getResourceIdentifier());
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("role profile loaded");
            }
            this.importProfileDelta(profileRoot, roleFragment, "role-delta", "layout-delta");
            this.importProfileDelta(profileRoot, roleFragment, "role-delta", "sunlets-delta");
            this.addProfilePart(profileRoot, roleFragment, "role-delta", "portal-profile");
            this.importProfileDelta(profileRoot, roleFragment, "role-delta", "personal-delta");
        }

        // types
        res = (Resource)config.get(Constants.CONF_ROLEDELTA_TYPERESOURCE);
        if (adminProfile == false && res != null) {
            pars.setSingleParameterValue("profile", "role-type-delta");
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("loading role type profile");
            }
            roleFragment = this.loadXML(res.getResourceType(), null,
                                        res.getResourceIdentifier(), pars,
View Full Code Here

                                String id,
                                boolean adminProfile)
    throws ProcessingException, SAXException, javax.xml.transform.TransformerException {
        // calling method is synced
        DocumentFragment userFragment;
        SourceParameters pars;
        pars = new SourceParameters();
        pars.setSingleParameterValue("ID", id);
        pars.setSingleParameterValue("role", role);
        pars.setSingleParameterValue("application", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_APPLICATION_NAME));
        pars.setSingleParameterValue("handler", (String)this.request.getAttribute(org.apache.cocoon.sunshine.sunrise.Constants.REQUEST_ATTRIBUTE_HANDLER_NAME));
        pars.setSingleParameterValue("profile", "user-delta");

        Resource res = (Resource)config.get(Constants.CONF_USERDELTA_LOADRESOURCE);
        if (res != null) {
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("loading user profile");
            }
            userFragment = this.loadXML(res.getResourceType(), null,
                                        res.getResourceIdentifier(), pars,
                                        "Error loading user profile " + res.getResourceIdentifier());
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("user profile loaded");
            }
            this.importProfileDelta(profileRoot, userFragment, "user-delta", "layout-delta");
            this.importProfileDelta(profileRoot, userFragment, "user-delta", "sunlets-delta");
            this.addProfilePart(profileRoot, userFragment, "user-delta", "portal-profile");
            this.importProfileDelta(profileRoot, userFragment, "user-delta", "personal-delta");
        }

        // types
        res = (Resource)config.get(Constants.CONF_USERDELTA_TYPERESOURCE);
        if (adminProfile == false && res != null) {
            pars.setSingleParameterValue("profile", "user-type-delta");
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("loading user type profile");
            }
            userFragment = this.loadXML(res.getResourceType(), null,
                                        res.getResourceIdentifier(), pars,
View Full Code Here

TOP

Related Classes of org.apache.avalon.excalibur.source.SourceParameters

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.