Debian Codegraph @

rhino/src/org/mozilla/javascript/xml/XMLLib.java

raw symbols SCIP
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.xml;
8
9 import org.mozilla.javascript.*;
10
11 public abstract class XMLLib
12 {
13 private static final Object XML_LIB_KEY = new Object();
14
15 /**
16 * An object which specifies an XMLLib implementation to be used at runtime.
17 *
18 * This interface should be considered experimental. It may be better
19 * (and certainly more flexible) to write an interface that returns an
20 * XMLLib object rather than a class name, for example. But that would
21 * cause many more ripple effects in the code, all the way back to
22 * {@link ScriptRuntime}.
23 */
24 public static abstract class Factory {
25
26 public static Factory create(final String className) {
27 return new Factory() {
28 @Override
29 public String getImplementationClassName() {
30 return className;
31 }
32 };
33 }
34
35 public abstract String getImplementationClassName();
36 }
37
38 public static XMLLib extractFromScopeOrNull(Scriptable scope)
39 {
40 ScriptableObject so = ScriptRuntime.getLibraryScopeOrNull(scope);
41 if (so == null) {
42 // If library is not yet initialized, return null
43 return null;
44 }
45
46 // Ensure lazily initialization of real XML library instance
47 // which is done on first access to XML property
48 ScriptableObject.getProperty(so, "XML");
49
50 return (XMLLib)so.getAssociatedValue(XML_LIB_KEY);
51 }
52
53 public static XMLLib extractFromScope(Scriptable scope)
54 {
55 XMLLib lib = extractFromScopeOrNull(scope);
56 if (lib != null) {
57 return lib;
58 }
59 String msg = ScriptRuntime.getMessage0("msg.XML.not.available");
60 throw Context.reportRuntimeError(msg);
61 }
62
63 protected final XMLLib bindToScope(Scriptable scope)
64 {
65 ScriptableObject so = ScriptRuntime.getLibraryScopeOrNull(scope);
66 if (so == null) {
67 // standard library should be initialized at this point
68 throw new IllegalStateException();
69 }
70 return (XMLLib)so.associateValue(XML_LIB_KEY, this);
71 }
72
73 public abstract boolean isXMLName(Context cx, Object name);
74
75 public abstract Ref nameRef(Context cx, Object name,
76 Scriptable scope, int memberTypeFlags);
77
78 public abstract Ref nameRef(Context cx, Object namespace, Object name,
79 Scriptable scope, int memberTypeFlags);
80
81 /**
82 * Escapes the reserved characters in a value of an attribute.
83 *
84 * @param value Unescaped text
85 * @return The escaped text
86 */
87 public abstract String escapeAttributeValue(Object value);
88
89 /**
90 * Escapes the reserved characters in a value of a text node.
91 *
92 * @param value Unescaped text
93 * @return The escaped text
94 */
95 public abstract String escapeTextValue(Object value);
96
97
98 /**
99 * Construct namespace for default xml statement.
100 */
101 public abstract Object toDefaultXmlNamespace(Context cx, Object uriValue);
102
103 public void setIgnoreComments(boolean b) {
104 throw new UnsupportedOperationException();
105 }
106
107 public void setIgnoreWhitespace(boolean b) {
108 throw new UnsupportedOperationException();
109 }
110
111 public void setIgnoreProcessingInstructions(boolean b) {
112 throw new UnsupportedOperationException();
113 }
114
115 public void setPrettyPrinting(boolean b) {
116 throw new UnsupportedOperationException();
117 }
118
119 public void setPrettyIndent(int i) {
120 throw new UnsupportedOperationException();
121 }
122
123 public boolean isIgnoreComments() {
124 throw new UnsupportedOperationException();
125 }
126
127 public boolean isIgnoreProcessingInstructions() {
128 throw new UnsupportedOperationException();
129 }
130
131 public boolean isIgnoreWhitespace() {
132 throw new UnsupportedOperationException();
133 }
134
135 public boolean isPrettyPrinting() {
136 throw new UnsupportedOperationException();
137 }
138
139 public int getPrettyIndent() {
140 throw new UnsupportedOperationException();
141 }
142 }