@Override public void setText(final String text) { // TODO: remove ALL children? final NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node child = nodes.item(i); if (child.getNodeType() == Node.TEXT_NODE) { element.removeChild(child); } } if (!Strings.isNullOrEmpty(text)) { element.appendChild(document.createTextNode(text)); } }
@Nullable private Node getUniqueElementByTagName(@Nonnull final String tagName) { NodeList nodes = ((Element)entryNode).getElementsByTagName(tagName); return nodes.getLength() == 1 ? nodes.item(0) : null; }
@Override protected Element getFirstChildElement( Element parent ) { Node node = parent.getFirstChild(); while( node != null && !( node instanceof Element )) { node = node.getNextSibling(); } return (Element) node; }
@Override public String getAttribute(final String name) { checkNotNull(name); if (!element.hasAttribute(name)) return null; return element.getAttribute(name); }
@Override public void setAttribute(final String name, final String value) { checkNotNull(name); if (value != null) { element.setAttribute(name, value); } else { element.removeAttribute(name); } }
@Override public XMLPacket addChild(final String name, final String namespace) { final Element newElement = document.createElement(checkNotNull(name)); if (namespace != null) { newElement.setAttribute("xmlns", namespace); } element.appendChild(newElement); return new XMLPacketImplGWT(newElement); }
@Override public XMLPacket getFirstChild(final String name, final String namespace) { checkNotNull(name); checkNotNull(namespace); final NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node node = nodes.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } final Element element = (Element) node; if (!"*".equals(name) && !name.equals(element.getTagName())) { continue; } if (!"*".equals(namespace) && !namespace.equals(element.getNamespaceURI())) { continue; } return new XMLPacketImplGWT(element); } return null; }
private List<Node> getNodesByTagName( Element element, String tagName ) { List<Node> nodes = new ArrayList<Node>(); NodeList list = element.getChildNodes(); for ( int i = 0; i < list.getLength(); i++ ) { Node node = list.item( i ); if ( node != null && node.getNodeName().equals( tagName ) ) { nodes.add( node ); } } return nodes; }
@Override public XMLPacket addChild(final HasXML child) { checkArgument(checkNotNull(child.getXML()) instanceof XMLPacketImplGWT); final Element newElement = (Element) document.importNode(((XMLPacketImplGWT) child.getXML()).element, true); element.appendChild(newElement); return new XMLPacketImplGWT(newElement); }
public void valueChanged(Object node, int columnIndex) { Element element = nodes.get(node); element.setAttribute(getAttributeName(columnIndex), getAttributeValue(node, columnIndex)); updateTextArea(); }
public void nodeRemoved(Object parent, Object node, int index) { Element parentNode = parent == null ? root : nodes.get(parent); Element childNode = nodes.get(node); parentNode.removeChild(childNode); nodes.remove(node); updateTextArea(); }
@Override public ImmutableMap<String, String> getAttributes() { final ImmutableMap.Builder<String, String> result = ImmutableMap.builder(); final NamedNodeMap attribs = element.getAttributes(); for (int i = 0; i < attribs.getLength(); i++) { final Attr attrib = (Attr) attribs.item(i); result.put(attrib.getName(), attrib.getValue()); } return result.build(); }
@Override public String getNamespace() { return element.getNamespaceURI(); }
public void nodeAdded(Object parent, Object node, int index) { Element parentNode = nodes.get(parent); Element childNode = document.createElement("event"); for (int i = 0; i < model.getColumnCount(); i++) { childNode.setAttribute(getAttributeName(i), getAttributeValue(node, i)); } parentNode.appendChild(childNode); nodes.put(node, childNode); updateTextArea(); }
@Override public ImmutableList<XMLPacket> getChildren(final String name, final String namespace) { checkNotNull(name); checkNotNull(namespace); final ImmutableList.Builder<XMLPacket> result = ImmutableList.builder(); final NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node node = nodes.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } final Element element = (Element) node; if (!"*".equals(name) && !name.equals(element.getTagName())) { continue; } if (!"*".equals(namespace) && !namespace.equals(element.getNamespaceURI())) { continue; } result.add(new XMLPacketImplGWT(element)); } return result.build(); }
@Override public String getText() { final StringBuilder result = new StringBuilder(); final NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node child = nodes.item(i); if (child.getNodeType() == Node.TEXT_NODE) result.append(child.getNodeValue()); } return result.toString(); }
databaseName.appendChild( databaseNameText ); databaseConnection.appendChild( databaseName ); databasePort.appendChild( databasePortText ); databaseConnection.appendChild( databasePort ); hostname.appendChild( hostnameText ); databaseConnection.appendChild( hostname ); indexTablespace.appendChild( indexTablespaceText ); databaseConnection.appendChild( indexTablespace ); dataTablespace.appendChild( dataTablespaceText ); databaseConnection.appendChild( dataTablespace ); informixServername.appendChild( informixServernameText ); databaseConnection.appendChild( informixServername ); name.appendChild( nameText ); databaseConnection.appendChild( name ); username.appendChild( usernameTxt ); databaseConnection.appendChild( username ); password.appendChild( passwordText ); databaseConnection.appendChild( password ); accessType.appendChild( accessTypeText ); databaseConnection.appendChild( accessType );
protected XMLPacketImplGWT(final String name, @Nullable final String namespace) { document = XMLParser.createDocument(); element = document.createElement(name); if (namespace != null) { element.setAttribute("xmlns", namespace); } document.appendChild(element); }
@Override public void removeChild(final HasXML child) { checkArgument(child.getXML() instanceof XMLPacketImplGWT); element.removeChild(((XMLPacketImplGWT) child.getXML()).element); }
@Override @SuppressWarnings( { "cast", "unchecked" } ) protected Map<String, String> getAttributesAsMap( Element element ) { NamedNodeMap nodes = element.getAttributes(); int length = nodes.getLength(); if ( length == 0 ) { return (Map<String, String>) Collections.EMPTY_MAP; } Map<String, String> attributes = new HashMap<String, String>( length ); for ( int loop = 0; loop < length; loop++ ) { Node node = nodes.item( loop ); attributes.put( node.getNodeName(), node.getNodeValue() ); } return attributes; } }