|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.core.registry.cdconvertor; import org.netbeans.spi.convertor.Convertor; import org.w3c.dom.*; /** * * @author David Konecny */ public class CDConvertor implements Convertor { private static final String NAMESPACE = "http://www.netbeans.org/ns/cd"; public CDConvertor() { } public Object read(org.w3c.dom.Element element) { String artist = null; String album = null; NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element)node; if (e.getNodeName().equals("artist")) { artist = getTextValue(e); } if (e.getNodeName().equals("album")) { album = getTextValue(e); } } } return new CD(artist, album); } public org.w3c.dom.Element write(Document doc, Object inst) { CD cd = (CD)inst; Element element = doc.createElementNS(NAMESPACE, "cd"); Element e = doc.createElementNS(NAMESPACE, "artist"); Text t = doc.createTextNode(cd.artist); e.appendChild(t); element.appendChild(e); e = doc.createElementNS(NAMESPACE, "album"); t = doc.createTextNode(cd.album); e.appendChild(t); element.appendChild(e); return element; } // THIS IMPL IS NOT ROBUST. DO NOT REUSE IT! private String getTextValue(Element element) { NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.TEXT_NODE) { return ((Text)node).getData(); } } return null; } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.