repr-io.cpp revision b4eef97ac778907224e9fbe78323a55c669f4e5f
/*
* Dirty DOM-like tree
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <cstring>
#include <string>
#include <stdexcept>
#include "xml/attribute-record.h"
#include "xml/rebase-hrefs.h"
#include "xml/simple-document.h"
#include "xml/text-node.h"
#include "io/uristream.h"
#include "io/stringstream.h"
#include "io/gzipstream.h"
#include "extension/extension.h"
#include "attribute-rel-util.h"
#include "preferences.h"
#include <glibmm/miscutils.h>
static Node *sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map);
static gint sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar *default_ns, GHashTable *prefix_map);
int inlineattrs, int indent,
gchar const *old_href_abs_base,
gchar const *new_href_abs_base);
int inlineattrs, int indent,
gchar const *old_href_abs_base,
gchar const *new_href_abs_base);
#ifdef HAVE_LIBWMF
static char * sp_wmf_image_name (void * context);
#endif /* HAVE_LIBWMF */
class XmlSource
{
public:
: filename(0),
encoding(0),
fp(0),
firstFewLen(0),
dummy("x"),
instr(0),
gzin(0)
{
for (int k=0;k<4;k++)
{
firstFew[k]=0;
}
}
virtual ~XmlSource()
{
close();
if ( encoding ) {
encoding = 0;
}
}
bool SystemCheck; // Checks for SYSTEM Entities
char const* getEncoding() const { return encoding; }
int close();
private:
const char* filename;
char* encoding;
unsigned char firstFew[4];
int firstFewLen;
};
{
int retVal = -1;
this->SystemCheck = false;
if ( fp ) {
// First peek in the file to see what it is
if ( fp ) {
// first check for compression
//g_message(" the file being read is gzip'd. extract it");
fp = 0;
some = 0;
int single = 0;
{
if ( single >= 0 ) {
} else {
break;
}
}
}
int encSkip = 0;
encSkip = 2;
encSkip = 2;
} else if ( (some >= 3) && (firstFew[0] == 0xef) && (firstFew[1] == 0xbb) && (firstFew[2] == 0xbf) ) {
encSkip = 3;
}
if ( encSkip ) {
}
firstFewLen = some;
retVal = 0; // no error
}
}
return retVal;
}
{
}
{
int retVal = -1;
if ( context ) {
if(self->SystemCheck) {
// Check for ENTITY SYSTEM cdata and kill with fire, does
// Break svg files who use entities for ns and system entities.
"<!ENTITY\\s+[^>\\s]+\\s+SYSTEM\\s+\"[^>\"]+\"\\s*>",
}
}
return retVal;
}
{
if ( context ) {
}
return 0;
}
{
int retVal = 0;
if ( firstFewLen > 0 ) {
if ( len < firstFewLen ) {
}
firstFewLen -= some;
} else if ( gzin ) {
int single = 0;
{
if ( single >= 0 ) {
} else {
break;
}
}
} else {
}
retVal = -1;
} else {
}
return retVal;
}
{
if ( gzin ) {
delete gzin;
gzin = 0;
}
if ( instr ) {
fp = 0;
delete instr;
instr = 0;
}
if ( fp ) {
fp = 0;
}
return 0;
}
/**
* Reads XML from a file, including WMF files, and returns the Document.
* The default namespace can also be specified, if desired.
*/
{
// g_warning( "Reading file: %s", filename );
/* fixme: A file can disappear at any time, including between now and when we actually try to
* open it. Get rid of the above test once we're sure that we correctly handle
* non-existence. */
// TODO: bulia, please look over
gsize bytesWritten = 0;
// TODO: need to replace with our own fopen and reading
#ifdef HAVE_LIBWMF
}
}
#endif // !HAVE_LIBWMF
if ( !doc ) {
// For some reason, failed ns loading results in this
// We try a system check version of load with NOENT for adobe
xmlFreeDoc( doc );
src.SystemCheck = true;
}
}
}
if ( doc ) {
xmlFreeDoc( doc );
}
if ( localFilename ) {
g_free( localFilename );
}
return rdoc;
}
/**
* Reads and parses XML from a buffer, returning it as an Document
*/
{
if (doc) {
xmlFreeDoc (doc);
}
return rdoc;
}
/**
* Reads and parses XML from a buffer, returning it as an Document
*/
{
}
namespace Inkscape {
struct compare_quark_ids {
}
};
}
namespace {
static PrefixMap prefix_map;
} else {
if (prefix_end) {
return prefix;
} else {
return GQuark(0);
}
}
}
}
namespace {
}
}
}
}
}
/**
* Reads in a XML file to create a Document
*/
{
return NULL;
}
return NULL;
}
if (!root) {
} else {
break;
}
}
}
/* promote elements of some XML documents that don't use namespaces
* into their default namespace */
}
}
}
// Clean unnecessary attributes and style properties from SVG documents. (Controlled by
// preferences.) Note: internal Inkscape svg files will also be cleaned (filters.svg,
// icons.svg). How can one tell if a file is internal?
if( clean ) {
}
}
}
return rdoc;
}
gint sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar */*default_ns*/, GHashTable *prefix_map)
{
if (ns){
prefix = reinterpret_cast<const xmlChar*>( sp_xml_ns_uri_prefix(reinterpret_cast<const gchar*>(ns->href),
}
else {
}
}
else {
}
if (prefix) {
} else {
}
}
static Node *sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map)
{
gchar c[256];
return NULL; // empty text node
}
xmlChar *p;
; // skip all whitespace
if (!(*p)) { // this is an all-whitespace node, and preserve == default
return NULL; // we do not preserve all-whitespace nodes unless we are asked to
}
// We keep track of original node type so that CDATA sections are preserved on output.
}
}
}
return NULL;
}
/* TODO remember node->ns->prefix if node->ns != NULL */
/* TODO remember prop->ns->prefix if prop->ns != NULL */
}
}
}
if (crepr) {
}
}
return repr;
}
gchar const *default_ns,
gchar const *old_href_abs_base,
gchar const *new_href_abs_base)
{
/* fixme: do this The Right Way */
if (str) {
}
{
} else {
}
}
}
}
{
return buf;
}
gchar const *const old_href_abs_base,
gchar const *const new_href_abs_base)
{
Inkscape::IO::OutputStreamWriter *out = compress ? new Inkscape::IO::OutputStreamWriter( *gout ) : new Inkscape::IO::OutputStreamWriter( bout );
delete out;
delete gout;
}
/**
* Returns true if file successfully saved.
*
* \param filename The actual file to do I/O to, which might be a temp file.
*
* \param for_filename The base URI [actually filename] to assume for purposes of rewriting
* xlink:href attributes.
*/
{
if (!filename) {
return false;
}
bool compress;
{
}
return false;
}
if (for_filename) {
} else {
}
/* effic: Once we're confident that we never need (or never want) to resort
* to using sodipodi:absref instead of the xlink:href value,
* then we should do `if streq() { free them and set both to NULL; }'. */
}
sp_repr_save_stream(doc, file, default_ns, compress, old_href_abs_base.c_str(), new_href_abs_base.c_str());
return false;
}
return true;
}
/**
* Returns true iff file successfully saved.
*/
{
}
/* (No doubt this function already exists elsewhere.) */
{
if (val) {
switch (*val) {
}
}
}
}
static void repr_write_comment( Writer &out, const gchar * val, bool addWhitespace, gint indentLevel, int indent )
{
if ( indentLevel > 16 ) {
indentLevel = 16;
}
if (addWhitespace && indent) {
for (gint i = 0; i < indentLevel; i++) {
}
}
}
// WARNING out.printf() and out.writeString() are *NOT* non-ASCII friendly.
if (val) {
}
} else {
}
if (addWhitespace) {
}
}
namespace {
typedef std::map<Glib::QueryQuark, Inkscape::Util::ptr_shared<char>, Inkscape::compare_quark_ids> NSMap;
static LocalNameMap local_name_map;
} else {
if (prefix_end) {
return prefix_end + 1;
} else {
return name_string;
}
}
}
if (uri) {
} else if ( prefix != xml_prefix ) {
}
} else {
}
}
}
{
}
}
{
}
}
}
}
int inlineattrs, int indent,
gchar const *const old_href_base,
gchar const *const new_href_base)
{
// Clean unnecessary attributes and stype properties. (Controlled by preferences.)
}
{
if ( prefix != xml_prefix ) {
if ( elide_prefix == prefix ) {
}
}
} else {
// if there are non-namespaced elements, we can't globally
// use a default namespace
elide_prefix = GQuark(0);
}
}
}
int inlineattrs, int indent,
gchar const *const old_href_base,
gchar const *const new_href_base)
{
// Preserve CDATA sections, not converting '&' to &, etc.
} else {
}
break;
}
break;
}
break;
}
repr->attributeList(),
break;
}
break;
}
default: {
}
}
}
int inlineattrs, int indent,
gchar const *old_href_base,
gchar const *new_href_base )
{
bool loose = false;
if ( indent_level > 16 ) {
indent_level = 16;
}
if (add_whitespace && indent) {
for (gint i = 0; i < indent_level; i++) {
}
}
}
gchar const *element_name;
} else {
}
// if this is a <text> element, suppress formatting whitespace
// for its content and children:
add_whitespace = false;
}
// THIS DOESN'T APPEAR TO DO ANYTHING. Can it be commented out or deleted?
{
//gchar const *xxAbsref = 0;
//} else if ( ai->key == absref_key ) {
//xxAbsref = ai->value;
}
}
// Might add a special case for absref but no href.
//g_message("href rebase test with [%s] and [%s]", xxHref, xxAbsref);
//std::string newOne = rebase_href_attrs( old_href_base, new_href_base, xxHref, xxAbsref );
}
}
{
if (!inlineattrs) {
if (indent) {
}
}
}
}
}
break;
}
}
if (repr->firstChild()) {
if (loose && add_whitespace) {
}
}
for (gint i = 0; i < indent_level; i++) {
}
}
}
} else {
}
// text elements cannot nest, so we can output newline
// after closing text
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :