Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "XFormsInstanceContext.hxx"
22 :
23 : #include "DomBuilderContext.hxx"
24 : #include "xformsapi.hxx"
25 :
26 : #include <rtl/ustring.hxx>
27 : #include <com/sun/star/uno/Reference.hxx>
28 : #include <com/sun/star/beans/XPropertySet.hpp>
29 : #include <com/sun/star/beans/PropertyValue.hpp>
30 : #include <com/sun/star/xml/dom/XDocument.hpp>
31 : #include <com/sun/star/xforms/XModel.hpp>
32 : #include <tools/debug.hxx>
33 :
34 : #include <xmloff/xmlnmspe.hxx>
35 : #include <xmloff/xmltoken.hxx>
36 : #include <xmloff/xmlimp.hxx>
37 : #include <xmloff/xmlerror.hxx>
38 : #include <xmloff/nmspmap.hxx>
39 :
40 :
41 : using rtl::OUString;
42 : using com::sun::star::uno::Reference;
43 : using com::sun::star::uno::makeAny;
44 : using com::sun::star::uno::UNO_QUERY;
45 : using com::sun::star::uno::Sequence;
46 : using com::sun::star::xforms::XModel;
47 : using com::sun::star::beans::XPropertySet;
48 : using com::sun::star::beans::PropertyValue;
49 : using com::sun::star::xml::sax::XAttributeList;
50 :
51 : using xmloff::token::IsXMLToken;
52 : using xmloff::token::XML_INSTANCE;
53 : using xmloff::token::XML_SRC;
54 : using xmloff::token::XML_ID;
55 :
56 : static SvXMLTokenMapEntry aAttributes[] =
57 : {
58 : TOKEN_MAP_ENTRY( NONE, SRC ),
59 : TOKEN_MAP_ENTRY( NONE, ID ),
60 : XML_TOKEN_MAP_END
61 : };
62 :
63 0 : XFormsInstanceContext::XFormsInstanceContext(
64 : SvXMLImport& rImport,
65 : sal_uInt16 nPrefix,
66 : const OUString& rLocalName,
67 : Reference<XPropertySet> xModel ) :
68 : TokenContext( rImport, nPrefix, rLocalName, aAttributes, aEmptyMap ),
69 0 : mxModel( Reference<XModel>( xModel, UNO_QUERY ) )
70 : {
71 : DBG_ASSERT( mxModel.is(), "need model" );
72 0 : }
73 :
74 0 : XFormsInstanceContext::~XFormsInstanceContext()
75 : {
76 0 : }
77 :
78 0 : SvXMLImportContext* XFormsInstanceContext::CreateChildContext(
79 : sal_uInt16 nPrefix,
80 : const OUString& rLocalName,
81 : const Reference<XAttributeList>& )
82 : {
83 0 : SvXMLImportContext* pContext = NULL;
84 :
85 : // only the first element child of an xforms:instance element
86 : // is used as an instance. The other children remainder must be
87 : // ignored.
88 0 : if( mxInstance.is() )
89 : {
90 0 : GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rLocalName );
91 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
92 : }
93 : else
94 : {
95 : // create new DomBuilderContext. Save reference to tree in Model.
96 : DomBuilderContext* pInstance =
97 0 : new DomBuilderContext( GetImport(), nPrefix, rLocalName );
98 0 : mxInstance = pInstance->getTree();
99 0 : pContext = pInstance;
100 : }
101 :
102 : DBG_ASSERT( pContext != NULL, "no context!" );
103 0 : return pContext;
104 :
105 : }
106 :
107 0 : void XFormsInstanceContext::EndElement()
108 : {
109 0 : Sequence<PropertyValue> aSequence( 3 );
110 0 : PropertyValue* pSequence = aSequence.getArray();
111 0 : pSequence[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("Instance") );
112 0 : pSequence[0].Value <<= mxInstance;
113 0 : pSequence[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("ID") );
114 0 : pSequence[1].Value <<= msId;
115 0 : pSequence[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("URL") );
116 0 : pSequence[2].Value <<= msURL;
117 :
118 0 : mxModel->getInstances()->insert( makeAny( aSequence ) );
119 0 : }
120 :
121 :
122 0 : void XFormsInstanceContext::HandleAttribute(
123 : sal_uInt16 nToken,
124 : const rtl::OUString& rValue )
125 : {
126 0 : switch( nToken )
127 : {
128 : case XML_SRC:
129 0 : msURL = rValue;
130 0 : break;
131 : case XML_ID:
132 0 : msId = rValue;
133 0 : break;
134 : default:
135 : OSL_FAIL( "should not happen" );
136 0 : break;
137 : }
138 0 : }
139 :
140 0 : SvXMLImportContext* XFormsInstanceContext::HandleChild(
141 : sal_uInt16,
142 : sal_uInt16,
143 : const OUString&,
144 : const Reference<XAttributeList>& )
145 : {
146 : OSL_FAIL( "to be handled by CreateChildContext" );
147 0 : return NULL;
148 : }
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|