XMLmind XML Editor - Developer's Guide

Hussein Shafie

Pixware

91 rue Gambetta,
78120 Rambouillet,
France,
Phone: +33 (0)1 30 59 81 44,
Web: www.xmlmind.com/xmleditor
Email:  (public mailing list)

March 29, 2017

Abstract

XMLmind XML Editor (XXE for short) can be customized/extended substantially without having to write a single line of code. However there are some cases where programming against the Java™ API of XXE becomes inevitable. This document covers all the extension points of XXE, from writing advanced configurations to extending the GUI of XXE. Moreover, it also explains how to embed an advanced XML editor based on XXE your Java™ application. For experienced Java™ programmers only.


Table of Contents

1. Introduction
1. What you'll learn
2. Best practices
3. Compiling and running the code samples
I. Extending XMLmind XML Editor
2. Programming the Document Object Model
1. The sample program
2. Compiling and running the sample program
3. Names and Namespaces
4. Document nodes
5. Document traversal
6. Loading and saving a document
7. XML node properties
3. Using XPath
1. The two implementations of XPath contained in XMLmind XML Editor
2. Compiling and running the sample program
3. Compiling and evaluating an XPath expression
3.1. XNode
3.2. Two steps: parse and evaluate
3.3. ExprContext
4. XPath value types
4.1. evalAsNumber
4.2. evalAsBoolean
4.3. evalAsNodeSet
4.4. evalAsVariant
5. Matching a node against an XPath pattern
4. Writing a command
1. Compiling and running the code sample
2. What is a command?
2.1. The CommandBase base class.
3. A sample command: ConvertCaseCmd
3.1. First step: prepare
3.2. Second step: execute
3.3. Reporting errors from commands
5. More commands
1. Highlighting text
1.1. Marks other than dot, mark, selected and selected2
1.2. Description of prepare
1.3. Step by step description of execute
2. A validating command
2.1. ElementEditor
2.2. Step by step description of prepare
2.3. Step by step description of execute
3. How to avoid writing a validating command
3.1. Delegating node insertion to the ubiquitous Paste command
3.2. Step by step description of prepare
3.3. Step by step description of execute
4. Recordable commands
6. Writing a validateHook
1. What is a validation hook?
2. Compiling and running the code sample
3. Implementing the ValidateHook interface
7. Writing a custom attribute editor
1. What is a custom attribute editor?
2. Compiling and running the code sample
3. A custom editor for the bgcolor attribute
8. Writing style sheet extensions
1. The problem
2. The solution
2.1. Solution of problem #1: invoke a custom method computing a CSS property value
2.1.1. The StyleSheetExtension class
2.1.2. The localize method
2.2. Solution of problem #2: implement a StyleSpecs which knows how to style nested emphasis elements
2.2.1. The implementation of interface StyleSpecs
2.3. Solution of problem #3: invoke a custom method computing the number of a listitem and use a BasicElementObserver to update orderedlists when needed to
2.3.1. Interface BasicElementObserver
2.3.2. The implementation of interface BasicElementObserver
2.4. Solution of problem #4: implement an AttributeValueEditor
2.4.1. Passive custom views
2.4.2. Active custom views: specialized editors embedded in the DocumentView
3. Compiling and testing the sample style sheet extensions
9. Extending the GUI of XMLmind XML Editor
1. A framework for creating XML editors
2. High-level building blocks
3. Compiling and running the code sample
4. A custom About dialog box
5. A custom tool which counts the words found in the active document
5.1. How to count words in an XML document?
5.2. Best strategy
5.3. The word counter tool
6. A custom preferences sheet which parametrizes the word counter
10. Writing a plug-in
1. What is a plug-in?
2. Steps needed to write, package and deploy a plug-in
11. Packaging an add-on for XMLmind XML Editor integrated add-on manager
1. Why packaging add-ons?
2. Creating useful add-on descriptors
II. Embedding an advanced XML editor based on XXE in your Java™ application
12. Creating a self-contained xxe.jar file
1. Using deployxxe to create a a self-contained xxe.jar file
2. Optional JAR files
13. Adding an XML editor to your application
1. Compiling and running the code sample
2. A multi-document, multi-view, XML editor contained in JFrame
3. A single-document, single-view, XML editor contained in a JPanel
4. Being notified when the user edit documents using the XML editor
5. Instructing the XML editor to perform an action
14. More control over the embedded XML editor
1. Embedding the equivalent of the desktop application
2. Under the hood
3. Deriving your own class from a subclass of App
III. A lightweight XML Editor based on XXE components
15. A simple XML editor
1. Compiling and running the code sample
2. Assembling the GUI
3. The NodePath component
3.1. What is a NodePath?
3.2. Using the NodePath to trigger Commands
3.3. Using menus and tool bars to trigger Commands
4. Loading a document
4.1. Opening a document
4.2. Closing a document
5. Updating the GUI
5.1. Enabling and disabling menu items
5.2. Being notified when the document is modified
5.3. Being notified when the editing context changes
6. Saving a document
7. Validating a document
8. Printing a document
16. The Style menu of SimpleEditor
1. Populating the Style menu with items
2. StyleSheetInfo
3. Changing the style sheet of a StyledDocumentView

List of Figures

1.1. The Create Project wizard
8.1. A message having a xml:lang="fr" attribute
8.2. In the three following paragraphs, nested emphasis elements (containing words "nested emphasis text") are displayed using a non-italic font
8.3. Two orderedlists, the second one having a continuation="continues" attribute
8.4. Four smiley elements represented by four comboboxes
13.1. The main window of the "EmbedDemo" code sample
13.2. An XMLPanel
13.3. An XMLPanel2
15.1. SimpleEditor
15.2. NodePath
15.3. Edit popup menu
15.4. PreferredPrefixDialog
15.5. AttributeTool
15.6. DiagnosticsTool
16.1. Style menu

List of Tables

13.1. App “services”