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>
39 #include <rtl/ref.hxx>
43 using namespace ::
std;
44 using namespace ::
cppu;
55 class OInputStream :
public WeakImplHelper < XInputStream >
64 virtual sal_Int32 SAL_CALL readBytes(
Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
override
66 nBytesToRead = std::min(nBytesToRead, m_seq.getLength() -
nPos);
71 virtual sal_Int32 SAL_CALL readSomeBytes(
72 css::uno::Sequence< sal_Int8 >& aData,
73 sal_Int32 nMaxBytesToRead )
override
75 return readBytes( aData, nMaxBytesToRead );
77 virtual void SAL_CALL skipBytes( sal_Int32 )
override
81 virtual sal_Int32 SAL_CALL available( )
override
83 return m_seq.getLength() -
nPos;
85 virtual void SAL_CALL closeInput( )
override
90 Sequence< sal_Int8> m_seq;
100 Reference< XInputStream > r;
102 FILE *
f = fopen( pcFile ,
"rb" );
106 fprintf(stderr,
"failure opening %s\n", pcFile);
110 if (fseek( f , 0 , SEEK_END ) == -1)
112 fprintf(stderr,
"failure fseeking %s\n", pcFile);
120 fprintf(stderr,
"failure ftelling %s\n", pcFile);
125 if (fseek( f , 0 , SEEK_SET ) == -1)
127 fprintf(stderr,
"failure fseeking %s\n", pcFile);
132 Sequence<sal_Int8> seqIn(nLength);
133 if (fread( seqIn.getArray(), nLength , 1 , f ) == 1)
134 r.set(
new OInputStream( seqIn ) );
136 fprintf(stderr,
"failure reading %s\n", pcFile);
143 class TestDocumentHandler :
144 public WeakImplHelper< XExtendedDocumentHandler , XEntityResolver , XErrorHandler >
147 TestDocumentHandler(
const char* locale,
const char* outFile )
151 , of(outFile, locale)
155 virtual ~TestDocumentHandler( )
override
163 virtual void SAL_CALL error(
const Any& aSAXParseException)
override
166 printf(
"Error !\n" );
168 "error from error handler",
169 Reference < XInterface >() ,
170 aSAXParseException );
172 virtual void SAL_CALL fatalError(
const Any& )
override
175 printf(
"Fatal Error !\n" );
177 virtual void SAL_CALL warning(
const Any& )
override
179 printf(
"Warning !\n" );
186 stack<LocaleNode *> currentNode ;
189 virtual void SAL_CALL startDocument()
override
191 printf(
"parsing document %s started\n", theLocale.c_str());
192 of.writeAsciiString(
"#include <sal/types.h>\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] );
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';
static LocaleNode * createNode(const OUString &name, const Reference< XAttributeList > &attr)
void addChild(LocaleNode *node)
void setValue(std::u16string_view oValue)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
static Reference< XInputStream > createStreamFromFile(const char *pcFile)
virtual void generateCode(const OFileWriter &of) const
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
void(* f)(TrueTypeTable *)