1999-02-09 11:05:17 +03:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License
|
|
|
|
* Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
* the License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Grendel mail/news client.
|
|
|
|
*
|
1999-03-07 22:58:40 +03:00
|
|
|
* The Initial Developer of the Original Code is Giao Nguyen
|
|
|
|
* <grail@cafebabe.org>. Portions created by Giao Nguyen are Copyright
|
|
|
|
* (C) 1999 Giao Nguyen. All Rights Reserved.
|
1999-02-09 11:05:17 +03:00
|
|
|
*
|
1999-03-07 22:58:40 +03:00
|
|
|
* Contributors: Morgan Schweers <morgan@vixen.com>
|
1999-02-09 11:05:17 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
package grendel.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.awt.Container;
|
|
|
|
|
|
|
|
import javax.swing.JComponent;
|
|
|
|
|
|
|
|
import org.w3c.dom.Node;
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
|
|
|
|
public abstract class XMLWidgetBuilder {
|
|
|
|
/**
|
|
|
|
* The properties bundle that the builder will reference to for
|
|
|
|
* things like getReferencedLabel.
|
|
|
|
*/
|
1999-06-20 06:15:35 +04:00
|
|
|
protected Properties properties = new Properties();
|
1999-02-09 11:05:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference point into the CLASSPATH for locating the XML file.
|
|
|
|
*/
|
|
|
|
protected Class ref;
|
|
|
|
|
1999-02-19 12:02:35 +03:00
|
|
|
/**
|
|
|
|
* Set the reference point for URL location.
|
|
|
|
*
|
|
|
|
* @param ref the reference point for local urls to be loaded from.
|
|
|
|
*/
|
|
|
|
public void setReference(Class ref) {
|
|
|
|
this.ref = ref;
|
|
|
|
}
|
|
|
|
|
1999-02-09 11:05:17 +03:00
|
|
|
/**
|
|
|
|
* Set the element as the item containing configuration for the
|
|
|
|
* builder. This would usually be the link tag in the head.
|
|
|
|
*
|
|
|
|
* @param config the element containing configuration data
|
|
|
|
*/
|
|
|
|
public void setConfiguration(Element config) {
|
|
|
|
try {
|
|
|
|
URL linkURL;
|
1999-02-19 12:02:35 +03:00
|
|
|
Class local = ((ref == null) ? getClass() : ref);;
|
1999-02-09 11:05:17 +03:00
|
|
|
// get the string properties
|
1999-06-20 06:15:35 +04:00
|
|
|
if (config.getAttribute("href").length() != 0
|
1999-02-09 11:05:17 +03:00
|
|
|
&& config.getAttribute("role").equals("stringprops")
|
|
|
|
&& config.getTagName().equals("link")) {
|
1999-02-19 12:02:35 +03:00
|
|
|
|
1999-06-20 06:15:35 +04:00
|
|
|
// this should never return null
|
1999-02-19 12:02:35 +03:00
|
|
|
linkURL = local.getResource(config.getAttribute("href"));
|
1999-06-20 06:15:35 +04:00
|
|
|
properties.load(linkURL.openStream());
|
1999-02-09 11:05:17 +03:00
|
|
|
}
|
|
|
|
} catch (IOException io) {
|
|
|
|
io.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-06 10:07:34 +03:00
|
|
|
/**
|
|
|
|
* Get a label referenced by the string properties file.
|
|
|
|
* @param current the element to process
|
|
|
|
* @param attr the attribute to look up
|
|
|
|
* @return the string as post lookup, or the string pre lookup if
|
|
|
|
* the lookup failed
|
|
|
|
*/
|
1999-02-09 11:05:17 +03:00
|
|
|
public String getReferencedLabel(Element current, String attr) {
|
|
|
|
String label = current.getAttribute(attr);
|
|
|
|
|
|
|
|
// if it starts with a '$' we crossreference to properties
|
1999-03-01 02:53:40 +03:00
|
|
|
if (label != null && label.length() > 0
|
|
|
|
&& label.charAt(0) == '$') {
|
1999-02-09 11:05:17 +03:00
|
|
|
String key = label.substring(1);
|
|
|
|
label = properties.getProperty(key, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
}
|