001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xml.stream;
030:
031: import java.io.IOException;
032: import static javax.xml.XMLConstants.*;
033: import org.w3c.dom.*;
034: import com.caucho.vfs.WriteStream;
035:
036: /**
037: * Binding to a namespace URL.
038: */
039: final class NamespaceBinding {
040: private String _prefix;
041:
042: private String _uri;
043:
044: private int _version;
045:
046: // namespaces are only emitted (written) when writeNamespace() or
047: // writeDefaultNamespace() is called explicitly.
048: private boolean _emit = false;
049:
050: NamespaceBinding(String prefix, String uri, int version) {
051: _prefix = prefix;
052: _uri = uri;
053: _version = version;
054: }
055:
056: String getUri() {
057: return _uri;
058: }
059:
060: void setUri(String uri) {
061: _uri = uri;
062: }
063:
064: void setVersion(int version) {
065: _version = version;
066: }
067:
068: int getVersion() {
069: return _version;
070: }
071:
072: String getPrefix() {
073: return _prefix;
074: }
075:
076: void setPrefix(String prefix) {
077: _prefix = prefix;
078: }
079:
080: void emit(WriteStream ws) throws IOException {
081: if (_emit) {
082: if (DEFAULT_NS_PREFIX.equals(_prefix)) {
083: ws.print(" ");
084: ws.print(XMLNS_ATTRIBUTE);
085: } else {
086: ws.print(" ");
087: ws.print(XMLNS_ATTRIBUTE);
088: ws.print(":");
089: ws.print(Escapifier.escape(_prefix));
090: }
091:
092: ws.print("=\"");
093: ws.print(Escapifier.escape(_uri));
094: ws.print('"');
095:
096: _emit = false;
097: }
098: }
099:
100: boolean isEmit() {
101: return _emit;
102: }
103:
104: void setEmit(boolean emit) {
105: _emit = emit;
106: }
107:
108: public String toString() {
109: return "NamespaceBinding[prefix=" + _prefix + ",uri=" + _uri
110: + ",version=" + _version + ",emit=" + _emit + "]";
111: }
112: }
|