1 package com.protomatter.syslog.xml; 2 3 52 53 import java.io.*; 54 import java.net.*; 55 import java.util.*; 56 import com.protomatter.syslog.*; 57 import com.protomatter.xml.*; 58 import org.jdom.*; 59 import org.jdom.output.*; 60 import org.jdom.input.*; 61 62 65 public class SimpleLogPolicy_Helper 66 implements XMLConfigHelper 67 { 68 119 public void configure(Object what, Element e) 120 throws SyslogInitException 121 { 122 SimpleLogPolicy policy = (SimpleLogPolicy)what; 123 124 String tmp = e.getChildTextTrim("logMask", e.getNamespace()); 125 if (tmp != null) 126 { 127 policy.setLogMask(tmp); 128 } 129 130 tmp = e.getChildTextTrim("channels", e.getNamespace()); 131 if (tmp == null) 132 tmp = ""; 133 134 policy.removeAllChannels(); 138 StringTokenizer st = new StringTokenizer(tmp, ", "); 139 while (st.hasMoreTokens()) 140 { 141 String chan = st.nextToken(); 142 if (chan.equals("ALL_CHANNEL")) 143 policy.addChannel(Syslog.ALL_CHANNEL); 144 else if (chan.equals("DEFAULT_CHANNEL")) 145 policy.addChannel(Syslog.DEFAULT_CHANNEL); 146 else 147 policy.addChannel(chan); 148 } 149 } 150 151 public Element getConfiguration(Object o, Element element) 152 { 153 SimpleLogPolicy policy = (SimpleLogPolicy)o; 154 if (element == null) 155 { 156 element = new Element("Policy"); 157 element.setAttribute("name", policy.getName()); 158 element.setAttribute("class", policy.getClass().getName()); 159 } 160 161 Element param = new Element("channels"); 162 boolean allChannels = false; 163 Iterator i = policy.getChannels(); 164 while (i.hasNext()) 165 { 166 String channel = (String )i.next(); 167 if (Syslog.ALL_CHANNEL.equals(channel)) 168 allChannels = true; 169 } 170 171 if (allChannels) 172 { 173 param.setText("ALL_CHANNEL"); 174 } 175 else 176 { 177 StringBuffer channelList = new StringBuffer (); 178 i = policy.getChannels(); 179 while (i.hasNext()) 180 { 181 channelList.append(i.next()); 182 if (i.hasNext()) 183 channelList.append(", "); 184 } 185 param.setText(channelList.toString()); 186 } 187 element.getChildren().add(param); 188 189 Element mask = new Element("logMask"); 190 mask.setText(Syslog.getLogMaskAsString(policy.getLogMask())); 191 element.getChildren().add(mask); 192 193 return element; 194 } 195 } 196 | Popular Tags |