|
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.examples.modules.minicomposer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.MissingResourceException; import org.netbeans.api.convertor.ConvertorException; import org.netbeans.api.registry.Context; import org.netbeans.api.registry.ObjectRef; import org.netbeans.spi.convertor.Convertor; import org.openide.execution.NbProcessDescriptor; import org.openide.util.NbBundle; import org.openide.util.Utilities; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.w3c.dom.Text; /** * Storage for {@link ExternalPlayer}s. * @author Jesse Glick */ public class ExternalPlayerConvertor implements Convertor { private static final String NS = "http://openide.netbeans.org/examples/minicomposer"; public ExternalPlayerConvertor() {} public Object read(Element element) throws ConvertorException { String label; NodeList l = element.getElementsByTagNameNS(NS, "label"); if (l.getLength() == 1) { Element lab = (Element)l.item(0); String bund = text((Element)lab.getElementsByTagNameNS(NS, "bundle").item(0)); String key = text((Element)lab.getElementsByTagNameNS(NS, "key").item(0)); try { label = NbBundle.getBundle(bund).getString(key); } catch (MissingResourceException e) { throw (ConvertorException)new ConvertorException(e.toString()).initCause(e); } } else { label = null; } l = element.getElementsByTagNameNS(NS, "command"); assert l.getLength() == 1; String command = text((Element)l.item(0)); l = element.getElementsByTagNameNS(NS, "arguments"); assert l.getLength() == 1; l = ((Element)l.item(0)).getElementsByTagNameNS(NS, "*"); String[] params = new String[l.getLength()]; for (int i = 0; i < l.getLength(); i++) { Element arg = (Element)l.item(i); if (arg.getLocalName().equals("aufile")) { params[i] = ExternalPlayer.TAG_AUFILE; } else { assert arg.getLocalName().equals("literal"); params[i] = text(arg); } } NbProcessDescriptor pc = new NbProcessDescriptor( command, Utilities.escapeParameters(params), NbBundle.getMessage(ExternalPlayerConvertor.class, "MSG_format_hint")); ExternalPlayer p = new ExternalPlayer(pc, label); return p; } public Element write(Document doc, Object inst) { ExternalPlayer p = (ExternalPlayer)inst; NbProcessDescriptor pc = p.getPlayerCommand(); Element ep = doc.createElementNS(NS, "external-player"); // ignore label - we never write it, it is only for registration { Element comm = doc.createElementNS(NS, "command"); comm.appendChild(doc.createTextNode(pc.getProcessName())); ep.appendChild(comm); } { Element args = doc.createElementNS(NS, "arguments"); String[] ss = Utilities.parseParameters(pc.getArguments()); for (int i = 0; i < ss.length; i++) { if (ss[i].equals(ExternalPlayer.TAG_AUFILE)) { args.appendChild(doc.createElementNS(NS, "aufile")); } else { Element lit = doc.createElementNS(NS, "literal"); lit.appendChild(doc.createTextNode(ss[i])); args.appendChild(lit); } } ep.appendChild(args); } assert ep.getNamespaceURI().equals(NS); return ep; } private static String text(Element el) { assert el != null; NodeList l = el.getChildNodes(); assert l.getLength() == 1; return ((Text)l.item(0)).getNodeValue(); } } |
... 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.