33
33
import org.xml.sax.helpers.DefaultHandler;
35
35
import org.scilab.modules.helptools.external.ExternalXMLHandler;
36
import org.scilab.modules.helptools.external.HTMLScilabHandler;
38
39
* Class the convert a DocBook xml file
41
42
public class DocbookTagConverter extends DefaultHandler {
43
44
private static final String DOCBOOKURI = "http://docbook.org/ns/docbook";
44
private static final Class[] argsType = new Class[]{Map.class, String.class};
45
private static final Class[] argsType = new Class[] {Map.class, String.class};
46
47
private Map<String, Method> mapMeth = new HashMap();
47
48
private Map<String, ExternalXMLHandler> externalHandlers = new HashMap();
48
49
private List<DocbookTagConverter> converters;
49
50
private final File in;
50
private DocbookElement baseElement = new DocbookElement(null, null);
51
private DocbookElement baseElement = new DocbookElement(null, null, null);
51
52
private Stack<DocbookElement> stack = new Stack();
52
53
private String errors = "";
112
return (String) method.invoke(this, new Object[]{attributes, contents});
113
return (String) method.invoke(this, new Object[] {attributes, contents});
113
114
} catch (IllegalAccessException e) {
114
115
throw new UnhandledDocbookTagException(tag);
115
116
} catch (InvocationTargetException e) {
167
173
* @param tagName the tag name
168
174
* @return true if the contents of the tag must be escaped
170
public boolean isEscapable(String tagName) {
176
public boolean isEscapable(String tagName, String uri) {
226
232
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
227
233
currentFileName = systemId;
234
HTMLScilabHandler.getInstance().resetCompt();
228
235
if (converters != null) {
229
236
for (DocbookTagConverter conv : converters) {
230
237
conv.resolveEntity(publicId, systemId);
240
247
public void startDocument() throws SAXException {
241
stack.push(baseElement.getNewInstance(null, null));
248
stack.push(baseElement.getNewInstance(null, null, null));
242
249
if (converters != null) {
243
250
for (DocbookTagConverter conv : converters) {
244
251
conv.startDocument();
269
276
for (int i = 0; i < len; i++) {
270
277
map.put(attributes.getLocalName(i), attributes.getValue(i));
272
stack.push(baseElement.getNewInstance(localName, map));
279
stack.push(baseElement.getNewInstance(localName, uri, map));
274
281
ExternalXMLHandler h = externalHandlers.get(uri);
279
286
StringBuilder buf = h.startExternalXML(localName, attributes);
280
287
if (buf != null) {
281
DocbookElement elem = baseElement.getNewInstance(localName, null);
288
DocbookElement elem = baseElement.getNewInstance(localName, uri, null);
282
289
elem.setStringBuilder(buf);
283
290
stack.push(elem);
342
349
public void characters(char[] ch, int start, int length) throws SAXException {
343
350
int end = start + length;
345
if (isEscapable(stack.peek().getName())) {
352
if (isEscapable(stack.peek().getName(), stack.peek().getURI())) {
346
353
StringBuilder buf = stack.peek().getStringBuilder();
347
354
int save = start;
348
355
for (int i = start; i < end; i++) {
351
buf.append(ch, save, i - save);
352
buf.append("'");
356
buf.append(ch, save, i - save);
357
buf.append(""");
361
buf.append(ch, save, i - save);
366
buf.append(ch, save, i - save);
371
buf.append(ch, save, i - save);
358
buf.append(ch, save, i - save);
359
buf.append("'");
363
buf.append(ch, save, i - save);
364
buf.append(""");
368
buf.append(ch, save, i - save);
373
buf.append(ch, save, i - save);
378
buf.append(ch, save, i - save);