xref: /trunk/main/xmloff/source/script/XMLStarBasicContextFactory.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLStarBasicContextFactory.hxx"
31 #include <xmloff/XMLEventsImportContext.hxx>
32 #include <tools/debug.hxx>
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include "xmloff/xmlnmspe.hxx"
36 #include <xmloff/xmltoken.hxx>
37 
38 
39 using namespace ::xmloff::token;
40 
41 using ::rtl::OUString;
42 using ::com::sun::star::xml::sax::XAttributeList;
43 using ::com::sun::star::beans::PropertyValue;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::Any;
47 
48 
49 XMLStarBasicContextFactory::XMLStarBasicContextFactory() :
50     sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
51     sLibrary(RTL_CONSTASCII_USTRINGPARAM("Library")),
52     sMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName")),
53     sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic"))
54 {
55 }
56 
57 XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
58 {
59 }
60 
61 SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
62     SvXMLImport& rImport,
63     sal_uInt16 p_nPrefix,
64     const OUString& rLocalName,
65     const Reference<XAttributeList> & xAttrList,
66     XMLEventsImportContext* rEvents,
67     const OUString& rApiEventName,
68     const OUString& /*rApiLanguage*/)
69 {
70     OUString sLibraryVal;
71     OUString sMacroNameVal;
72 
73     sal_Int16 nCount = xAttrList->getLength();
74     for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
75     {
76         OUString sLocalName;
77         sal_uInt16 nPrefix = rImport.GetNamespaceMap().
78             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), &sLocalName );
79 
80         if (XML_NAMESPACE_SCRIPT == nPrefix)
81         {
82 //          if (IsXMLToken(sLocalName, XML_LIBRARY))
83 //          {
84 //              sLibraryVal = xAttrList->getValueByIndex(nAttr);
85 //          }
86 //          if (IsXMLToken(sLocalName, XML_LOCATION))
87 //          {
88 //              sLibraryVal = xAttrList->getValueByIndex(nAttr);
89 //                if ( IsXMLToken( sLibraryVal, XML_APPLICATION ) )
90 //                    sLibraryVal =
91 //                        OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
92 //          }
93 //          else
94             if (IsXMLToken(sLocalName, XML_MACRO_NAME))
95             {
96                 sMacroNameVal = xAttrList->getValueByIndex(nAttr);
97             }
98             // else: ingore
99         }
100         // else: ignore
101     }
102 
103     const OUString& rApp = GetXMLToken( XML_APPLICATION );
104     const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
105     if( sMacroNameVal.getLength() > rApp.getLength()+1 &&
106         sMacroNameVal.copy(0,rApp.getLength()).equalsIgnoreAsciiCase( rApp ) &&
107         ':' == sMacroNameVal[rApp.getLength()] )
108     {
109         sLibraryVal = OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice"));
110         sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
111     }
112     else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
113         sMacroNameVal.copy(0,rDoc.getLength()).equalsIgnoreAsciiCase( rDoc ) &&
114         ':' == sMacroNameVal[rDoc.getLength()] )
115     {
116         sLibraryVal = rDoc;
117         sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
118     }
119 
120     Sequence<PropertyValue> aValues(3);
121 
122     // EventType
123     aValues[0].Name = sEventType;
124     aValues[0].Value <<= sStarBasic;
125 
126     // library name
127     aValues[1].Name = sLibrary;
128     aValues[1].Value <<= sLibraryVal;
129 
130     // macro name
131     aValues[2].Name = sMacroName;
132     aValues[2].Value <<= sMacroNameVal;
133 
134     // add values for event now
135     rEvents->AddEventValues(rApiEventName, aValues);
136 
137     // return dummy context
138     return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
139 }
140