1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <testshl/simpleheader.hxx>
25 #include <odiapi/xxml/XXmlReader.hxx>
26 #include <odiapi/props/Properties.hxx>
27 #include <odiapi/sl/od_sl.hxx>
28 
29 #include "../odiapi/FileLoggerImpl.hxx"
30 #include "../odiapi/ExternalViewLogger.hxx"
31 
32 #include <osl/file.hxx>
33 #include <osl/thread.hxx>
34 
35 using namespace writerfilter;
36 using namespace osl;
37 using namespace rtl;
38 using namespace util;
39 
40 class MyHandler : public xxml::ContentHandler
41 {
42 public:
startDocument()43 	virtual void startDocument()
44 	{
45 	}
endDocument()46 	virtual void endDocument()
47 	{
48 	}
startElement(QName_t name,QName_t attrName[],const xxml::Value * attrValue[],int attrs)49 	virtual void startElement(QName_t name, QName_t attrName[], const xxml::Value *attrValue[], int attrs)
50 	{
51 		printf("<{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
52 		for(int i=0;i<attrs;i++)
53 		{
54 			printf("@{%s}:%s=\"%s\"\n", QName::serializer().getNamespaceUri(attrName[i]), QName::serializer().getLocalName(attrName[i]), attrValue[i]->getOString().getStr());
55 		}
56 	}
endElement(QName_t name)57 	virtual void endElement(QName_t name)
58 	{
59 		printf("</{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
60 	}
characters(const xxml::Value & value)61 	virtual void characters(const xxml::Value &value)
62 	{
63 		printf("\"%s\"\n", value.getOString().getStr());
64 	}
65 
66 };
67 
getTempFileName(const OUString & fileName)68 OString getTempFileName(const OUString& fileName)
69 {
70   OUString ousTmpUrl;
71   FileBase::getTempDirURL(ousTmpUrl);
72   if (!ousTmpUrl.endsWithIgnoreAsciiCaseAsciiL("/", 1))
73 	ousTmpUrl += OUString::createFromAscii("/");
74   ousTmpUrl += fileName;
75 
76   OUString sysTmpPath;
77   FileBase::getSystemPathFromFileURL(ousTmpUrl, sysTmpPath);
78 
79   return OUStringToOString(sysTmpPath, osl_getThreadTextEncoding());
80 }
81 
82 class TestXXML : public CppUnit::TestFixture
83 {
84 public:
test()85 	void test()
86 	{
87 		odiapi::props::PropertyPool::Pointer_t propertyPool=odiapi::props::createPropertyPool();
88 		std::auto_ptr<ODSLHandler> handler=ODSLHandler::createODSLHandler(propertyPool);
89 		std::auto_ptr<xxml::XXmlReader> reader=xxml::XXmlReader::createXXmlReader(*handler);
90 		reader->read("helloworld.odt.flat.xml");
91 
92 		OString tmpFileName = getTempFileName(OUString::createFromAscii("dumpSlPool_int.dot"));
93 		printf("Pool dump: %s\n", tmpFileName.getStr());
94 		FileLoggerImpl fl(tmpFileName.getStr());
95 		propertyPool->dump(&fl);
96 
97 		OString tmpFileName2 = getTempFileName(OUString::createFromAscii("dumpSlPool_ext.dot"));
98 		printf("Pool dump: %s\n", tmpFileName2.getStr());
99 		ExternalViewLoggerImpl evl(tmpFileName2.getStr());
100 		propertyPool->dump(&evl);
101 	}
102 
103 	CPPUNIT_TEST_SUITE(TestXXML);
104 	CPPUNIT_TEST(test);
105 
106 
107 	CPPUNIT_TEST_SUITE_END();
108 };
109 
110 //#####################################
111 // register test suites
112 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestXXML, "TestXXML");
113 
114 NOADDITIONAL;
115