[GME-commit] GMESRC/GME/XmlBackEnd Transcoder.cpp, NONE, 1.1 Transcoder.h, NONE, 1.1 CoreXmlFile.cpp, 1.27, 1.28 CoreXmlFile.h, 1.11, 1.12 VSSLoginDlg.cpp, 1.4, 1.5 VSSLoginDlg.h, 1.4, 1.5 XmlBackEnd.vcproj, 1.7, 1.8
Log messages of CVS commits
gme-commit at list.isis.vanderbilt.edu
Mon Feb 18 14:13:58 CST 2008
Update of /project/gme-repository/GMESRC/GME/XmlBackEnd
In directory escher:/tmp/cvs-serv13687
Modified Files:
CoreXmlFile.cpp CoreXmlFile.h VSSLoginDlg.cpp VSSLoginDlg.h
XmlBackEnd.vcproj
Added Files:
Transcoder.cpp Transcoder.h
Log Message:
Transcoder added for UTF-8 encoding.
SERF does not like to test with info for fake URLs.
CVS User: Zoltan Molnar, ISIS (zolmol)
Index: XmlBackEnd.vcproj
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/XmlBackEnd/XmlBackEnd.vcproj,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** XmlBackEnd.vcproj 15 Feb 2008 21:06:43 -0000 1.7
--- XmlBackEnd.vcproj 18 Feb 2008 20:13:56 -0000 1.8
***************
*** 47,50 ****
--- 47,51 ----
copy ..\lib\subv_$(ConfigurationName)\libaprutil.dll $(OutDir)
copy ..\lib\subv_$(ConfigurationName)\libapriconv.dll $(OutDir)
+ copy ..\lib\xerces-c_2_8D.dll "$(OutDir)"
regsvr32 /s /c "$(TargetPath)"
echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
***************
*** 126,129 ****
--- 127,131 ----
copy ..\lib\subv_$(ConfigurationName)\libaprutil.dll $(OutDir)
copy ..\lib\subv_$(ConfigurationName)\libapriconv.dll $(OutDir)
+ copy ..\lib\xerces-c_2_8.dll "$(OutDir)"
regsvr32 /s /c "$(TargetPath)"
echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
***************
*** 355,358 ****
--- 357,363 ----
</File>
<File
+ RelativePath=".\Transcoder.cpp">
+ </File>
+ <File
RelativePath="VSSLoginDlg.cpp">
<FileConfiguration
***************
*** 544,547 ****
--- 549,555 ----
<File
RelativePath=".\SvnWorkBench.h">
+ </File>
+ <File
+ RelativePath=".\Transcoder.h">
</File>
<File
--- NEW FILE: Transcoder.h ---
#ifndef XML_TRANS_H
#define XML_TRANS_H
#include <fstream> // fstream.h
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/framework/XMLFormatter.hpp>
XERCES_CPP_NAMESPACE_USE
class Transcoder : private XMLFormatTarget, private std::ofstream
{
public:
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
Transcoder();
~Transcoder();
void init( const char *, const char * const);
void finalize();
enum Modes
{
NoEscape, // normal transcoding
StdEscape // additionally escaping special characters like &<>'"
};
// -----------------------------------------------------------------------
// Implementations of the format target interface
// -----------------------------------------------------------------------
void writeChars
(
const XMLByte* const toWrite
, const unsigned int count
, XMLFormatter* const formatter
);
Transcoder& operator << ( Modes mode);
Transcoder& operator << ( metaid_type toWrite);
Transcoder& operator << ( const XMLCh* const toWrite);
Transcoder& operator << ( const char * const toWrite);
Transcoder& operator << ( const char toWrite);
Transcoder& operator << ( const std::string& toWrite);
bool isOpen();
private :
XMLFormatter* m_pFormatter;
};
#endif // XML_TRANS_H
Index: CoreXmlFile.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/XmlBackEnd/CoreXmlFile.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** CoreXmlFile.cpp 15 Feb 2008 21:06:43 -0000 1.27
--- CoreXmlFile.cpp 18 Feb 2008 20:13:56 -0000 1.28
***************
*** 18,21 ****
--- 18,22 ----
#include "FileHelp.h"
#include "DirSupplier.h"
+ #include "Transcoder.h"
using namespace XERCES_CPP_NAMESPACE;
***************
*** 157,180 ****
}
- void encodeXMLString( string& in, string& out )
- {
- int size = in.length();
- out = "";
-
- for( int i=0; i<size; ++i )
- {
- switch( in[i] )
- {
- case '<' : out += "<"; break;
- case '>' : out += ">"; break;
- case '&' : out += "&"; break;
- case '\'': out += "'"; break;
- case '\"': out += """; break;
- default : out += in[i];
- }
- }
- }
-
-
void bin2string( const unsigned char * bytes, int len, std::string& str )
{
--- 158,161 ----
***************
*** 2296,2299 ****
--- 2277,2282 ----
}
+ // method used to clear all objects before a new attempt to read a project.
+ // it is used by ~CCoreXmlFile, or ::CloseProject also.
void CCoreXmlFile::clearAll()
{
***************
*** 3428,3437 ****
{
return; // file exists, is read-only, no chance of writing into it
}
// open file
! FILE * file = fopen( fileName.c_str(), "w" ); // because of 'w' it succeeds only with checkedout files!!!
! if( file != NULL )
{
bool deleted = false;
// Is this object deleted according to its current state?
--- 3411,3427 ----
{
return; // file exists, is read-only, no chance of writing into it
+ // it also means there was no change
}
// open file
! // previously the "w" mode used by fopen guarranteed that only read-write files are opened
! // now with Transcoder, exceptions will be thrown whenever a file can't be opened because it is read-only.
! // That's why it is a good thing to check (above) for read-onlyness
! Transcoder ofs;
! try
{
+ ofs.init( fileName.c_str(), "UTF-8"); // create a transcoder fstream
+ // Transcoder dumps by default the xml version and encoding
+
bool deleted = false;
// Is this object deleted according to its current state?
***************
*** 3450,3462 ****
if( !deleted)
{
- // to encode correctly the special characters in each separate file
- fprintf(file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
-
// write objects recursively
! writeObject( container, file, true, "", currentTime2 );
}
// deleted containers will have a file of 0 size
! fclose(file);
// now it's time to get file's exact 'Modified At' attribute
--- 3440,3449 ----
if( !deleted)
{
// write objects recursively
! writeObject( container, ofs, true, "", currentTime2 );
}
// deleted containers will have a file of 0 size
! ofs.finalize();
// now it's time to get file's exact 'Modified At' attribute
***************
*** 3478,3484 ****
}
}
! else
{
! // TODO: the file is probably read only (it means there was no change)
}
}
--- 3465,3478 ----
}
}
! catch( hresult_exception& e)
{
! if( e.hr == E_INVALID_FILENAME) // file could not be opened
! sendMsg( "Error while saving. Could not open file " + fileName, MSG_ERROR);
! else
! sendMsg( "Unknown error while saving file " + fileName, MSG_ERROR);
! }
! catch( ...)
! {
! sendMsg( "Generic error while saving file " + fileName, MSG_ERROR);
}
}
***************
*** 3494,3498 ****
}
! void CCoreXmlFile::writeObject(XmlObject * obj, FILE * file, bool container, const char * prefix, CTime lastWriteTime )
{
std::string str;
--- 3488,3492 ----
}
! void CCoreXmlFile::writeObject(XmlObject * obj, Transcoder& ofs, bool container, const char * prefix, CTime lastWriteTime )
{
std::string str;
***************
*** 3508,3512 ****
bool spec_root = metaToken == "Root"; // or: m_metaid==METAID_ROOT
if( spec_root) // <!DOCTYPE Root SYSTEM "my.dtd">
! fprintf( file, "<!DOCTYPE Root SYSTEM \"xmga.dtd\">\n");
// the multiline case? for details see Mga\MgaGeneric.cpp
--- 3502,3506 ----
bool spec_root = metaToken == "Root"; // or: m_metaid==METAID_ROOT
if( spec_root) // <!DOCTYPE Root SYSTEM "my.dtd">
! ofs << "<!DOCTYPE Root SYSTEM \"xmga.dtd\">\n";
// the multiline case? for details see Mga\MgaGeneric.cpp
***************
*** 3522,3528 ****
// only when Root is the owner, we will use a preable in the CDATA section for Comment
! fprintf(file, "%s<%S MetaId=\"%d\" Id=\"%s\"", prefix, metaToken, obj->m_metaid, str.c_str() );
if( obj->m_deleted )
! fprintf(file, " deleted=\"true\"");
// write pointers, attributes
--- 3516,3522 ----
// only when Root is the owner, we will use a preable in the CDATA section for Comment
! ofs << Transcoder::NoEscape << prefix << "<" << metaToken << " MetaId=\"" << obj->m_metaid << "\" Id=\"" << str << "\"";
if( obj->m_deleted )
! ofs << " deleted=\"true\"";
// write pointers, attributes
***************
*** 3568,3584 ****
bool spec_attr = spec_care && (attribToken == "StrValue" || attribToken == "RegNodeValue" || attribToken == "Comment");
- string encodedAttrVal;
- encodeXMLString( attrVal, encodedAttrVal );
-
if( spec_attr) // spec_care is also true
spec_value = attrVal; // store the (possibly multiline) original value, without encoding
else // regular dump:
! fprintf(file, " %S=\"%s\"", attribToken, encodedAttrVal.c_str() );
}
}
! fprintf(file, ">" );
if( spec_care) // right after the element, without whitespace, (in sync with readObject())
! fprintf(file, "<![CDATA[%s%s]]>", spec_preamble.c_str(), spec_value.c_str()); // encoding not needed since it goes to CDATA
! fprintf(file, "\n" );
--- 3562,3585 ----
bool spec_attr = spec_care && (attribToken == "StrValue" || attribToken == "RegNodeValue" || attribToken == "Comment");
if( spec_attr) // spec_care is also true
spec_value = attrVal; // store the (possibly multiline) original value, without encoding
else // regular dump:
! ofs << " " << attribToken << "=\"" << Transcoder::StdEscape << attrVal << Transcoder::NoEscape << "\"";
}
}
! ofs << Transcoder::NoEscape << ">";
if( spec_care) // right after the element, without whitespace, (in sync with readObject())
! {
! // only a little attention is paid to possbile
! // occurences of ']]>' in the data
! if( spec_value.find( "]]>") != std::string::npos)
! {
! sendMsg( "Special character string ']]>' found among one element's properties, will be replaced by ']] >'", MSG_INFO);
! spec_value.replace( spec_value.find( "]]>"), 3, "]] >");
! }
! // encoding not needed since it goes to CDATA
! ofs << "<![CDATA[" << spec_preamble << spec_value << "]]>";
! }
! ofs << "\n";
***************
*** 3602,3606 ****
ASSERT( it3 != m_parentMap.end() );
if( it3->second + ATTRID_COLLECTION == it->first )
! writeObject( obj2, file, false, newPrefix.c_str(), lastWriteTime );
}
}
--- 3603,3607 ----
ASSERT( it3 != m_parentMap.end() );
if( it3->second + ATTRID_COLLECTION == it->first )
! writeObject( obj2, ofs, false, newPrefix.c_str(), lastWriteTime );
}
}
***************
*** 3608,3612 ****
}
! fprintf(file, "%s</%S>\n",prefix, metaToken);
}
--- 3609,3613 ----
}
! ofs << Transcoder::NoEscape << prefix << "</" << metaToken << ">\n";
}
***************
*** 4091,4097 ****
dlg.m_user = m_userOpts.m_useAccountInfo? m_userOpts.m_defUserName.c_str(): "";
dlg.m_password = m_userOpts.m_useAccountInfo? m_userOpts.m_defPassword.c_str(): "";
- //if( p_svnText) dlg.m_text = "Please provide at least your SVN username. Password can be later provided when it is asked by the server.";//You may provide default username/password in case the svn client will face an authentication challenge from the server. In case these are not provided you might be later prompted for the credentials required by the server.";
- //else dlg.m_text = "This project is connected to a SourceSafe database. You have to login to the database to work with this project.";
- //if( p_svnText) dlg.m_database = m_svnUrl.c_str();
// execute DoModal only if one of the booleans below is false
--- 4092,4095 ----
***************
*** 6234,6237 ****
--- 6232,6237 ----
HR_THROW(E_FILEOPEN);
}
+ #if(USESERF) // serf does not like the test below
+ #else
if( isVersionedInSVN( m_svnUrl + "/" + m_projectName, /*isDir = */true, /* suppressErrorMsg = */true))
{
***************
*** 6239,6243 ****
HR_THROW(E_FILEOPEN);
}
!
bool main_created = mkdirSVN( m_svnUrl, m_projectName, m_folderPath);
if( !main_created)
--- 6239,6243 ----
HR_THROW(E_FILEOPEN);
}
! #endif
bool main_created = mkdirSVN( m_svnUrl, m_projectName, m_folderPath);
if( !main_created)
Index: CoreXmlFile.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/XmlBackEnd/CoreXmlFile.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** CoreXmlFile.h 15 Feb 2008 21:06:43 -0000 1.11
--- CoreXmlFile.h 18 Feb 2008 20:13:56 -0000 1.12
***************
*** 16,19 ****
--- 16,20 ----
#include "OperOptions.h"
#include "MsgConsole.h"
+ #include "Transcoder.h"
const metaobjidpair_type ROOT_ID_PAIR = {METAID_ROOT, OBJID_ROOT};
***************
*** 616,620 ****
void writeXMLFile (XmlObject * container);
! void writeObject (XmlObject * obj, FILE * file, bool container, const char * prefix, CTime lastWriteTime );
void applyLastWrTime (XmlObject * obj, bool container, CTime lastWriteTime );
--- 617,621 ----
void writeXMLFile (XmlObject * container);
! void writeObject (XmlObject * obj, Transcoder& file, bool container, const char * prefix, CTime lastWriteTime );
void applyLastWrTime (XmlObject * obj, bool container, CTime lastWriteTime );
Index: VSSLoginDlg.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/XmlBackEnd/VSSLoginDlg.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** VSSLoginDlg.cpp 13 Feb 2008 18:54:57 -0000 1.4
--- VSSLoginDlg.cpp 18 Feb 2008 20:13:56 -0000 1.5
***************
*** 39,43 ****
DDX_Text(pDX, IDC_STATIC_DATABASE, m_database);
DDX_Text(pDX, IDC_STATIC_PROJECT, m_project);
- DDX_Text(pDX, IDC_STATIC_WELCOME, m_text);
//}}AFX_DATA_MAP
}
--- 39,42 ----
***************
*** 57,62 ****
{
CDialog::OnInitDialog();
- if( !m_text.IsEmpty())
- SetWindowText("Default credentials to be used");
m_aborted = false;
--- 56,59 ----
Index: VSSLoginDlg.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/XmlBackEnd/VSSLoginDlg.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** VSSLoginDlg.h 13 Feb 2008 18:54:57 -0000 1.4
--- VSSLoginDlg.h 18 Feb 2008 20:13:56 -0000 1.5
***************
*** 24,28 ****
CString m_database;
CString m_project;
- CString m_text;
//}}AFX_DATA
--- 24,27 ----
--- NEW FILE: Transcoder.cpp ---
#include "stdafx.h"
#include "Transcoder.h"
#include <xercesc/util/XMLUniDefs.hpp>
static const XMLCh gXMLDecl1[] =
{
chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l
, chSpace, chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i
, chLatin_o, chLatin_n, chEqual, chDoubleQuote, chDigit_1, chPeriod
, chDigit_0, chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
, chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
, chDoubleQuote, chNull
}; // = `<?xml version="1.0" encoding="`
static const XMLCh gXMLDecl2[] =
{
chDoubleQuote, chQuestion, chCloseAngle
, chLF, chNull
}; // = `"?>LF`
// ---------------------------------------------------------------------------
// Transcoder: Constructors and Destructor
// ---------------------------------------------------------------------------
Transcoder::Transcoder()
: m_pFormatter(0)
{
}
Transcoder::~Transcoder()
{
if ( m_pFormatter)
{
delete m_pFormatter;
m_pFormatter = 0;
}
if ( is_open()) close();
}
void Transcoder::init( const char * f, const char * const encodingName)
{
ASSERT( !m_pFormatter);
XMLPlatformUtils::Initialize();
m_pFormatter = new XMLFormatter
(
encodingName
, 0
, this
, XMLFormatter::NoEscapes
, XMLFormatter::UnRep_CharRef
);
ASSERT( !is_open() );
open( f, std::ios::out | std::ios::trunc);
if( fail() || !is_open() )
HR_THROW(E_INVALID_FILENAME);
*m_pFormatter << gXMLDecl1 << m_pFormatter->getEncodingName() << gXMLDecl2; //will dump '<?xml version="1.0" encoding="UTF-8"?>
}
void Transcoder::finalize()
{
delete m_pFormatter;
m_pFormatter = 0;
close();
XMLPlatformUtils::Terminate();
}
Transcoder&
Transcoder::operator <<( Modes mode)
{
if ( mode == NoEscape)
*m_pFormatter << XMLFormatter::NoEscapes;
else if ( mode == StdEscape)
*m_pFormatter << XMLFormatter::StdEscapes;
return *this;
}
Transcoder&
Transcoder::operator <<( metaid_type toWrite)
{
std::ofstream::operator<<( toWrite);
return *this;
}
Transcoder&
Transcoder::operator <<( const XMLCh* const toWrite)
{
*m_pFormatter << toWrite;
return *this;
}
Transcoder&
Transcoder::operator <<( const char * const toWrite)
{
XMLCh * fUnicodeForm = XMLString::transcode( toWrite);
Transcoder::operator<<( fUnicodeForm);
delete fUnicodeForm;
return *this;
}
Transcoder&
Transcoder::operator <<( const char toWrite)
{
char tmp[2] = { toWrite, 0 };
Transcoder::operator<<( tmp);
return *this;
}
Transcoder&
Transcoder::operator <<( const std::string& toWrite)
{
Transcoder::operator<<( toWrite.c_str());
return *this;
}
// ---------------------------------------------------------------------------
// Transcoder: Overrides of the output formatter target interface
// ---------------------------------------------------------------------------
void Transcoder::writeChars(const XMLByte* const toWrite,
const unsigned int count,
XMLFormatter* const formatter)
{
ASSERT( sizeof( XMLByte) == sizeof( char));
write( (const char * const)toWrite, count);//zolmol: cast from const unsigned char * const
}
bool Transcoder::isOpen()
{
return is_open();
}
More information about the GME-commit
mailing list