Package org.apache.cocoon.environment

Examples of org.apache.cocoon.environment.Context


     * @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


*
* @version $Id: ResetCounterAction.java 369531 2006-01-16 17:45:53Z jbq $
*/
public class ResetCounterAction implements Action {
  public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception {
    Context context = ObjectModelHelper.getContext(objectModel);
    Integer count = new Integer(0);
    context.setAttribute("count", count);
    return new HashMap();
  }
View Full Code Here

  }

  public void generate() throws IOException, SAXException, ProcessingException {
    consumer.startDocument();
    consumer.startElement("", "context", "context", new AttributesImpl());
    Context context = ObjectModelHelper.getContext(objectModel);
    Enumeration keys = context.getAttributeNames();
    while (keys.hasMoreElements()) {
      String key = (String) keys.nextElement();
      Object value = context.getAttribute(key);
      AttributesImpl attrs = new AttributesImpl();
      attrs.addAttribute("", "name", "name", "CDATA", key);
      consumer.startElement("", "key", "key", attrs);
      String str = value.toString();
      consumer.characters(str.toCharArray(), 0, str.length());
View Full Code Here

      throw new CascadingRuntimeException("Could not find parameter key", e);
    }
  }
 
  public static void increment(Map objectModel, String key) {
    Context context = ObjectModelHelper.getContext(objectModel);
    Integer count = (Integer) context.getAttribute(key);
    if (count == null) {
      count = new Integer(0);
    }
    count = new Integer(count.intValue() + 1);
    context.setAttribute(key, count);
  }
View Full Code Here

public class ResourceExistsSelector extends AbstractLogEnabled
  implements ThreadSafe, Selector {

    public boolean select(String expression, Map objectModel, Parameters parameters) {

        Context context = ObjectModelHelper.getContext(objectModel);
        URL url = null;
        expression = parameters.getParameter("prefix", "/") + expression;
        try {
            url = context.getResource(expression);
            if (url == null) {
                return false;
            } else { return true; }
        } catch (MalformedURLException e) {
            getLogger().warn("Selector expression '"+expression+"' is not a valid URL");
View Full Code Here

    /**
     * Returns the mime-type of the resource in process.
     */
    public String getMimeType() {
        Context ctx = ObjectModelHelper.getContext(objectModel);

        if (ctx != null) {
            if (ctx.getMimeType(source) != null) {
                return ctx.getMimeType(source);
            }
            else {
                return inputSource.getMimeType();
            }
        }
View Full Code Here

                    int scope)
    {
        XScriptVariableScope s;

        if (scope == XScriptManager.GLOBAL_SCOPE) {
            Context context = ObjectModelHelper.getContext(objectModel);
            synchronized (context) {
                s = (XScriptVariableScope) context.getAttribute(CONTEXT);
                if (s == null) {
                    context.setAttribute(CONTEXT, s = new XScriptVariableScope());
                }
            }
        } else if (scope == XScriptManager.SESSION_SCOPE) {
            Session session = ObjectModelHelper.getRequest(objectModel).getSession();
            synchronized (session) {
View Full Code Here

    /**
     * Returns the mime-type of the resource in process.
     */
    public String getMimeType() {
        Context ctx = ObjectModelHelper.getContext(objectModel);
        return (ctx != null) ? ctx.getMimeType(this.source) : null;
    }
View Full Code Here

  public TestBeanAction() {
  }

  public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters param) throws java.lang.Exception {
      Request request = ObjectModelHelper.getRequest(objectModel);
      Context context = ObjectModelHelper.getContext(objectModel);
      if(context != null)
        request.setAttribute("Wale",new  TestBean("Wale in the big sea","context"));

      Session session =request.getSession(true);
      session.setAttribute("Mouse",new  TestBean("Liveing in the session","session"));
View Full Code Here

                return;
              }
            }
          }
          if(sourcemap == null || VALUE_CONTEXT.equals(sourcemap)){
            Context context = ObjectModelHelper.getContext(objectModel);
            if(context != null){
              toInsert=context.getAttribute(name);
              if(toInsert != null){
                insertBean(toInsert,mapping);
                return;
              }
            }
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.