Preserve the original EOL
This commit is contained in:
parent
b3ed8c5d69
commit
b4661d535c
|
@ -13,22 +13,24 @@ pixmapdir = /usr/share/pixmaps
|
|||
applicationsdir = /usr/share/applications
|
||||
|
||||
# the application source, library search path, and link libraries
|
||||
xmlcopyeditor_SOURCES = xmlcopyeditor.cpp associatedialog.cpp casehandler.cpp \
|
||||
contexthandler.cpp dtd2schema.cpp globalreplacedialog.cpp housestyle.cpp \
|
||||
housestylereader.cpp myhtmlpane.cpp nocasecompare.cpp readfile.cpp \
|
||||
replace.cpp styledialog.cpp threadreaper.cpp wraplibxml.cpp \
|
||||
wrapregex.cpp wraptempfilename.cpp xmlassociatedtd.cpp xmlassociatexsd.cpp \
|
||||
xmlassociatexsl.cpp xmlctrl.cpp xmldoc.cpp xmlencodinghandler.cpp \
|
||||
xmlfilterreader.cpp xmlpromptgenerator.cpp xmlrulereader.cpp \
|
||||
xmlschemalocator.cpp xmlutf8reader.cpp xsllocator.cpp \
|
||||
wrapexpat.cpp mypropertysheet.cpp rule.cpp housestylewriter.cpp myipc.cpp \
|
||||
aboutdialog.cpp pathresolver.cpp mynotebook.cpp insertpanel.cpp \
|
||||
xmlwordcount.cpp getword.cpp locationpanel.cpp catalogresolver.cpp \
|
||||
xmlparseschemans.cpp xmlshallowvalidator.cpp wrapxerces.cpp \
|
||||
findreplacepanel.cpp commandpanel.cpp xercescatalogresolver.cpp \
|
||||
binaryfile.cpp xmlencodingspy.cpp wrapaspell.cpp validationthread.cpp \
|
||||
wrapdaisy.cpp exportdialog.cpp mp3album.cpp xmlprodnote.cpp \
|
||||
xmlsuppressprodnote.cpp xmlcopyimg.cpp xmlschemagenerator.cpp \
|
||||
xmlcopyeditor_SOURCES = aboutdialog.cpp associatedialog.cpp binaryfile.cpp \
|
||||
casehandler.cpp catalogresolver.cpp commandpanel.cpp \
|
||||
contexthandler.cpp dtd2schema.cpp exportdialog.cpp \
|
||||
findreplacepanel.cpp getword.cpp globalreplacedialog.cpp \
|
||||
housestyle.cpp housestylereader.cpp housestylewriter.cpp \
|
||||
insertpanel.cpp locationpanel.cpp mp3album.cpp myhtmlpane.cpp \
|
||||
myipc.cpp mynotebook.cpp mypropertysheet.cpp nocasecompare.cpp \
|
||||
pathresolver.cpp readfile.cpp replace.cpp rule.cpp styledialog.cpp \
|
||||
threadreaper.cpp validationthread.cpp wrapaspell.cpp wrapdaisy.cpp \
|
||||
wrapexpat.cpp wraplibxml.cpp wrapregex.cpp wraptempfilename.cpp \
|
||||
wrapxerces.cpp xercescatalogresolver.cpp xmlassociatedtd.cpp \
|
||||
xmlassociatexsd.cpp xmlassociatexsl.cpp xmlcopyeditor.cpp \
|
||||
xmlcopyimg.cpp xmlctrl.cpp xmldoc.cpp xmlencodinghandler.cpp \
|
||||
xmlencodingspy.cpp xmlfilterreader.cpp xmlparseschemans.cpp \
|
||||
xmlprodnote.cpp xmlpromptgenerator.cpp xmlrulereader.cpp \
|
||||
xmlschemagenerator.cpp xmlschemalocator.cpp xmlshallowvalidator.cpp \
|
||||
xmlsuppressprodnote.cpp xmltextinfo.cpp xmlutf8reader.cpp \
|
||||
xmlwordcount.cpp xsllocator.cpp \
|
||||
xmlcopyeditor.spec xmlcopyeditor.png custom.xpm
|
||||
|
||||
xmlcopyeditor_LDADD = $(WX_LIBS) \
|
||||
|
|
|
@ -50,35 +50,35 @@ CONFIG_CLEAN_VPATH_FILES =
|
|||
am__installdirs = "$(DESTDIR)$(bindir)" \
|
||||
"$(DESTDIR)$(xmlcopyeditordir)" "$(DESTDIR)$(pixmapdir)"
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
am_xmlcopyeditor_OBJECTS = xmlcopyeditor.$(OBJEXT) \
|
||||
associatedialog.$(OBJEXT) casehandler.$(OBJEXT) \
|
||||
contexthandler.$(OBJEXT) dtd2schema.$(OBJEXT) \
|
||||
am_xmlcopyeditor_OBJECTS = aboutdialog.$(OBJEXT) \
|
||||
associatedialog.$(OBJEXT) binaryfile.$(OBJEXT) \
|
||||
casehandler.$(OBJEXT) catalogresolver.$(OBJEXT) \
|
||||
commandpanel.$(OBJEXT) contexthandler.$(OBJEXT) \
|
||||
dtd2schema.$(OBJEXT) exportdialog.$(OBJEXT) \
|
||||
findreplacepanel.$(OBJEXT) getword.$(OBJEXT) \
|
||||
globalreplacedialog.$(OBJEXT) housestyle.$(OBJEXT) \
|
||||
housestylereader.$(OBJEXT) myhtmlpane.$(OBJEXT) \
|
||||
nocasecompare.$(OBJEXT) readfile.$(OBJEXT) replace.$(OBJEXT) \
|
||||
housestylereader.$(OBJEXT) housestylewriter.$(OBJEXT) \
|
||||
insertpanel.$(OBJEXT) locationpanel.$(OBJEXT) \
|
||||
mp3album.$(OBJEXT) myhtmlpane.$(OBJEXT) myipc.$(OBJEXT) \
|
||||
mynotebook.$(OBJEXT) mypropertysheet.$(OBJEXT) \
|
||||
nocasecompare.$(OBJEXT) pathresolver.$(OBJEXT) \
|
||||
readfile.$(OBJEXT) replace.$(OBJEXT) rule.$(OBJEXT) \
|
||||
styledialog.$(OBJEXT) threadreaper.$(OBJEXT) \
|
||||
wraplibxml.$(OBJEXT) wrapregex.$(OBJEXT) \
|
||||
wraptempfilename.$(OBJEXT) xmlassociatedtd.$(OBJEXT) \
|
||||
xmlassociatexsd.$(OBJEXT) xmlassociatexsl.$(OBJEXT) \
|
||||
xmlctrl.$(OBJEXT) xmldoc.$(OBJEXT) \
|
||||
xmlencodinghandler.$(OBJEXT) xmlfilterreader.$(OBJEXT) \
|
||||
xmlpromptgenerator.$(OBJEXT) xmlrulereader.$(OBJEXT) \
|
||||
xmlschemalocator.$(OBJEXT) xmlutf8reader.$(OBJEXT) \
|
||||
xsllocator.$(OBJEXT) wrapexpat.$(OBJEXT) \
|
||||
mypropertysheet.$(OBJEXT) rule.$(OBJEXT) \
|
||||
housestylewriter.$(OBJEXT) myipc.$(OBJEXT) \
|
||||
aboutdialog.$(OBJEXT) pathresolver.$(OBJEXT) \
|
||||
mynotebook.$(OBJEXT) insertpanel.$(OBJEXT) \
|
||||
xmlwordcount.$(OBJEXT) getword.$(OBJEXT) \
|
||||
locationpanel.$(OBJEXT) catalogresolver.$(OBJEXT) \
|
||||
xmlparseschemans.$(OBJEXT) xmlshallowvalidator.$(OBJEXT) \
|
||||
wrapxerces.$(OBJEXT) findreplacepanel.$(OBJEXT) \
|
||||
commandpanel.$(OBJEXT) xercescatalogresolver.$(OBJEXT) \
|
||||
binaryfile.$(OBJEXT) xmlencodingspy.$(OBJEXT) \
|
||||
wrapaspell.$(OBJEXT) validationthread.$(OBJEXT) \
|
||||
wrapdaisy.$(OBJEXT) exportdialog.$(OBJEXT) mp3album.$(OBJEXT) \
|
||||
xmlprodnote.$(OBJEXT) xmlsuppressprodnote.$(OBJEXT) \
|
||||
xmlcopyimg.$(OBJEXT) xmlschemagenerator.$(OBJEXT)
|
||||
validationthread.$(OBJEXT) wrapaspell.$(OBJEXT) \
|
||||
wrapdaisy.$(OBJEXT) wrapexpat.$(OBJEXT) wraplibxml.$(OBJEXT) \
|
||||
wrapregex.$(OBJEXT) wraptempfilename.$(OBJEXT) \
|
||||
wrapxerces.$(OBJEXT) xercescatalogresolver.$(OBJEXT) \
|
||||
xmlassociatedtd.$(OBJEXT) xmlassociatexsd.$(OBJEXT) \
|
||||
xmlassociatexsl.$(OBJEXT) xmlcopyeditor.$(OBJEXT) \
|
||||
xmlcopyimg.$(OBJEXT) xmlctrl.$(OBJEXT) xmldoc.$(OBJEXT) \
|
||||
xmlencodinghandler.$(OBJEXT) xmlencodingspy.$(OBJEXT) \
|
||||
xmlfilterreader.$(OBJEXT) xmlparseschemans.$(OBJEXT) \
|
||||
xmlprodnote.$(OBJEXT) xmlpromptgenerator.$(OBJEXT) \
|
||||
xmlrulereader.$(OBJEXT) xmlschemagenerator.$(OBJEXT) \
|
||||
xmlschemalocator.$(OBJEXT) xmlshallowvalidator.$(OBJEXT) \
|
||||
xmlsuppressprodnote.$(OBJEXT) xmltextinfo.$(OBJEXT) \
|
||||
xmlutf8reader.$(OBJEXT) xmlwordcount.$(OBJEXT) \
|
||||
xsllocator.$(OBJEXT)
|
||||
xmlcopyeditor_OBJECTS = $(am_xmlcopyeditor_OBJECTS)
|
||||
am__DEPENDENCIES_1 =
|
||||
xmlcopyeditor_DEPENDENCIES = $(am__DEPENDENCIES_1) \
|
||||
|
@ -287,22 +287,24 @@ pixmapdir = /usr/share/pixmaps
|
|||
applicationsdir = /usr/share/applications
|
||||
|
||||
# the application source, library search path, and link libraries
|
||||
xmlcopyeditor_SOURCES = xmlcopyeditor.cpp associatedialog.cpp casehandler.cpp \
|
||||
contexthandler.cpp dtd2schema.cpp globalreplacedialog.cpp housestyle.cpp \
|
||||
housestylereader.cpp myhtmlpane.cpp nocasecompare.cpp readfile.cpp \
|
||||
replace.cpp styledialog.cpp threadreaper.cpp wraplibxml.cpp \
|
||||
wrapregex.cpp wraptempfilename.cpp xmlassociatedtd.cpp xmlassociatexsd.cpp \
|
||||
xmlassociatexsl.cpp xmlctrl.cpp xmldoc.cpp xmlencodinghandler.cpp \
|
||||
xmlfilterreader.cpp xmlpromptgenerator.cpp xmlrulereader.cpp \
|
||||
xmlschemalocator.cpp xmlutf8reader.cpp xsllocator.cpp \
|
||||
wrapexpat.cpp mypropertysheet.cpp rule.cpp housestylewriter.cpp myipc.cpp \
|
||||
aboutdialog.cpp pathresolver.cpp mynotebook.cpp insertpanel.cpp \
|
||||
xmlwordcount.cpp getword.cpp locationpanel.cpp catalogresolver.cpp \
|
||||
xmlparseschemans.cpp xmlshallowvalidator.cpp wrapxerces.cpp \
|
||||
findreplacepanel.cpp commandpanel.cpp xercescatalogresolver.cpp \
|
||||
binaryfile.cpp xmlencodingspy.cpp wrapaspell.cpp validationthread.cpp \
|
||||
wrapdaisy.cpp exportdialog.cpp mp3album.cpp xmlprodnote.cpp \
|
||||
xmlsuppressprodnote.cpp xmlcopyimg.cpp xmlschemagenerator.cpp \
|
||||
xmlcopyeditor_SOURCES = aboutdialog.cpp associatedialog.cpp binaryfile.cpp \
|
||||
casehandler.cpp catalogresolver.cpp commandpanel.cpp \
|
||||
contexthandler.cpp dtd2schema.cpp exportdialog.cpp \
|
||||
findreplacepanel.cpp getword.cpp globalreplacedialog.cpp \
|
||||
housestyle.cpp housestylereader.cpp housestylewriter.cpp \
|
||||
insertpanel.cpp locationpanel.cpp mp3album.cpp myhtmlpane.cpp \
|
||||
myipc.cpp mynotebook.cpp mypropertysheet.cpp nocasecompare.cpp \
|
||||
pathresolver.cpp readfile.cpp replace.cpp rule.cpp styledialog.cpp \
|
||||
threadreaper.cpp validationthread.cpp wrapaspell.cpp wrapdaisy.cpp \
|
||||
wrapexpat.cpp wraplibxml.cpp wrapregex.cpp wraptempfilename.cpp \
|
||||
wrapxerces.cpp xercescatalogresolver.cpp xmlassociatedtd.cpp \
|
||||
xmlassociatexsd.cpp xmlassociatexsl.cpp xmlcopyeditor.cpp \
|
||||
xmlcopyimg.cpp xmlctrl.cpp xmldoc.cpp xmlencodinghandler.cpp \
|
||||
xmlencodingspy.cpp xmlfilterreader.cpp xmlparseschemans.cpp \
|
||||
xmlprodnote.cpp xmlpromptgenerator.cpp xmlrulereader.cpp \
|
||||
xmlschemagenerator.cpp xmlschemalocator.cpp xmlshallowvalidator.cpp \
|
||||
xmlsuppressprodnote.cpp xmltextinfo.cpp xmlutf8reader.cpp \
|
||||
xmlwordcount.cpp xsllocator.cpp \
|
||||
xmlcopyeditor.spec xmlcopyeditor.png custom.xpm
|
||||
|
||||
xmlcopyeditor_LDADD = $(WX_LIBS) \
|
||||
|
@ -499,6 +501,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlschemalocator.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlshallowvalidator.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlsuppressprodnote.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmltextinfo.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlutf8reader.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlwordcount.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xsllocator.Po@am__quote@
|
||||
|
|
|
@ -25,12 +25,14 @@
|
|||
#include "xmlassociatedtd.h"
|
||||
|
||||
XmlAssociateDtd::XmlAssociateDtd (
|
||||
const wxString &path,
|
||||
const wxString &publicID,
|
||||
const char *encoding,
|
||||
size_t size )
|
||||
: WrapExpat ( encoding )
|
||||
, d ( new DtdData() )
|
||||
const XmlTextInfo &info,
|
||||
const wxString &path,
|
||||
const wxString &publicID,
|
||||
const char *encoding,
|
||||
size_t size )
|
||||
: WrapExpat ( encoding )
|
||||
, d ( new DtdData() )
|
||||
, mInfo ( info )
|
||||
{
|
||||
d->buffer.reserve ( size );
|
||||
d->path = path;
|
||||
|
@ -67,7 +69,7 @@ void XMLCALL XmlAssociateDtd::start ( void *data,
|
|||
if ( !d->associated )
|
||||
{
|
||||
associate ( d, el );
|
||||
d->buffer += "\n";
|
||||
d->buffer += pThis->mInfo.mEOL.utf8_str();
|
||||
d->associated = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <expat.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "wrapexpat.h"
|
||||
#include "xmltextinfo.h"
|
||||
|
||||
struct DtdData : public ParserData
|
||||
{
|
||||
|
@ -37,6 +37,7 @@ class XmlAssociateDtd : public WrapExpat
|
|||
{
|
||||
public:
|
||||
XmlAssociateDtd (
|
||||
const XmlTextInfo &info,
|
||||
const wxString &path = wxEmptyString,
|
||||
const wxString &publicID = wxEmptyString,
|
||||
const char *encoding = NULL,
|
||||
|
@ -48,7 +49,7 @@ class XmlAssociateDtd : public WrapExpat
|
|||
}
|
||||
private:
|
||||
std::auto_ptr<DtdData> d;
|
||||
std::string encoding;
|
||||
const XmlTextInfo &mInfo;
|
||||
static void XMLCALL start (
|
||||
void *data,
|
||||
const XML_Char *el,
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
#include "xmlassociatexsl.h"
|
||||
|
||||
XmlAssociateXsl::XmlAssociateXsl (
|
||||
const XmlTextInfo &info,
|
||||
const wxString &path,
|
||||
const char *encoding,
|
||||
size_t size )
|
||||
: WrapExpat ( encoding )
|
||||
, d ( new XslData() )
|
||||
, mInfo ( info )
|
||||
{
|
||||
d->buffer.reserve ( size );
|
||||
d->path = path;
|
||||
|
@ -64,7 +66,8 @@ void XMLCALL XmlAssociateXsl::start ( void *data,
|
|||
{
|
||||
d->buffer += "<?xml-stylesheet type=\"text/xsl\" href=\"";
|
||||
d->buffer += d->path.utf8_str(); // TODO: Apply the encoding of the parser
|
||||
d->buffer += "\"?>\n";
|
||||
d->buffer += "\"?>";
|
||||
d->buffer += pThis->mInfo.mEOL.utf8_str();
|
||||
d->associated = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <expat.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "wrapexpat.h"
|
||||
#include "xmltextinfo.h"
|
||||
|
||||
struct XslData : public ParserData
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ class XmlAssociateXsl : public WrapExpat
|
|||
{
|
||||
public:
|
||||
XmlAssociateXsl (
|
||||
const XmlTextInfo &info,
|
||||
const wxString &path = wxEmptyString,
|
||||
const char *encoding = NULL,
|
||||
size_t size = BUFSIZ );
|
||||
|
@ -48,7 +49,7 @@ class XmlAssociateXsl : public WrapExpat
|
|||
}
|
||||
private:
|
||||
std::auto_ptr<XslData> d;
|
||||
std::string encoding;
|
||||
const XmlTextInfo &mInfo;
|
||||
static void XMLCALL start (
|
||||
void *data,
|
||||
const XML_Char *el,
|
||||
|
|
|
@ -5739,6 +5739,9 @@ void MyFrame::OnAssociate ( wxCommandEvent& event )
|
|||
if ( ( doc = getActiveDocument() ) == NULL )
|
||||
return;
|
||||
|
||||
XmlTextInfo info ( doc->getFullFileName() );
|
||||
info.parse ( doc->myGetTextRaw() );
|
||||
|
||||
wxString title, label, type, extension, path, defaulturl, defaultaux;
|
||||
wxString auxiliaryLabel;
|
||||
int id = event.GetId();
|
||||
|
@ -5748,24 +5751,26 @@ void MyFrame::OnAssociate ( wxCommandEvent& event )
|
|||
type = _ ( "Public DTD" );
|
||||
extension = _T ( "*.dtd" );
|
||||
defaulturl = lastDtdPublic;
|
||||
defaultaux = lastDtdPublicAux;
|
||||
defaultaux = info.mDtdFile.empty()
|
||||
? lastDtdPublicAux : info.mDtdFile;
|
||||
break;
|
||||
case ID_ASSOCIATE_DTD_SYSTEM:
|
||||
type = _ ( "System DTD" );
|
||||
extension = _T ( "*.dtd" );
|
||||
defaulturl = lastDtdSystem;
|
||||
defaulturl = info.mDtdFile.empty() ? lastDtdSystem : info.mDtdFile;
|
||||
defaultaux = _T ( "" );
|
||||
break;
|
||||
case ID_ASSOCIATE_W3C_SCHEMA:
|
||||
type = _ ( "XML Schema" );
|
||||
extension = _T ( "*.xsd" );
|
||||
defaulturl = lastSchema;
|
||||
defaulturl = info.mXsdFile.empty() ? lastSchema : info.mXsdFile;
|
||||
defaultaux = _T ( "" );
|
||||
break;
|
||||
case ID_ASSOCIATE_XSL:
|
||||
type = _ ( "XSLT stylesheet" );
|
||||
extension = _T ( "*.xsl;*.xslt" );
|
||||
defaulturl = lastXslStylesheet;
|
||||
defaulturl = info.mXslFile.empty()
|
||||
? lastXslStylesheet : info.mXslFile;
|
||||
defaultaux = _T ( "" );
|
||||
break;
|
||||
default:
|
||||
|
@ -5856,14 +5861,14 @@ void MyFrame::OnAssociate ( wxCommandEvent& event )
|
|||
}
|
||||
else if ( id == ID_ASSOCIATE_DTD_SYSTEM || id == ID_ASSOCIATE_DTD_PUBLIC )
|
||||
{
|
||||
XmlAssociateDtd parser ( path, aux, "UTF-8" );
|
||||
XmlAssociateDtd parser ( info, path, aux, "UTF-8" );
|
||||
if ( !parser.parse ( utf8Buffer ) )
|
||||
return;
|
||||
modifiedBuffer = parser.getBuffer();
|
||||
}
|
||||
else if ( id == ID_ASSOCIATE_XSL )
|
||||
{
|
||||
XmlAssociateXsl parser( path, "UTF-8" );
|
||||
XmlAssociateXsl parser( info, path, "UTF-8" );
|
||||
if ( !parser.parse ( utf8Buffer ) )
|
||||
return;
|
||||
modifiedBuffer = parser.getBuffer();
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright 2014 Zane U. Ji.
|
||||
*
|
||||
* This file is part of Xml Copy Editor.
|
||||
*
|
||||
* Xml Copy Editor 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; version 2 of the License.
|
||||
*
|
||||
* Xml Copy Editor 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 Xml Copy Editor; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "xmltextinfo.h"
|
||||
|
||||
XmlTextInfo::XmlTextInfo
|
||||
( const wxString &path
|
||||
, const char *encoding /*= NULL*/
|
||||
)
|
||||
: WrapExpat ( encoding )
|
||||
{
|
||||
XML_SetUserData ( p, this );
|
||||
XML_SetBase ( p, path.utf8_str() );
|
||||
XML_SetDoctypeDeclHandler ( p, startdoctypehandler, NULL );
|
||||
XML_SetProcessingInstructionHandler ( p, processinghandler );
|
||||
XML_SetElementHandler ( p, start, NULL );
|
||||
XML_SetDefaultHandlerExpand ( p, defaulthandler );
|
||||
}
|
||||
|
||||
XmlTextInfo::~XmlTextInfo()
|
||||
{
|
||||
}
|
||||
|
||||
void XMLCALL XmlTextInfo::startdoctypehandler
|
||||
( void *data
|
||||
, const XML_Char *doctypeName
|
||||
, const XML_Char *sysid
|
||||
, const XML_Char *pubid
|
||||
, int has_internal_subset
|
||||
)
|
||||
{
|
||||
XmlTextInfo *pThis = (XmlTextInfo *)data;
|
||||
|
||||
pThis->mDocTypeName = wxString::FromUTF8 ( doctypeName );
|
||||
}
|
||||
|
||||
void XMLCALL XmlTextInfo::processinghandler
|
||||
( void *data
|
||||
, const XML_Char *target
|
||||
, const XML_Char *datastring
|
||||
)
|
||||
{
|
||||
XmlTextInfo *pThis = (XmlTextInfo *)data;
|
||||
|
||||
if ( strcmp ( target, "xml-stylesheet" ) )
|
||||
return;
|
||||
|
||||
char *href = strstr ( ( char * ) datastring, "href" );
|
||||
if ( !href )
|
||||
return;
|
||||
href += strlen ( "href" );
|
||||
|
||||
char ch = '"'; // Is '' or "" used?
|
||||
char *start = strchr ( href, ch);
|
||||
char *p = strchr ( href, '\'');
|
||||
if ( start == NULL
|
||||
|| ( p != NULL && start > p ) )
|
||||
{
|
||||
start = p;
|
||||
ch = '\'';
|
||||
}
|
||||
if ( !start++ )
|
||||
return;
|
||||
while ( isspace ( *start ) )
|
||||
start++;
|
||||
|
||||
char *end = strchr ( start, ch);
|
||||
if ( !end )
|
||||
return;
|
||||
while ( isspace ( end[-1] ) )
|
||||
end--;
|
||||
|
||||
pThis->mXslFile = wxString::FromUTF8 ( start, end - start );
|
||||
}
|
||||
|
||||
void XMLCALL XmlTextInfo::start
|
||||
( void *data
|
||||
, const XML_Char *el
|
||||
, const XML_Char **attr
|
||||
)
|
||||
{
|
||||
XmlTextInfo *pThis = (XmlTextInfo *)data;
|
||||
|
||||
for ( ; *attr; attr += 2 )
|
||||
{
|
||||
if ( strstr ( *attr, ":noNamespaceSchemaLocation" ) )
|
||||
{
|
||||
pThis->mXsdFile = wxString::FromUTF8 ( attr[1] );
|
||||
break;
|
||||
}
|
||||
if ( strstr ( *attr, ":schemaLocation" ) )
|
||||
{ // TODO: Support multiple schemas
|
||||
std::string str ( attr[1] );
|
||||
char *p = strtok ( ( char * ) str.c_str(), " \t\r\n" );
|
||||
if ( !p )
|
||||
continue;
|
||||
p = strtok ( NULL, " \t\r\n" );
|
||||
if ( !p )
|
||||
continue;
|
||||
pThis->mXsdFile = wxString::FromUTF8 ( p );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pThis->mDocTypeName = wxString::FromUTF8 ( el );
|
||||
|
||||
XML_SetElementHandler ( pThis->p, NULL, NULL );
|
||||
}
|
||||
|
||||
void XMLCALL XmlTextInfo::defaulthandler
|
||||
( void *data
|
||||
, const XML_Char *s
|
||||
, int len
|
||||
)
|
||||
{
|
||||
XmlTextInfo *pThis = (XmlTextInfo *)data;
|
||||
const char *p = s;
|
||||
const char *end = s + len;
|
||||
while ( p < end && *p != '\r' )
|
||||
p++;
|
||||
if ( p < end )
|
||||
{
|
||||
if ( p + 1 < end && p[1] == '\n' )
|
||||
pThis->mEOL = _T ( "\r\n" );
|
||||
else
|
||||
pThis->mEOL = _T ( "\n" );
|
||||
XML_SetDefaultHandlerExpand ( pThis->p, NULL );
|
||||
return;
|
||||
}
|
||||
|
||||
p = s;
|
||||
while ( p < end && *p != '\r')
|
||||
p++;
|
||||
if ( p < end )
|
||||
{
|
||||
pThis->mEOL = _T ( "\n" );
|
||||
XML_SetDefaultHandlerExpand ( pThis->p, NULL );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2014 Zane U. Ji.
|
||||
*
|
||||
* This file is part of Xml Copy Editor.
|
||||
*
|
||||
* Xml Copy Editor 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; version 2 of the License.
|
||||
*
|
||||
* Xml Copy Editor 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 Xml Copy Editor; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef XMLASSOCIATEINFO_H_
|
||||
#define XMLASSOCIATEINFO_H_
|
||||
|
||||
#include "wrapexpat.h"
|
||||
|
||||
class XmlTextInfo : public WrapExpat
|
||||
{
|
||||
public:
|
||||
XmlTextInfo
|
||||
( const wxString &path
|
||||
, const char *encoding = NULL
|
||||
);
|
||||
virtual ~XmlTextInfo();
|
||||
|
||||
private:
|
||||
static void XMLCALL startdoctypehandler
|
||||
( void *userData
|
||||
, const XML_Char *doctypeName
|
||||
, const XML_Char *sysid
|
||||
, const XML_Char *pubid
|
||||
, int has_internal_subset
|
||||
);
|
||||
static void XMLCALL processinghandler
|
||||
( void *data
|
||||
, const XML_Char *target
|
||||
, const XML_Char *datastring
|
||||
);
|
||||
static void XMLCALL start
|
||||
( void *data
|
||||
, const XML_Char *el
|
||||
, const XML_Char **attr
|
||||
);
|
||||
static void XMLCALL defaulthandler
|
||||
( void *data
|
||||
, const XML_Char *s
|
||||
, int len
|
||||
);
|
||||
|
||||
public:
|
||||
wxString mDocTypeName;
|
||||
wxString mDtdFile, mXsdFile, mXslFile;
|
||||
wxString mEOL;
|
||||
};
|
||||
|
||||
#endif /* XMLASSOCIATEINFO_H_ */
|
Loading…
Reference in New Issue