From: Lars H. <lh...@us...> - 2005-07-08 16:27:32
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9420/src/org/tmapiutils/impexp/cxtm/utils Modified Files: SimpleXMLC14N.java Log Message: Tabs -> Whitespaces Index: SimpleXMLC14N.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/utils/SimpleXMLC14N.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SimpleXMLC14N.java 5 Mar 2005 17:09:38 -0000 1.1 --- SimpleXMLC14N.java 8 Jul 2005 16:27:23 -0000 1.2 *************** *** 1,189 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! package org.tmapiutils.impexp.cxtm.utils; ! ! import java.io.IOException; ! import java.io.OutputStream; ! import java.io.OutputStreamWriter; ! import java.io.UnsupportedEncodingException; ! import java.io.Writer; ! import java.util.Iterator; ! import java.util.TreeSet; ! ! import org.xml.sax.Attributes; ! import org.xml.sax.ContentHandler; ! import org.xml.sax.Locator; ! import org.xml.sax.SAXException; ! ! /** ! * A very simple implementation of XML canonicalisation ! * this implementation is really only designed to handle ! * the output generated by the XTMCanonicalizer class ! * and should not be used for general XML canonicalisation! ! */ ! public class SimpleXMLC14N implements ContentHandler { ! ! private StringBuffer m_charBuf; ! private OutputStream m_outputStream; ! private Writer m_out; ! private boolean m_insertLinefeeds = false; ! private boolean m_inDocument = false; ! private static final String STAGO = "<"; ! private static final String STAGC = ">"; ! private static final String ETAGO = "</"; ! private static final String ETAGC = ">"; ! private static final int LF = 10; ! ! public SimpleXMLC14N(OutputStream os) throws UnsupportedEncodingException ! { ! m_outputStream = os; ! m_out = new OutputStreamWriter(os, "UTF-8"); ! } ! ! public void setInsertLinefeeds(boolean b) { ! m_insertLinefeeds = b; ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endDocument() ! */ ! public void endDocument() throws SAXException { ! try { ! m_out.flush(); ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startDocument() ! */ ! public void startDocument() throws SAXException { ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#characters(char[], int, int) ! */ ! public void characters(char[] ch, int start, int length) ! throws SAXException { ! if (m_charBuf == null) m_charBuf = new StringBuffer(); ! m_charBuf.append(ch, start, length); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) ! */ ! public void ignorableWhitespace(char[] ch, int start, int length) ! throws SAXException { ! // Ignore ignorable whitespace ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String) ! */ ! public void endPrefixMapping(String prefix) throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String) ! */ ! public void skippedEntity(String name) throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process entities."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator) ! */ ! public void setDocumentLocator(Locator locator) { ! // NO-OP ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) ! */ ! public void processingInstruction(String target, String data) ! throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String) ! */ ! public void startPrefixMapping(String prefix, String uri) ! throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) ! */ ! public void endElement(String namespaceURI, String localName, String qName) ! throws SAXException { ! try { ! if (m_charBuf != null) { ! m_out.write(normalize(m_charBuf.toString())); ! } else { ! m_out.write(LF); ! } ! m_out.write(ETAGO); ! m_out.write(qName); ! m_out.write(ETAGC); ! m_charBuf = null; ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) ! */ ! public void startElement( ! String namespaceURI, ! String localName, ! String qName, ! Attributes atts) ! throws SAXException { ! try { ! if (m_inDocument) m_out.write(LF); ! m_out.write(STAGO); ! m_out.write(normalize(qName)); ! if ((atts != null) && (atts.getLength() > 0)) { ! TreeSet ts = new TreeSet(); ! for (int i = 0; i < atts.getLength(); i++) { ! ts.add(atts.getQName(i)); ! } ! Iterator it = ts.iterator(); ! while (it.hasNext()) { ! String qname = (String)it.next(); ! m_out.write(' '); ! m_out.write(normalize(qname)); ! m_out.write("=\""); ! m_out.write(atts.getValue(qname)); ! m_out.write('"'); ! } ! } ! m_out.write(STAGC); ! m_inDocument = true; ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! private String normalize(String str) { ! return str; ! } ! } --- 1,189 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! package org.tmapiutils.impexp.cxtm.utils; ! ! import java.io.IOException; ! import java.io.OutputStream; ! import java.io.OutputStreamWriter; ! import java.io.UnsupportedEncodingException; ! import java.io.Writer; ! import java.util.Iterator; ! import java.util.TreeSet; ! ! import org.xml.sax.Attributes; ! import org.xml.sax.ContentHandler; ! import org.xml.sax.Locator; ! import org.xml.sax.SAXException; ! ! /** ! * A very simple implementation of XML canonicalisation ! * this implementation is really only designed to handle ! * the output generated by the XTMCanonicalizer class ! * and should not be used for general XML canonicalisation! ! */ ! public class SimpleXMLC14N implements ContentHandler { ! ! private StringBuffer m_charBuf; ! private OutputStream m_outputStream; ! private Writer m_out; ! private boolean m_insertLinefeeds = false; ! private boolean m_inDocument = false; ! private static final String STAGO = "<"; ! private static final String STAGC = ">"; ! private static final String ETAGO = "</"; ! private static final String ETAGC = ">"; ! private static final int LF = 10; ! ! public SimpleXMLC14N(OutputStream os) throws UnsupportedEncodingException ! { ! m_outputStream = os; ! m_out = new OutputStreamWriter(os, "UTF-8"); ! } ! ! public void setInsertLinefeeds(boolean b) { ! m_insertLinefeeds = b; ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endDocument() ! */ ! public void endDocument() throws SAXException { ! try { ! m_out.flush(); ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startDocument() ! */ ! public void startDocument() throws SAXException { ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#characters(char[], int, int) ! */ ! public void characters(char[] ch, int start, int length) ! throws SAXException { ! if (m_charBuf == null) m_charBuf = new StringBuffer(); ! m_charBuf.append(ch, start, length); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) ! */ ! public void ignorableWhitespace(char[] ch, int start, int length) ! throws SAXException { ! // Ignore ignorable whitespace ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String) ! */ ! public void endPrefixMapping(String prefix) throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String) ! */ ! public void skippedEntity(String name) throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process entities."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator) ! */ ! public void setDocumentLocator(Locator locator) { ! // NO-OP ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) ! */ ! public void processingInstruction(String target, String data) ! throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String) ! */ ! public void startPrefixMapping(String prefix, String uri) ! throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) ! */ ! public void endElement(String namespaceURI, String localName, String qName) ! throws SAXException { ! try { ! if (m_charBuf != null) { ! m_out.write(normalize(m_charBuf.toString())); ! } else { ! m_out.write(LF); ! } ! m_out.write(ETAGO); ! m_out.write(qName); ! m_out.write(ETAGC); ! m_charBuf = null; ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) ! */ ! public void startElement( ! String namespaceURI, ! String localName, ! String qName, ! Attributes atts) ! throws SAXException { ! try { ! if (m_inDocument) m_out.write(LF); ! m_out.write(STAGO); ! m_out.write(normalize(qName)); ! if ((atts != null) && (atts.getLength() > 0)) { ! TreeSet ts = new TreeSet(); ! for (int i = 0; i < atts.getLength(); i++) { ! ts.add(atts.getQName(i)); ! } ! Iterator it = ts.iterator(); ! while (it.hasNext()) { ! String qname = (String)it.next(); ! m_out.write(' '); ! m_out.write(normalize(qname)); ! m_out.write("=\""); ! m_out.write(atts.getValue(qname)); ! m_out.write('"'); ! } ! } ! m_out.write(STAGC); ! m_inDocument = true; ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! private String normalize(String str) { ! return str; ! } ! } |