Index: src/wp/impexp/xp/Makefile.am =================================================================== --- src/wp/impexp/xp/Makefile.am (révision 35072) +++ src/wp/impexp/xp/Makefile.am (copie de travail) @@ -36,6 +36,8 @@ ie_exp_RTF_listenerWriteDoc.h \ ie_exp_Text.cpp \ ie_exp_Text.h \ + ie_exp_XML.cpp \ + ie_exp_XML.h \ ie_FileInfo.cpp \ ie_FileInfo.h \ ie_imp_AbiWord_1.cpp \ Index: src/wp/impexp/xp/ie_exp_AbiWord_1.cpp =================================================================== --- src/wp/impexp/xp/ie_exp_AbiWord_1.cpp (révision 35072) +++ src/wp/impexp/xp/ie_exp_AbiWord_1.cpp (copie de travail) @@ -32,10 +32,6 @@ #include "ut_string_class.h" #include "ut_uuid.h" -#ifdef ENABLE_RESOURCE_MANAGER -#include "xap_ResourceManager.h" -#endif - #include "xap_App.h" #include "pt_Types.h" @@ -114,7 +110,7 @@ /*****************************************************************/ IE_Exp_AbiWord_1::IE_Exp_AbiWord_1(PD_Document * pDocument, bool isTemplate, bool isCompressed) - : IE_Exp(pDocument), m_bIsTemplate(isTemplate), m_bIsCompressed(isCompressed), m_pListener(0), m_output(0) + : IE_Exp_XML(pDocument), m_bIsTemplate(isTemplate), m_bIsCompressed(isCompressed), m_pListener(0) { m_error = 0; @@ -131,57 +127,10 @@ { } -UT_uint32 IE_Exp_AbiWord_1::_writeBytes(const UT_Byte * pBytes, UT_uint32 length) -{ - if(!pBytes || !length) - return 0; - - if (m_output) - { - gsf_output_write(m_output, length, pBytes); - return length; - } - else - { - return IE_Exp::_writeBytes(pBytes, length); - } -} - -void IE_Exp_AbiWord_1::_setupFile() -{ - // allow people to override this on the command line or otherwise - const std::string & prop = (getProperty ("compress")); - if (!prop.empty()) - m_bIsCompressed = UT_parseBool(prop.c_str (), m_bIsCompressed); - - if (m_bIsCompressed) - { - GsfOutput * gzip = gsf_output_gzip_new(getFp (), NULL); - m_output = gzip; - } - else - { - m_output = 0; - } -} - -static void close_gsf_handle(GsfOutput * output) -{ - if (output) - { - gsf_output_close (output); - g_object_unref (G_OBJECT (output)); - } -} - /*****************************************************************/ /*****************************************************************/ -#ifdef ENABLE_RESOURCE_MANAGER -class ABI_EXPORT s_AbiWord_1_Listener : public PL_Listener, XAP_ResourceManager::Writer -#else class ABI_EXPORT s_AbiWord_1_Listener : public PL_Listener -#endif { public: s_AbiWord_1_Listener(PD_Document * pDocument, @@ -227,18 +176,17 @@ void _closeRDFAnchor(void); void _closeTag(void); void _openSpan(PT_AttrPropIndex apiSpan); - void _openTag(const char * szPrefix, const char * szSuffix, - bool bNewLineAfter, PT_AttrPropIndex api, - UT_uint32 iXID, + void _openTag(const char * szPrefix, bool bHasContent, + PT_AttrPropIndex api, UT_uint32 iXID, bool bIgnoreProperties = false); - void _outputData(const UT_UCSChar * p, UT_uint32 length); - void _outputXMLChar(const gchar * data, UT_uint32 length); - void _outputXMLChar(const std::string & s) + //void _outputData(const UT_UCSChar * p, UT_uint32 length); + //void _outputXMLChar(const gchar * data, UT_uint32 length); + /*void _outputXMLChar(const std::string & s) { _outputXMLChar(s.c_str(), s.size()); - } - void _outputXMLAttribute(const gchar * key, const gchar * value, UT_uint32 length); - void _outputXMLAttribute(const gchar * key, const std::string& value ); + }*/ + //void _outputXMLAttribute(const gchar * key, const gchar * value, UT_uint32 length); + //void _outputXMLAttribute(const gchar * key, const std::string& value ); void _handleStyles(void); void _handleLists(void); void _handlePageSize(void); @@ -278,7 +226,7 @@ if (!m_bInSection) return; - m_pie->write("\n"); + m_pie->endElement(); m_bInSection = false; return; } @@ -289,7 +237,7 @@ if (m_iInTable == 0) return; - m_pie->write("\n"); + m_pie->endElement(); m_iInTable--; return; } @@ -300,7 +248,7 @@ if (m_iInCell == 0) return; - m_pie->write("\n"); + m_pie->endElement(); m_iInCell--; return; } @@ -310,8 +258,10 @@ if (!m_bInBlock) return; - m_pie->write("

