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

📄 althtmlwriter.java

📁 Memoranda( 从前以jNotes2而闻名) 是一个日志管理和个人项目管理工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    String vAlign = from.getAttribute(key).toString();                    if (vAlign.indexOf("sup") >= 0) {                        to.addAttribute(HTML.Tag.SUP, SimpleAttributeSet.EMPTY);                    }                    if (vAlign.indexOf("sub") >= 0) {                        to.addAttribute(HTML.Tag.SUB, SimpleAttributeSet.EMPTY);                    }                }                else if (key == CSS.Attribute.TEXT_ALIGN) {                    to.addAttribute(HTML.Attribute.ALIGN, from.getAttribute(key).toString());                }                else {                    // default is to store in a HTML style attribute                    if (value.length() > 0) {                        value = value + "; ";                    }                    value = value + key + ": " + from.getAttribute(key);                }            }            else {                to.addAttribute(key, from.getAttribute(key));            }        }        if (value.length() > 0) {            to.addAttribute(HTML.Attribute.STYLE, value);        }    }    /**     * Create/update an HTML &lt;font&gt; tag attribute.  The     * value of the attribute should be a MutableAttributeSet so     * that the attributes can be updated as they are discovered.     */    private static void createFontAttribute(CSS.Attribute a, AttributeSet from, MutableAttributeSet to) {        MutableAttributeSet fontAttr = (MutableAttributeSet) to.getAttribute(HTML.Tag.FONT);        if (fontAttr == null) {            fontAttr = new SimpleAttributeSet();            to.addAttribute(HTML.Tag.FONT, fontAttr);        }        // edit the parameters to the font tag        String htmlValue = from.getAttribute(a).toString();        if (a == CSS.Attribute.FONT_FAMILY) {            fontAttr.addAttribute(HTML.Attribute.FACE, htmlValue);        }        else if (a == CSS.Attribute.FONT_SIZE) {            fontAttr.addAttribute(HTML.Attribute.SIZE, htmlValue);        }        else if (a == CSS.Attribute.COLOR) {            fontAttr.addAttribute(HTML.Attribute.COLOR, htmlValue);        }    }    /**     * Copies the given AttributeSet to a new set, converting     * any CSS attributes found to arguments of an HTML style     * attribute.     */    private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {        Enumeration keys = from.getAttributeNames();        String value = "";        while (keys.hasMoreElements()) {            Object key = keys.nextElement();            if (key instanceof CSS.Attribute) {                value = value + " " + key + "=" + from.getAttribute(key) + ";";            }            else {                to.addAttribute(key, from.getAttribute(key));            }        }        if (value.length() > 0) {            to.addAttribute(HTML.Attribute.STYLE, value);        }    }    //    // Overrides the writing methods to only break a string when    // canBreakString is true.    // In a future release it is likely AbstractWriter will get this    // functionality.    //    /**     * Writes the line separator. This is overriden to make sure we don't     * replace the newline content in case it is outside normal ascii.     */    protected void writeLineSeparator() throws IOException {        boolean oldReplace = replaceEntities;        replaceEntities = false;        super.writeLineSeparator();        replaceEntities = oldReplace;    }    /**     * This method is overriden to map any character entities, such as     * &lt; to &amp;lt;. <code>super.output</code> will be invoked to     * write the content.     */    protected void output(char[] chars, int start, int length) throws IOException {        if (!replaceEntities) {            super.output(chars, start, length);            return;        }        int last = start;        length += start;        for (int counter = start; counter < length; counter++) {            // This will change, we need better support character level            // entities.            switch (chars[counter]) {                // Character level entities.                case '<' :                    if (counter > last) {                        super.output(chars, last, counter - last);                    }                    last = counter + 1;                    output("&lt;");                    break;                case '>' :                    if (counter > last) {                        super.output(chars, last, counter - last);                    }                    last = counter + 1;                    output("&gt;");                    break;                case '&' :                    if (counter > last) {                        super.output(chars, last, counter - last);                    }                    last = counter + 1;                    output("&amp;");                    break;                case '"' :                    if (counter > last) {                        super.output(chars, last, counter - last);                    }                    last = counter + 1;                    output("&quot;");                    break;                    // Special characters                case '\n' :                case '\t' :                case '\r' :                    break;                default :                    /**                     * [alex]I've replaced the following line to avoid to substitute non-ascii characters by numeric                     * values by default. Use _nument=true if you need that substitution                     * Original "if" condition: if (chars [counter]< ' ' || chars [counter] > 127)                      */                    if ((chars[counter] < ' ') || (_nument && chars[counter] > 127)) {                        if (counter > last) {                            super.output(chars, last, counter - last);                        }                        last = counter + 1;                        // If the character is outside of ascii, write the                        // numeric value.                        output("&#");                        output(String.valueOf((int) chars[counter]));                        output(";");                    }                    break;            }        }        if (last < length) {            super.output(chars, last, length - last);        }    }    /**     * This directly invokes super's <code>output</code> after converting     * <code>string</code> to a char[].     */    private void output(String string) throws IOException {        int length = string.length();        if (tempChars == null || tempChars.length < length) {            tempChars = new char[length];        }        string.getChars(0, length, tempChars, 0);        super.output(tempChars, 0, length);    }    /**     * This class extends DefaultListModel, and also implements     * the ListSelectionModel interface, allowing for it to store state     * relevant to a SELECT form element which is implemented as a List.     * If SELECT has a size attribute whose value is greater than 1,     * or if allows multiple selection then a JList is used to      * represent it and the OptionListModel is used as its model.     * It also stores the initial state of the JList, to ensure an     * accurate reset, if the user requests a reset of the form.     *      @author Sunita Mani      @version 1.9 12/03/01     */    class OptionListModel extends DefaultListModel implements ListSelectionModel, Serializable {        private static final int MIN = -1;        private static final int MAX = Integer.MAX_VALUE;        private int selectionMode = SINGLE_SELECTION;        private int minIndex = MAX;        private int maxIndex = MIN;        private int anchorIndex = -1;        private int leadIndex = -1;        private int firstChangedIndex = MAX;        private int lastChangedIndex = MIN;        private boolean isAdjusting = false;        private BitSet value = new BitSet(32);        private BitSet initialValue = new BitSet(32);        protected EventListenerList listenerList = new EventListenerList();        protected boolean leadAnchorNotificationEnabled = true;        public int getMinSelectionIndex() {            return isSelectionEmpty() ? -1 : minIndex;        }        public int getMaxSelectionIndex() {            return maxIndex;        }        public boolean getValueIsAdjusting() {            return isAdjusting;        }        public int getSelectionMode() {            return selectionMode;        }        public void setSelectionMode(int selectionMode) {            switch (selectionMode) {                case SINGLE_SELECTION :                case SINGLE_INTERVAL_SELECTION :                case MULTIPLE_INTERVAL_SELECTION :                    this.selectionMode = selectionMode;                    break;                default :                    throw new IllegalArgumentException("invalid selectionMode");            }        }        public boolean isSelectedIndex(int index) {            return ((index < minIndex) || (index > maxIndex)) ? false : value.get(index);        }        public boolean isSelectionEmpty() {            return (minIndex > maxIndex);        }        public void addListSelectionListener(ListSelectionListener l) {            listenerList.add(ListSelectionListener.class, l);        }        public void removeListSelectionListener(ListSelectionListener l) {            listenerList.remove(ListSelectionListener.class, l);        }        /**         * Returns an array of all the <code>ListSelectionListener</code>s added         * to this OptionListModel with addListSelectionListener().         *         * @return all of the <code>ListSelectionListener</code>s added or an empty         *         array if no listeners have been added         * @since 1.4         */        public ListSelectionListener[] getListSelectionListeners() {            return (ListSelectionListener[]) listenerList.getListeners(ListSelectionListener.class);        }        /**         * Notify listeners that we are beginning or ending a         * series of value changes         */        protected void fireValueChanged(boolean isAdjusting) {            fireValueChanged(getMinSelectionIndex(), getMaxSelectionIndex(), isAdjusting);        }        /**         * Notify ListSelectionListeners that the value of the selection,         * in the closed interval firstIndex,lastIndex, has changed.         */        protected void fireValueChanged(int firstIndex, int lastIndex) {            fireValueChanged(firstIndex, lastIndex, getValueIsAdjusting());        }        /**         * @param firstIndex The first index in the interval.         * @param index1 The last index in the interval.         * @param isAdjusting True if this is the final change in a series of them.         * @see EventListenerList         */        protected void fireValueChanged(int firstIndex, int lastIndex, boolean isAdjusting) {            Object[] listeners = listenerList.getListenerList();            ListSelectionEvent e = null;            for (int i = listeners.length - 2; i >= 0; i -= 2) {                if (listeners[i] == ListSelectionListener.class) {                    if (e == null) {                        e = new ListSelectionEvent(this, firstIndex, lastIndex, isAdjusting);                    }                    ((ListSelectionListener) listeners[i + 1]).valueChanged(e);                }            }        }        private void fireValueChanged() {            if (lastChangedIndex == MIN) {                return;            }            /* Change the values before sending the event to the             * listeners in case the event causes a listener to make             * another change to the selection.             */            int oldFirstChangedIndex = firstChangedIndex;            int oldLastChangedIndex = lastChangedIndex;            firstChangedIndex = MAX;            lastChangedIndex = MIN;            fireValueChanged(oldFirstChangedIndex, oldLastChangedIndex);        }        // Update first and last change indices        private void markAsDirty(int r) {            firstChangedIndex = Math.min(firstChangedIndex, r);            lastChangedIndex = Math.max(lastChangedIndex, r);        }        // Set the state at this index and update all relevant state.        private void set(int r) {            if (value.get(r)) {                return;            }            value.set(r);            //Option option = (Option) get(r);            //option.setSelection(true);            markAsDirty(r);            // Update minimum and maximum indices            minIndex = Math.min(minIndex, r);            maxIndex = Math.max(maxIndex, r);        }        // Clear the state at this index and update all relevant state.        private void clear(int r) {            if (!value.get(r)) {                return;            }            value.clear(r);            //Option option = (Option) get(r);            //option.setSelection(false);            markAsDirty(r);            // Update minimum and maximum indices            /*               If (r > minIndex) the minimum has not changed.               The case (r < minIndex) is not possible because r'th value was set.               We only need to check for the case when lowest entry has been cleared,               and in this case we need to search for the first value set above it.            */            if (r == minIndex) {                for (minIndex = minIndex + 1; minIndex <= maxIndex; minIndex++) {                    if (value.get(minIndex)) {                        break;                    }                }            }            /*

⌨️ 快捷键说明

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