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_scripting.hxx"
30 
31 #include "ScriptElement.hxx"
32 #include <util/util.hxx>
33 
34 using namespace ::rtl;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 
38 typedef ::std::vector < ::std::pair < ::rtl::OUString, bool > >  dependencies_vec;
39 typedef ::std::vector < ::std::pair < ::rtl::OUString, ::rtl::OUString > > deliveries_vec;
40 
41 namespace scripting_impl
42 {
43 
44 //*************************************************************************
45 /**
46     Construct a ScriptElement from a ScriptData object
47 
48     @param sII
49     the ScriptDataObject
50 */
51 ScriptElement::ScriptElement( ScriptData & sII ) :
52         XMLElement( OUSTR( "parcel" ) ),
53         m_sII( sII )
54 {
55     OSL_TRACE( "ScriptElement ctor called\n" );
56 
57     addAttribute( OUSTR( "language" ), sII.language );
58     addAttribute( OUSTR( "xmlns:parcel" ), OUSTR( "scripting.dtd" ) );
59     XMLElement* xScriptElt = new XMLElement( OUSTR( "script" ) );
60     xScriptElt->addAttribute( OUSTR( "language" ), sII.language );
61     Reference < xml::sax::XAttributeList > xal( xScriptElt );
62     addSubElement( xal );
63 
64     strpair_map::const_iterator mp_it = sII.locales.begin();
65     strpair_map::const_iterator mp_itend = sII.locales.end();
66 
67     for( ; mp_it != mp_itend; ++mp_it )
68     {
69         XMLElement* xel = new XMLElement( OUSTR( "locale" ) );
70         xel->addAttribute( OUSTR( "lang" ), mp_it->first );
71 
72         {
73             XMLElement* subxel = new XMLElement( OUSTR( "displayname" ) );
74             subxel->addAttribute( OUSTR( "value" ), mp_it->second.first );
75             Reference < xml::sax::XAttributeList > subxattl( subxel );
76             xel->addSubElement( subxattl );
77         }
78         {
79             XMLElement* subxel = new XMLElement( OUSTR( "description" ),
80                                      mp_it->second.second );
81             Reference< xml::sax::XAttributeList > subxattl( subxel );
82             xel->addSubElement( subxattl );
83         }
84 
85         Reference < xml::sax::XAttributeList > xal( xel );
86         xScriptElt->addSubElement( xal );
87     }
88 
89     {
90         XMLElement* xel = new XMLElement( OUSTR( "functionname" ) );
91         xel->addAttribute( OUSTR( "value" ), sII.functionname );
92         Reference < xml::sax::XAttributeList > xal( xel );
93         xScriptElt->addSubElement( xal );
94     }
95 
96     {
97         XMLElement* xel = new XMLElement( OUSTR( "logicalname" ) );
98         xel->addAttribute( OUSTR( "value" ), sII.logicalname );
99         Reference < xml::sax::XAttributeList > xal( xel );
100         xScriptElt->addSubElement( xal );
101     }
102 
103     props_vec::const_iterator vp_it = sII.languagedepprops.begin();
104     props_vec::const_iterator vp_itend = sII.languagedepprops.end();
105 
106     if ( vp_it != vp_itend )
107     {
108         XMLElement* xel = new XMLElement( OUSTR( "languagedepprops" ) );
109 
110         for( ; vp_it != vp_itend ; ++vp_it )
111         {
112             XMLElement* subxel =  new XMLElement( OUSTR( "prop" ) );
113             subxel->addAttribute( OUSTR( "name" ), vp_it->first );
114             subxel->addAttribute( OUSTR( "value" ), vp_it->second );
115             Reference < xml::sax::XAttributeList > subxattl( subxel );
116             xel->addSubElement( subxattl );
117         }
118 
119         Reference < xml::sax::XAttributeList > xal( xel );
120         xScriptElt->addSubElement( xal );
121     }
122 
123     filesets_map::const_iterator fm_it = sII.filesets.begin();
124     filesets_map::const_iterator fm_itend = sII.filesets.end();
125 
126     for( ; fm_it != fm_itend; ++fm_it )
127     {
128         XMLElement* xel = new XMLElement( OUSTR( "fileset" ) );
129         xel->addAttribute( OUSTR( "name" ), fm_it->first );
130 
131         vp_it = fm_it->second.first.begin();
132         vp_itend = fm_it->second.first.end();
133 
134         for( ; vp_it != vp_itend; ++vp_it )
135         {
136             XMLElement* subxel = new XMLElement( OUSTR( "prop" ) );
137             subxel->addAttribute( OUSTR( "name" ), vp_it->first );
138             subxel->addAttribute( OUSTR("value"), vp_it->second );
139             Reference < xml::sax::XAttributeList > subxattl( subxel );
140             xel->addSubElement( subxattl );
141        }
142 
143        strpairvec_map::const_iterator sm_it = fm_it->second.second.begin();
144        strpairvec_map::const_iterator sm_itend = fm_it->second.second.end();
145 
146        if( sm_it != sm_itend )
147        {
148            // was there a purpose for contstructing this
149            // XMLElement* subxel = new XMLElement( OUSTR( "file" ) );
150            xel->addAttribute( OUSTR( "name" ), sm_it->first );
151 
152        }
153     }
154 }
155 
156 //*************************************************************************
157 ScriptElement::~ScriptElement() SAL_THROW(())
158 {
159 }
160 
161 } // namespace scripting_impl
162