25 #include <rtl/strbuf.hxx>
26 #include <osl/diagnose.h>
27 #include <com/sun/star/xml/sax/SAXException.hpp>
30 #if OSL_DEBUG_LEVEL > 0
31 #include <osl/file.hxx>
41 SaxEmitter::SaxEmitter(
const uno::Reference< xml::sax::XDocumentHandler >& xDocHdl ) :
44 OSL_PRECOND(
m_xDocHdl.is(),
"SaxEmitter(): invalid doc handler");
51 catch( xml::sax::SAXException& )
54 #if OSL_DEBUG_LEVEL > 0
55 static const char* pDir = getenv(
"DBG_PDFIMPORT_DIR" );
58 OUString
aStr( OStringToOUString( pDir, RTL_TEXTENCODING_UTF8 ) );
60 osl_getFileURLFromSystemPath( aStr.pData, &aFileURL.pData );
61 pStream =
new osl::File( aFileURL +
"/pdfimport.xml" );
62 if(
pStream->open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ) )
64 pStream->open( osl_File_OpenFlag_Write );
79 catch( xml::sax::SAXException& )
82 #if OSL_DEBUG_LEVEL > 0
94 OUString aTag = OUString::createFromAscii( pTag );
95 uno::Reference< xml::sax::XAttributeList > xAttr(
101 catch( xml::sax::SAXException& )
104 #if OSL_DEBUG_LEVEL > 0
108 sal_uInt64 nWritten = 0;
110 pStream->write(
" ", 4, nWritten );
112 OStringBuffer
aBuf( 1024 );
115 for(
const auto& rProperty : rProperties )
119 aBuf.append(
"=\"" );
123 aBuf.append(
">\n" );
124 pStream->write( aBuf.getStr(), aBuf.getLength(), nWritten );
135 catch( xml::sax::SAXException& )
138 #if OSL_DEBUG_LEVEL > 0
142 sal_uInt64 nWritten = 0;
143 pStream->write( aStr.getStr(), aStr.getLength(), nWritten );
150 OUString aTag = OUString::createFromAscii( pTag );
155 catch( xml::sax::SAXException& )
158 #if OSL_DEBUG_LEVEL > 0
162 sal_uInt64 nWritten = 0;
164 pStream->write(
" ", 4, nWritten );
166 OString
aBuf = OString::Concat(
"</") + pTag +
">\n";
167 pStream->write( aBuf.getStr(), aBuf.getLength(), nWritten );
174 return std::make_shared<SaxEmitter>(xDocHdl);
std::unordered_map< OUString, OUString > PropertyMap
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
virtual void write(const OUString &rString) override
Write PCTEXT as-is to output.
std::shared_ptr< XmlEmitter > XmlEmitterSharedPtr
XmlEmitterSharedPtr createSaxEmitter(const css::uno::Reference< css::xml::sax::XDocumentHandler > &xDocHdl)
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xDocHdl
virtual void beginTag(const char *pTag, const PropertyMap &rProperties) override
Open up a tag with the given properties.
virtual void endTag(const char *pTag) override
Close previously opened tag.
virtual ~SaxEmitter() override
static osl::File * pStream