2012-05-30 00:19:22 +02:00
|
|
|
/***************************************************************************
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
(c) 2012 Adrien Prokopowicz <prokopy@users.sourceforge.net>
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
This program 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; either version 2, or (at your option)
|
|
|
|
any later version.
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
This program 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 this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
#include "CDocument.h"
|
|
|
|
|
|
|
|
#include "gbi.h"
|
|
|
|
#include "document.h"
|
|
|
|
#include "element.h"
|
2012-06-05 23:17:45 +02:00
|
|
|
#include "utils.h"
|
2012-05-30 00:19:22 +02:00
|
|
|
|
|
|
|
#define THIS (static_cast<CDocument*>(_object)->doc)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
BEGIN_METHOD(CDocument_new, GB_STRING fileName)
|
[GB.XML]
OPT : A few compilation optimizations in headers inclusions.
OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems.
OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification).
OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes.
OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list.
OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser).
OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file.
OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text.
OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object.
OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations.
BUG : When loading a document from a file, now correctly releases the file data.
BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results.
git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
|
|
|
|
2012-06-05 23:17:45 +02:00
|
|
|
if(Node::NoInstanciate) return;
|
2012-06-30 00:02:43 +02:00
|
|
|
if(GB.Is(_object, GB.FindClass("HtmlDocument"))) return;//Called as inherited HtmlDocument constructor
|
2012-06-05 23:17:45 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
if(!MISSING(fileName))
|
2012-04-21 00:57:18 +02:00
|
|
|
{
|
2012-05-30 00:19:22 +02:00
|
|
|
THIS = new Document(STRING(fileName), LENGTH(fileName));
|
2012-04-21 00:57:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-30 00:19:22 +02:00
|
|
|
THIS = new Document();
|
2012-04-21 00:57:18 +02:00
|
|
|
}
|
2012-05-30 00:19:22 +02:00
|
|
|
|
|
|
|
THIS->GBObject = (CDocument*)(_object);
|
2012-04-21 00:57:18 +02:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
BEGIN_METHOD_VOID(CDocument_free)
|
|
|
|
|
2012-06-30 00:02:43 +02:00
|
|
|
delete THIS;
|
2012-05-30 00:19:22 +02:00
|
|
|
|
|
|
|
END_METHOD
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
BEGIN_METHOD(CDocument_fromString, GB_STRING content)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-06-05 23:17:45 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
THIS->setContent(STRING(content), LENGTH(content));
|
|
|
|
}
|
|
|
|
catch(XMLParseException &e)
|
|
|
|
{
|
|
|
|
GB.Error(e.what());
|
|
|
|
}
|
[GB.XML]
OPT : A few compilation optimizations in headers inclusions.
OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems.
OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification).
OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes.
OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list.
OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser).
OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file.
OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text.
OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object.
OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations.
BUG : When loading a document from a file, now correctly releases the file data.
BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results.
git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
|
|
|
|
2012-04-21 00:57:18 +02:00
|
|
|
END_METHOD
|
|
|
|
|
2012-06-06 00:38:58 +02:00
|
|
|
BEGIN_METHOD(CDocument_tostring, GB_BOOLEAN indent)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
char *str = 0;
|
|
|
|
size_t len = 0;
|
|
|
|
|
2012-06-06 00:38:58 +02:00
|
|
|
THIS->toGBString(&str, &len, VARG(indent) ? 0 : -1);
|
2012-05-30 00:19:22 +02:00
|
|
|
|
|
|
|
GB.ReturnString(str);
|
2012-04-21 00:57:18 +02:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CDocument_content)
|
|
|
|
|
|
|
|
if(READ_PROPERTY)
|
|
|
|
{
|
2012-05-30 00:19:22 +02:00
|
|
|
char *str = 0;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
THIS->toGBString(&str, &len);
|
|
|
|
|
|
|
|
GB.ReturnString(str);
|
2012-04-21 00:57:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-05 23:17:45 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
THIS->setContent(PSTRING(), PLENGTH());
|
|
|
|
}
|
|
|
|
catch(XMLParseException &e)
|
|
|
|
{
|
|
|
|
GB.Error(e.what());
|
|
|
|
}
|
2012-04-21 00:57:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
BEGIN_PROPERTY(CDocument_root)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
GBI::Return((Node*)(THIS->root));
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
END_PROPERTY
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
BEGIN_METHOD(CDocument_open, GB_STRING fileName)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-06-05 23:17:45 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
THIS->Open(STRING(fileName), LENGTH(fileName));
|
|
|
|
}
|
|
|
|
catch(XMLParseException &e)
|
|
|
|
{
|
|
|
|
GB.Error(e.what());
|
|
|
|
}
|
2012-04-21 00:57:18 +02:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2012-06-06 00:38:58 +02:00
|
|
|
BEGIN_METHOD(CDocument_save, GB_STRING fileName; GB_BOOLEAN indent)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-06-06 00:38:58 +02:00
|
|
|
THIS->save(GB.ToZeroString(ARG(fileName)), VARG(indent));
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
END_METHOD
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-06-25 14:44:15 +02:00
|
|
|
BEGIN_METHOD(CDocument_getElementsByTagName, GB_STRING tagName; GB_INTEGER mode; GB_INTEGER depth;)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
GB_ARRAY array;
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-06-25 14:44:15 +02:00
|
|
|
THIS->getGBElementsByTagName(STRING(tagName), LENGTH(tagName), &array, VARGOPT(mode, GB_STRCOMP_BINARY), VARGOPT(depth, -1));
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
GB.ReturnObject(array);
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
END_METHOD
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-06-25 18:33:14 +02:00
|
|
|
BEGIN_METHOD(CDocument_getElementsByNamespace, GB_STRING name; GB_INTEGER mode; GB_INTEGER depth;)
|
|
|
|
|
|
|
|
GB_ARRAY array;
|
|
|
|
|
|
|
|
THIS->getGBElementsByNameSpace(STRING(name), LENGTH(name), &array, VARGOPT(mode, GB_STRCOMP_BINARY), VARGOPT(depth, -1));
|
|
|
|
|
|
|
|
GB.ReturnObject(array);
|
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
BEGIN_PROPERTY(CDocument_getAll)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
GB_ARRAY array;
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
THIS->getAllElements(&array);
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
GB.ReturnObject(array);
|
2012-04-21 00:57:18 +02:00
|
|
|
|
|
|
|
END_METHOD
|
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
BEGIN_METHOD(CDocument_createElement, GB_STRING tagName)
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
Element *elmt = new Element(STRING(tagName), LENGTH(tagName));
|
2012-06-30 00:02:43 +02:00
|
|
|
Node::NoInstanciate = true;
|
2012-05-30 00:19:22 +02:00
|
|
|
GBI::Return(elmt);
|
2012-06-30 00:02:43 +02:00
|
|
|
Node::NoInstanciate = false;
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
END_METHOD
|
2012-04-21 00:57:18 +02:00
|
|
|
|
|
|
|
GB_DESC CDocumentDesc[] =
|
|
|
|
{
|
[GB.XML]
OPT : A few compilation optimizations in headers inclusions.
OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems.
OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification).
OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes.
OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list.
OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser).
OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file.
OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text.
OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object.
OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations.
BUG : When loading a document from a file, now correctly releases the file data.
BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results.
git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
|
|
|
GB_DECLARE("XmlDocument", sizeof(CDocument)),
|
2012-04-21 00:57:18 +02:00
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
GB_METHOD("_new", "", CDocument_new, "[(FileName)s]"),
|
2012-04-21 00:57:18 +02:00
|
|
|
GB_METHOD("_free", "", CDocument_free, ""),
|
2012-05-30 00:19:22 +02:00
|
|
|
|
|
|
|
GB_METHOD("CreateElement", "XmlElement", CDocument_createElement, "(TagName)s"),
|
2012-04-21 00:57:18 +02:00
|
|
|
GB_PROPERTY_READ("Root", "XmlElement", CDocument_root),
|
2012-05-30 00:19:22 +02:00
|
|
|
GB_PROPERTY_READ("All", "XmlElement[]", CDocument_getAll),
|
2012-06-25 14:44:15 +02:00
|
|
|
GB_METHOD("GetElementsByTagName", "XmlElement[]", CDocument_getElementsByTagName, "(TagName)s[(Mode)i(Depth)i]"),
|
2012-06-25 18:33:14 +02:00
|
|
|
GB_METHOD("GetElementsByNamespace", "XmlElement[]", CDocument_getElementsByNamespace, "(Namespace)s[(Mode)i(Depth)i]"),
|
|
|
|
|
2012-05-30 00:19:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
GB_PROPERTY("Content", "s", CDocument_content),
|
2012-04-21 00:57:18 +02:00
|
|
|
GB_METHOD("FromString", "", CDocument_fromString, "(Data)s"),
|
|
|
|
GB_METHOD("HtmlFromString", "", CDocument_fromString, "(Data)s"),
|
2012-06-06 00:38:58 +02:00
|
|
|
GB_METHOD("ToString", "s", CDocument_tostring, "[(Indent)b]"),
|
2012-05-30 00:19:22 +02:00
|
|
|
|
|
|
|
GB_METHOD("Open", "", CDocument_open, "(FileName)s"),
|
2012-06-06 00:38:58 +02:00
|
|
|
GB_METHOD("Save", "", CDocument_save, "(FileName)s[(Indent)b]"),
|
|
|
|
GB_METHOD("Write", "", CDocument_save, "(FileName)s[(Indent)b]"),
|
2012-05-30 00:19:22 +02:00
|
|
|
|
2012-04-21 00:57:18 +02:00
|
|
|
|
|
|
|
GB_END_DECLARE
|
|
|
|
};
|