Download Firefox: WindowsMac OS X
logo       
Google Custom Search
    AddThis Social Bookmark Button

BXE and DocBook - it works!: msg#00000

Subject: BXE and DocBook - it works!
Hello,

I've recently come across the task to write a DocBook-based wiki. I needed
and WYSIWYG Editor component and hadn't heard of BXE before.
But I found it and was SO happy!!
But then it turned out that the editor could parse simple RelaxNG schemes,
but not the DocBook schema.
There was not much information about that available in the internet and
one posting on the bx-editor-user list.

So I started investigating what could cause this "bug" with BXE and
DocBook and finally made it work.

I've written a small log about the changes I've made. I really hope that
they will be incorporated into future release of BXE.

I'm new to this list and to BXE, so please don't beat me if something is
COMPLETELY wrong.

_________________________________________________________________________

Changes to make BXE support DocBook RelaxNG (and other more complex
grammars as well)

Version of BXE that was used for the modifications:
2.0-dev 200601170330 Rev: 1448

The source code snippets used here are the ones from the
file versions of this revision fetched from SVN

General
------------------------------

The BXE is the only freely available WYSIWYG XML editor. It works great
with simple grammars. But due to the lack of support for *all* elements of
the RelaxNG namespace it fails to parse more complex grammars (like the
DocBook schemes: 4.x - 5.x and Simplified DocBook 1.0 / 1.1).

After two weeks of digging deep into the Javascript code is was possible
to tweak the BXE so that it was able to let me edit a "simplified docbook"
document.


Why only "simplified" DocBook?
------------------------------

Well, the schema file is about 109kb and it takes about 2 sec. to load and
parse it.
If you take a look at the "normal" DocBook schema, which is about 450kb
(as RelaxNG) and split into 5 files, you will soon see that it takes more
than 15 sec. to parse the schema (and you will have to confirm "Yes, the
script can continue, don't stop it now" in Firefox more than once). The
problem is that the schema is completely parsed in the browser.
Maybe the parsing procedure can be optimized one day?!


Changes
------------------------------

a) Changes for supporting more RelaxNG elements
#################################################################

/relaxng/RelaxNG.js

#########################
DocBook starts with a choice!
BXE wasn't expecting a choice element at the start. To make it simple,
we only take the first choice element from the start.

Line: 293, insert:
--
                // The following part was missing in BXE!!
                // A grammar can also allow to start with a choice
                if (startChildren[i].isRelaxNGElement("choice")) {
                        var choiceChilds = startChildren[i].childNodes;
                        var xp = "/rng:grammar/rng:define[@name = '" +
choiceChilds[i].getAttribute("name") + "']/rng:element"
                        startNode = 
this.xmldoc.documentElement.getXPathFirst(xp);
                        break Ende;
                }
--
#########################
DocBook removes all /optional/attribute and /group nodes. That's not good.
At least commenting out this
part didn't cause trouble.
--
Between line 83 and 84 insert: /*
and one line 126 close the comment: */
--

#########################
Add "group" as a RelaxNG element that is being parsed. For the easiness of
the
thing I added group to the "choice" case:

Line 543, insert below:
--
                        case "group":
--

so it's a fallthrough and we have the same node handling as it would be a
choice node.
I'm not sure if this is correct, but it made DocBook work, because its
grammar uses
a lot of group nodes.

#########################

Don't create a node object for empty nodes!! This was the last showstopper
before
the full simplified docbook grammar could be parsed.
Currently an empty node is creating an EmptyVDOM object.
So I've changed this code (line 558/559) :

--
                                this.appendChild( new EmptyVDOM() );
                                this._hasEmpty = true;
--

TO

--
                                this.addEmptyNode();// needed for DocBook 
compatiblity; soeren
--

and added this function to the file /relaxng/EmptyVDOM.js, line 48:

--
NodeVDOM.prototype.addEmptyNode = function() {

        this._hasEmpty = true;

};
--
#########################

In this file (EmptyVDOM.js) I had to wrap a special section into a try/catch
block:

Lines 150/151:

--
                                try {
                                        _attr[i].isValid(ctxt);
                                        _vdomAttr[_attr[i].name] = true;
                                } catch(e) {}
--
#########################

Back to /relaxng/RelaxNG.js NOW!

The ReleaxNG element "notAllowed" was not supported. As a quick and dirty
fix I added it
to the switch clause in RelaxNG.js, before line 561 (   case "data": )

--
                        case "notAllowed":
                                this.appendChild( new NotAllowedVDOM() );
                                this._hasEmpty = true;
                                break;
--

This requires a new class "NotAllowedVDOM".
Add it somewhere in this file. I did it before the line

--
EmptyVDOM.prototype = new NodeVDOM();
--

Add:

--
// Added by soeren
// for DocBook compatibility
NotAllowedVDOM.prototype = new NodeVDOM();

function NotAllowedVDOM(node) {
        this.node = node;
        this.type = "RELAXNG_NOTALLOWED";
        this.nodeName = "RELAXNG_NOTALLOWED";
}

NotAllowedVDOM.prototype.isValid  = function() {
        return false;
}

NotAllowedVDOM.prototype.allowedElements = function() {
        return null;
}
--

#################################

That's it for the first part.

#################################################################

b) Bug fixes

Sorry that I didn't use the bugtracker for now.

#################################
file /js/bxeFunctions.js

Lines 212/213 ( the errors are explained in the comments):
--
                // soeren: must call "cloneNode" on documentElement object
                var doc = bxe_config.xmldoc.documentElement.cloneNode(true);
                // soeren: cannot use doc. here!!
                var res = bxe_config.xmldoc.evaluate("//@__bxe_id", doc, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
--
The same on line 221
Change to
--
                // soeren: cannot use doc. here!!
                res = bxe_config.xmldoc.evaluate("//@__bxe_defaultcontent", 
doc, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
--
#################################
file /js/widget.js

A small thing: Sometimes an XMLNode object has NO vdom property. This
might occur due to
errors while parsing the RelaxNG.

But on line 699 BXE assumes that a vdom property is existant! That's not
good as it
leads to an ugly Javascrpt error.

Change
--
                this.Popup.initTitle(node.XMLNode.vdom.bxeName);
--

TO

--
                if( node.XMLNode.vdom ) {
                        this.Popup.initTitle(node.XMLNode.vdom.bxeName);
                }
                else {
                        this.Popup.initTitle( node.XMLNode.localName );
                }
--

So it uses the local node name for the popup title.

____________________________________________________________________________

That's it for now.

The wiki-style script I'm working on will be a PHP-based plugin for the
content management system Joomla! (also known as Mambo).
It's called "DocBook:Collab".

ciao, Soeren

-- 
The future of eCommerce:
VirtueMart & Joomla!
http://virtuemart.net

-- 
bx-editor-dev mailing list
bx-editor-dev@xxxxxxxxxxxxxxxx
http://lists.bitflux.ch/cgi-bin/listinfo/bx-editor-dev



<Prev in Thread] Current Thread [Next in Thread>