Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLSymbolImageContext.hxx"
30 : : #include <xmloff/xmltoken.hxx>
31 : : #include <xmloff/xmltkmap.hxx>
32 : : #include "xmloff/xmlnmspe.hxx"
33 : : #include <xmloff/xmlimp.hxx>
34 : : #include <xmloff/nmspmap.hxx>
35 : : #include <xmloff/XMLBase64ImportContext.hxx>
36 : : #include <com/sun/star/io/XOutputStream.hpp>
37 : :
38 [ # # ][ # # ]: 0 : TYPEINIT1( XMLSymbolImageContext, XMLElementPropertyContext );
39 : :
40 : : using namespace ::com::sun::star;
41 : :
42 : : enum SvXMLTokenMapAttrs
43 : : {
44 : : XML_TOK_SYMBOL_IMAGE_HREF,
45 : : XML_TOK_SYMBOL_IMAGE_TYPE,
46 : : XML_TOK_SYMBOL_IMAGE_ACTUATE,
47 : : XML_TOK_SYMBOL_IMAGE_SHOW,
48 : : XML_TOK_SYMBOL_IMAGE_END = XML_TOK_UNKNOWN
49 : : };
50 : :
51 : : static SvXMLTokenMapEntry aSymbolImageAttrTokenMap[] =
52 : : {
53 : : { XML_NAMESPACE_XLINK, ::xmloff::token::XML_HREF, XML_TOK_SYMBOL_IMAGE_HREF },
54 : : { XML_NAMESPACE_XLINK, ::xmloff::token::XML_TYPE, XML_TOK_SYMBOL_IMAGE_TYPE },
55 : : { XML_NAMESPACE_XLINK, ::xmloff::token::XML_ACTUATE, XML_TOK_SYMBOL_IMAGE_ACTUATE },
56 : : { XML_NAMESPACE_XLINK, ::xmloff::token::XML_SHOW, XML_TOK_SYMBOL_IMAGE_SHOW },
57 : : XML_TOKEN_MAP_END
58 : : };
59 : :
60 : 0 : XMLSymbolImageContext::XMLSymbolImageContext(
61 : : SvXMLImport& rImport, sal_uInt16 nPrfx,
62 : : const ::rtl::OUString& rLName,
63 : : const XMLPropertyState& rProp,
64 : : ::std::vector< XMLPropertyState > &rProps ) :
65 : : XMLElementPropertyContext(
66 : 0 : rImport, nPrfx, rLName, rProp, rProps )
67 : : {
68 : 0 : }
69 : :
70 : 0 : XMLSymbolImageContext::~XMLSymbolImageContext()
71 [ # # ]: 0 : {}
72 : :
73 : 0 : void XMLSymbolImageContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
74 : : {
75 [ # # ]: 0 : SvXMLTokenMap aTokenMap( aSymbolImageAttrTokenMap );
76 : 0 : ::rtl::OUString aLocalName;
77 : :
78 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ # # ]
79 [ # # ]: 0 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
80 : : {
81 [ # # ][ # # ]: 0 : const ::rtl::OUString& rAttrName = xAttrList->getNameByIndex( i );
82 : : sal_uInt16 nPrefix =
83 : 0 : GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
84 [ # # ]: 0 : &aLocalName );
85 [ # # ][ # # ]: 0 : const ::rtl::OUString& rValue = xAttrList->getValueByIndex( i );
86 : :
87 [ # # ]: 0 : switch( aTokenMap.Get( nPrefix, aLocalName ) )
[ # # # ]
88 : : {
89 : : case XML_TOK_SYMBOL_IMAGE_HREF:
90 : 0 : msURL = rValue;
91 : 0 : break;
92 : : case XML_TOK_SYMBOL_IMAGE_ACTUATE:
93 : : case XML_TOK_SYMBOL_IMAGE_TYPE:
94 : : case XML_TOK_SYMBOL_IMAGE_SHOW:
95 : : // these values are currently not interpreted
96 : : // it is always assumed 'actuate=onLoad', 'type=simple', 'show=embed'
97 : 0 : break;
98 : : }
99 [ # # ]: 0 : }
100 : 0 : }
101 : :
102 : 0 : SvXMLImportContext* XMLSymbolImageContext::CreateChildContext(
103 : : sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
104 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
105 : : {
106 : 0 : SvXMLImportContext* pContext = NULL;
107 [ # # ]: 0 : if( xmloff::token::IsXMLToken( rLocalName,
108 : 0 : xmloff::token::XML_BINARY_DATA ) )
109 : : {
110 [ # # ][ # # ]: 0 : if( msURL.isEmpty() && ! mxBase64Stream.is() )
[ # # ]
111 : : {
112 [ # # ]: 0 : mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
113 [ # # ]: 0 : if( mxBase64Stream.is() )
114 : 0 : pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
115 : : rLocalName, xAttrList,
116 [ # # ]: 0 : mxBase64Stream );
117 : : }
118 : : }
119 [ # # ]: 0 : if( ! pContext )
120 : : {
121 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
122 : : }
123 : :
124 : 0 : return pContext;
125 : : }
126 : :
127 : 0 : void XMLSymbolImageContext::EndElement()
128 : : {
129 : 0 : ::rtl::OUString sResolvedURL;
130 : :
131 [ # # ]: 0 : if( !msURL.isEmpty() )
132 : : {
133 [ # # ]: 0 : sResolvedURL = GetImport().ResolveGraphicObjectURL( msURL, sal_False );
134 : : }
135 [ # # ]: 0 : else if( mxBase64Stream.is() )
136 : : {
137 [ # # ]: 0 : sResolvedURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
138 [ # # ]: 0 : mxBase64Stream = 0;
139 : : }
140 : :
141 [ # # ]: 0 : if( !sResolvedURL.isEmpty())
142 : : {
143 : : // aProp is a member of XMLElementPropertyContext
144 [ # # ]: 0 : aProp.maValue <<= sResolvedURL;
145 : 0 : SetInsert( sal_True );
146 : : }
147 : :
148 [ # # ]: 0 : XMLElementPropertyContext::EndElement();
149 : 0 : }
150 : :
151 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|