/* Crossmark importer/exporter * Copyright (C) 2006 Marc Maurer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include "ie_exp_Crossmark.h" #include "ie_impexp_Crossmark.h" IE_Exp_Crossmark_Sniffer::IE_Exp_Crossmark_Sniffer() : IE_ExpSniffer(0 /* TODO: use the correct mimetype */) { } IE_Exp_Crossmark_Sniffer::~IE_Exp_Crossmark_Sniffer() { } bool IE_Exp_Crossmark_Sniffer::recognizeSuffix (const char * szSuffix) { // not sure what the official Crossmark suffix is return !g_ascii_strcasecmp(szSuffix,".txt"); } UT_Error IE_Exp_Crossmark_Sniffer::constructExporter (PD_Document * pDocument, IE_Exp ** ppie) { IE_Exp_Crossmark * p = new IE_Exp_Crossmark(pDocument); *ppie = p; return UT_OK; } bool IE_Exp_Crossmark_Sniffer::getDlgLabels (const char ** pszDesc, const char ** pszSuffixList, IEFileType * ft) { *pszDesc = "Crossmark (.txt)"; *pszSuffixList = "*.txt"; *ft = getFileType(); return true; } /****************************************************************************/ /****************************************************************************/ IE_Exp_Crossmark::IE_Exp_Crossmark(PD_Document * pDocument) : IE_Exp (pDocument), m_pListener(0) { } IE_Exp_Crossmark::~IE_Exp_Crossmark() { } UT_Error IE_Exp_Crossmark::_writeDocument(void) { UT_DEBUGMSG(("Crossmark Exporter: _writeDocument\n")); m_pListener = _constructListener(); if (!m_pListener) return UT_IE_NOMEMORY; if (getDocRange()) getDoc()->tellListenerSubset(static_cast(m_pListener),getDocRange()); else getDoc()->tellListener(static_cast(m_pListener)); DELETEP(m_pListener); return ((m_error) ? UT_IE_COULDNOTWRITE : UT_OK); } PL_Listener * IE_Exp_Crossmark::_constructListener(void) { UT_DEBUGMSG(("Crossmark Exporter: _constructListener\n")); return new Crossmark_Listener(getDoc(), this); } /****************************************************************************/ /****************************************************************************/ Crossmark_Listener::Crossmark_Listener(PD_Document * pDocument, IE_Exp_Crossmark * pie) : m_pDocument(pDocument), m_pie(pie) { } Crossmark_Listener::~Crossmark_Listener() { } void Crossmark_Listener::_outputData(const UT_UCSChar * data, UT_uint32 length) { UT_ByteBuf bBuf; const UT_UCSChar * pData; int mbLen; char pC[MY_MB_LEN_MAX]; m_wctomb.setOutCharset("UTF-8"); // this is not specified yet in the crossmark spec; for now, we always use UTF-8 for (pData=data; (pData=1); bBuf.append(reinterpret_cast(pC),mbLen); } } m_pie->write(reinterpret_cast(bBuf.getPointer(0)), bBuf.getLength()); } bool Crossmark_Listener::populate(PL_StruxFmtHandle sfh, const PX_ChangeRecord * pcr) { switch (pcr -> getType ()) { case PX_ChangeRecord :: PXT_InsertSpan: { const PX_ChangeRecord_Span * pcrs = static_cast (pcr); PT_BufIndex bi = pcrs->getBufIndex(); const UT_UCS4Char * pData = m_pDocument->getPointer(bi); _outputData(pData, pcrs->getLength()); return true; } case PX_ChangeRecord::PXT_InsertObject: { const PX_ChangeRecord_Object * pcro = static_cast (pcr); PT_AttrPropIndex api = pcr->getIndexAP(); switch (pcro->getObjectType()) { default: UT_ASSERT_HARMLESS(UT_TODO); return true; } return true; } default: return true; } return true; } bool Crossmark_Listener::populateStrux(PL_StruxDocHandle sdh, const PX_ChangeRecord * pcr, PL_StruxFmtHandle * psfh) { return true; } bool Crossmark_Listener::change(PL_StruxFmtHandle sfh, const PX_ChangeRecord * pcr) { return true; } bool Crossmark_Listener::insertStrux(PL_StruxFmtHandle sfh, const PX_ChangeRecord * pcr, PL_StruxDocHandle sdh, PL_ListenerId lid, void (* pfnBindHandles)(PL_StruxDocHandle sdhNew, PL_ListenerId lid, PL_StruxFmtHandle sfhNew)) { return true; } bool Crossmark_Listener::signal(UT_uint32 iSignal) { return true; }