summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoWeblogSelectElement.java
blob: 145b938ecbf26e5063344abb32aab588ea547099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.madore.damlengine;

import java.util.ArrayList;
import org.w3c.dom.*;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSParser;
import org.w3c.dom.ls.LSInput;

public final class TodoWeblogSelectElement extends TodoDefaultElement {

    public static class Factory extends TodoElement.Factory {
	@Override
	public TodoWeblogSelectElement newItem(Element node,
					       Context ctx,
					       TodoItem caller) {
	    return new TodoWeblogSelectElement(node, ctx, caller);
	}
    }

    public TodoWeblogSelectElement(Element node,
				   Context ctx,
				   TodoItem caller) {
	super(node, ctx, caller);
    }

    @Override
    public void handleNodeOnly() {
	if ( ctx.wsc == null ) {
	    throw new IllegalStateException("weblog-select element encountered with no weblog selection state");
	}
	final DOMImplementationLS domi
	    = (DOMImplementationLS)ctx.doc.getImplementation();
	LSParser par = domi.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
	ArrayList<TodoElement> toProcess
	    = new ArrayList<TodoElement>(ctx.wsc.xmlData.size());
	for ( String str : ctx.wsc.xmlData ) {
	    LSInput input = domi.createLSInput();
	    input.setStringData(str);
	    // Xerces2 does not implement parseWithContext() :-(
	    // Node newNode = par.parseWithContext(input, node,
	    // 					LSParser.ACTION_INSERT_BEFORE);
	    Document temp = par.parse(input);
	    Node newNode = ctx.doc.adoptNode(temp.getDocumentElement());
	    node.getParentNode().insertBefore(newNode, node);
	    TodoElement it
		= TodoElement.getTodoElement((Element)newNode,
					     this.ctx, this);
	    toProcess.add(it);
	}
	node.getParentNode().removeChild(node);
	this.ownerDeque.registerAtStart(toProcess);
    }

}