1 16 package org.apache.cocoon.components.modules.output; 17 18 import org.apache.avalon.framework.activity.Disposable; 19 import org.apache.avalon.framework.configuration.Configurable; 20 import org.apache.avalon.framework.configuration.Configuration; 21 import org.apache.avalon.framework.configuration.ConfigurationException; 22 import org.apache.avalon.framework.logger.AbstractLogEnabled; 23 24 import org.apache.cocoon.environment.ObjectModelHelper; 25 import org.apache.cocoon.environment.Request; 26 import org.apache.cocoon.util.HashMap; 27 28 import java.util.Map ; 29 30 39 public abstract class AbstractOutputModule extends AbstractLogEnabled 40 implements OutputModule, Configurable, Disposable { 41 42 46 protected HashMap settings; 47 48 58 public void configure(Configuration conf) throws ConfigurationException { 59 Configuration[] parameters = conf.getChildren(); 60 this.settings = new HashMap(parameters.length + 1); 62 for (int i = 0; i < parameters.length; i++) { 63 String key = parameters[i].getName(); 64 String val = parameters[i].getValue(""); 65 this.settings.put(key, val); 66 } 67 } 68 69 72 public void dispose() { 73 this.settings = null; 75 } 76 77 86 protected void transientSetAttribute(Map objectModel, String trans_place, String name, Object value) { 87 final Request request = ObjectModelHelper.getRequest(objectModel); 88 89 Map map = (Map) request.getAttribute(trans_place); 90 if (map == null) { 91 map = new java.util.HashMap (); 93 } 94 95 map.put(name, value); 96 request.setAttribute(trans_place, map); 97 } 98 99 105 protected void rollback(Map objectModel, String trans_place) { 106 ObjectModelHelper.getRequest(objectModel).removeAttribute(trans_place); 107 } 108 109 117 protected boolean attributeExists(Map objectModel, String trans_place, String name) { 118 final Request request = ObjectModelHelper.getRequest(objectModel); 119 120 Map map = (Map) request.getAttribute(trans_place); 121 if (map == null) { 122 return false; 123 } 124 125 return map.containsKey(name); 126 } 127 128 136 protected Map prepareCommit(Map objectModel, String trans_place) { 137 final Request request = ObjectModelHelper.getRequest(objectModel); 138 139 Map data = (Map) request.getAttribute(trans_place); 140 request.removeAttribute(trans_place); 141 return data; 142 } 143 } 144 | Popular Tags |