1 16 package org.apache.cocoon.transformation.helpers; 17 18 import org.apache.avalon.framework.parameters.Parameters; 19 import org.apache.excalibur.source.SourceParameters; 20 import org.xml.sax.Attributes ; 21 import org.xml.sax.SAXException ; 22 23 import java.util.Iterator ; 24 25 26 35 public final class ParametersRecorder 36 extends NOPRecorder { 37 38 private SourceParameters parameters; 39 private String key; 40 private StringBuffer buffer; 41 42 46 public ParametersRecorder() { 47 super(); 48 this.parameters = new SourceParameters(); 49 } 50 51 public SourceParameters getParameters(Parameters source) { 52 if (source != null) { 53 String [] names = source.getNames(); 54 if (names != null) { 56 String currentParameterName; 57 for(int i=0; i<names.length; i++) { 58 currentParameterName = names[i]; 59 this.parameters.setParameter(currentParameterName, source.getParameter(currentParameterName, "")); 62 } 63 } 64 } 65 return parameters; 66 } 67 68 public SourceParameters getParameters(SourceParameters source) { 69 if (source != null) { 70 Iterator iter = source.getParameterNames(); 71 Iterator valuesIter; 72 String value, parName; 73 while (iter.hasNext() == true) { 74 parName = (String )iter.next(); 75 valuesIter = source.getParameterValues(parName); 76 while (valuesIter.hasNext() == true) { 77 value = (String )valuesIter.next(); 78 this.parameters.setParameter(parName, value); 79 } 80 } 81 } 82 return parameters; 83 } 84 85 public void startElement(String namespace, String name, String raw, 86 Attributes attr) 87 throws SAXException { 88 if (this.key == null) { 89 this.key = name; 90 this.buffer = new StringBuffer (); 91 } 92 } 93 94 public void endElement(String namespace, String name, String raw) 95 throws SAXException { 96 if (this.key != null && this.key.equals(name) == true) { 97 String value = this.buffer.toString().trim(); 98 if (value.length() > 0) { 99 this.parameters.setParameter(this.key, value); 100 } 101 this.buffer = null; 102 this.key = null; 103 } 104 } 105 106 public void characters(char ary[], int start, int length) 107 throws SAXException { 108 if (this.key != null && this.buffer != null) { 109 String value = new String (ary, start, length).trim(); 110 if (value.length() > 0) { 111 buffer.append(value); 112 } else { 113 buffer.append(' '); 114 } 115 } 116 } 117 118 } 119 | Popular Tags |