propertymanager.java
来自「很棒的web服务器源代码」· Java 代码 · 共 213 行
JAVA
213 行
// PropertyManager.java// $Id: PropertyManager.java,v 1.8 2000/08/16 21:37:28 ylafon Exp $// (c) COPYRIGHT MIT and INRIA, 1997.// Please first read the full copyright statement in file COPYRIGHT.htmlpackage org.w3c.jigadmin;import java.util.Enumeration;import java.util.Hashtable;import java.util.Properties;import java.util.StringTokenizer;import java.util.Vector;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;import java.io.BufferedInputStream;import java.io.File;import java.io.InputStream;import java.io.PrintStream;import org.w3c.jigsaw.admin.RemoteAccessException;import org.w3c.jigsaw.admin.RemoteResource;import org.w3c.tools.resources.Attribute;class ResourceClassProperties { // The class we're handling the configuration for String entryPath = null; // The zip file this classes configuration is at ZipFile zip = null; // The class editor properties Properties editorProperties = null; // The set of registered helpers for that editor's class String helperClasses[] = new String[0]; // The helpers properties (map help classes to properties) Hashtable helperProperties = null; // The attribute properties Hashtable attributeProperties = null; /** * Parse | separated property value into a String array. * @param p Properties to look into. * @param name The property to look for and parse. * @return A non-null but potentially zero-length string array. */ static String[] getStringArray(Properties p, String name) { String v = (String) p.get(name); if ( v == null ) return new String[0]; // Parse the property value: StringTokenizer st = new StringTokenizer(v, "|"); int len = st.countTokens(); String ret[] = new String[len]; for (int i = 0 ; i < ret.length ; i++) { ret[i] = st.nextToken(); } return ret; } /** * Does this class config allows for helper aggregation. * If <strong>true</strong> this means that the GUI should instantiate * all inherited helpers to construct the resource editor. * @return A boolean. */ boolean aggregateHelpers() { if ( editorProperties == null ) return true; String s = (String) editorProperties.get("aggregateHelpers"); return (s != null) && s.equalsIgnoreCase("true"); } /** * Does this class config allows for attribute aggregation. * If <strong>true</strong> this means that the GUI should instantiate * an editor for all inherited attributes. * @return A boolean. */ boolean aggregateAttributes() { if ( editorProperties == null ) return true; String s = (String) editorProperties.get("aggregateAttributes"); return (s != null) && s.equalsIgnoreCase("true"); } /** * Should the config aggregate specific attribute editor properties. * @return A boolean. */ boolean aggregateAttributeProperties() { return false; } /** * Utility - Load a directory of prop files into given hashtable. * @param into Hashtable to fill in with Properties instance. * @param dir Directory to load. */ void loadPropertyDirectory(Hashtable into, ZipFile zip, String dir) { try { Enumeration entries = zip.entries(); while( entries.hasMoreElements() ) { ZipEntry entry = (ZipEntry) entries.nextElement(); String name = entry.getName(); if (name.startsWith(dir) && name.endsWith(".p")) { Properties p = new Properties(); InputStream in = (new BufferedInputStream (zip.getInputStream(entry))); p.load(in); in.close(); // Register them into the hashtable: into.put(name.substring(dir.length()+1, name.length()-2), p); } } } catch (Exception ex) { ex.printStackTrace(); } } /** * Initialize that class config. * This method will load the resource editor properties, than the helper * specific properties, and finally the attribute properties. */ void initialize() { // Load the editor properties: try { ZipEntry propentry = zip.getEntry(entryPath + "properties"); if (propentry != null) { InputStream in = (new BufferedInputStream (zip.getInputStream(propentry))); editorProperties = new Properties(); editorProperties.load(in); in.close(); } } catch (Exception ex) { ex.printStackTrace(); } // From the editor properties, get the set of helpers: if ( editorProperties != null ) helperClasses = getStringArray(editorProperties, "helpers"); // Load the helpers specific properties: helperProperties = new Hashtable(11); loadPropertyDirectory(helperProperties, zip, entryPath + "helpers"); // Load the specific attribute editor properties: attributeProperties = new Hashtable(11); loadPropertyDirectory(attributeProperties, zip,entryPath + "attrs"); } String[] getHelperClasses() { return helperClasses; } Properties getHelperProperties(String clsname) { Properties p = (Properties) helperProperties.get(clsname); return p; } Properties getAttributeProperties(String name) { Properties p = (Properties) attributeProperties.get(name); return p; } Properties getEditorProperties() { return editorProperties; } String getEditorClass() { if ( editorProperties == null ) return null; return (String) editorProperties.get("class"); } boolean isEditable() { if ( editorProperties == null ) return true; String editable = (String)editorProperties.get("editable"); if (editable == null) return true; return (! editable.equalsIgnoreCase("false")); } boolean isExtensible() { if ( editorProperties == null ) return true; String extensible = (String)editorProperties.get("extensible"); if (extensible == null) return true; return (! extensible.equalsIgnoreCase("false")); } ResourceClassProperties(String entryPath, ZipFile zip) { this.entryPath = entryPath; this.zip = zip; initialize(); }}/** * The PropertyManager * @version $Revision: 1.8 $ * @author Beno顃 Mah
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?