uristream.cpp revision 8a6cdb1b534b7b6101222bcf53d47465a0bd7a91
/**
* Phoebe DOM Implementation.
*
* This is a C++ approximation of the W3C DOM model, which follows
* fairly closely the specifications in the various .idl files, copies of
* which are provided for reference. Most important is this one:
*
*
* Authors:
* Bob Jamison
*
* Copyright (C) 2005 Bob Jamison
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Our base String stream classes. We implement these to
* be based on DOMString
*
* Authors:
* Bob Jamison <rjamison@titan.com>
*
* Copyright (C) 2004 Inkscape.org
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "uristream.h"
namespace org
{
namespace w3c
{
namespace dom
{
namespace io
{
//#########################################################################
//# U R I I N P U T S T R E A M / R E A D E R
//#########################################################################
/**
*
*/
{
init();
}
/**
*
*/
{
//get information from uri
switch (scheme)
{
case URI::SCHEME_FILE:
{
if (!inf)
{
throw StreamException(err);
}
break;
}
case URI::SCHEME_DATA:
{
//printf("in data:'%s'\n", data);
dataPos = 0;
break;
}
case URI::SCHEME_HTTP:
case URI::SCHEME_HTTPS:
{
{
throw StreamException(err);
}
break;
}
}
closed = false;
}
/**
*
*/
{
close();
}
/**
* Returns the number of bytes that can be read (or skipped over) from
* this input stream without blocking by the next caller of a method for
* this input stream.
*/
{
return 0;
}
/**
* Closes this input stream and releases any system resources
* associated with the stream.
*/
{
if (closed)
return;
switch (scheme)
{
case URI::SCHEME_FILE:
{
if (!inf)
return;
break;
}
case URI::SCHEME_DATA:
{
//do nothing
break;
}
case URI::SCHEME_HTTP:
case URI::SCHEME_HTTPS:
{
httpClient.close();
break;
}
}//switch
closed = true;
}
/**
* Reads the next byte of data from the input stream. -1 if EOF
*/
{
int retVal = -1;
if (closed)
{
return -1;
}
switch (scheme)
{
case URI::SCHEME_FILE:
{
{
retVal = -1;
}
else
{
}
break;
}
case URI::SCHEME_DATA:
{
{
retVal = -1;
}
else
{
}
break;
}
case URI::SCHEME_HTTP:
case URI::SCHEME_HTTPS:
{
break;
}
}//switch
return retVal;
}
/**
*
*/
{
}
/**
*
*/
{
delete inputStream;
}
/**
*
*/
{
return inputStream->available();
}
/**
*
*/
{
inputStream->close();
}
/**
*
*/
{
return ch;
}
//#########################################################################
//# U R I O U T P U T S T R E A M / W R I T E R
//#########################################################################
/**
*
*/
throw (StreamException): closed(false),
ownsFile(true),
{
init();
}
/**
*
*/
{
//get information from uri
//printf("out schemestr:'%s' scheme:'%d'\n", schemestr, scheme);
switch (scheme)
{
case URI::SCHEME_FILE:
{
//printf("out path:'%s'\n", cpath);
if (!outf)
{
throw StreamException(err);
}
break;
}
case URI::SCHEME_DATA:
{
data = "data:";
break;
}
}//switch
}
/**
*
*/
{
close();
}
/**
* Closes this output stream and releases any system resources
* associated with this stream.
*/
{
if (closed)
return;
switch (scheme)
{
case URI::SCHEME_FILE:
{
if (!outf)
return;
if ( ownsFile )
break;
}
case URI::SCHEME_DATA:
{
break;
}
}//switch
closed = true;
}
/**
* Flushes this output stream and forces any buffered output
* bytes to be written out.
*/
{
if (closed)
return;
switch (scheme)
{
case URI::SCHEME_FILE:
{
if (!outf)
return;
break;
}
case URI::SCHEME_DATA:
{
//nothing
break;
}
}//switch
}
/**
* Writes the specified byte to this output stream.
*/
{
if (closed)
return -1;
switch (scheme)
{
case URI::SCHEME_FILE:
{
if (!outf)
return -1;
//fwrite(uch, 1, 1, outf);
break;
}
case URI::SCHEME_DATA:
{
break;
}
}//switch
return 1;
}
/**
*
*/
throw (StreamException)
{
}
/**
*
*/
{
delete outputStream;
}
/**
*
*/
{
outputStream->close();
}
/**
*
*/
{
outputStream->flush();
}
/**
*
*/
{
return -1;
return 1;
}
} //namespace io
} //namespace dom
} //namespace w3c
} //namespace org
//#########################################################################
//# E N D O F F I L E
//#########################################################################