Back to index

lightning-sunbird  0.9+nobinonly
txXMLOutput.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is TransforMiiX XSLT processor code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Peter Van der Beken <peterv@propagandism.org>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef TRANSFRMX_XML_OUTPUT_H
00040 #define TRANSFRMX_XML_OUTPUT_H
00041 
00042 #include "txXMLEventHandler.h"
00043 #include "txList.h"
00044 #include "txStack.h"
00045 #include "txOutputFormat.h"
00046 #include "XMLUtils.h"
00047 
00048 #define DASH            '-'
00049 #define TX_CR           '\r'
00050 #define TX_LF           '\n'
00051 
00052 #define AMPERSAND       '&'
00053 #define APOSTROPHE      '\''
00054 #define GT              '>'
00055 #define LT              '<'
00056 #define QUOTE           '"'
00057 
00058 #define AMP_ENTITY      "&amp;"
00059 #define APOS_ENTITY     "&apos;"
00060 #define GT_ENTITY       "&gt;"
00061 #define LT_ENTITY       "&lt;"
00062 #define QUOT_ENTITY     "&quot;"
00063 #define HEX_ENTITY      "&#"
00064 
00065 #define CDATA_END       "]]>"
00066 #define CDATA_START     "<![CDATA["
00067 #define COMMENT_START   "<!--"
00068 #define COMMENT_END     "-->"
00069 #define DOCTYPE_START   "<!DOCTYPE "
00070 #define DOCTYPE_END     ">"
00071 #define DOUBLE_QUOTE    "\""
00072 #define EQUALS          "="
00073 #define FORWARD_SLASH   "/"
00074 #define L_ANGLE_BRACKET "<"
00075 #define PI_START        "<?"
00076 #define PI_END          "?>"
00077 #define PUBLIC          "PUBLIC"
00078 #define R_ANGLE_BRACKET ">"
00079 #define SEMICOLON       ";"
00080 #define SPACE           " "
00081 #define SYSTEM          "SYSTEM"
00082 #define XML_DECL        "xml version="
00083 #define XML_VERSION     "1.0"
00084 
00085 class txOutAttr {
00086 public:
00087     txOutAttr(PRInt32 aNsID, nsIAtom* aLocalName, const nsAString& aValue);
00088     txExpandedName mName;
00089     nsString mValue;
00090     MBool mShorthand;
00091 };
00092 
00093 class txXMLOutput : public txAOutputXMLEventHandler
00094 {
00095 public:
00096     txXMLOutput(txOutputFormat* aFormat, ostream* aOut);
00097     virtual ~txXMLOutput();
00098 
00099     static const int DEFAULT_INDENT;
00100 
00101     TX_DECL_TXAXMLEVENTHANDLER
00102     TX_DECL_TXAOUTPUTXMLEVENTHANDLER
00103 
00104 protected:
00105     virtual void closeStartTag(MBool aUseEmptyElementShorthand);
00106     void printUTF8Char(PRUnichar& ch);
00107     void printUTF8Chars(const nsAString& aData);
00108     void printWithXMLEntities(const nsAString& aData,
00109                               MBool aAttribute = MB_FALSE);
00110 
00111     ostream* mOut;
00112     txOutputFormat mOutputFormat;
00113     MBool mUseEmptyElementShorthand;
00114     MBool mHaveDocumentElement;
00115     MBool mStartTagOpen;
00116     MBool mAfterEndTag;
00117     MBool mInCDATASection;
00118     PRUint32 mIndentLevel;
00119     txList mAttributes;
00120     txStack mCDATASections;
00121 
00122 private:
00123     PRUnichar mBuffer[4];
00124 };
00125 
00126 #endif