| 1 | /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | |
| 7 | package org.mozilla.javascript.ast; |
| 8 | |
| 9 | /** |
| 10 | * AST node for an XML-text-only component of an XML literal expression. This |
| 11 | * node differs from a {@link StringLiteral} in that it does not have quotes for |
| 12 | * delimiters. |
| 13 | */ |
| 14 | public class XmlString extends XmlFragment { |
| 15 | |
| 16 | private String xml; |
| 17 | |
| 18 | public XmlString() { |
| 19 | } |
| 20 | |
| 21 | public XmlString(int pos) { |
| 22 | super(pos); |
| 23 | } |
| 24 | |
| 25 | public XmlString(int pos, String s) { |
| 26 | super(pos); |
| 27 | setXml(s); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Sets the string for this XML component. Sets the length of the |
| 32 | * component to the length of the passed string. |
| 33 | * @param s a string of xml text |
| 34 | * @throws IllegalArgumentException} if {@code s} is {@code null} |
| 35 | */ |
| 36 | public void setXml(String s) { |
| 37 | assertNotNull(s); |
| 38 | xml = s; |
| 39 | setLength(s.length()); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns the xml string for this component. |
| 44 | * Note that it may not be well-formed XML; it is a fragment. |
| 45 | */ |
| 46 | public String getXml() { |
| 47 | return xml; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public String toSource(int depth) { |
| 52 | return makeIndent(depth) + xml; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Visits this node. There are no children to visit. |
| 57 | */ |
| 58 | @Override |
| 59 | public void visit(NodeVisitor v) { |
| 60 | v.visit(this); |
| 61 | } |
| 62 | } |