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/XModel2.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 com::sun::star::uno::Reference;
42 : using com::sun::star::uno::makeAny;
43 : using com::sun::star::uno::UNO_QUERY;
44 : using com::sun::star::uno::Sequence;
45 : using com::sun::star::xforms::XModel2;
46 : using com::sun::star::beans::XPropertySet;
47 : using com::sun::star::beans::PropertyValue;
48 : using com::sun::star::xml::sax::XAttributeList;
49 :
50 : using xmloff::token::IsXMLToken;
51 : using xmloff::token::XML_INSTANCE;
52 : using xmloff::token::XML_SRC;
53 : using xmloff::token::XML_ID;
54 :
55 : static const SvXMLTokenMapEntry aAttributes[] =
56 : {
57 : TOKEN_MAP_ENTRY( NONE, SRC ),
58 : TOKEN_MAP_ENTRY( NONE, ID ),
59 : XML_TOKEN_MAP_END
60 : };
61 :
62 0 : XFormsInstanceContext::XFormsInstanceContext(
63 : SvXMLImport& rImport,
64 : sal_uInt16 nPrefix,
65 : const OUString& rLocalName,
66 : const Reference<XModel2> & xModel ) :
67 : TokenContext( rImport, nPrefix, rLocalName, aAttributes, aEmptyMap ),
68 0 : mxModel( xModel )
69 : {
70 : DBG_ASSERT( mxModel.is(), "need model" );
71 0 : }
72 :
73 0 : XFormsInstanceContext::~XFormsInstanceContext()
74 : {
75 0 : }
76 :
77 0 : SvXMLImportContext* XFormsInstanceContext::CreateChildContext(
78 : sal_uInt16 nPrefix,
79 : const OUString& rLocalName,
80 : const Reference<XAttributeList>& )
81 : {
82 0 : SvXMLImportContext* pContext = NULL;
83 :
84 : // only the first element child of an xforms:instance element
85 : // is used as an instance. The other children remainder must be
86 : // ignored.
87 0 : if( mxInstance.is() )
88 : {
89 0 : GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rLocalName );
90 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
91 : }
92 : else
93 : {
94 : // create new DomBuilderContext. Save reference to tree in Model.
95 : DomBuilderContext* pInstance =
96 0 : new DomBuilderContext( GetImport(), nPrefix, rLocalName );
97 0 : mxInstance = pInstance->getTree();
98 0 : pContext = pInstance;
99 : }
100 :
101 : DBG_ASSERT( pContext != NULL, "no context!" );
102 0 : return pContext;
103 :
104 : }
105 :
106 0 : void XFormsInstanceContext::EndElement()
107 : {
108 0 : Sequence<PropertyValue> aSequence( 3 );
109 0 : PropertyValue* pSequence = aSequence.getArray();
110 0 : pSequence[0].Name = "Instance";
111 0 : pSequence[0].Value <<= mxInstance;
112 0 : pSequence[1].Name = "ID";
113 0 : pSequence[1].Value <<= msId;
114 0 : pSequence[2].Name = "URL";
115 0 : pSequence[2].Value <<= msURL;
116 :
117 0 : mxModel->getInstances()->insert( makeAny( aSequence ) );
118 0 : }
119 :
120 :
121 0 : void XFormsInstanceContext::HandleAttribute(
122 : sal_uInt16 nToken,
123 : const OUString& rValue )
124 : {
125 0 : switch( nToken )
126 : {
127 : case XML_SRC:
128 0 : msURL = rValue;
129 0 : break;
130 : case XML_ID:
131 0 : msId = rValue;
132 0 : break;
133 : default:
134 : OSL_FAIL( "should not happen" );
135 0 : break;
136 : }
137 0 : }
138 :
139 0 : SvXMLImportContext* XFormsInstanceContext::HandleChild(
140 : sal_uInt16,
141 : sal_uInt16,
142 : const OUString&,
143 : const Reference<XAttributeList>& )
144 : {
145 : OSL_FAIL( "to be handled by CreateChildContext" );
146 0 : return NULL;
147 : }
148 :
149 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|