⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogsettings.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    private void load(Document document, Element root) {        name = root.getAttribute(TAG_NAME);        NodeList l = root.getElementsByTagName(TAG_ITEM);        for (int i = 0; i < l.getLength(); i++) {            Node n = l.item(i);            if (root == n.getParentNode()) {                String key = ((Element) l.item(i)).getAttribute(TAG_KEY);                String value = ((Element) l.item(i)).getAttribute(TAG_VALUE);                items.put(key, value);            }        }        l = root.getElementsByTagName(TAG_LIST);        for (int i = 0; i < l.getLength(); i++) {            Node n = l.item(i);            if (root == n.getParentNode()) {                Element child = (Element) l.item(i);                String key = child.getAttribute(TAG_KEY);                NodeList list = child.getElementsByTagName(TAG_ITEM);                List valueList = new ArrayList();                for (int j = 0; j < list.getLength(); j++) {                    Element node = (Element) list.item(j);                    if (child == node.getParentNode()) {                        valueList.add(node.getAttribute(TAG_VALUE));                    }                }                String[] value = new String[valueList.size()];                valueList.toArray(value);                arrayItems.put(key, value);            }        }        l = root.getElementsByTagName(TAG_SECTION);        for (int i = 0; i < l.getLength(); i++) {            Node n = l.item(i);            if (root == n.getParentNode()) {                DialogSettings s = new DialogSettings("NoName");//$NON-NLS-1$                s.load(document, (Element) n);                addSection(s);            }        }    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void put(String key, String[] value) {        arrayItems.put(key, value);    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void put(String key, double value) {        put(key, String.valueOf(value));    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void put(String key, float value) {        put(key, String.valueOf(value));    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void put(String key, int value) {        put(key, String.valueOf(value));    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void put(String key, long value) {        put(key, String.valueOf(value));    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void put(String key, String value) {        items.put(key, value);    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void put(String key, boolean value) {        put(key, String.valueOf(value));    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void save(Writer writer) throws IOException {    	save(new XMLWriter(writer));    }    /* (non-Javadoc)     * Method declared on IDialogSettings.     */    public void save(String fileName) throws IOException {        FileOutputStream stream = new FileOutputStream(fileName);        XMLWriter writer = new XMLWriter(stream);        save(writer);        writer.close();    }    /* (non-Javadoc)     * Save the settings in the <code>document</code>.     */    private void save(XMLWriter out) {    	HashMap attributes = new HashMap(2);    	attributes.put(TAG_NAME, name == null ? "" : name); //$NON-NLS-1$        out.startTag(TAG_SECTION, attributes);        attributes.clear();        for (Iterator i = items.keySet().iterator(); i.hasNext();) {            String key = (String) i.next();            attributes.put(TAG_KEY, key == null ? "" : key); //$NON-NLS-1$            String string = (String) items.get(key);            attributes.put(TAG_VALUE, string == null ? "" : string); //$NON-NLS-1$                    out.printTag(TAG_ITEM, attributes, true);        }        attributes.clear();        for (Iterator i = arrayItems.keySet().iterator(); i.hasNext();) {            String key = (String) i.next();            attributes.put(TAG_KEY, key == null ? "" : key); //$NON-NLS-1$            out.startTag(TAG_LIST, attributes);            String[] value = (String[]) arrayItems.get(key);            attributes.clear();            if (value != null) {                for (int index = 0; index < value.length; index++) {                    String string = value[index];                    attributes.put(TAG_VALUE, string == null ? "" : string); //$NON-NLS-1$                    out.printTag(TAG_ITEM, attributes, true);                }            }            out.endTag(TAG_LIST);            attributes.clear();        }        for (Iterator i = sections.values().iterator(); i.hasNext();) {            ((DialogSettings) i.next()).save(out);        }        out.endTag(TAG_SECTION);    }        /**     * A simple XML writer.  Using this instead of the javax.xml.transform classes allows     * compilation against JCL Foundation (bug 80059).      */    private static class XMLWriter extends PrintWriter {    	protected int tab;    	/* constants */    	protected static final String XML_VERSION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$    	public XMLWriter(OutputStream output) throws UnsupportedEncodingException {    		super(new OutputStreamWriter(output, "UTF8")); //$NON-NLS-1$    		tab = 0;    		println(XML_VERSION);    	}    	public XMLWriter(Writer output) {    		super(output);    		tab = 0;    		println(XML_VERSION);    	}    	public void endTag(String name) {    		tab--;    		printTag("/" + name, null, false); //$NON-NLS-1$    	}    	private void printTabulation() {    		for (int i = 0; i < tab; i++) {				super.print('\t');			}    	}    	public void printTag(String name, HashMap parameters, boolean close) {    		printTag(name, parameters, true, true, close);    	}    	private void printTag(String name, HashMap parameters, boolean shouldTab, boolean newLine, boolean close) {    		StringBuffer sb = new StringBuffer();    		sb.append('<');    		sb.append(name);    		if (parameters != null) {				for (Enumeration e = Collections.enumeration(parameters.keySet()); e.hasMoreElements();) {    				sb.append(" "); //$NON-NLS-1$    				String key = (String) e.nextElement();    				sb.append(key);    				sb.append("=\""); //$NON-NLS-1$    				sb.append(getEscaped(String.valueOf(parameters.get(key))));    				sb.append("\""); //$NON-NLS-1$    			}			}    		if (close) {				sb.append('/');			}    		sb.append('>');    		if (shouldTab) {				printTabulation();			}    		if (newLine) {				println(sb.toString());			} else {				print(sb.toString());			}    	}    	public void startTag(String name, HashMap parameters) {    		startTag(name, parameters, true);    		tab++;    	}    	private void startTag(String name, HashMap parameters, boolean newLine) {    		printTag(name, parameters, true, newLine, false);    	}    	private static void appendEscapedChar(StringBuffer buffer, char c) {    		String replacement = getReplacement(c);    		if (replacement != null) {    			buffer.append('&');    			buffer.append(replacement);    			buffer.append(';');    		} else {    			buffer.append(c);    		}    	}    	private static String getEscaped(String s) {    		StringBuffer result = new StringBuffer(s.length() + 10);    		for (int i = 0; i < s.length(); ++i) {				appendEscapedChar(result, s.charAt(i));			}    		return result.toString();    	}    	private static String getReplacement(char c) {    		// Encode special XML characters into the equivalent character references.    		// The first five are defined by default for all XML documents.    		// The next three (#xD, #xA, #x9) are encoded to avoid them			// being converted to spaces on deserialization    		switch (c) {    			case '<' :    				return "lt"; //$NON-NLS-1$    			case '>' :    				return "gt"; //$NON-NLS-1$    			case '"' :    				return "quot"; //$NON-NLS-1$    			case '\'' :    				return "apos"; //$NON-NLS-1$    			case '&' :    				return "amp"; //$NON-NLS-1$    			case '\r':					return "#x0D"; //$NON-NLS-1$				case '\n':					return "#x0A"; //$NON-NLS-1$				case '\u0009':					return "#x09"; //$NON-NLS-1$    		}    		return null;    	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -