【BIRT】Birtレポートからレポートパラメータを抽出するjavaサンプル
package birtAnalizer;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class xmlParseSample3 extends DefaultHandler{
public static void main(String args) throws IOException, ParserConfigurationException, SAXException {
String path1 = "/Applications/eclipse.app/Contents/MacOS/workspace/reportDs/design";
File file1 = new File(path1);
File fileArray1 = file1.listFiles();
for (File f: fileArray1){
if(f.isFile()) {
System.out.println(f.getName());
SAXParserFactory spfactory = SAXParserFactory.newInstance();
SAXParser parser = spfactory.newSAXParser();
parser.parse(new File(f.getAbsolutePath()), new xmlParseSample3());
}
}
}
//start Document
public void startDocument() {
}
//start Element
public void startElement(String uri,
String localName,
String qName,
Attributes attributes) {
if(qName.equals("scalar-parameter")) {
for (int i=0;i<attributes.getLength();i++) {
if(attributes.getLocalName(i).equals("name")){
System.out.println("ReportParameter"+","+attributes.getValue(i));
}
}
}
}
//Text
public void characters(char[] ch,
int offset,
int length) {
}
//End Element
public void endElement(String uri,
String localName,
String qName) {
}
//End of Document
public void endDocument(){
}
}