propertymanager.java
来自「很棒的web服务器源代码」· Java 代码 · 共 542 行 · 第 1/2 页
JAVA
542 行
// PropertyManager.java// $Id: PropertyManager.java,v 1.15 2000/08/16 21:37:26 ylafon Exp $// (c) COPYRIGHT MIT and INRIA, 1997.// Please first read the full copyright statement in file COPYRIGHT.htmlpackage org.w3c.jigadm;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; } ResourceClassProperties(String entryPath, ZipFile zip) { this.entryPath = entryPath; this.zip = zip; initialize(); }}public class PropertyManager { /** * The root for the property files. */ protected File root = null; protected File zipfile = null; /** * The set of resource classes we know about. * Maps class names to ResourceClassProperty */ protected Hashtable classProperties = null; /** /** * the mapping of icon names to icon locations */ protected Properties iconProperties = null; /** * the hashtable of mime types */ protected Hashtable mimeTypes = null; private boolean inited = false; protected static Properties merge(Properties into , Properties source , boolean overide) { Properties p = (Properties) into.clone(); Enumeration e = source.keys(); while ( e.hasMoreElements() ) { Object key = e.nextElement(); if ((! overide) && into.get(key) != null) continue; Object val = source.get(key); p.put(key, val); } return p; } protected static Properties merge(Properties into, Properties source) { return merge(into, source, true); } /** * Load the properties from the root directory. */ protected void initialize() { ZipFile zip = null; try { zip = new ZipFile(this.zipfile); } catch (Exception ex) { ex.printStackTrace(); return; } Enumeration entries = zip.entries(); classProperties = new Hashtable(11); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); String entry_name = entry.getName(); if (entry_name.equals( "icons"+ File.separator)) //reserved continue; // Skip non directory entries if (! entry.isDirectory() ) continue; // only first level sub directories if (entry_name.indexOf(File.separator) == entry_name.lastIndexOf(File.separator)) { ResourceClassProperties rcp = null; rcp = new ResourceClassProperties(entry_name, zip); classProperties.put(entry_name.substring(0, entry_name.length()-1 ), rcp); } } // and now the icons mapping try { ZipEntry icons = zip.getEntry("icons.p"); InputStream in = (new BufferedInputStream (zip.getInputStream(icons))); iconProperties = new Properties(); iconProperties.load(in); in.close(); } catch (Exception ex) { ex.printStackTrace(); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?