/** * Set the enclosed <code>PARAM<code> children. * @param newObjectParams The new parameters. */ public void setObjectParams(HashMap newObjectParams) { NodeList kids; Node node; Tag tag; String paramName; String paramValue; List attributes; TextNode string; kids = getChildren(); if (null == kids) kids = new NodeList(); else // erase objectParams from kids for (int i = 0; i < kids.size(); ) { node = kids.elementAt(i); if (node instanceof Tag) if (((Tag) node).getTagName().equals("PARAM")) { kids.remove(i); // remove whitespace too if (i < kids.size()) { node = kids.elementAt(i); if (node instanceof TextNode) { string = (TextNode) node; if (0 == string.getText().trim().length()) kids.remove(i); } } } else i++; else i++; } // add newObjectParams to kids for (Iterator e = newObjectParams.entrySet().iterator(); e.hasNext(); ) { Map.Entry entry = (Entry) e.next(); attributes = new ArrayList(); // should the tag copy the attributes? paramName = (String) entry.getKey(); paramValue = (String) entry.getValue(); attributes.add(new Attribute("PARAM", null)); attributes.add(new Attribute(" ")); attributes.add(new Attribute("VALUE", paramValue, '"')); attributes.add(new Attribute(" ")); attributes.add(new Attribute("NAME", paramName.toUpperCase(), '"')); tag = new TagNode(null, 0, 0, attributes); kids.add(tag); } // set kids as new children setChildren(kids); }
// It's a bit of work to insert a node with the htmlparser module. private void insertRowAfter(Row existingRow, Row childRow) { NodeList rowNodes = tableNode.getChildren(); int index = rowNodes.indexOf(existingRow.rowNode); Stack<Node> tempStack = new Stack<Node>(); while (rowNodes.size() - 1 > index) { tempStack.push(rowNodes.elementAt(tableNode.getChildren().size() - 1)); rowNodes.remove(rowNodes.size() - 1); } rowNodes.add(childRow.rowNode); while (tempStack.size() > 0) { rowNodes.add(tempStack.pop()); } }