1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include "xmloff/xmlnmspe.hxx"
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmluconv.hxx>
31 #include "XMLTextFrameContext.hxx"
32 #include "XMLTextFrameHyperlinkContext.hxx"
33 
34 // OD 2004-04-21 #i26791#
35 #include <txtparaimphint.hxx>
36 
37 using ::rtl::OUString;
38 using ::rtl::OUStringBuffer;
39 
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::text;
42 using namespace ::com::sun::star::xml::sax;
43 using namespace ::com::sun::star::beans;
44 using namespace ::xmloff::token;
45 
46 TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext );
47 
XMLTextFrameHyperlinkContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<XAttributeList> & xAttrList,TextContentAnchorType eATyp)48 XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
49 		SvXMLImport& rImport,
50 		sal_uInt16 nPrfx, const OUString& rLName,
51 		const Reference< XAttributeList > & xAttrList,
52 		TextContentAnchorType eATyp ) :
53 	SvXMLImportContext( rImport, nPrfx, rLName ),
54 	eDefaultAnchorType( eATyp ),
55 	bMap( sal_False )
56 {
57 	OUString sShow;
58 	const SvXMLTokenMap& rTokenMap =
59 		GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
60 
61 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
62 	for( sal_Int16 i=0; i < nAttrCount; i++ )
63 	{
64 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
65 		const OUString& rValue = xAttrList->getValueByIndex( i );
66 
67 		OUString aLocalName;
68 		sal_uInt16 nPrefix =
69 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
70 															&aLocalName );
71 		switch( rTokenMap.Get( nPrefix, aLocalName ) )
72 		{
73 		case XML_TOK_TEXT_HYPERLINK_HREF:
74 			sHRef = GetImport().GetAbsoluteReference( rValue );
75 			break;
76 		case XML_TOK_TEXT_HYPERLINK_NAME:
77 			sName = rValue;
78 			break;
79 		case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
80 			sTargetFrameName = rValue;
81 			break;
82 		case XML_TOK_TEXT_HYPERLINK_SHOW:
83 			sShow = rValue;
84 			break;
85 		case XML_TOK_TEXT_HYPERLINK_SERVER_MAP:
86 			{
87 				sal_Bool bTmp;
88 				if( rImport.GetMM100UnitConverter().convertBool( bTmp,
89 																  rValue ) )
90 				{
91 					bMap = bTmp;
92 				}
93 			}
94 			break;
95 		}
96 	}
97 
98 	if( sShow.getLength() && !sTargetFrameName.getLength() )
99 	{
100 		if( IsXMLToken( sShow, XML_NEW ) )
101 			sTargetFrameName =
102 					OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) );
103 		else if( IsXMLToken( sShow, XML_REPLACE ) )
104 			sTargetFrameName =
105 					OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) );
106 	}
107 }
108 
~XMLTextFrameHyperlinkContext()109 XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
110 {
111 }
112 
EndElement()113 void XMLTextFrameHyperlinkContext::EndElement()
114 {
115 }
116 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)117 SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext(
118 		sal_uInt16 nPrefix,
119 		const OUString& rLocalName,
120 		const Reference< XAttributeList > & xAttrList )
121 {
122 	SvXMLImportContext *pContext = 0;
123 	XMLTextFrameContext *pTextFrameContext = 0;
124 
125 	if( XML_NAMESPACE_DRAW == nPrefix )
126 	{
127 		if( IsXMLToken( rLocalName, XML_FRAME ) )
128 			pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
129 												rLocalName, xAttrList,
130 												eDefaultAnchorType );
131 	}
132 
133 	if( pTextFrameContext )
134 	{
135 		pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
136 		pContext = pTextFrameContext;
137 		xFrameContext = pContext;
138 	}
139 	else
140 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
141 
142 	return pContext;
143 }
144 
145 
GetAnchorType() const146 TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
147 {
148 	if( xFrameContext.Is() )
149 	{
150 		SvXMLImportContext *pContext = &xFrameContext;
151 		return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType();
152 	}
153 	else
154 		return eDefaultAnchorType;
155 
156 }
157 
GetTextContent() const158 Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
159 {
160 	Reference <XTextContent > xTxt;
161 	if( xFrameContext.Is() )
162 	{
163 		SvXMLImportContext *pContext = &xFrameContext;
164 		xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
165 	}
166 
167 	return xTxt;
168 }
169 
170 // --> OD 2004-08-24 #33242#
GetShape() const171 Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
172 {
173     Reference < drawing::XShape > xShape;
174     if( xFrameContext.Is() )
175     {
176         SvXMLImportContext *pContext = &xFrameContext;
177         xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
178     }
179 
180     return xShape;
181 }
182 // <--
183 
184 
185