View Javadoc

    1   /*
    2    * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    3    *
    4    * This software is open source.
    5    * See the bottom of this file for the licence.
    6    */
    7
    8   package org.dom4j.tree;
    9
    10  import java.util.Map;
    11
    12  import org.dom4j.Element;
    13
    14  /***
    15   * <p>
    16   * <code>DefaultProcessingInstruction</code> is the default Processing
    17   * Instruction implementation. It is a doubly linked node which supports the
    18   * parent relationship and can be modified in place.
    19   * </p>
    20   *
    21   * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
    22   * @version $Revision: 1.13 $
    23   */
    24  public class DefaultProcessingInstruction extends
    25          org.dom4j.tree.FlyweightProcessingInstruction {
    26      /*** The parent of this node */
    27      private Element parent;
    28
    29      /***
    30       * <p>
    31       * This will create a new PI with the given target and values
    32       * </p>
    33       *
    34       * @param target
    35       *            is the name of the PI
    36       * @param values
    37       *            is the <code>Map</code> values for the PI
    38       */
    39      public DefaultProcessingInstruction(String target, Map values) {
    40          super(target, values);
    41      }
    42
    43      /***
    44       * <p>
    45       * This will create a new PI with the given target and values
    46       * </p>
    47       *
    48       * @param target
    49       *            is the name of the PI
    50       * @param values
    51       *            is the values for the PI
    52       */
    53      public DefaultProcessingInstruction(String target, String values) {
    54          super(target, values);
    55      }
    56
    57      /***
    58       * <p>
    59       * This will create a new PI with the given target and values
    60       * </p>
    61       *
    62       * @param parent
    63       *            is the parent element
    64       * @param target
    65       *            is the name of the PI
    66       * @param values
    67       *            is the values for the PI
    68       */
    69      public DefaultProcessingInstruction(Element parent, String target,
    70              String values) {
    71          super(target, values);
    72          this.parent = parent;
    73      }
    74
    75      public void setTarget(String target) {
    76          this.target = target;
    77      }
    78
    79      public void setText(String text) {
    80          this.text = text;
    81          this.values = parseValues(text);
    82      }
    83
    84      public void setValues(Map values) {
    85          this.values = values;
    86          this.text = toString(values);
    87      }
    88
    89      public void setValue(String name, String value) {
    90          values.put(name, value);
    91      }
    92
    93      public Element getParent() {
    94          return parent;
    95      }
    96
    97      public void setParent(Element parent) {
    98          this.parent = parent;
    99      }
    100
    101     public boolean supportsParent() {
    102         return true;
    103     }
    104
    105     public boolean isReadOnly() {
    106         return false;
    107     }
    108 }
    109
    110 /*
    111  * Redistribution and use of this software and associated documentation
    112  * ("Software"), with or without modification, are permitted provided that the
    113  * following conditions are met:
    114  *
    115  * 1. Redistributions of source code must retain copyright statements and
    116  * notices. Redistributions must also contain a copy of this document.
    117  *
    118  * 2. Redistributions in binary form must reproduce the above copyright notice,
    119  * this list of conditions and the following disclaimer in the documentation
    120  * and/or other materials provided with the distribution.
    121  *
    122  * 3. The name "DOM4J" must not be used to endorse or promote products derived
    123  * from this Software without prior written permission of MetaStuff, Ltd. For
    124  * written permission, please contact dom4j-info@metastuff.com.
    125  *
    126  * 4. Products derived from this Software may not be called "DOM4J" nor may
    127  * "DOM4J" appear in their names without prior written permission of MetaStuff,
    128  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
    129  *
    130  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
    131  *
    132  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
    133  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    134  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    135  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
    136  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    137  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    138  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    139  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    140  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    141  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    142  * POSSIBILITY OF SUCH DAMAGE.
    143  *
    144  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    145  */