\n"); + m_pie->endElement(); m_bInBlock = false; + m_pie->setPrettyPrint(true); + m_pie->addString(NULL, "\n"); return; } @@ -327,7 +277,8 @@ void s_AbiWord_1_Listener::_closeTag(void) { - if (m_bOpenChar) m_pie->write(""); + if (m_bOpenChar) + m_pie->endElement(); m_bOpenChar = false; } @@ -336,7 +287,7 @@ if (!m_pCurrentField) return; _closeSpan(); - m_pie->write(""); + m_pie->endElement(); m_pCurrentField = NULL; return; } @@ -346,7 +297,7 @@ if (!m_bInHyperlink) return; _closeSpan(); - m_pie->write(""); + m_pie->endElement(); m_bInHyperlink = false; return; } @@ -358,7 +309,7 @@ return; UT_DEBUGMSG(("Doing close annotation object method \n")); _closeSpan(); - m_pie->write(""); + m_pie->endElement(); m_bInAnnotation = false; return; } @@ -367,7 +318,7 @@ { UT_DEBUGMSG(("Doing close rdf anchor object method \n")); _closeSpan(); - m_pie->write(""); + m_pie->endElement(); return; } @@ -383,133 +334,26 @@ if (!apiSpan) // don't write tag for empty A/P return; - _openTag("c","",false,apiSpan,0); + _openTag("c",true,apiSpan,0); m_bInSpan = true; m_apiLastSpan = apiSpan; return; } -void s_AbiWord_1_Listener::_openTag(const char * szPrefix, const char * szSuffix, - bool bNewLineAfter, PT_AttrPropIndex api, - UT_uint32 iXID, +void s_AbiWord_1_Listener::_openTag(const char * szPrefix, bool bHasContent, + PT_AttrPropIndex api, UT_uint32 iXID, bool bIgnoreProperties) { -#ifdef ENABLE_RESOURCE_MANAGER - UT_ASSERT_HARMLESS (!m_bOpenChar); - - UT_UTF8String tag("<"); - UT_UTF8String url; - UT_UTF8String esc; - - tag += szPrefix; - const PP_AttrProp * pAP = NULL; - bool bHaveProp = m_pDocument->getAttrProp (api, &pAP); - if (bHaveProp && pAP) - { - const gchar * szName = 0; - const gchar * szValue = 0; - - UT_uint32 k = 0; - while (pAP->getNthAttribute (k++, szName, szValue)) - { -#if 0 - // - // Strip out Author attributes for now. - // - if( !m_pDocument->isExportAuthorAtts() && strcmp(szName,PT_AUTHOR_NAME) == 0) - continue; -#endif - tag += " "; - tag += szName; - tag += "=\""; - - if ((strcmp (szName, "href") == 0) || (strcmp (szName, "xlink:href") == 0)) - { - if(*szValue == '/') - { - XAP_ResourceManager & RM = m_pDocument->resourceManager (); - XAP_ExternalResource * re = dynamic_cast(RM.resource (szValue, false)); - if (re) - { - url = re->URL (); - url.escapeURL(); - tag += url; - } - } - else - { - url = szValue; - url.escapeURL(); - tag += url; - } - } - else - { - esc = szValue; - esc.escapeXML(); - tag += esc; - } - - - tag += "\""; - } - - if(iXID != 0) - { - // insert xid attribute - tag += " "; - tag += PT_XID_ATTRIBUTE_NAME; - tag += "=\""; - UT_UTF8String s; - UT_UTF8String_sprintf(s, "%d\"", iXID); - tag += s; - } - - if (!bIgnoreProperties) - { - k = 0; - while (pAP->getNthProperty (k++, szName, szValue)) - { - if (k == 1) - { - tag += " "; - tag += PT_PROPS_ATTRIBUTE_NAME; - tag += "=\""; - } - else tag += "; "; - - tag += szName; - tag += ":"; - - esc = szValue; - esc.escapeXML(); - tag += esc; - } - if (k > 1) tag += "\""; - } - } - if (szSuffix) - if (*szSuffix == '/') - tag += "/"; - tag += ">"; - if (bNewLineAfter) tag += "\n"; - m_pie->write (tag.utf8_str (), tag.byteLength()); - - if (strcmp (szPrefix, "c") == 0) m_bOpenChar = true; - -#else /* ENABLE_RESOURCE_MANAGER */ - const PP_AttrProp * pAP = NULL; bool bHaveProp = m_pDocument->getAttrProp(api,&pAP); - xxx_UT_DEBUGMSG(("_openTag: api %d, bHaveProp %d\n",api, bHaveProp)); + xxx_UT_DEBUGMSG(("_openTag: api %d, bHaveProp %d\n", api, bHaveProp)); UT_return_if_fail(szPrefix && *szPrefix); - m_pie->write("<"); + m_pie->startElement(szPrefix); if(strcmp(szPrefix,"c")== 0) m_bOpenChar = true; - m_pie->write(szPrefix); if (bHaveProp && pAP) { UT_UTF8String url; @@ -529,41 +373,27 @@ if( !m_pDocument->isExportAuthorAtts() && strcmp(szName,PT_AUTHOR_NAME) == 0) continue; - m_pie->write(" "); - m_pie->write(static_cast(szName)); - m_pie->write("=\""); - if ((strcmp (szName, "href") == 0) || (strcmp (szName, "xlink:href") == 0)) { url = szValue; url.escapeURL(); - _outputXMLChar(url.utf8_str(), url.byteLength()); + m_pie->addString(szName, url.utf8_str()); } else { - _outputXMLChar(szValue, strlen(szValue)); + m_pie->addString(szName, szValue); } - m_pie->write("\""); } if(iXID != 0) { // insert xid attribute - m_pie->write(" "); - m_pie->write(PT_XID_ATTRIBUTE_NAME); - m_pie->write("=\""); - UT_String s; - UT_String_sprintf(s, "%d\"", iXID); - m_pie->write(s.c_str()); + m_pie->addInt("xid", iXID); } if (!bIgnoreProperties && pAP->getNthProperty(0,szName,szValue)) { - m_pie->write(" "); - m_pie->write(static_cast(PT_PROPS_ATTRIBUTE_NAME)); - m_pie->write("=\""); - m_pie->write(static_cast(szName)); - m_pie->write(":"); - _outputXMLChar(szValue, strlen(szValue)); + std::ostringstream buf; + buf << szName << ":" << szValue; UT_uint32 j = 1; while (pAP->getNthProperty(j++,szName,szValue)) { @@ -572,224 +402,79 @@ // the property at all? For now I fixed it by the latter. if (*szValue) { - m_pie->write("; "); - m_pie->write(static_cast(szName)); - m_pie->write(":"); - _outputXMLChar(szValue, strlen(szValue)); + buf << "; " << szName << ":" << szValue; } } - m_pie->write("\""); + m_pie->addString(PT_PROPS_ATTRIBUTE_NAME, buf.str()); } } if(strcmp(szPrefix,"math") == 0) { - UT_UTF8String tag; const char * szPropVal = NULL; pAP->getAttribute("dataid",szPropVal); if(szPropVal != NULL) { - tag = ">"; - if (bNewLineAfter) tag += "\n"; - m_pie->write (tag.utf8_str (), tag.byteLength()); - tag.clear(); - tag = "startElement("image"); + std::string tag = "snapshot-svg-"; tag += szPropVal; - tag += "\""; - tag += " "; - tag += PT_PROPS_ATTRIBUTE_NAME; - tag += "=\""; + m_pie->addString("dataid", tag); bool bFound = pAP->getProperty("height", szPropVal); - UT_UTF8String sVal; + std::ostringstream buf; + bool need_sep = false; if(bFound) { double dInch = static_cast(atoi(szPropVal))/UT_LAYOUT_RESOLUTION; - UT_UTF8String_sprintf(sVal,"%fin",dInch); - tag += "height:"; - tag += sVal; - tag += "; "; + buf << "height:" << dInch << "in"; + need_sep = true; } bFound = pAP->getProperty("width", szPropVal); if(bFound) { + if (need_sep) + buf << "; "; double dInch = static_cast(atoi(szPropVal))/UT_LAYOUT_RESOLUTION; - UT_UTF8String_sprintf(sVal,"%fin",dInch); - tag += "width:"; - tag += sVal; + buf << "width:" << dInch << "in"; } - tag += "\""; - tag += "/"; - tag += ">"; - tag += "addString(PT_PROPS_ATTRIBUTE_NAME, buf.str()); + m_pie->endElement(); } - else - { - if (szSuffix) - if (*szSuffix == '/') - tag += "/"; - tag += ">"; - if (bNewLineAfter) tag += "\n"; - } - m_pie->write (tag.utf8_str (), tag.byteLength()); } else if(strcmp(szPrefix,"embed") == 0) { - UT_UTF8String tag; const char * szPropVal = NULL; pAP->getAttribute("dataid",szPropVal); if(szPropVal != NULL) { - bool has_svg; - tag = ">"; - if (bNewLineAfter) tag += "\n"; - std::string sID = std::string("snapshot-svg-") + szPropVal; - has_svg = m_pDocument->getDataItemDataByName(sID.c_str (), NULL, NULL, NULL); - m_pie->write (tag.utf8_str (), tag.byteLength()); - tag.clear(); - tag = "startElement("image"); + std::string tag = std::string("snapshot-svg-") + szPropVal; + if (!m_pDocument->getDataItemDataByName(tag.c_str (), NULL, NULL, NULL)) + tag = std::string("snapshot-png-") + szPropVal; + m_pie->addString("dataid", tag); bool bFound = pAP->getProperty("height", szPropVal); - UT_UTF8String sVal; + std::ostringstream buf; + bool need_sep = false; if(bFound) { double dInch = static_cast(atoi(szPropVal))/UT_LAYOUT_RESOLUTION; - UT_UTF8String_sprintf(sVal,"%fin",dInch); - tag += "height:"; - tag += sVal; - tag += "; "; + buf << "height:" << dInch << "in"; + need_sep = true; } bFound = pAP->getProperty("width", szPropVal); if(bFound) { + if (need_sep) + buf << "; "; double dInch = static_cast(atoi(szPropVal))/UT_LAYOUT_RESOLUTION; - UT_UTF8String_sprintf(sVal,"%fin",dInch); - tag += "width:"; - tag += sVal; + buf << "width:" << dInch << "in"; } - tag += "\""; - tag += "/"; - tag += ">"; - tag += "addString(PT_PROPS_ATTRIBUTE_NAME, buf.str()); + m_pie->endElement(); } - else - { - if (szSuffix) - if (*szSuffix == '/') - tag += "/"; - tag += ">"; - if (bNewLineAfter) tag += "\n"; - } - m_pie->write (tag.utf8_str (), tag.byteLength()); } - else - { - if (szSuffix) - if (*szSuffix == '/') - m_pie->write ("/"); - m_pie->write (">"); - if (bNewLineAfter) - m_pie->write ("\n"); - } - // m_bInTag = true; -#endif /* ENABLE_RESOURCE_MANAGER */ + if (!bHasContent) + m_pie->endElement(); } -// This method is very much like _outputData but uses gchars instead of UT_UCS4_Char's. -void s_AbiWord_1_Listener::_outputXMLChar(const gchar * data, UT_uint32 length) -{ - UT_UTF8String sBuf (data, length); - sBuf.escapeXML(); - - m_pie->write(sBuf.utf8_str(),sBuf.byteLength()); -} - -// This is very much like _outputXMLChar but adds the >>> key="value" <<< padding an quoting for you -void s_AbiWord_1_Listener::_outputXMLAttribute(const gchar * key, const gchar * value, UT_uint32 length) -{ - m_pie->write(" "); - m_pie->write(key); - m_pie->write("=\""); - _outputXMLChar ( value, length ); - m_pie->write("\" "); -} - -void s_AbiWord_1_Listener::_outputXMLAttribute(const gchar * key, const std::string& value ) -{ - _outputXMLAttribute( key, value.c_str(), value.length() ); -} - - - -void s_AbiWord_1_Listener::_outputData(const UT_UCSChar * data, UT_uint32 length) -{ - UT_UTF8String sBuf; - const UT_UCSChar * pData; - - UT_return_if_fail(sizeof(UT_Byte) == sizeof(char)); - sBuf.reserve(length); - - for (pData=data; (pData': - sBuf += ">"; - pData++; - break; - - case '&': - sBuf += "&"; - pData++; - break; - - case UCS_LF: // LF -- representing a Forced-Line-Break - sBuf += "
"; - pData++; - break; - - case UCS_VTAB: // VTAB -- representing a Forced-Column-Break - sBuf += ""; - pData++; - break; - - case UCS_TAB: - sBuf += "\t"; - pData++; - break; - - case UCS_FF: // FF -- representing a Forced-Page-Break - sBuf += ""; - pData++; - break; - - default: - if (*pData < 0x20) // Silently eat these characters. - pData++; - else - { - sBuf.appendUCS4 (pData, 1); - pData++; - } - } - } - - m_pie->write(sBuf.utf8_str(),sBuf.byteLength()); -} - s_AbiWord_1_Listener::s_AbiWord_1_Listener(PD_Document * pDocument, IE_Exp_AbiWord_1 * pie, bool isTemplate) @@ -810,9 +495,6 @@ m_iInCell = 0; m_bInAnnotation = false; - m_pie->write("\n"); - m_pie->write ("\n"); - /*********************************************************************************** The fixed attributes of the token that used to reside @@ -819,6 +501,7 @@ here are now found in PD_Document::setAttrProp() ************************************************************************************/ + m_pie->setDocType ("\n"); // we want to update the XID counter and the template status UT_String s; @@ -833,18 +516,20 @@ pDocument->setAttributes(attr); - _openTag("abiword", NULL, true, pDocument->getAttrPropIndex(),false,0); + _openTag("abiword", true, pDocument->getAttrPropIndex(),false,0); // NOTE we output the following preamble in XML comments. // NOTE this information is for human viewing only. - m_pie->write("\n"); - m_pie->write("\n"); - m_pie->write("\n"); - m_pie->write("\n"); - m_pie->write("\n"); - m_pie->write("\n\n"); - + m_pie->addString(NULL, "\n"); + m_pie->addComment("========================================================================"); + m_pie->addComment("This file is an AbiWord document. "); + m_pie->addComment("AbiWord is a free, Open Source word processor. "); + m_pie->addComment("More information about AbiWord is available at http://www.abisource.com/"); + m_pie->addComment("You should not edit this file by hand. "); + m_pie->addComment("========================================================================"); + m_pie->addString(NULL, "\n"); + // end of preamble. // now we begin the actual document. @@ -869,7 +554,7 @@ _closeSection(); _handleDataItems(); - m_pie->write("\n"); + m_pie->endElement(); UT_VECTOR_PURGEALL(UT_UTF8String * ,m_vecSnapNames); } @@ -906,7 +591,7 @@ _openSpan(api); PT_BufIndex bi = pcrs->getBufIndex(); - _outputData(m_pDocument->getPointer(bi),pcrs->getLength()); + m_pie->addString(NULL, m_pDocument->getPointer(bi), pcrs->getLength()); return true; } @@ -921,12 +606,10 @@ { _closeSpan(); _closeField(); -#ifndef ENABLE_RESOURCE_MANAGER const gchar* image_name = getObjectKey(api, static_cast("dataid")); if (image_name) m_pUsedImages.insert(image_name); -#endif - _openTag("image","/",false,api,pcr->getXID()); + _openTag("image",false,api,pcr->getXID()); return true; } @@ -934,7 +617,7 @@ { _closeSpan(); _closeField(); - _openTag("field","",false,api,pcr->getXID()); + _openTag("field",true,api,pcr->getXID()); m_pCurrentField = pcro->getField(); UT_ASSERT_HARMLESS(m_pCurrentField); return true; @@ -943,7 +626,7 @@ { _closeSpan(); _closeField(); - _openTag("math","/",false,api,pcr->getXID()); + _openTag("math",false,api,pcr->getXID()); const gchar* image_name = getObjectKey(api, static_cast("dataid")); if (image_name) { @@ -967,7 +650,7 @@ { _closeSpan(); _closeField(); - _openTag("embed","/",false,api,pcr->getXID()); + _openTag("embed",false,api,pcr->getXID()); const gchar* image_name = getObjectKey(api, static_cast("dataid")); if (image_name) { @@ -987,7 +670,7 @@ { _closeSpan(); _closeField(); - _openTag("bookmark", "/",false, api,pcr->getXID(),true); + _openTag("bookmark", false, api,pcr->getXID(),true); return true; } @@ -1013,7 +696,7 @@ if(bFound) { //this is the start of the hyperlink - _openTag("a", "",false, api,pcr->getXID(),true); + _openTag("a", true, api,pcr->getXID(),true); m_bInHyperlink = true; } @@ -1040,7 +723,7 @@ if(bFound) { //this is the start of the Annotation - _openTag("ann", "",false, api,pcr->getXID(),true); + _openTag("ann", true, api,pcr->getXID(),true); UT_DEBUGMSG(("Doing open annotation object \n")); m_bInAnnotation = true; } @@ -1057,7 +740,7 @@ RDFAnchor a( pAP ); if( !a.isEnd() ) { - _openTag("textmeta", "",false, api,pcr->getXID(),true); + _openTag("textmeta", true, api,pcr->getXID(),true); } else { @@ -1098,12 +781,10 @@ UT_return_val_if_fail(pcr->getType() == PX_ChangeRecord::PXT_InsertStrux, false); const PX_ChangeRecord_Strux * pcrx = static_cast (pcr); *psfh = 0; // we don't need it. -#ifndef ENABLE_RESOURCE_MANAGER PT_AttrPropIndex api = pcr->getIndexAP(); const gchar* image_name = getObjectKey(api, static_cast(PT_STRUX_IMAGE_DATAID)); if (image_name) m_pUsedImages.insert(image_name); -#endif switch (pcrx->getStruxType()) { @@ -1116,7 +797,7 @@ _closeAnnotation(); _closeBlock(); _closeSection(); - _openTag("section","",true,pcr->getIndexAP(),pcr->getXID()); + _openTag("section",true,pcr->getIndexAP(),pcr->getXID()); m_bInSection = true; return true; } @@ -1127,7 +808,7 @@ _closeHyperlink(); _closeAnnotation(); _closeBlock(); - _openTag("table","",true,pcr->getIndexAP(),pcr->getXID()); + _openTag("table",true,pcr->getIndexAP(),pcr->getXID()); m_iInTable++; return true; } @@ -1138,7 +819,7 @@ _closeHyperlink(); _closeAnnotation(); _closeBlock(); - _openTag("cell","",true,pcr->getIndexAP(),pcr->getXID()); + _openTag("cell",true,pcr->getIndexAP(),pcr->getXID()); m_iInCell++; return true; } @@ -1149,7 +830,7 @@ _closeHyperlink(); _closeAnnotation(); m_bInBlock = false; - _openTag("foot","",true,pcr->getIndexAP(),pcr->getXID()); + _openTag("foot",true,pcr->getIndexAP(),pcr->getXID()); return true; } case PTX_SectionAnnotation: @@ -1171,7 +852,7 @@ _closeHyperlink(); _closeAnnotation(); m_bInBlock = false; - _openTag("endnote","",true,pcr->getIndexAP(),pcr->getXID()); + _openTag("endnote",true,pcr->getIndexAP(),pcr->getXID()); return true; } case PTX_SectionTOC: @@ -1182,7 +863,7 @@ _closeAnnotation(); _closeBlock(); m_bInBlock = false; - _openTag("toc","",true,pcr->getIndexAP(),pcr->getXID()); + _openTag("toc",true,pcr->getIndexAP(),pcr->getXID()); return true; } case PTX_SectionMarginnote: @@ -1192,7 +873,7 @@ _closeHyperlink(); _closeAnnotation(); _closeBlock(); - _openTag("margin","",true,pcr->getIndexAP(),pcr->getXID()); + _openTag("margin",true,pcr->getIndexAP(),pcr->getXID()); return true; } case PTX_SectionFrame: @@ -1202,7 +883,7 @@ _closeHyperlink(); _closeAnnotation(); _closeBlock(); - _openTag("frame","",true,pcr->getIndexAP(),pcr->getXID()); + _openTag("frame",true,pcr->getIndexAP(),pcr->getXID()); return true; } case PTX_EndTable: @@ -1232,7 +913,7 @@ _closeHyperlink(); _closeAnnotation(); _closeBlock(); - m_pie->write(""); + m_pie->endElement(); m_bInBlock = true; return true; } @@ -1244,7 +925,7 @@ // Lets not close out hyperlinks to start with // _closeHyperlink(); _closeBlock(); - m_pie->write(""); + m_pie->endElement(); m_bInBlock = true; return true; } @@ -1255,7 +936,7 @@ _closeHyperlink(); _closeAnnotation(); _closeBlock(); - m_pie->write(""); + m_pie->endElement(); m_bInBlock = true; return true; } @@ -1266,7 +947,7 @@ _closeHyperlink(); _closeAnnotation(); _closeBlock(); - m_pie->write(""); + m_pie->endElement(); return true; } case PTX_EndMarginnote: @@ -1285,7 +966,7 @@ _closeHyperlink(); _closeAnnotation(); _closeBlock(); - m_pie->write(""); + m_pie->endElement(); return true; } case PTX_Block: @@ -1294,7 +975,8 @@ _closeField(); _closeHyperlink(); _closeBlock(); - _openTag("p","",false,pcr->getIndexAP(),pcr->getXID()); + _openTag("p",true,pcr->getIndexAP(),pcr->getXID()); + m_pie->setPrettyPrint(false); m_bInBlock = true; return true; } @@ -1330,65 +1012,21 @@ return false; } -/* base64-encoded object data - */ -UT_Error s_AbiWord_1_Listener::write_base64 (void * /*context*/, const char * base64, UT_uint32 length, bool /*final*/) -{ - m_pie->write (base64, length); - m_pie->write ("\n"); - - return UT_OK; -} - -/* start tag & attributes - */ -UT_Error s_AbiWord_1_Listener::write_xml (void * /*context*/, const char * name, const char * const * atts) -{ - UT_UTF8String tag(" <"); - - tag += name; - - const char * const * attr = atts; - while (*attr) - { - tag += " "; - tag += *attr++; - tag += "=\""; - tag += *attr++; - tag += "\""; - } - tag += ">\n"; - - m_pie->write (tag.utf8_str (), tag.byteLength()); - - return UT_OK; -} - -/* end tag - */ -UT_Error s_AbiWord_1_Listener::write_xml (void * /*context*/, const char * name) -{ - UT_UTF8String tag(" \n"; - - m_pie->write (tag.utf8_str (), tag.byteLength()); - - return UT_OK; -} - /*****************************************************************/ /*****************************************************************/ UT_Error IE_Exp_AbiWord_1::_writeDocument(void) { - _setupFile(); + // allow people to override this on the command line or otherwise + const std::string & prop = (getProperty ("compress")); + if (!prop.empty()) + m_bIsCompressed = UT_parseBool(prop.c_str (), m_bIsCompressed); + setupFile(m_bIsCompressed); m_pListener = new s_AbiWord_1_Listener(getDoc(),this, m_bIsTemplate); if (!m_pListener) { - close_gsf_handle(m_output); + closeHandle(); return UT_IE_NOMEMORY; } @@ -1404,7 +1042,7 @@ delete m_pListener; m_pListener = NULL; - close_gsf_handle(m_output); + closeHandle(); if (!bStatusTellListener) { @@ -1434,12 +1072,12 @@ pStyle = vecStyles.getNthItem(k); if (!bWroteOpenStyleSection) { - m_pie->write("\n"); + m_pie->startElement("styles"); bWroteOpenStyleSection = true; } PT_AttrPropIndex api = pStyle->getIndexAP(); - _openTag("s","/",true,api,0); + _openTag("s",false,api,0); } UT_GenericVector * pStyles = NULL; @@ -1457,18 +1095,18 @@ if (!bWroteOpenStyleSection) { - m_pie->write("\n"); + m_pie->startElement("styles"); bWroteOpenStyleSection = true; } PT_AttrPropIndex api = pStyle->getIndexAP(); - _openTag("s","/",true,api,0); + _openTag("s",false,api,0); } delete pStyles; if (bWroteOpenStyleSection) - m_pie->write("\n"); + m_pie->endElement(); return; } @@ -1497,10 +1135,10 @@ if (!bWroteOpenListSection) { - m_pie->write("\n"); + m_pie->startElement("lists"); bWroteOpenListSection = true; } - m_pie->write("startElement("l"); for (UT_sint32 i = 0; i < ((UT_sint32)vAttrs.size()) - 1; i += 2) { @@ -1513,14 +1151,10 @@ LCheck("list-delim") || LCheck("list-decimal")) { - m_pie->write(" "); - m_pie->write(s.utf8_str()); - m_pie->write("=\""); - m_pie->write(vAttrs[i+1].utf8_str()); - m_pie->write("\""); + m_pie->addString(s.utf8_str(), vAttrs[i+1].utf8_str()); } } - m_pie->write("/>\n"); + m_pie->endElement(); // No, no, you can't g_free attr and expect good things to happen. FREEP(attr0); } @@ -1529,7 +1163,7 @@ #undef LCheck if (bWroteOpenListSection) - m_pie->write("\n"); + m_pie->endElement(); return; } @@ -1561,25 +1195,24 @@ return ; } - m_pie->write("\n"); + m_pie->startElement("metadata"); std::map::const_iterator iter = ref.begin(); for ( ; iter != ref.end(); ++iter ) { if( !iter->second.empty() ) { - m_pie->write( "first ) ; - m_pie->write ( "\">" ) ; - _outputXMLChar ( iter->second ) ; - m_pie->write ( "\n" ) ; + m_pie->startElement("m"); + m_pie->addString("key", iter->first); + m_pie->addString(NULL, iter->second); + m_pie->endElement() ; } } - m_pie->write("\n"); + m_pie->endElement(); } void s_AbiWord_1_Listener::_handleRDF(void) { - m_pie->write("\n"); + m_pie->startElement("rdf"); // // Walk every subject in the RDF model @@ -1603,24 +1236,22 @@ PD_URI predicate = poiter->first; PD_Object object = poiter->second; - - m_pie->write("startElement("t"); + m_pie->addString("s", subject.toString()); + m_pie->addString("p", predicate.toString()); { std::stringstream ss; ss << object.getObjectType(); - _outputXMLAttribute( "objecttype", ss.str() ); + m_pie->addString("objecttype", ss.str()); } - _outputXMLAttribute( "xsdtype", object.getXSDType() ); - m_pie->write(" >"); + m_pie->addString("xsdtype", object.getXSDType()); UT_UTF8String esc = object.toString().c_str(); - _outputXMLChar ( esc.utf8_str(), esc.byteLength() ) ; - m_pie->write("\n"); - } + m_pie->addString(NULL, esc.utf8_str()); + m_pie->endElement(); + } } - m_pie->write("\n"); + m_pie->endElement(); } void s_AbiWord_1_Listener::_handlePageSize(void) @@ -1628,31 +1259,21 @@ // // Code to write out the PageSize Definitions to disk // - m_pie->write("write(m_pDocument->m_docPageSize.getPredefinedName()); - m_pie->write("\""); - - m_pie->write(" orientation=\""); - if(m_pDocument->m_docPageSize.isPortrait() == true) - m_pie->write("portrait\""); - else - m_pie->write("landscape\""); + m_pie->startElement("pagesize"); + m_pie->addString("pagetype", m_pDocument->m_docPageSize.getPredefinedName()); + m_pie->addString("orientation", + (m_pDocument->m_docPageSize.isPortrait() == true)? + "portrait": "landscape"); UT_Dimension docUnit = m_pDocument->m_docPageSize.getDims(); - - UT_LocaleTransactor t(LC_NUMERIC, "C"); - m_pie->write( UT_String_sprintf(" width=\"%f\"", m_pDocument->m_docPageSize.Width(docUnit)).c_str() ); - m_pie->write( UT_String_sprintf(" height=\"%f\"",m_pDocument->m_docPageSize.Height(docUnit)).c_str() ); - m_pie->write(" units=\""); - m_pie->write(UT_dimensionName(docUnit)); - m_pie->write("\""); - m_pie->write( UT_String_sprintf(" page-scale=\"%f\"/>\n",m_pDocument->m_docPageSize.getScale()).c_str() ); + m_pie->addFloat("width", m_pDocument->m_docPageSize.Width(docUnit)); + m_pie->addFloat("height", m_pDocument->m_docPageSize.Height(docUnit)); + m_pie->addString("units", UT_dimensionName(docUnit)); + m_pie->addFloat("page-scale", m_pDocument->m_docPageSize.getScale()); + m_pie->endElement(); } void s_AbiWord_1_Listener::_handleDataItems(void) { -#ifdef ENABLE_RESOURCE_MANAGER - m_pDocument->resourceManager().write_xml (0, *this); -#else bool bWroteOpenDataSection = false; const char * szName; @@ -1682,7 +1303,7 @@ if (!bWroteOpenDataSection) { - m_pie->write("\n"); + m_pie->startElement("data"); bWroteOpenDataSection = true; } @@ -1723,20 +1344,17 @@ if (status) { - m_pie->write("startElement("d"); + m_pie->addString("name", szName); if (!mimeType.empty()) { - m_pie->write("\" mime-type=\""); - _outputXMLChar(mimeType.c_str(), mimeType.size()); + m_pie->addString("mime-type", mimeType.c_str()); } if (encoded) { - m_pie->write("\" base64=\"yes\">\n"); - // break up the Base64 blob as a series lines + std::ostringstream buf; + m_pie->addString("base64", "yes"); + // break up the Base64 blob as a series lines // like MIME does. UT_uint32 jLimit = bbEncoded.getLength(); @@ -1745,22 +1363,21 @@ for (j=0; jwrite(reinterpret_cast(bbEncoded.getPointer(j)),jSize); - m_pie->write("\n"); + buf.write(reinterpret_cast(bbEncoded.getPointer(j)),jSize); + buf << std::endl; } } else { - m_pie->write("\" base64=\"no\">\n"); - m_pie->write(reinterpret_cast(bbEncoded.getPointer(0)), bbEncoded.getLength()); + m_pie->addString("base64", "no"); + m_pie->addString(NULL, reinterpret_cast(bbEncoded.getPointer(0))); } - m_pie->write("\n"); + m_pie->endElement(); } } if (bWroteOpenDataSection) - m_pie->write("\n"); -#endif + m_pie->endElement(); } void s_AbiWord_1_Listener::_handleRevisions(void) @@ -1780,34 +1397,30 @@ if (!bWroteOpenRevisionsSection) { - s = UT_std_string_sprintf("\n", - m_pDocument->isShowRevisions(), - m_pDocument->isMarkRevisions(), - m_pDocument->getShowRevisionId(), - m_pDocument->isAutoRevisioning()); - - m_pie->write(s.c_str()); + m_pie->startElement("revisions"); + m_pie->addBool("show", m_pDocument->isShowRevisions()); + m_pie->addBool("mark", m_pDocument->isMarkRevisions()); + m_pie->addInt("show-level", m_pDocument->getShowRevisionId()); + m_pie->addBool("auto", m_pDocument->isAutoRevisioning()); bWroteOpenRevisionsSection = true; } - s = UT_std_string_sprintf("", - pRev->getId(), - pRev->getStartTime(), - pRev->getVersion()); - - m_pie->write(s.c_str()); + m_pie->startElement("r"); + m_pie->addUint("id",pRev->getId()); + m_pie->addLint("time-started", pRev->getStartTime()); + m_pie->addUint("version", pRev->getVersion()); if(pRev->getDescription()) { - _outputData(pRev->getDescription(), UT_UCS4_strlen(pRev->getDescription())); + m_pie->addString(NULL, pRev->getDescription(), UT_UCS4_strlen(pRev->getDescription())); } - m_pie->write("\n"); + m_pie->endElement(); } if (bWroteOpenRevisionsSection) - m_pie->write("\n"); + m_pie->endElement(); return; } @@ -1833,24 +1446,25 @@ if (!bWroteOpenSection) { - UT_UTF8String_sprintf(s, "\n", - m_pDocument->getDocVersion(), - static_cast(m_pDocument->getEditTime()), - static_cast(m_pDocument->getLastSavedTime()), - m_pDocument->getDocUUIDString()); - - m_pie->write(s.utf8_str()); + m_pie->startElement("history"); + m_pie->addInt("version", m_pDocument->getDocVersion()); + m_pie->addInt("edit-time", static_cast(m_pDocument->getEditTime())); + m_pie->addInt("last-saved", static_cast(m_pDocument->getLastSavedTime())); + m_pie->addString("uid", m_pDocument->getDocUUIDString()); bWroteOpenSection = true; } - UT_UTF8String_sprintf(s, "\n", - iVersion, static_cast(tStarted), hUid.utf8_str(),bAuto, iXID); - - m_pie->write(s.utf8_str()); + m_pie->startElement("version"); + m_pie->addInt("id", iVersion); + m_pie->addInt("started", static_cast(tStarted)); + m_pie->addString("uid", hUid.utf8_str()); + m_pie->addBool("auto", bAuto); + m_pie->addInt("top-xid", iXID); + m_pie->endElement(); } if (bWroteOpenSection) - m_pie->write("\n"); + m_pie->endElement(); return; } @@ -1860,21 +1474,18 @@ UT_sint32 nAuthors = m_pDocument-> getNumAuthors(); if(nAuthors <= 0) return; - m_pie->write("\n"); + m_pie->startElement("authors"); UT_sint32 i = 0; UT_String sVal; for(i=0;igetNthAuthor(i); - m_pie->write("getAuthorInt()); - m_pie->write(sVal.c_str()); - m_pie->write("\" "); + m_pie->startElement("author"); + m_pie->addInt("id", pAuthor->getAuthorInt()); PP_AttrProp * pAP = pAuthor->getAttrProp(); if(pAP->getPropertyCount()>0) { - m_pie->write(static_cast(PT_PROPS_ATTRIBUTE_NAME)); - m_pie->write("=\""); + std::ostringstream buf; const gchar * szName = NULL; const gchar * szValue = NULL; UT_uint32 j = 0; @@ -1883,16 +1494,14 @@ if (szName && *szName && szValue && *szValue) { if(j>1) - m_pie->write("; "); - m_pie->write(static_cast(szName)); - m_pie->write(":"); - _outputXMLChar(szValue, strlen(szValue)); + buf << "; "; + buf << szName << ":" << szValue; } } - m_pie->write("\""); + m_pie->addString(PT_PROPS_ATTRIBUTE_NAME,buf.str()); } - m_pie->write("/>\n"); + m_pie->endElement(); } - m_pie->write("\n"); + m_pie->endElement(); } Index: src/wp/impexp/xp/ie_exp_AbiWord_1.h =================================================================== --- src/wp/impexp/xp/ie_exp_AbiWord_1.h (révision 35072) +++ src/wp/impexp/xp/ie_exp_AbiWord_1.h (copie de travail) @@ -21,8 +21,9 @@ #ifndef IE_EXP_ABIWORD_1_H #define IE_EXP_ABIWORD_1_H -#include "ie_exp.h" +#include "ie_exp_XML.h" #include "pl_Listener.h" +//#include class PD_Document; class s_AbiWord_1_Listener; @@ -46,7 +47,7 @@ IE_Exp ** ppie); }; -class ABI_EXPORT IE_Exp_AbiWord_1 : public IE_Exp +class ABI_EXPORT IE_Exp_AbiWord_1 : public IE_Exp_XML { public: IE_Exp_AbiWord_1(PD_Document * pDocument, bool isTemplate = false, bool isCompressed = false); @@ -54,15 +55,11 @@ protected: virtual UT_Error _writeDocument(void); - void _setupFile(void); - virtual UT_uint32 _writeBytes(const UT_Byte * pBytes, UT_uint32 length); private: bool m_bIsTemplate; bool m_bIsCompressed; s_AbiWord_1_Listener * m_pListener; - - GsfOutput * m_output; }; #endif /* IE_EXP_ABIWORD_1_H */ Index: src/wp/impexp/xp/ie_exp_XML.cpp =================================================================== --- src/wp/impexp/xp/ie_exp_XML.cpp (révision 0) +++ src/wp/impexp/xp/ie_exp_XML.cpp (copie de travail) @@ -0,0 +1,188 @@ +/* AbiWord + * Copyright (C) 2015 Jean Brefort + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ +#include "ie_exp_XML.h" +#include +#include "ut_debugmsg.h" + +IE_Exp_XML::IE_Exp_XML(PD_Document * pDocument): + IE_Exp (pDocument), m_zip(0), m_xml(0) +{ +} + +IE_Exp_XML::~IE_Exp_XML() +{ +} + +void IE_Exp_XML::setupFile(bool compressed) +{ + UT_ASSERT_HARMLESS (!m_xml); + if (compressed) + { + m_zip = gsf_output_gzip_new(getFp (), NULL); + m_xml = gsf_xml_out_new (m_zip); + } + else + { + m_zip = GSF_OUTPUT(g_object_ref(getFp ())); + m_xml = gsf_xml_out_new (getFp()); + } +} + +void IE_Exp_XML::closeHandle() +{ + if (m_xml) { + g_object_unref(m_xml); + m_xml = 0; + } + if (m_zip) { + g_object_unref(m_zip); + m_zip = 0; + } +} + +void IE_Exp_XML::setDocType(char const *doctype) +{ + gsf_xml_out_set_doc_type(m_xml, doctype); +} + +void IE_Exp_XML::startElement(char const *name) +{ + gsf_xml_out_start_element(m_xml, name); +} + +void IE_Exp_XML::endElement(void) +{ + gsf_xml_out_end_element(m_xml); +} + +void IE_Exp_XML::addBool(char const *id, bool value) +{ + gsf_xml_out_add_bool(m_xml, id, value); +} + +void IE_Exp_XML::addComment(char const *comment) +{ + gsf_output_write(m_zip, 5, reinterpret_cast("\n")); +} + +void IE_Exp_XML::addFloat(char const *id, double value, int precision) +{ + gsf_xml_out_add_float(m_xml, id, value, precision); +} + +void IE_Exp_XML::addInt(char const *id, int value) +{ + gsf_xml_out_add_int(m_xml, id, value); +} + +void IE_Exp_XML::addLint(char const *id, long value) +{ + std::ostringstream buf; + buf << value; + gsf_xml_out_add_cstr_unchecked(m_xml, id, buf.str().c_str()); +} + +void IE_Exp_XML::addLuint(char const *id, unsigned long value) +{ + std::ostringstream buf; + buf << value; + gsf_xml_out_add_cstr_unchecked(m_xml, id, buf.str().c_str()); +} + +void IE_Exp_XML::addString(char const *id, char const *value) +{ + gsf_xml_out_add_cstr(m_xml, id, value); +} + +void IE_Exp_XML::addString(char const *id, std::string const &value) +{ + gsf_xml_out_add_cstr(m_xml, id, value.c_str()); +} + +void IE_Exp_XML::addString(char const *id, UT_UCSChar const *data, int length) +{ + UT_UTF8String sBuf; + const UT_UCSChar * pData; + + UT_return_if_fail(sizeof(UT_Byte) == sizeof(char)); + sBuf.reserve(length); + + for (pData=data; (pData': + sBuf += ">"; + pData++; + break; + + case '&': + sBuf += "&"; + pData++; + break; + + case UCS_LF: // LF -- representing a Forced-Line-Break + sBuf += "
"; + pData++; + break; + + case UCS_VTAB: // VTAB -- representing a Forced-Column-Break + sBuf += ""; + pData++; + break; + + case UCS_TAB: + sBuf += "\t"; + pData++; + break; + + case UCS_FF: // FF -- representing a Forced-Page-Break + sBuf += ""; + pData++; + break; + + default: + if (*pData < 0x20) // Silently eat these characters. + pData++; + else + { + sBuf.appendUCS4 (pData, 1); + pData++; + } + } + } + gsf_xml_out_add_cstr_unchecked(m_xml, id, sBuf.utf8_str()); +} + +void IE_Exp_XML::addUint(char const *id, unsigned value) +{ + gsf_xml_out_add_uint(m_xml, id, value); +} + +void IE_Exp_XML::setPrettyPrint(bool pretty) +{ + g_object_set (m_xml, "pretty-print", pretty, NULL); +} Index: src/wp/impexp/xp/ie_exp_XML.h =================================================================== --- src/wp/impexp/xp/ie_exp_XML.h (révision 0) +++ src/wp/impexp/xp/ie_exp_XML.h (copie de travail) @@ -0,0 +1,58 @@ +/* AbiWord + * Copyright (C) 2015 Jean Brefort + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ + + +#ifndef IE_EXP_XML_H +#define IE_EXP_XML_H + +#include "ie_exp.h" +#include + +class ABI_EXPORT IE_Exp_XML: public IE_Exp +{ +public: + IE_Exp_XML(PD_Document * pDocument); + virtual ~IE_Exp_XML(); + +public: + void setupFile(bool compressed); + void closeHandle(); + void setDocType(char const *doctype); + void startElement(char const *name); + void endElement(); + void addBool(char const *id, bool value); + void addComment(char const *comment); + void addFloat(char const *id, double value, int precision = -1); + void addInt(char const *id, int value); + void addLint(char const *id, long value); + void addLuint(char const *id, unsigned long value); + void addString(char const *id, char const *value); + void addString(char const *id, std::string const &value); + void addString(char const *id, UT_UCSChar const *data, int length); + void addUint(char const *id, unsigned value); + + void setPrettyPrint(bool pretty); + +private: + + GsfOutput *m_zip; + GsfXMLOut *m_xml; +}; + +#endif /* IE_EXP_XML_H */