1*e9cbe144SAndrew Rist /************************************************************** 2*e9cbe144SAndrew Rist * 3*e9cbe144SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e9cbe144SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e9cbe144SAndrew Rist * distributed with this work for additional information 6*e9cbe144SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e9cbe144SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e9cbe144SAndrew Rist * "License"); you may not use this file except in compliance 9*e9cbe144SAndrew Rist * with the License. You may obtain a copy of the License at 10*e9cbe144SAndrew Rist * 11*e9cbe144SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e9cbe144SAndrew Rist * 13*e9cbe144SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e9cbe144SAndrew Rist * software distributed under the License is distributed on an 15*e9cbe144SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e9cbe144SAndrew Rist * KIND, either express or implied. See the License for the 17*e9cbe144SAndrew Rist * specific language governing permissions and limitations 18*e9cbe144SAndrew Rist * under the License. 19*e9cbe144SAndrew Rist * 20*e9cbe144SAndrew Rist *************************************************************/ 21*e9cbe144SAndrew Rist 22*e9cbe144SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <processinginstruction.hxx> 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <string.h> 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 29cdf0e10cSrcweir 30cdf0e10cSrcweir 31cdf0e10cSrcweir namespace DOM 32cdf0e10cSrcweir { CProcessingInstruction(CDocument const & rDocument,::osl::Mutex const & rMutex,xmlNodePtr const pNode)33cdf0e10cSrcweir CProcessingInstruction::CProcessingInstruction( 34cdf0e10cSrcweir CDocument const& rDocument, ::osl::Mutex const& rMutex, 35cdf0e10cSrcweir xmlNodePtr const pNode) 36cdf0e10cSrcweir : CProcessingInstruction_Base(rDocument, rMutex, 37cdf0e10cSrcweir NodeType_PROCESSING_INSTRUCTION_NODE, pNode) 38cdf0e10cSrcweir { 39cdf0e10cSrcweir } 40cdf0e10cSrcweir saxify(const Reference<XDocumentHandler> & i_xHandler)41cdf0e10cSrcweir void CProcessingInstruction::saxify( 42cdf0e10cSrcweir const Reference< XDocumentHandler >& i_xHandler) { 43cdf0e10cSrcweir if (!i_xHandler.is()) throw RuntimeException(); 44cdf0e10cSrcweir Reference< XExtendedDocumentHandler > xExtended(i_xHandler, UNO_QUERY); 45cdf0e10cSrcweir if (xExtended.is()) { 46cdf0e10cSrcweir xExtended->processingInstruction(getTarget(), getData()); 47cdf0e10cSrcweir } 48cdf0e10cSrcweir } 49cdf0e10cSrcweir 50cdf0e10cSrcweir /** 51cdf0e10cSrcweir The content of this processing instruction. 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir OUString SAL_CALL getData()54cdf0e10cSrcweir CProcessingInstruction::getData() throw (RuntimeException) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir ::osl::MutexGuard const g(m_rMutex); 57cdf0e10cSrcweir 58cdf0e10cSrcweir if (0 == m_aNodePtr) { 59cdf0e10cSrcweir return ::rtl::OUString(); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir char const*const pContent( 63cdf0e10cSrcweir reinterpret_cast<char const*>(m_aNodePtr->content)); 64cdf0e10cSrcweir if (0 == pContent) { 65cdf0e10cSrcweir return ::rtl::OUString(); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir OUString const ret(pContent, strlen(pContent), RTL_TEXTENCODING_UTF8); 68cdf0e10cSrcweir return ret; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir /** 72cdf0e10cSrcweir The target of this processing instruction. 73cdf0e10cSrcweir */ 74cdf0e10cSrcweir OUString SAL_CALL getTarget()75cdf0e10cSrcweir CProcessingInstruction::getTarget() throw (RuntimeException) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir ::osl::MutexGuard const g(m_rMutex); 78cdf0e10cSrcweir 79cdf0e10cSrcweir if (0 == m_aNodePtr) { 80cdf0e10cSrcweir return ::rtl::OUString(); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir char const*const pName( 84cdf0e10cSrcweir reinterpret_cast<char const*>(m_aNodePtr->name)); 85cdf0e10cSrcweir if (0 == pName) { 86cdf0e10cSrcweir return ::rtl::OUString(); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir OUString const ret(pName, strlen(pName), RTL_TEXTENCODING_UTF8); 89cdf0e10cSrcweir return ret; 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir /** 93cdf0e10cSrcweir The content of this processing instruction. 94cdf0e10cSrcweir */ setData(OUString const & rData)95cdf0e10cSrcweir void SAL_CALL CProcessingInstruction::setData(OUString const& rData) 96cdf0e10cSrcweir throw (RuntimeException, DOMException) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir ::osl::MutexGuard const g(m_rMutex); 99cdf0e10cSrcweir 100cdf0e10cSrcweir if (0 == m_aNodePtr) { 101cdf0e10cSrcweir throw RuntimeException(); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir OString const data( 105cdf0e10cSrcweir ::rtl::OUStringToOString(rData, RTL_TEXTENCODING_UTF8)); 106cdf0e10cSrcweir xmlChar const*const pData( 107cdf0e10cSrcweir reinterpret_cast<xmlChar const*>(data.getStr()) ); 108cdf0e10cSrcweir xmlFree(m_aNodePtr->content); 109cdf0e10cSrcweir m_aNodePtr->content = xmlStrdup(pData); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir OUString SAL_CALL getNodeName()113cdf0e10cSrcweir CProcessingInstruction::getNodeName() throw (RuntimeException) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir ::osl::MutexGuard const g(m_rMutex); 116cdf0e10cSrcweir 117cdf0e10cSrcweir if (0 == m_aNodePtr) { 118cdf0e10cSrcweir return ::rtl::OUString(); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir sal_Char const*const pName = 122cdf0e10cSrcweir reinterpret_cast<sal_Char const*>(m_aNodePtr->name); 123cdf0e10cSrcweir OUString const ret(pName, strlen(pName), RTL_TEXTENCODING_UTF8); 124cdf0e10cSrcweir return ret; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir getNodeValue()127cdf0e10cSrcweir OUString SAL_CALL CProcessingInstruction::getNodeValue() 128cdf0e10cSrcweir throw (RuntimeException) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir return getData(); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir void SAL_CALL setNodeValue(OUString const & rNodeValue)134cdf0e10cSrcweir CProcessingInstruction::setNodeValue(OUString const& rNodeValue) 135cdf0e10cSrcweir throw (RuntimeException, DOMException) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir return setData(rNodeValue); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140