lsimpl.cpp revision fd81cca9448f3ec45db258eb73b8de41f301e4e1
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Phoebe DOM Implementation.
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This is a C++ approximation of the W3C DOM model, which follows
c869993e79c1eafbec61a56bf6cea848fe754c71xy * fairly closely the specifications in the various .idl files, copies of
c869993e79c1eafbec61a56bf6cea848fe754c71xy * which are provided for reference. Most important is this one:
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Authors:
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Bob Jamison
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Copyright (C) 2005-2007 Bob Jamison
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This library is free software; you can redistribute it and/or
c869993e79c1eafbec61a56bf6cea848fe754c71xy * modify it under the terms of the GNU Lesser General Public
c869993e79c1eafbec61a56bf6cea848fe754c71xy * License as published by the Free Software Foundation; either
c869993e79c1eafbec61a56bf6cea848fe754c71xy * version 2.1 of the License, or (at your option) any later version.
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * This library is distributed in the hope that it will be useful,
c869993e79c1eafbec61a56bf6cea848fe754c71xy * but WITHOUT ANY WARRANTY; without even the implied warranty of
c869993e79c1eafbec61a56bf6cea848fe754c71xy * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Lesser General Public License for more details.
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * You should have received a copy of the GNU Lesser General Public
c869993e79c1eafbec61a56bf6cea848fe754c71xy * License along with this library; if not, write to the Free Software
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include "domimpl.h"
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include "events.h"
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include "traversal.h"
fa25784ca4b51c206177d891a654f1d36a25d41fxy#include "lsimpl.h"
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <stdarg.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xynamespace org
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xynamespace w3c
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xynamespace dom
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xynamespace ls
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*#########################################################################
c869993e79c1eafbec61a56bf6cea848fe754c71xy## LSParserImpl
c869993e79c1eafbec61a56bf6cea848fe754c71xy#########################################################################*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xybool LSParserImpl::getBusy()
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy return false;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xyDocumentPtr LSParserImpl::parse(const LSInput &input)
c869993e79c1eafbec61a56bf6cea848fe754c71xy throw(dom::DOMException, LSException)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#### Check the various inputs of 'input' in order, according
c869993e79c1eafbec61a56bf6cea848fe754c71xy //# to the L&S spec
c869993e79c1eafbec61a56bf6cea848fe754c71xy LSReader *lsreader = input.getCharacterStream();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (lsreader)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy DOMString buf;
c869993e79c1eafbec61a56bf6cea848fe754c71xy while (true)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy int ch = lsreader->get();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (ch < 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy buf.push_back((XMLCh)ch);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy XmlReader reader;
c869993e79c1eafbec61a56bf6cea848fe754c71xy DocumentPtr doc = reader.parse(buf);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return doc;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
fa25784ca4b51c206177d891a654f1d36a25d41fxy
c869993e79c1eafbec61a56bf6cea848fe754c71xy LSInputStream *inputStream = input.getByteStream();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (inputStream)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy DOMString buf;
c869993e79c1eafbec61a56bf6cea848fe754c71xy while (true)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy int ch = inputStream->get();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (ch < 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy buf.push_back((XMLCh)ch);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy XmlReader reader;
c869993e79c1eafbec61a56bf6cea848fe754c71xy DocumentPtr doc = reader.parse(buf);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return doc;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy DOMString stringData = input.getStringData();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (stringData.size() > 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy XmlReader reader;
c869993e79c1eafbec61a56bf6cea848fe754c71xy DocumentPtr doc = reader.parse(stringData);
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl return doc;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl }
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl DOMString systemId = input.getSystemId();
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl if (systemId.size() > 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy //lets not do this yet
c869993e79c1eafbec61a56bf6cea848fe754c71xy return NULL;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy DOMString publicId = input.getPublicId();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (publicId.size() > 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy //lets not do this yet
c869993e79c1eafbec61a56bf6cea848fe754c71xy return NULL;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy return NULL;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xyDocumentPtr LSParserImpl::parseURI(const DOMString &/*uri*/)
c869993e79c1eafbec61a56bf6cea848fe754c71xy throw(dom::DOMException, LSException)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy return NULL;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy /**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xyNodePtr LSParserImpl::parseWithContext(const LSInput &/*input*/,
c869993e79c1eafbec61a56bf6cea848fe754c71xy const NodePtr /*contextArg*/,
c869993e79c1eafbec61a56bf6cea848fe754c71xy unsigned short /*action*/)
c869993e79c1eafbec61a56bf6cea848fe754c71xy throw(dom::DOMException, LSException)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy return NULL;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy//##################
c869993e79c1eafbec61a56bf6cea848fe754c71xy//# Non-API methods
c869993e79c1eafbec61a56bf6cea848fe754c71xy//##################
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*#########################################################################
c869993e79c1eafbec61a56bf6cea848fe754c71xy## LSSerializerImpl
c869993e79c1eafbec61a56bf6cea848fe754c71xy#########################################################################*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xybool LSSerializerImpl::write(
c869993e79c1eafbec61a56bf6cea848fe754c71xy const NodePtr nodeArg,
c869993e79c1eafbec61a56bf6cea848fe754c71xy const LSOutput &destination)
c869993e79c1eafbec61a56bf6cea848fe754c71xy throw (LSException)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf = "";
c869993e79c1eafbec61a56bf6cea848fe754c71xy indent = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy writeNode(nodeArg);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //## Check in order specified in the L&S specs
c869993e79c1eafbec61a56bf6cea848fe754c71xy LSWriter *writer = destination.getCharacterStream();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (writer)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (unsigned int i=0 ; i<outbuf.size() ; i++)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy int ch = outbuf[i];
c869993e79c1eafbec61a56bf6cea848fe754c71xy writer->put(ch);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy return true;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy LSOutputStream *outputStream = destination.getByteStream();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (outputStream)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (unsigned int i=0 ; i<outbuf.size() ; i++)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy int ch = outbuf[i];
c869993e79c1eafbec61a56bf6cea848fe754c71xy writer->put(ch);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy return true;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy DOMString systemId = destination.getSystemId();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (systemId.size() > 0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy //DO SOMETHING
c869993e79c1eafbec61a56bf6cea848fe754c71xy return true;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy return false;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xybool LSSerializerImpl::writeToURI(const NodePtr nodeArg,
c869993e79c1eafbec61a56bf6cea848fe754c71xy const DOMString &uriArg)
c869993e79c1eafbec61a56bf6cea848fe754c71xy throw(LSException)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf = "";
c869993e79c1eafbec61a56bf6cea848fe754c71xy indent = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy writeNode(nodeArg);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy DOMString uri = uriArg;
c869993e79c1eafbec61a56bf6cea848fe754c71xy char *fileName = (char *) uri.c_str(); //temporary hack
c869993e79c1eafbec61a56bf6cea848fe754c71xy FILE *f = fopen(fileName, "rb");
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (!f)
c869993e79c1eafbec61a56bf6cea848fe754c71xy return false;
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (unsigned int i=0 ; i<outbuf.size() ; i++)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy int ch = outbuf[i];
c869993e79c1eafbec61a56bf6cea848fe754c71xy fputc(ch, f);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy fclose(f);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return false;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xyDOMString LSSerializerImpl::writeToString(const NodePtr nodeArg)
c869993e79c1eafbec61a56bf6cea848fe754c71xy throw(dom::DOMException, LSException)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf = "";
c869993e79c1eafbec61a56bf6cea848fe754c71xy indent = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy writeNode(nodeArg);
c869993e79c1eafbec61a56bf6cea848fe754c71xy return outbuf;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy//##################
c869993e79c1eafbec61a56bf6cea848fe754c71xy//# Non-API methods
c869993e79c1eafbec61a56bf6cea848fe754c71xy//##################
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid LSSerializerImpl::spaces()
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (int i=0 ; i<indent ; i++)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf.push_back(' ');
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid LSSerializerImpl::po(char const *fmt, ...)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy char str[257];
c869993e79c1eafbec61a56bf6cea848fe754c71xy va_list args;
c869993e79c1eafbec61a56bf6cea848fe754c71xy va_start(args, fmt);
c869993e79c1eafbec61a56bf6cea848fe754c71xy vsnprintf(str, 256, fmt, args);
c869993e79c1eafbec61a56bf6cea848fe754c71xy va_end(args) ;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl outbuf.append(str);
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl}
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bglvoid LSSerializerImpl::pos(const DOMString &str)
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl{
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl outbuf.append(str);
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid LSSerializerImpl::poxml(const DOMString &str)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (unsigned int i=0 ; i<str.size() ; i++)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy XMLCh ch = (XMLCh) str[i];
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (ch == '&')
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf.append("&ampr;");
c869993e79c1eafbec61a56bf6cea848fe754c71xy else if (ch == '<')
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf.append("&lt;");
c869993e79c1eafbec61a56bf6cea848fe754c71xy else if (ch == '>')
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf.append("&gt;");
c869993e79c1eafbec61a56bf6cea848fe754c71xy else if (ch == '"')
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf.append("&quot;");
c869993e79c1eafbec61a56bf6cea848fe754c71xy else if (ch == '\'')
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf.append("&apos;");
c869993e79c1eafbec61a56bf6cea848fe754c71xy else
c869993e79c1eafbec61a56bf6cea848fe754c71xy outbuf.push_back(ch);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/**
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid LSSerializerImpl::writeNode(const NodePtr nodeArg)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy NodePtr node = nodeArg;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy int type = node->getNodeType();
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy switch (type)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#############
c869993e79c1eafbec61a56bf6cea848fe754c71xy //# DOCUMENT
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#############
c869993e79c1eafbec61a56bf6cea848fe754c71xy case Node::DOCUMENT_NODE:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy DocumentPtr doc = dynamic_cast<Document *>(node.get());
c869993e79c1eafbec61a56bf6cea848fe754c71xy writeNode(doc->getDocumentElement());
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#############
c869993e79c1eafbec61a56bf6cea848fe754c71xy //# TEXT
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#############
c869993e79c1eafbec61a56bf6cea848fe754c71xy case Node::TEXT_NODE:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy poxml(node->getNodeValue());
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#############
c869993e79c1eafbec61a56bf6cea848fe754c71xy //# CDATA
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#############
c869993e79c1eafbec61a56bf6cea848fe754c71xy case Node::CDATA_SECTION_NODE:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy pos("<![CDATA[");
c869993e79c1eafbec61a56bf6cea848fe754c71xy poxml(node->getNodeValue());
c869993e79c1eafbec61a56bf6cea848fe754c71xy pos("]]>");
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#############
c869993e79c1eafbec61a56bf6cea848fe754c71xy //# ELEMENT
c869993e79c1eafbec61a56bf6cea848fe754c71xy //#############
c869993e79c1eafbec61a56bf6cea848fe754c71xy case Node::ELEMENT_NODE:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl indent+=2;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl NamedNodeMap attributes = node->getAttributes();
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl int nrAttrs = attributes.getLength();
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //### Start open tag
c869993e79c1eafbec61a56bf6cea848fe754c71xy spaces();
c869993e79c1eafbec61a56bf6cea848fe754c71xy po("<");
c869993e79c1eafbec61a56bf6cea848fe754c71xy pos(node->getNodeName());
c869993e79c1eafbec61a56bf6cea848fe754c71xy //if (nrAttrs>0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy // pos(newLine);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //### Attributes
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (int i=0 ; i<nrAttrs ; i++)
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy NodePtr attr = attributes.item(i);
c869993e79c1eafbec61a56bf6cea848fe754c71xy spaces();
c869993e79c1eafbec61a56bf6cea848fe754c71xy pos(attr->getNodeName());
c869993e79c1eafbec61a56bf6cea848fe754c71xy po("=\"");
c869993e79c1eafbec61a56bf6cea848fe754c71xy pos(attr->getNodeValue());
c869993e79c1eafbec61a56bf6cea848fe754c71xy po("\"");
c869993e79c1eafbec61a56bf6cea848fe754c71xy //pos(newLine);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //### Finish open tag
c869993e79c1eafbec61a56bf6cea848fe754c71xy //if (nrAttrs>0)
c869993e79c1eafbec61a56bf6cea848fe754c71xy // spaces();
c869993e79c1eafbec61a56bf6cea848fe754c71xy po(">");
c869993e79c1eafbec61a56bf6cea848fe754c71xy //pos(newLine);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //### Contents
c869993e79c1eafbec61a56bf6cea848fe754c71xy //spaces();
c869993e79c1eafbec61a56bf6cea848fe754c71xy pos(node->getNodeValue());
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //### Children
c869993e79c1eafbec61a56bf6cea848fe754c71xy for (NodePtr child = node->getFirstChild() ;
c869993e79c1eafbec61a56bf6cea848fe754c71xy child.get() ;
c869993e79c1eafbec61a56bf6cea848fe754c71xy child=child->getNextSibling())
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy writeNode(child);
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy //### Close tag
c869993e79c1eafbec61a56bf6cea848fe754c71xy //spaces();
c869993e79c1eafbec61a56bf6cea848fe754c71xy po("</");
c869993e79c1eafbec61a56bf6cea848fe754c71xy pos(node->getNodeName());
c869993e79c1eafbec61a56bf6cea848fe754c71xy po(">");
c869993e79c1eafbec61a56bf6cea848fe754c71xy pos(newLine);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy indent-=2;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy }//switch
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy} //namespace ls
c869993e79c1eafbec61a56bf6cea848fe754c71xy} //namespace dom
c869993e79c1eafbec61a56bf6cea848fe754c71xy} //namespace w3c
c869993e79c1eafbec61a56bf6cea848fe754c71xy} //namespace org
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*#########################################################################
c869993e79c1eafbec61a56bf6cea848fe754c71xy## E N D O F F I L E
c869993e79c1eafbec61a56bf6cea848fe754c71xy#########################################################################*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy