1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <testshl/simpleheader.hxx>
29 #include <odiapi/xxml/XXmlReader.hxx>
30 #include <odiapi/props/Properties.hxx>
31 #include <odiapi/sl/od_sl.hxx>
32 
33 #include "../odiapi/FileLoggerImpl.hxx"
34 #include "../odiapi/ExternalViewLogger.hxx"
35 
36 #include <osl/file.hxx>
37 #include <osl/thread.hxx>
38 
39 using namespace writerfilter;
40 using namespace osl;
41 using namespace rtl;
42 using namespace util;
43 
44 class MyHandler : public xxml::ContentHandler
45 {
46 public:
47 	virtual void startDocument()
48 	{
49 	}
50 	virtual void endDocument()
51 	{
52 	}
53 	virtual void startElement(QName_t name, QName_t attrName[], const xxml::Value *attrValue[], int attrs)
54 	{
55 		printf("<{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
56 		for(int i=0;i<attrs;i++)
57 		{
58 			printf("@{%s}:%s=\"%s\"\n", QName::serializer().getNamespaceUri(attrName[i]), QName::serializer().getLocalName(attrName[i]), attrValue[i]->getOString().getStr());
59 		}
60 	}
61 	virtual void endElement(QName_t name)
62 	{
63 		printf("</{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
64 	}
65 	virtual void characters(const xxml::Value &value)
66 	{
67 		printf("\"%s\"\n", value.getOString().getStr());
68 	}
69 
70 };
71 
72 OString getTempFileName(const OUString& fileName)
73 {
74   OUString ousTmpUrl;
75   FileBase::getTempDirURL(ousTmpUrl);
76   if (!ousTmpUrl.endsWithIgnoreAsciiCaseAsciiL("/", 1))
77 	ousTmpUrl += OUString::createFromAscii("/");
78   ousTmpUrl += fileName;
79 
80   OUString sysTmpPath;
81   FileBase::getSystemPathFromFileURL(ousTmpUrl, sysTmpPath);
82 
83   return OUStringToOString(sysTmpPath, osl_getThreadTextEncoding());
84 }
85 
86 class TestXXML : public CppUnit::TestFixture
87 {
88 public:
89 	void test()
90 	{
91 		odiapi::props::PropertyPool::Pointer_t propertyPool=odiapi::props::createPropertyPool();
92 		std::auto_ptr<ODSLHandler> handler=ODSLHandler::createODSLHandler(propertyPool);
93 		std::auto_ptr<xxml::XXmlReader> reader=xxml::XXmlReader::createXXmlReader(*handler);
94 		reader->read("helloworld.odt.flat.xml");
95 
96 		OString tmpFileName = getTempFileName(OUString::createFromAscii("dumpSlPool_int.dot"));
97 		printf("Pool dump: %s\n", tmpFileName.getStr());
98 		FileLoggerImpl fl(tmpFileName.getStr());
99 		propertyPool->dump(&fl);
100 
101 		OString tmpFileName2 = getTempFileName(OUString::createFromAscii("dumpSlPool_ext.dot"));
102 		printf("Pool dump: %s\n", tmpFileName2.getStr());
103 		ExternalViewLoggerImpl evl(tmpFileName2.getStr());
104 		propertyPool->dump(&evl);
105 	}
106 
107 	CPPUNIT_TEST_SUITE(TestXXML);
108 	CPPUNIT_TEST(test);
109 
110 
111 	CPPUNIT_TEST_SUITE_END();
112 };
113 
114 //#####################################
115 // register test suites
116 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestXXML, "TestXXML");
117 
118 NOADDITIONAL;
119