1 14 package org.compiere.print; 15 16 import java.util.*; 17 18 import org.xml.sax.helpers.*; 19 import org.xml.sax.*; 20 21 27 public class PrintDataHandler extends DefaultHandler 28 { 29 33 public PrintDataHandler(Properties ctx) 34 { 35 m_ctx = ctx; 36 } 38 39 private Properties m_ctx = null; 40 41 private PrintData m_pd = null; 42 43 44 private String m_curPDEname = null; 45 46 private StringBuffer m_curPDEvalue = null; 47 48 private PrintData m_curPD = null; 49 50 54 public PrintData getPrintData() 55 { 56 return m_pd; 57 } 59 60 61 70 public void startElement(String uri, String localName, String qName, Attributes attributes) 71 throws org.xml.sax.SAXException  72 { 73 if (qName.equals(PrintData.XML_TAG)) 74 { 75 String name = attributes.getValue(PrintData.XML_ATTRIBUTE_NAME); 76 if (m_pd == null) 77 { 78 m_pd = new PrintData(m_ctx, name); 79 push(m_pd); 80 } 81 else 82 { 83 PrintData temp = new PrintData(m_ctx, name); 84 m_curPD.addNode(temp); 85 push(temp); 86 } 87 } 88 else if (qName.equals(PrintData.XML_ROW_TAG)) 89 { 90 m_curPD.addRow(false, 0); 91 } 92 else if (qName.equals(PrintDataElement.XML_TAG)) 93 { 94 m_curPDEname = attributes.getValue(PrintDataElement.XML_ATTRIBUTE_NAME); 95 m_curPDEvalue = new StringBuffer (); 96 } 97 } 99 107 public void characters (char ch[], int start, int length) 108 throws SAXException 109 { 110 m_curPDEvalue.append(ch, start, length); 111 } 113 120 public void endElement (String uri, String localName, String qName) 121 throws SAXException 122 { 123 if (qName.equals(PrintData.XML_TAG)) 124 { 125 pop(); 126 } 127 else if (qName.equals(PrintDataElement.XML_TAG)) 128 { 129 m_curPD.addNode(new PrintDataElement(m_curPDEname, m_curPDEvalue.toString(),0)); 130 } 131 } 133 134 135 136 private ArrayList m_stack = new ArrayList(); 137 138 142 private void push (PrintData newPD) 143 { 144 m_stack.add(newPD); 146 m_curPD = newPD; 147 } 149 152 private void pop () 153 { 154 if (m_stack.size() > 0) 156 m_stack.remove(m_stack.size()-1); 157 if (m_stack.size() > 0) 159 m_curPD = (PrintData)m_stack.get(m_stack.size()-1); 160 } 162 }
| Popular Tags
|