30#include <com/sun/star/lang/XComponent.hpp>
32#include <com/sun/star/xml/sax/SAXException.hpp>
33#include <com/sun/star/xml/sax/Parser.hpp>
34#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
43using namespace ::
cppu;
54class OInputStream :
public WeakImplHelper < XInputStream >
63 virtual sal_Int32 SAL_CALL readBytes(
Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
override
65 nBytesToRead = std::min(nBytesToRead, m_seq.getLength() - nPos);
70 virtual sal_Int32 SAL_CALL readSomeBytes(
71 css::uno::Sequence< sal_Int8 >& aData,
72 sal_Int32 nMaxBytesToRead )
override
74 return readBytes( aData, nMaxBytesToRead );
76 virtual void SAL_CALL skipBytes( sal_Int32 )
override
80 virtual sal_Int32 SAL_CALL available( )
override
82 return m_seq.getLength() -
nPos;
84 virtual void SAL_CALL closeInput( )
override
89 Sequence< sal_Int8> m_seq;
99 Reference< XInputStream > r;
101 FILE *f = fopen( pcFile ,
"rb" );
105 fprintf(stderr,
"failure opening %s\n", pcFile);
109 if (fseek( f , 0 , SEEK_END ) == -1)
111 fprintf(stderr,
"failure fseeking %s\n", pcFile);
119 fprintf(stderr,
"failure ftelling %s\n", pcFile);
124 if (fseek( f , 0 , SEEK_SET ) == -1)
126 fprintf(stderr,
"failure fseeking %s\n", pcFile);
131 Sequence<sal_Int8> seqIn(
nLength);
132 if (fread( seqIn.getArray(),
nLength , 1 , f ) == 1)
133 r.set(
new OInputStream( seqIn ) );
135 fprintf(stderr,
"failure reading %s\n", pcFile);
142class TestDocumentHandler :
143 public WeakImplHelper< XExtendedDocumentHandler , XEntityResolver , XErrorHandler >
146 TestDocumentHandler(
const char* locale,
const char* outFile )
150 , of(outFile, locale)
154 virtual ~TestDocumentHandler( )
override
162 virtual void SAL_CALL error(
const Any& aSAXParseException)
override
165 printf(
"Error !\n" );
167 "error from error handler",
168 Reference < XInterface >() ,
169 aSAXParseException );
171 virtual void SAL_CALL fatalError(
const Any& )
override
174 printf(
"Fatal Error !\n" );
176 virtual void SAL_CALL warning(
const Any& )
override
178 printf(
"Warning !\n" );
185 std::stack<LocaleNode *> currentNode ;
188 virtual void SAL_CALL startDocument()
override
190 printf(
"parsing document %s started\n", theLocale.c_str());
191 of.writeAsciiString(
"#include <sal/types.h>\n\n\n");
192 of.writeAsciiString(
"#include <rtl/ustring.hxx>\n\n\n");
193 of.writeAsciiString(
"#include <stdio.h>\n\n");
194 of.writeAsciiString(
"extern \"C\" {\n\n");
197 virtual void SAL_CALL endDocument()
override
205 printf(
"Error: in data for %s: %d\n", theLocale.c_str(), err);
212 printf(
"Error: no data for %s\n", theLocale.c_str());
214 printf(
"parsing document %s finished\n", theLocale.c_str());
216 of.writeAsciiString(
"} // extern \"C\"\n\n");
220 virtual void SAL_CALL startElement(
const OUString& aName,
221 const Reference< XAttributeList > & xAttribs)
override
225 if (!currentNode.empty() ) {
231 currentNode.push (l);
235 virtual void SAL_CALL endElement(
const OUString& )
override
240 virtual void SAL_CALL characters(
const OUString& aChars)
override
247 virtual void SAL_CALL ignorableWhitespace(
const OUString& )
override
251 virtual void SAL_CALL processingInstruction(
const OUString& ,
const OUString& )
override
256 virtual void SAL_CALL setDocumentLocator(
const Reference< XLocator> & )
override
261 virtual InputSource SAL_CALL resolveEntity(
262 const OUString& sPublicId,
263 const OUString& sSystemId)
override
266 source.sSystemId = sSystemId;
267 source.sPublicId = sPublicId;
275 virtual void SAL_CALL startCDATA()
override
278 virtual void SAL_CALL endCDATA()
override
281 virtual void SAL_CALL comment(
const OUString& )
override
284 virtual void SAL_CALL
unknown(
const OUString& )
override
288 virtual void SAL_CALL allowLineBreak()
override
295 std::string theLocale;
305 printf(
"usage : %s <locale> <XML inputfile> <destination file>\n", argv[0] );
309 Reference< XComponentContext > xContext(
316 Reference< XParser > rParser = Parser::create(xContext);
322 rParser->setDocumentHandler( pDocHandler );
323 rParser->setEntityResolver( pDocHandler );
328 source.sSystemId = OUString::createFromAscii( argv[2] );
331 rParser->parseStream( source );
333 nError = pDocHandler->nError;
334 css::uno::Reference<css::lang::XComponent>(
335 xContext, css::uno::UNO_QUERY_THROW)->dispose();
337 }
catch (css::uno::Exception & e) {
338 std::cerr <<
"ERROR: " << e.Message <<
'\n';
void addChild(LocaleNode *node)
static LocaleNode * createNode(const OUString &name, const Reference< XAttributeList > &attr)
void setValue(std::u16string_view oValue)
virtual void generateCode(const OFileWriter &of) const
constexpr OUStringLiteral aData
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
static Reference< XInputStream > createStreamFromFile(const char *pcFile)
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)