pax_global_header 0000666 0000000 0000000 00000000064 14404057722 0014517 g ustar 00root root 0000000 0000000 52 comment=a77ffc4a70e91945603f4947828cd7d4633a3cdb
jettison-jettison-1.5.4/ 0000775 0000000 0000000 00000000000 14404057722 0015222 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/.github/ 0000775 0000000 0000000 00000000000 14404057722 0016562 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/.github/workflows/ 0000775 0000000 0000000 00000000000 14404057722 0020617 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/.github/workflows/codeql-analysis.yml 0000664 0000000 0000000 00000005351 14404057722 0024436 0 ustar 00root root 0000000 0000000 # For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '38 10 * * 5'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'java' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# âšī¸ Command-line programs to run using the OS shell.
# đ See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
jettison-jettison-1.5.4/.gitignore 0000664 0000000 0000000 00000000241 14404057722 0017207 0 ustar 00root root 0000000 0000000 .idea/
.mvn/
*.iml
*.ipr
*.iws
.DS_Store
.checkstyle
.classpath
.ekstazi
.pmd
.pmdruleset
.pmdruleset.xml
.project
.ruleset
.settings/
target/
velocity.log
bin/
jettison-jettison-1.5.4/LICENSE 0000664 0000000 0000000 00000026136 14404057722 0016237 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
jettison-jettison-1.5.4/README.md 0000664 0000000 0000000 00000001400 14404057722 0016474 0 ustar 00root root 0000000 0000000 Jettison is a Java library for converting XML to JSON and vice-versa with the help of StAX (https://en.wikipedia.org/wiki/StAX).
It implements XMLStreamWriter and XMLStreamReader and supports Mapped and BadgerFish conventions. Latest release is 1.4.0.
For example, with a Mapped convention, JAXB processes JAXB beans and emits XMLStreamWriter events which are processed by Jettison
with the XML data being converted to JSON. Likewise, when it reads JSON, it reports XMLStreamReader events for JAXB to populate JAXB
beans.
Note improving and supporting the Mapped convention code is the main focus of this project. However the pull requests from
BadgerFish convention users are welcomed.
Jettison was originally created by Dan Diephouse and hosted at Codehause.
jettison-jettison-1.5.4/pom.xml 0000664 0000000 0000000 00000017211 14404057722 0016541 0 ustar 00root root 0000000 0000000 4.0.0org.codehaus.jettisonjettison1.5.4bundleJettisonA StAX implementation for JSON.https://github.com/jettison-json/jettisonApache License, Version 2.0http://www.apache.org/licenses/LICENSE-2.0junitjunit4.13.2testcom.fasterxml.woodstoxwoodstox-core6.4.0testscm:git:http://github.com/jettison-json/jettison.gitscm:git:https://github.com/jettison-json/jettison.githttps://github.com/jettison-json/jettisonjettison-1.5.4ossrhhttps://oss.sonatype.org/content/repositories/snapshotsossrhhttps://oss.sonatype.org/service/local/staging/deploy/maven2/org.apache.maven.pluginsmaven-enforcer-plugin3.0.0enforce-mavenenforce3.2.5org.apache.maven.pluginsmaven-compiler-plugin3.10.11.81.8truetruetruetrueorg.sonatype.pluginsnexus-staging-maven-plugin1.6.13trueossrhhttps://oss.sonatype.org/trueorg.apache.felixmaven-bundle-plugintrue5.1.6${project.artifactId}${project.groupId}.${project.artifactId}org.codehaus.jettison*;version=${project.version}javax.xml,*${project.name}${project.version}
<_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))
<_nouses>true
org.apache.maven.pluginsmaven-release-plugin2.5.3falseclean installdeploy-Preleasetruereleasetruemaven-deploy-plugin2.8.2${deploy.altRepository}truemaven-gpg-plugin3.0.1signorg.apache.maven.pluginsmaven-source-pluginattach-sourcesjar-no-forkorg.apache.maven.pluginsmaven-javadoc-pluginattach-javadocsjarorg.apache.maven.pluginsmaven-project-info-reports-pluginorg.apache.maven.pluginsmaven-javadoc-pluginorg.apache.maven.pluginsmaven-surefire-pluginpertestThe Jettison Teamhttps://github.com/jettison-json/jettison
jettison-jettison-1.5.4/src/ 0000775 0000000 0000000 00000000000 14404057722 0016011 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/ 0000775 0000000 0000000 00000000000 14404057722 0016735 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/ 0000775 0000000 0000000 00000000000 14404057722 0017656 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/ 0000775 0000000 0000000 00000000000 14404057722 0020445 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/ 0000775 0000000 0000000 00000000000 14404057722 0022240 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/ 0000775 0000000 0000000 00000000000 14404057722 0024077 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/AbstractDOMDocumentParser.java 0000664 0000000 0000000 00000006462 14404057722 0031731 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.dom.DOMResult;
import org.w3c.dom.Document;
/**
* An abstract JSON DOM parser
*
* @author Thomas.Diesler@jboss.com
* @author Dejan Bosanac
* @since 21-Mar-2008
*/
public class AbstractDOMDocumentParser {
private AbstractXMLInputFactory inputFactory;
protected AbstractDOMDocumentParser(AbstractXMLInputFactory inputFactory) {
this.inputFactory = inputFactory;
}
public Document parse(InputStream input) throws IOException {
try {
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(input);
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = readerFactory.createXMLEventReader(streamReader);
// Can not create a STaX writer for a DOMResult in woodstox-3.1.1
/*XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
Document nsDom = getDocumentBuilder().newDocument();
DOMResult result = new DOMResult(nsDom);
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(result);*/
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(baos);
eventWriter.add(eventReader);
eventWriter.close();
// This parsing step should not be necessary, if we could output to a DOMResult
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return getDocumentBuilder().parse(bais);
//return nsDom;
} catch (Exception ex) {
IOException ioex = new IOException("Cannot parse input stream");
ioex.initCause(ex);
throw ioex;
}
}
private DocumentBuilder getDocumentBuilder() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder;
} catch (ParserConfigurationException e) {
throw new RuntimeException("Failed to create DocumentBuilder", e);
}
}
} jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/AbstractDOMDocumentSerializer.java 0000664 0000000 0000000 00000004333 14404057722 0032601 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.dom.DOMSource;
import org.codehaus.jettison.badgerfish.BadgerFishXMLOutputFactory;
import org.w3c.dom.Element;
/**
* An abstract JSON DOM serializer
*
* @author Thomas.Diesler@jboss.com
* @author Dejan Bosanac
* @since 21-Mar-2008
*/
public class AbstractDOMDocumentSerializer {
private OutputStream output;
private AbstractXMLOutputFactory writerFactory;
public AbstractDOMDocumentSerializer(OutputStream output, AbstractXMLOutputFactory writerFactory) {
this.output = output;
this.writerFactory = writerFactory;
}
public void serialize(Element el) throws IOException {
if (output == null)
throw new IllegalStateException("OutputStream cannot be null");
try {
DOMSource source = new DOMSource(el);
XMLInputFactory readerFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = readerFactory
.createXMLStreamReader(source);
XMLEventReader eventReader = readerFactory
.createXMLEventReader(streamReader);
XMLEventWriter eventWriter = writerFactory
.createXMLEventWriter(output);
eventWriter.add(eventReader);
eventWriter.close();
} catch (XMLStreamException ex) {
IOException ioex = new IOException("Cannot serialize: " + el);
ioex.initCause(ex);
throw ioex;
}
}
} jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/AbstractXMLEventWriter.java 0000664 0000000 0000000 00000010466 14404057722 0031274 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.util.Iterator;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
/**
* An XMLEventWriter that delegates to an XMLStreamWriter.
*
* @author Thomas.Diesler@jboss.com
* @since 21-Mar-2008
*/
public class AbstractXMLEventWriter implements XMLEventWriter {
private XMLStreamWriter streamWriter;
public AbstractXMLEventWriter(XMLStreamWriter streamWriter) {
this.streamWriter = streamWriter;
}
public void add(XMLEvent event) throws XMLStreamException {
if (event.isStartDocument()) {
streamWriter.writeStartDocument();
} else if (event.isStartElement()) {
StartElement element = event.asStartElement();
QName elQName = element.getName();
if (elQName.getPrefix().length() > 0
&& elQName.getNamespaceURI().length() > 0)
streamWriter.writeStartElement(elQName.getPrefix(), elQName
.getLocalPart(), elQName.getNamespaceURI());
else if (elQName.getNamespaceURI().length() > 0)
streamWriter.writeStartElement(elQName.getNamespaceURI(),
elQName.getLocalPart());
else
streamWriter.writeStartElement(elQName.getLocalPart());
// Add element namespaces
Iterator namespaces = element.getNamespaces();
while (namespaces.hasNext()) {
Namespace ns = (Namespace) namespaces.next();
String prefix = ns.getPrefix();
String nsURI = ns.getNamespaceURI();
streamWriter.writeNamespace(prefix, nsURI);
}
// Add element attributes
Iterator attris = element.getAttributes();
while (attris.hasNext()) {
Attribute attr = (Attribute) attris.next();
QName atQName = attr.getName();
String value = attr.getValue();
if (atQName.getPrefix().length() > 0
&& atQName.getNamespaceURI().length() > 0)
streamWriter.writeAttribute(atQName.getPrefix(), atQName
.getNamespaceURI(), atQName.getLocalPart(), value);
else if (atQName.getNamespaceURI().length() > 0)
streamWriter.writeAttribute(atQName.getNamespaceURI(),
atQName.getLocalPart(), value);
else
streamWriter.writeAttribute(atQName.getLocalPart(), value);
}
} else if (event.isCharacters()) {
Characters chars = event.asCharacters();
streamWriter.writeCharacters(chars.getData());
} else if (event.isEndElement()) {
streamWriter.writeEndElement();
} else if (event.isEndDocument()) {
streamWriter.writeEndDocument();
} else {
throw new XMLStreamException("Unsupported event type: " + event);
}
}
public void add(XMLEventReader eventReader) throws XMLStreamException {
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
add(event);
}
close();
}
public void close() throws XMLStreamException {
streamWriter.close();
}
public void flush() throws XMLStreamException {
streamWriter.flush();
}
public NamespaceContext getNamespaceContext() {
return streamWriter.getNamespaceContext();
}
public String getPrefix(String prefix) throws XMLStreamException {
return streamWriter.getPrefix(prefix);
}
public void setDefaultNamespace(String namespace) throws XMLStreamException {
streamWriter.setDefaultNamespace(namespace);
}
public void setNamespaceContext(NamespaceContext nsContext)
throws XMLStreamException {
streamWriter.setNamespaceContext(nsContext);
}
public void setPrefix(String prefix, String uri) throws XMLStreamException {
streamWriter.setPrefix(prefix, uri);
}
} jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/AbstractXMLInputFactory.java 0000664 0000000 0000000 00000021411 14404057722 0031435 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.io.*;
import javax.xml.stream.EventFilter;
import javax.xml.stream.StreamFilter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLReporter;
import javax.xml.stream.XMLResolver;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.util.XMLEventAllocator;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import org.codehaus.jettison.json.JSONTokener;
public abstract class AbstractXMLInputFactory extends XMLInputFactory {
private final static int INPUT_BUF_SIZE = 1024;
private int bufSize = INPUT_BUF_SIZE;
protected AbstractXMLInputFactory() {
}
protected AbstractXMLInputFactory(int bufSize) {
this.bufSize = bufSize;
}
public XMLEventReader createFilteredReader(XMLEventReader arg0, EventFilter arg1) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLStreamReader createFilteredReader(XMLStreamReader arg0, StreamFilter arg1) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLEventReader createXMLEventReader(InputStream arg0, String encoding) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLEventReader createXMLEventReader(InputStream arg0) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLEventReader createXMLEventReader(Reader arg0) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLEventReader createXMLEventReader(Source arg0) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLEventReader createXMLEventReader(String systemId, InputStream arg1) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLEventReader createXMLEventReader(String systemId, Reader arg1) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLEventReader createXMLEventReader(XMLStreamReader arg0) throws XMLStreamException {
// TODO Auto-generated method stub
return null;
}
public XMLStreamReader createXMLStreamReader(InputStream is) throws XMLStreamException {
return createXMLStreamReader(is, null);
}
public XMLStreamReader createXMLStreamReader(InputStream is, String charset) throws XMLStreamException {
/* !!! This is not really correct: should (try to) auto-detect
* encoding, since JSON only allows 3 Unicode-based variants.
* For now it's ok to default to UTF-8 though.
*/
if (charset == null) {
charset = "UTF-8";
}
try {
String doc = readAll(is, charset);
return createXMLStreamReader(createNewJSONTokener(doc));
} catch (IOException e) {
throw new XMLStreamException(e);
}
}
protected JSONTokener createNewJSONTokener(String doc) {
return new JSONTokener(doc);
}
/**
* This helper method tries to read and decode input efficiently
* into a result String.
*/
private String readAll(InputStream in, String encoding)
throws IOException
{
final byte[] buffer = new byte[bufSize];
ByteArrayOutputStream bos = null;
while (true) {
int count = in.read(buffer);
if (count < 0) { // EOF
break;
}
/* Let's create buffer lazily, to be able to create something
* that's not too small (many resizes) or too big (slower
* to allocate): mostly to speed up handling of tiny docs.
*/
if (bos == null) {
int cap;
if (count < 64) {
cap = 64;
} else if (count == bufSize) {
// Let's assume there's more coming, not just this chunk
cap = bufSize * 4;
} else {
cap = count;
}
bos = new ByteArrayOutputStream(cap);
}
bos.write(buffer, 0, count);
}
return (bos == null) ? "" : bos.toString(encoding);
}
public abstract XMLStreamReader createXMLStreamReader(JSONTokener tokener) throws XMLStreamException;
public XMLStreamReader createXMLStreamReader(Reader reader) throws XMLStreamException {
try {
return createXMLStreamReader(new JSONTokener(readAll(reader)));
} catch (IOException e) {
throw new XMLStreamException(e);
}
}
private String readAll(Reader r)
throws IOException
{
// Let's see if it's a small doc, can read it all in a single buffer
char[] buf = new char[bufSize];
int len = 0;
do {
int count = r.read(buf, len, buf.length-len);
if (count < 0) { // Got it all
return (len == 0) ? "" : new String(buf, 0, len);
}
len += count;
} while (len < buf.length);
/* Filled the read buffer, need to coalesce. Let's assume there'll
* be a bit more data coming
*/
CharArrayWriter wrt = new CharArrayWriter(bufSize * 4);
wrt.write(buf, 0, len);
while ((len = r.read(buf)) != -1) {
wrt.write(buf, 0, len);
}
return wrt.toString();
}
public XMLStreamReader createXMLStreamReader(Source src) throws XMLStreamException
{
// Can only support simplest of sources:
if (src instanceof StreamSource) {
StreamSource ss = (StreamSource) src;
InputStream in = ss.getInputStream();
String systemId = ss.getSystemId();
if (in != null) {
if (systemId != null) {
return createXMLStreamReader(systemId, in);
}
return createXMLStreamReader(in);
}
Reader r = ss.getReader();
if (r != null) {
if (systemId != null) {
return createXMLStreamReader(systemId, r);
}
return createXMLStreamReader(r);
}
throw new UnsupportedOperationException("Only those javax.xml.transform.stream.StreamSource instances supported that have an InputStream or Reader");
}
throw new UnsupportedOperationException("Only javax.xml.transform.stream.StreamSource type supported");
}
public XMLStreamReader createXMLStreamReader(String systemId, InputStream arg1) throws XMLStreamException {
// How (if) should the system id be used?
return createXMLStreamReader(arg1, null);
}
public XMLStreamReader createXMLStreamReader(String systemId, Reader r) throws XMLStreamException {
return createXMLStreamReader(r);
}
public XMLEventAllocator getEventAllocator() {
// TODO Auto-generated method stub
return null;
}
public Object getProperty(String arg0) throws IllegalArgumentException {
// TODO: should gracefully handle standard properties
throw new IllegalArgumentException();
}
public XMLReporter getXMLReporter() {
return null;
}
public XMLResolver getXMLResolver() {
return null;
}
public boolean isPropertySupported(String arg0) {
return false;
}
public void setEventAllocator(XMLEventAllocator arg0) {
// TODO Auto-generated method stub
}
public void setProperty(String arg0, Object arg1) throws IllegalArgumentException {
// TODO: should gracefully handle standard properties
throw new IllegalArgumentException();
}
public void setXMLReporter(XMLReporter arg0) {
// TODO Auto-generated method stub
}
public void setXMLResolver(XMLResolver arg0) {
// TODO Auto-generated method stub
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/AbstractXMLOutputFactory.java 0000664 0000000 0000000 00000007137 14404057722 0031647 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
public abstract class AbstractXMLOutputFactory extends XMLOutputFactory {
public XMLEventWriter createXMLEventWriter(OutputStream out, String charset) throws XMLStreamException {
return new AbstractXMLEventWriter(createXMLStreamWriter(out, charset));
}
public XMLEventWriter createXMLEventWriter(OutputStream out) throws XMLStreamException {
return new AbstractXMLEventWriter(createXMLStreamWriter(out));
}
public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException {
return new AbstractXMLEventWriter(createXMLStreamWriter(result));
}
public XMLEventWriter createXMLEventWriter(Writer writer) throws XMLStreamException {
return new AbstractXMLEventWriter(createXMLStreamWriter(writer));
}
public XMLStreamWriter createXMLStreamWriter(OutputStream out, String charset) throws XMLStreamException {
if (charset == null) {
charset = "UTF-8";
}
try {
return createXMLStreamWriter(new OutputStreamWriter(out, charset));
} catch (UnsupportedEncodingException e) {
throw new XMLStreamException(e);
}
}
public XMLStreamWriter createXMLStreamWriter(OutputStream out) throws XMLStreamException {
return createXMLStreamWriter(out, null);
}
public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException {
// Can only support simplest of Result impls:
if (result instanceof StreamResult) {
StreamResult sr = (StreamResult) result;
OutputStream out = sr.getOutputStream();
if (out != null) {
return createXMLStreamWriter(out);
}
Writer w = sr.getWriter();
if (w != null) {
return createXMLStreamWriter(w);
}
throw new UnsupportedOperationException("Only those javax.xml.transform.stream.StreamResult instances supported that have an OutputStream or Writer");
}
throw new UnsupportedOperationException("Only javax.xml.transform.stream.StreamResult type supported");
}
public abstract XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException;
public Object getProperty(String arg0) throws IllegalArgumentException {
// TODO Auto-generated method stub
return null;
}
public boolean isPropertySupported(String arg0) {
// TODO Auto-generated method stub
return false;
}
public void setProperty(String arg0, Object arg1) throws IllegalArgumentException {
// TODO Auto-generated method stub
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/AbstractXMLStreamReader.java 0000664 0000000 0000000 00000012643 14404057722 0031373 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
public abstract class AbstractXMLStreamReader implements XMLStreamReader {
protected int event;
protected Node node;
public boolean isAttributeSpecified(int index) {
return false;
}
public boolean isCharacters() {
return event == CHARACTERS;
}
public boolean isEndElement() {
return event == END_ELEMENT;
}
public boolean isStandalone() {
return false;
}
public boolean isStartElement() {
return event == START_ELEMENT;
}
public boolean isWhiteSpace() {
return false;
}
public int nextTag() throws XMLStreamException {
int event = next();
while (event != START_ELEMENT && event != END_ELEMENT) {
event = next();
}
return event;
}
public int getEventType() {
return event;
}
public void require(int arg0, String arg1, String arg2) throws XMLStreamException {
}
public int getAttributeCount() {
return node.getAttributes().size();
}
public String getAttributeLocalName(int n) {
return getAttributeName(n).getLocalPart();
}
public QName getAttributeName(int n) {
Iterator itr = node.getAttributes().keySet().iterator();
QName name = null;
for (int i = 0; i <= n; i++) {
name = (QName) itr.next();
}
return name;
}
public String getAttributeNamespace(int n) {
return getAttributeName(n).getNamespaceURI();
}
public String getAttributePrefix(int n) {
return getAttributeName(n).getPrefix();
}
public String getAttributeValue(int n) {
Iterator itr = node.getAttributes().values().iterator();
String name = null;
for (int i = 0; i <= n; i++) {
name = (String) itr.next();
}
return name;
}
public String getAttributeValue(String ns, String local) {
return (String) node.getAttributes().get(new QName(ns, local));
}
public String getAttributeType(int index) {
return "CDATA";
}
public String getLocalName() {
return getName().getLocalPart();
}
public QName getName() {
return node.getName();
}
public String getNamespaceURI() {
return getName().getNamespaceURI();
}
public int getNamespaceCount() {
return node.getNamespaceCount();
}
public String getNamespacePrefix(int n) {
return node.getNamespacePrefix(n);
}
public String getNamespaceURI(int n) {
return node.getNamespaceURI(n);
}
public String getNamespaceURI(String prefix) {
return node.getNamespaceURI(prefix);
}
public boolean hasName() {
// TODO Auto-generated method stub
return false;
}
public boolean hasNext() throws XMLStreamException {
return event != END_DOCUMENT;
}
public boolean hasText() {
return event == CHARACTERS;
}
public boolean standaloneSet() {
return false;
}
public String getCharacterEncodingScheme() {
return null;
}
public String getEncoding() {
return null;
}
public Location getLocation() {
return new Location() {
public int getCharacterOffset() {
return 0;
}
public int getColumnNumber() {
return 0;
}
public int getLineNumber() {
return -1;
}
public String getPublicId() {
return null;
}
public String getSystemId() {
return null;
}
};
}
public String getPIData() {
return null;
}
public String getPITarget() {
return null;
}
public String getPrefix() {
return getName().getPrefix();
}
public Object getProperty(String arg0) throws IllegalArgumentException {
return null;
}
public String getVersion() {
return null;
}
public char[] getTextCharacters() {
String text = getText();
return text != null ? text.toCharArray() : new char[]{};
}
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException {
String text = getText();
if (text != null) {
text.getChars(sourceStart,sourceStart+length,target,targetStart);
return length;
} else {
return 0;
}
}
public int getTextLength() {
String text = getText();
return text != null ? text.length() : 0;
}
public int getTextStart() {
return 0;
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/AbstractXMLStreamWriter.java 0000664 0000000 0000000 00000005771 14404057722 0031451 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.util.ArrayList;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
public abstract class AbstractXMLStreamWriter implements XMLStreamWriter {
private ArrayList serializedAsArrays = new ArrayList();
private boolean arrayKeysWithSlashAvailable;
public void writeCData(String text) throws XMLStreamException {
writeCharacters(text);
}
public void writeCharacters(char[] arg0, int arg1, int arg2) throws XMLStreamException {
writeCharacters(new String(arg0, arg1, arg2));
}
public void writeEmptyElement(String prefix, String local, String ns) throws XMLStreamException {
writeStartElement(prefix, local, ns);
writeEndElement();
}
public void writeEmptyElement(String ns, String local) throws XMLStreamException {
writeStartElement(local, ns);
writeEndElement();
}
public void writeEmptyElement(String local) throws XMLStreamException {
writeStartElement(local);
writeEndElement();
}
public void writeStartDocument(String arg0, String arg1) throws XMLStreamException {
writeStartDocument();
}
public void writeStartDocument(String arg0) throws XMLStreamException {
writeStartDocument();
}
public void writeStartElement(String ns, String local) throws XMLStreamException {
writeStartElement("", local, ns);
}
public void writeStartElement(String local) throws XMLStreamException {
writeStartElement("", local, "");
}
public void writeComment(String arg0) throws XMLStreamException {
}
public void writeDTD(String arg0) throws XMLStreamException {
}
public void writeEndDocument() throws XMLStreamException {
}
public void serializeAsArray(String name) {
serializedAsArrays.add(name);
if (!arrayKeysWithSlashAvailable) {
arrayKeysWithSlashAvailable = name.contains("/");
}
}
/**
* @deprecated since 1.2 because of misspelling. Use serializeAsArray(String name) instead.
* @param name the name
*/
@Deprecated
public void seriliazeAsArray(String name) {
serializedAsArrays.add(name);
}
public ArrayList getSerializedAsArrays() {
return serializedAsArrays;
}
public boolean isArrayKeysWithSlashAvailable() {
return arrayKeysWithSlashAvailable;
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/Convention.java 0000664 0000000 0000000 00000002016 14404057722 0027063 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
public interface Convention {
void processAttributesAndNamespaces(Node n, JSONObject object)
throws JSONException, XMLStreamException;
QName createQName(String name, Node node) throws XMLStreamException;
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/JSONSequenceTooLargeException.java 0000664 0000000 0000000 00000001536 14404057722 0032525 0 ustar 00root root 0000000 0000000 /**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import org.codehaus.jettison.json.JSONException;
public class JSONSequenceTooLargeException extends JSONException {
private static final long serialVersionUID = -8281225263069171596L;
public JSONSequenceTooLargeException(String message) {
super(message);
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/Node.java 0000664 0000000 0000000 00000012072 14404057722 0025631 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
public class Node {
JSONObject object;
Map attributes;
Map namespaces;
Iterator keys;
QName name;
JSONArray array;
int arrayIndex;
String currentKey;
Node parent;
public Node(Node parent, String name, JSONObject object, Convention con)
throws JSONException, XMLStreamException {
this.parent = parent;
this.object = object;
/* Should really use a _Linked_ HashMap to preserve
* ordering (insert order) -- regular one has arbitrary ordering.
* But there are some funky dependencies within unit tests
* that will fail right now, need to investigate that bit more
*/
this.namespaces = new LinkedHashMap();
this.attributes = new LinkedHashMap();
con.processAttributesAndNamespaces(this, object);
keys = object.keys();
this.name = con.createQName(name, this);
}
public Node(String name, Convention con) throws XMLStreamException {
this.name = con.createQName(name, this);
this.namespaces = new HashMap();
this.attributes = new HashMap();
}
public Node(JSONObject object) {
this.object = object;
this.namespaces = new HashMap();
this.attributes = new HashMap();
}
public int getNamespaceCount() {
return namespaces.size();
}
public String getNamespaceURI(String prefix) {
String result = (String) namespaces.get(prefix);
if (result == null && parent != null) {
result = parent.getNamespaceURI(prefix);
}
return result;
}
public String getNamespaceURI(int index) {
if (index < 0 || index >= getNamespaceCount()) {
throw new IllegalArgumentException("Illegal index: element has "+getNamespaceCount()+" namespace declarations");
}
Iterator itr = namespaces.values().iterator();
while (--index >= 0) {
itr.next();
}
Object ns = itr.next();
return ns == null ? "" : ns.toString();
}
public String getNamespacePrefix(String URI) {
String result = null;
for (Iterator nsItr = namespaces.entrySet().iterator(); nsItr.hasNext();) {
Map.Entry e = (Map.Entry) nsItr.next();
if (e.getValue().equals(URI)) {
result = (String) e.getKey();
}
}
if (result == null && parent != null) {
result = parent.getNamespacePrefix(URI);
}
return result;
}
public String getNamespacePrefix(int index) {
if (index < 0 || index >= getNamespaceCount()) {
throw new IllegalArgumentException("Illegal index: element has "+getNamespaceCount()+" namespace declarations");
}
Iterator itr = namespaces.keySet().iterator();
while (--index >= 0) {
itr.next();
}
return itr.next().toString();
}
public void setNamespaces(Map namespaces) {
this.namespaces = namespaces;
}
public void setNamespace(String prefix, String uri) {
namespaces.put(prefix, uri);
}
public Map getAttributes() {
return attributes;
}
public void setAttribute(QName name, String value) {
attributes.put(name, value);
}
public Iterator getKeys() {
return keys;
}
public QName getName() {
return name;
}
public JSONObject getObject() {
return object;
}
public void setObject(JSONObject object) {
this.object = object;
}
public JSONArray getArray() {
return array;
}
public void setArray(JSONArray array) {
this.array = array;
}
public int getArrayIndex() {
return arrayIndex;
}
public void setArrayIndex(int arrayIndex) {
this.arrayIndex = arrayIndex;
}
public String getCurrentKey() {
return currentKey;
}
public void setCurrentKey(String currentKey) {
this.currentKey = currentKey;
}
public String toString() {
if (this.name != null) {
return this.name.toString();
} else {
return super.toString();
}
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/XsonNamespaceContext.java 0000664 0000000 0000000 00000003323 14404057722 0031054 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison;
import java.util.Iterator;
import java.util.Map;
import javax.xml.namespace.NamespaceContext;
import org.codehaus.jettison.util.FastStack;
public class XsonNamespaceContext implements NamespaceContext {
private FastStack nodes;
public XsonNamespaceContext(FastStack nodes) {
super();
this.nodes = nodes;
}
public String getNamespaceURI(String prefix) {
for (Iterator itr = nodes.iterator(); itr.hasNext();){
Node node = (Node) itr.next();
String uri = node.getNamespaceURI(prefix);
if (uri != null) {
return uri;
}
}
return null;
}
public String getPrefix(String namespaceURI) {
for (Iterator itr = nodes.iterator(); itr.hasNext();){
Node node = (Node) itr.next();
String prefix = node.getNamespacePrefix(namespaceURI);
if (prefix != null) {
return prefix;
}
}
return null;
}
public Iterator getPrefixes(String namespaceURI) {
return null;
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/badgerfish/ 0000775 0000000 0000000 00000000000 14404057722 0026175 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/badgerfish/BadgerFishConvention.java 0000664 0000000 0000000 00000007120 14404057722 0033101 0 ustar 00root root 0000000 0000000 /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison.badgerfish;
import java.util.Iterator;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import org.codehaus.jettison.Convention;
import org.codehaus.jettison.Node;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
public class BadgerFishConvention implements Convention {
public BadgerFishConvention() {
super();
}
public void processAttributesAndNamespaces(Node n, JSONObject object)
throws JSONException, XMLStreamException {
// Read in the attributes, and stop when there are no more
for (Iterator itr = object.keys(); itr.hasNext();) {
String k = (String) itr.next();
if (k.startsWith("@")) {
Object o = object.opt(k);
k = k.substring(1);
if (k.equals("xmlns")) {
// if its a string its a default namespace
if (o instanceof JSONObject) {
JSONObject jo = (JSONObject) o;
for (Iterator pitr = jo.keys(); pitr.hasNext(); ) {
String prefix = (String) pitr.next();
String uri = jo.getString(prefix);
if (prefix.equals("$")) {
prefix = "";
}
n.setNamespace(prefix, uri);
}
}
} else {
String strValue = (String) o;
QName name = null;
// note that a non-prefixed attribute name implies NO namespace,
// i.e. as opposed to the in-scope default namespace
if (k.contains(":")) {
name = createQName(k, n);
} else {
name = new QName(XMLConstants.DEFAULT_NS_PREFIX, k);
}
n.setAttribute(name, strValue);
}
itr.remove();
}
}
}
public QName createQName(String rootName, Node node) throws XMLStreamException {
int idx = rootName.indexOf(':');
if (idx != -1) {
String prefix = rootName.substring(0, idx);
String local = rootName.substring(idx+1);
String uri = (String) node.getNamespaceURI(prefix);
if (uri == null) {
throw new XMLStreamException("Invalid prefix " + prefix
+ " on element " + rootName);
}
return new QName(uri, local, prefix);
}
String uri = (String) node.getNamespaceURI("");
if (uri != null) {
return new QName(uri, rootName);
}
return new QName(rootName);
}
}
BadgerFishDOMDocumentParser.java 0000664 0000000 0000000 00000002016 14404057722 0034172 0 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/badgerfish /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison.badgerfish;
import org.codehaus.jettison.AbstractDOMDocumentParser;
/**
* JSON BadgerFish DOM parser
*
* @author Thomas.Diesler@jboss.com
* @author Dejan Bosanac
* @since 21-Mar-2008
*/
public class BadgerFishDOMDocumentParser extends AbstractDOMDocumentParser {
public BadgerFishDOMDocumentParser() {
super(new BadgerFishXMLInputFactory());
}
}
BadgerFishDOMDocumentSerializer.java 0000664 0000000 0000000 00000002135 14404057722 0035051 0 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/badgerfish /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison.badgerfish;
import java.io.OutputStream;
import org.codehaus.jettison.AbstractDOMDocumentSerializer;
/**
* JSON BadgeFish DOM serializer
*
* @author Thomas.Diesler@jboss.com
* @author Dejan Bosanac
* @since 21-Mar-2008
*/
public class BadgerFishDOMDocumentSerializer extends
AbstractDOMDocumentSerializer {
public BadgerFishDOMDocumentSerializer(OutputStream output) {
super(output, new BadgerFishXMLOutputFactory());
}
}
BadgerFishXMLInputFactory.java 0000664 0000000 0000000 00000002543 14404057722 0033714 0 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/badgerfish /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison.badgerfish;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.codehaus.jettison.AbstractXMLInputFactory;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.json.JSONTokener;
public class BadgerFishXMLInputFactory extends AbstractXMLInputFactory {
public BadgerFishXMLInputFactory() {
}
public XMLStreamReader createXMLStreamReader(JSONTokener tokener) throws XMLStreamException {
try {
JSONObject root = new JSONObject(tokener);
return new BadgerFishXMLStreamReader(root);
} catch (JSONException e) {
throw new XMLStreamException(e);
}
}
}
BadgerFishXMLOutputFactory.java 0000664 0000000 0000000 00000002106 14404057722 0034110 0 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/badgerfish /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison.badgerfish;
import java.io.Writer;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.codehaus.jettison.AbstractXMLOutputFactory;
public class BadgerFishXMLOutputFactory extends AbstractXMLOutputFactory {
public BadgerFishXMLOutputFactory() {
}
public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException {
return new BadgerFishXMLStreamWriter(writer);
}
}
BadgerFishXMLStreamReader.java 0000664 0000000 0000000 00000011734 14404057722 0033645 0 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/badgerfish /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison.badgerfish;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import org.codehaus.jettison.AbstractXMLStreamReader;
import org.codehaus.jettison.Node;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.util.FastStack;
public class BadgerFishXMLStreamReader extends AbstractXMLStreamReader {
private static final BadgerFishConvention CONVENTION = new BadgerFishConvention();
private FastStack nodes;
private String currentText;
public BadgerFishXMLStreamReader(JSONObject obj)
throws JSONException, XMLStreamException {
String rootName = (String) obj.keys().next();
this.node = new Node(null, rootName, obj.getJSONObject(rootName), CONVENTION);
this.nodes = new FastStack();
nodes.push(node);
event = START_DOCUMENT;
}
public int next() throws XMLStreamException {
if (event == START_DOCUMENT) {
event = START_ELEMENT;
} else {
if (event == END_ELEMENT && nodes.size() != 0) {
node = (Node) nodes.peek();
}
if (node.getArray() != null
&& node.getArray().length() > node.getArrayIndex()) {
Node arrayNode = node;
int idx = arrayNode.getArrayIndex();
try {
Object o = arrayNode.getArray().get(idx);
processKey(node.getCurrentKey(), o);
} catch (JSONException e) {
throw new XMLStreamException(e);
}
idx++;
arrayNode.setArrayIndex(idx);
} else if (node.getKeys() != null && node.getKeys().hasNext()) {
processElement();
} else {
if (nodes.size() != 0) {
event = END_ELEMENT;
node = (Node)nodes.pop();
} else {
event = END_DOCUMENT;
}
}
}
return event;
}
private void processElement() throws XMLStreamException {
try {
String nextKey = (String) node.getKeys().next();
Object newObj = node.getObject().get(nextKey);
processKey(nextKey, newObj);
} catch (JSONException e) {
throw new XMLStreamException(e);
}
}
private void processKey(String nextKey, Object newObj) throws JSONException, XMLStreamException {
if (nextKey.equals("$")) {
event = CHARACTERS;
if (newObj instanceof JSONArray) {
JSONArray arr = (JSONArray)newObj;
StringBuilder buf = new StringBuilder();
for (int i = 0; i < arr.length(); i++) {
buf.append(arr.get(i));
}
currentText = buf.toString();
} else {
currentText = newObj == null ? null : newObj.toString();
}
return;
} else if (newObj instanceof JSONObject) {
node = new Node((Node)nodes.peek(), nextKey, (JSONObject) newObj, CONVENTION);
nodes.push(node);
event = START_ELEMENT;
return;
} else if (newObj instanceof JSONArray) {
JSONArray arr = (JSONArray) newObj;
if (arr.length() == 0) {
next();
return;
}
// save some state information...
node.setArray(arr);
node.setArrayIndex(1);
node.setCurrentKey(nextKey);
processKey(nextKey, arr.get(0));
}
else {
throw new JSONException("Element [" + nextKey + "] did not contain object, array or text content.");
}
}
public void close() throws XMLStreamException {
}
public String getAttributeType(int arg0) {
return null;
}
public String getCharacterEncodingScheme() {
return null;
}
public String getElementText() throws XMLStreamException {
return currentText;
}
public NamespaceContext getNamespaceContext() {
return null;
}
public String getText() {
return currentText;
}
}
BadgerFishXMLStreamWriter.java 0000664 0000000 0000000 00000016645 14404057722 0033725 0 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/badgerfish /**
* Copyright 2006 Envoi Solutions LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.jettison.badgerfish;
import java.io.IOException;
import java.io.Writer;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import org.codehaus.jettison.AbstractXMLStreamWriter;
import org.codehaus.jettison.Node;
import org.codehaus.jettison.XsonNamespaceContext;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.util.FastStack;
public class BadgerFishXMLStreamWriter extends AbstractXMLStreamWriter {
private JSONObject root;
private JSONObject currentNode;
private Writer writer;
private FastStack nodes;
private String currentKey;
private NamespaceContext ctx;
public BadgerFishXMLStreamWriter(Writer writer) {
this(writer, new JSONObject());
}
public BadgerFishXMLStreamWriter(Writer writer,
JSONObject currentNode) {
this(writer, new JSONObject(), new FastStack());
}
public BadgerFishXMLStreamWriter(Writer writer,
JSONObject currentNode,
FastStack nodes) {
super();
this.currentNode = currentNode;
this.root = currentNode;
this.writer = writer;
this.nodes = nodes;
this.ctx = new XsonNamespaceContext(nodes);
}
public void close() throws XMLStreamException {
}
public void flush() throws XMLStreamException {
}
public NamespaceContext getNamespaceContext() {
return ctx;
}
public String getPrefix(String ns) throws XMLStreamException {
return getNamespaceContext().getPrefix(ns);
}
public Object getProperty(String arg0) throws IllegalArgumentException {
return null;
}
public void setDefaultNamespace(String arg0) throws XMLStreamException {
}
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
this.ctx = context;
}
public void setPrefix(String arg0, String arg1) throws XMLStreamException {
}
public void writeAttribute(String p, String ns, String local, String value) throws XMLStreamException {
String key = createAttributeKey(p, ns, local);
try {
getCurrentNode().put(key, value);
} catch (JSONException e) {
throw new XMLStreamException(e);
}
}
private String createAttributeKey(String p, String ns, String local) {
return "@" + createKey(p, ns, local);
}
private String createKey(String p, String ns, String local) {
if (p == null || p.equals("")) {
return local;
}
return p + ":" + local;
}
public void writeAttribute(String ns, String local, String value) throws XMLStreamException {
writeAttribute(null, ns, local, value);
}
public void writeAttribute(String local, String value) throws XMLStreamException {
writeAttribute(null, local, value);
}
public void writeCharacters(String text) throws XMLStreamException {
text = text.trim();
if (text.length() == 0) {
return;
}
try {
Object o = getCurrentNode().opt("$");
if (o instanceof JSONArray) {
((JSONArray) o).put(text);
} else if (o instanceof String) {
JSONArray arr = new JSONArray();
arr.put(o);
arr.put(text);
getCurrentNode().put("$", arr);
} else {
getCurrentNode().put("$", text);
}
} catch (JSONException e) {
throw new XMLStreamException(e);
}
}
public void writeDefaultNamespace(String ns) throws XMLStreamException {
writeNamespace("", ns);
}
public void writeEndElement() throws XMLStreamException {
if (getNodes().size() > 1) {
getNodes().pop();
currentNode = ((Node) getNodes().peek()).getObject();
}
}
public void writeEntityRef(String arg0) throws XMLStreamException {
// TODO Auto-generated method stub
}
public void writeNamespace(String prefix, String ns) throws XMLStreamException {
((Node) getNodes().peek()).setNamespace(prefix, ns);
try {
JSONObject nsObj = getCurrentNode().optJSONObject("@xmlns");
if (nsObj == null) {
nsObj = new JSONObject();
getCurrentNode().put("@xmlns", nsObj);
}
if (prefix.equals("")) {
prefix = "$";
}
nsObj.put(prefix, ns);
} catch (JSONException e) {
throw new XMLStreamException(e);
}
}
public void writeProcessingInstruction(String arg0, String arg1) throws XMLStreamException {
// TODO Auto-generated method stub
}
public void writeProcessingInstruction(String arg0) throws XMLStreamException {
// TODO Auto-generated method stub
}
public void writeStartDocument() throws XMLStreamException {
}
public void writeEndDocument() throws XMLStreamException {
try {
root.write(writer);
writer.flush();
} catch (JSONException e) {
throw new XMLStreamException(e);
} catch (IOException e) {
throw new XMLStreamException(e);
}
}
public void writeStartElement(String prefix, String local, String ns) throws XMLStreamException {
try {
// TODO ns
currentKey = createKey(prefix, ns, local);
Object existing = getCurrentNode().opt(currentKey);
if (existing instanceof JSONObject) {
JSONArray array = new JSONArray();
array.put(existing);
JSONObject newCurrent = new JSONObject();
array.put(newCurrent);
getCurrentNode().put(currentKey, array);
currentNode = newCurrent;
Node node = new Node(currentNode);
getNodes().push(node);
} else {
JSONObject newCurrent = new JSONObject();
if (existing instanceof JSONArray) {
((JSONArray) existing).put(newCurrent);
} else {
getCurrentNode().put(currentKey, newCurrent);
}
currentNode = newCurrent;
Node node = new Node(currentNode);
getNodes().push(node);
}
} catch (JSONException e) {
throw new XMLStreamException("Could not write start element!", e);
}
}
protected JSONObject getCurrentNode() {
return currentNode;
}
protected FastStack getNodes() {
return nodes;
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/json/ 0000775 0000000 0000000 00000000000 14404057722 0025050 5 ustar 00root root 0000000 0000000 jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/json/JSONArray.java 0000664 0000000 0000000 00000074256 14404057722 0027501 0 ustar 00root root 0000000 0000000 /*
Copyright (c) 2002 JSON.org
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.codehaus.jettison.json;
import java.io.IOException;
import java.io.Serializable;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ListIterator;
import java.util.Map;
/**
* A JSONArray is an ordered sequence of values. Its external text form is a
* string wrapped in square brackets with commas separating the values. The
* internal form is an object having get and opt
* methods for accessing the values by index, and put methods for
* adding or replacing values. The values can be any of these types:
* Boolean, JSONArray, JSONObject,
* Number, String, or the
* JSONObject.NULL object.
*
* The constructor can convert a JSON text into a Java object. The
* toString method converts to JSON text.
*
* A get method returns a value if one can be found, and throws an
* exception if one cannot be found. An opt method returns a
* default value instead of throwing an exception, and so is useful for
* obtaining optional values.
*
* The generic get() and opt() methods return an
* object which you can cast or query for type. There are also typed
* get and opt methods that do type checking and type
* coersion for you.
*
* The texts produced by the toString methods strictly conform to
* JSON syntax rules. The constructors are more forgiving in the texts they will
* accept:
*
*
An extra , (comma) may appear just
* before the closing bracket.
*
The null value will be inserted when there
* is , (comma) elision.
*
Strings may be quoted with ' (single
* quote).
*
Strings do not need to be quoted at all if they do not begin with a quote
* or single quote, and if they do not contain leading or trailing spaces,
* and if they do not contain any of these characters:
* { } [ ] / \ : , = ; # and if they do not look like numbers
* and if they are not the reserved words true,
* false, or null.
*
Values can be separated by ; (semicolon) as
* well as by , (comma).
*
Numbers may have the 0- (octal) or
* 0x- (hex) prefix.
*
Comments written in the slashshlash, slashstar, and hash conventions
* will be ignored.
*
* @author JSON.org
* @version 2
*/
public class JSONArray implements Serializable {
/**
* The arrayList where the JSONArray's properties are kept.
*/
private ArrayList myArrayList;
/**
* When set to true forward slashes are escaped within the array.
* When set to false no forward slashes are escaped.
* This setting is not inherited to any JSONObject or JSONArray members of the array.
* It is only for simple strings.
* Escaping needs to be set for each contained JSONObject or JSONArray object.
*/
private boolean escapeForwardSlashAlways = true;
public boolean isEscapeForwardSlashAlways() {
return escapeForwardSlashAlways;
}
public void setEscapeForwardSlashAlways(boolean escapeForwardSlashAlways) {
this.escapeForwardSlashAlways = escapeForwardSlashAlways;
}
/**
* Construct an empty JSONArray.
*/
public JSONArray() {
this.myArrayList = new ArrayList();
}
/**
* Construct an empty JSONArray with a given capacity.
* @param capacity the initial capacity
*/
public JSONArray(int capacity) {
this.myArrayList = new ArrayList(capacity);
}
/**
* Construct a JSONArray from a JSONTokener.
* @param x A JSONTokener
* @throws JSONException If there is a syntax error.
*/
public JSONArray(JSONTokener x) throws JSONException {
this();
if (x.nextClean() != '[') {
throw x.syntaxError("A JSONArray text must start with '['");
}
char c = x.nextClean();
if (c == 0) {
throw x.syntaxError("JSONArray text must end with ']'");
} else if (c == ',') {
throw x.syntaxError("JSONArray text has a trailing ','");
}
if (c == ']') {
return;
}
x.back();
for (;;) {
if (x.nextClean() == ',') {
if (c == '[') {
throw x.syntaxError("JSONArray text has a trailing ','");
}
x.back();
this.myArrayList.add(null);
} else {
x.back();
this.myArrayList.add(x.nextValue());
}
switch (x.nextClean()) {
case ';':
case ',':
char nextClean = x.nextClean();
if (nextClean == 0) {
throw x.syntaxError("JSONArray text has a trailing ','");
} else if (nextClean == ']') {
return;
}
x.back();
break;
case ']':
return;
default:
throw x.syntaxError("Expected a ',' or ']'");
}
}
}
/**
* Construct a JSONArray from a source sJSON text.
* @param string A string that begins with
* [ (left bracket)
* and ends with ] (right bracket).
* @throws JSONException If there is a syntax error.
*/
public JSONArray(String string) throws JSONException {
this(new JSONTokener(string));
}
/**
* Construct a JSONArray from a Collection.
* @param collection A Collection.
* @throws JSONException If there is a syntax error.
*/
public JSONArray(Collection collection) throws JSONException {
this(collection, 0);
}
private JSONArray(Collection collection, int recursionDepth) throws JSONException {
if (recursionDepth > JSONObject.getGlobalRecursionDepthLimit()) {
throw new JSONException("JSONArray has reached recursion depth limit of "
+ JSONObject.getGlobalRecursionDepthLimit());
}
this.myArrayList = (collection == null) ?
new ArrayList() :
new ArrayList(collection);
// ensure a pure hierarchy of JSONObjects and JSONArrays
for (ListIterator iter = myArrayList.listIterator(); iter.hasNext();) {
Object e = iter.next();
if (e instanceof Collection) {
iter.set(new JSONArray((Collection) e, recursionDepth + 1));
}
if (e instanceof Map) {
iter.set(new JSONObject((Map) e));
}
}
}
/**
* Get the object value associated with an index.
* @param index
* The index must be between 0 and length() - 1.
* @return An object value.
* @throws JSONException If there is no value for the index.
*/
public Object get(int index) throws JSONException {
Object o = opt(index);
if (o == null) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
return o;
}
/**
* Get the boolean value associated with an index.
* The string values "true" and "false" are converted to boolean.
*
* @param index The index must be between 0 and length() - 1.
* @return The truth.
* @throws JSONException If there is no value for the index or if the
* value is not convertable to boolean.
*/
public boolean getBoolean(int index) throws JSONException {
Object o = get(index);
if (o.equals(Boolean.FALSE) ||
(o instanceof String &&
((String)o).equalsIgnoreCase("false"))) {
return false;
} else if (o.equals(Boolean.TRUE) ||
(o instanceof String &&
((String)o).equalsIgnoreCase("true"))) {
return true;
}
throw new JSONException("JSONArray[" + index + "] is not a Boolean.");
}
/**
* Get the double value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
* @throws JSONException If the key is not found or if the value cannot
* be converted to a number.
*/
public double getDouble(int index) throws JSONException {
Object o = get(index);
try {
return o instanceof Number ?
((Number)o).doubleValue() :
Double.valueOf((String)o).doubleValue();
} catch (Exception e) {
throw new JSONException("JSONArray[" + index +
"] is not a number.");
}
}
/**
* Get the int value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
* @throws JSONException If the key is not found or if the value cannot
* be converted to a number.
* if the value cannot be converted to a number.
*/
public int getInt(int index) throws JSONException {
Object o = get(index);
return o instanceof Number ?
((Number)o).intValue() : (int)getDouble(index);
}
/**
* Get the JSONArray associated with an index.
* @param index The index must be between 0 and length() - 1.
* @return A JSONArray value.
* @throws JSONException If there is no value for the index. or if the
* value is not a JSONArray
*/
public JSONArray getJSONArray(int index) throws JSONException {
Object o = get(index);
if (o instanceof JSONArray) {
return (JSONArray)o;
}
throw new JSONException("JSONArray[" + index +
"] is not a JSONArray.");
}
/**
* Get the JSONObject associated with an index.
* @param index subscript
* @return A JSONObject value.
* @throws JSONException If there is no value for the index or if the
* value is not a JSONObject
*/
public JSONObject getJSONObject(int index) throws JSONException {
Object o = get(index);
if (o instanceof JSONObject) {
return (JSONObject)o;
}
throw new JSONException("JSONArray[" + index +
"] is not a JSONObject.");
}
/**
* Get the long value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
* @throws JSONException If the key is not found or if the value cannot
* be converted to a number.
*/
public long getLong(int index) throws JSONException {
Object o = get(index);
return o instanceof Number ?
((Number)o).longValue() : (long)getDouble(index);
}
/**
* Get the string associated with an index.
* @param index The index must be between 0 and length() - 1.
* @return A string value.
* @throws JSONException If there is no value for the index.
*/
public String getString(int index) throws JSONException {
return get(index).toString();
}
/**
* Determine if the value is null.
* @param index The index must be between 0 and length() - 1.
* @return true if the value at the index is null, or if there is no value.
*/
public boolean isNull(int index) {
return JSONObject.NULL.equals(opt(index));
}
/**
* Make a string from the contents of this JSONArray. The
* separator string is inserted between each element.
* Warning: This method assumes that the data structure is acyclical.
* @param separator A string that will be inserted between the elements.
* @return a string.
* @throws JSONException If the array contains an invalid number.
*/
public String join(String separator) throws JSONException {
int len = length();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i += 1) {
if (i > 0) {
sb.append(separator);
}
sb.append(JSONObject.valueToString(this.myArrayList.get(i), escapeForwardSlashAlways));
}
return sb.toString();
}
/**
* Get the number of elements in the JSONArray, included nulls.
*
* @return The length (or size).
*/
public int length() {
return this.myArrayList.size();
}
/**
* Get the optional object value associated with an index.
* @param index The index must be between 0 and length() - 1.
* @return An object value, or null if there is no
* object at that index.
*/
public Object opt(int index) {
return (index < 0 || index >= length()) ?
null : this.myArrayList.get(index);
}
/**
* Get the optional boolean value associated with an index.
* It returns false if there is no value at that index,
* or if the value is not Boolean.TRUE or the String "true".
*
* @param index The index must be between 0 and length() - 1.
* @return The truth.
*/
public boolean optBoolean(int index) {
return optBoolean(index, false);
}
/**
* Get the optional boolean value associated with an index.
* It returns the defaultValue if there is no value at that index or if
* it is not a Boolean or the String "true" or "false" (case insensitive).
*
* @param index The index must be between 0 and length() - 1.
* @param defaultValue A boolean default.
* @return The truth.
*/
public boolean optBoolean(int index, boolean defaultValue) {
try {
return getBoolean(index);
} catch (Exception e) {
return defaultValue;
}
}
/**
* Get the optional double value associated with an index.
* NaN is returned if there is no value for the index,
* or if the value is not a number and cannot be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
*/
public double optDouble(int index) {
return optDouble(index, Double.NaN);
}
/**
* Get the optional double value associated with an index.
* The defaultValue is returned if there is no value for the index,
* or if the value is not a number and cannot be converted to a number.
*
* @param index subscript
* @param defaultValue The default value.
* @return The value.
*/
public double optDouble(int index, double defaultValue) {
try {
return getDouble(index);
} catch (Exception e) {
return defaultValue;
}
}
/**
* Get the optional int value associated with an index.
* Zero is returned if there is no value for the index,
* or if the value is not a number and cannot be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
*/
public int optInt(int index) {
return optInt(index, 0);
}
/**
* Get the optional int value associated with an index.
* The defaultValue is returned if there is no value for the index,
* or if the value is not a number and cannot be converted to a number.
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
* @return The value.
*/
public int optInt(int index, int defaultValue) {
try {
return getInt(index);
} catch (Exception e) {
return defaultValue;
}
}
/**
* Get the optional JSONArray associated with an index.
* @param index subscript
* @return A JSONArray value, or null if the index has no value,
* or if the value is not a JSONArray.
*/
public JSONArray optJSONArray(int index) {
Object o = opt(index);
return o instanceof JSONArray ? (JSONArray)o : null;
}
/**
* Get the optional JSONObject associated with an index.
* Null is returned if the key is not found, or null if the index has
* no value, or if the value is not a JSONObject.
*
* @param index The index must be between 0 and length() - 1.
* @return A JSONObject value.
*/
public JSONObject optJSONObject(int index) {
Object o = opt(index);
return o instanceof JSONObject ? (JSONObject)o : null;
}
/**
* Get the optional long value associated with an index.
* Zero is returned if there is no value for the index,
* or if the value is not a number and cannot be converted to a number.
*
* @param index The index must be between 0 and length() - 1.
* @return The value.
*/
public long optLong(int index) {
return optLong(index, 0);
}
/**
* Get the optional long value associated with an index.
* The defaultValue is returned if there is no value for the index,
* or if the value is not a number and cannot be converted to a number.
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
* @return The value.
*/
public long optLong(int index, long defaultValue) {
try {
return getLong(index);
} catch (Exception e) {
return defaultValue;
}
}
/**
* Get the optional string value associated with an index. It returns an
* empty string if there is no value at that index. If the value
* is not a string and is not null, then it is coverted to a string.
*
* @param index The index must be between 0 and length() - 1.
* @return A String value.
*/
public String optString(int index) {
return optString(index, "");
}
/**
* Get the optional string associated with an index.
* The defaultValue is returned if the key is not found.
*
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
* @return A String value.
*/
public String optString(int index, String defaultValue) {
Object o = opt(index);
return o != null ? o.toString() : defaultValue;
}
/**
* Append a boolean value. This increases the array's length by one.
*
* @param value A boolean value.
* @return this.
*/
public JSONArray put(boolean value) {
put(value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
/**
* Put a value in the JSONArray, where the value will be a
* JSONArray which is produced from a Collection.
* @param value A Collection value.
* @return this.
* @throws JSONException If there is a syntax error.
*/
public JSONArray put(Collection value) throws JSONException {
put(new JSONArray(value));
return this;
}
/**
* Append a double value. This increases the array's length by one.
*
* @param value A double value.
* @throws JSONException if the value is not finite.
* @return this.
*/
public JSONArray put(double value) throws JSONException {
Double d = new Double(value);
JSONObject.testValidity(d);
put(d);
return this;
}
/**
* Append an int value. This increases the array's length by one.
*
* @param value An int value.
* @return this.
*/
public JSONArray put(int value) {
put(Integer.valueOf(value));
return this;
}
/**
* Append an long value. This increases the array's length by one.
*
* @param value A long value.
* @return this.
*/
public JSONArray put(long value) {
put(Long.valueOf(value));
return this;
}
/**
* Put a value in the JSONArray, where the value will be a
* JSONObject which is produced from a Map.
* @param value A Map value.
* @return this.
* @throws JSONException If there is a syntax error.
*/
public JSONArray put(Map value) throws JSONException {
put(new JSONObject(value));
return this;
}
/**
* Append an object value. This increases the array's length by one.
* @param value An object value. The value should be a
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
* JSONObject.NULL object.
* @return this.
*/
public JSONArray put(Object value) {
this.myArrayList.add(value);
return this;
}
public JSONArray remove(Object value) {
this.myArrayList.remove(value);
return this;
}
/**
* Put or replace a boolean value in the JSONArray. If the index is greater
* than the length of the JSONArray, then null elements will be added as
* necessary to pad it out.
* @param index The subscript.
* @param value A boolean value.
* @return this.
* @throws JSONException If the index is negative.
*/
public JSONArray put(int index, boolean value) throws JSONException {
put(index, value ? Boolean.TRUE : Boolean.FALSE);
return this;
}
/**
* Put a value in the JSONArray, where the value will be a
* JSONArray which is produced from a Collection.
* @param index The subscript.
* @param value A Collection value.
* @return this.
* @throws JSONException If the index is negative or if the value is
* not finite.
*/
public JSONArray put(int index, Collection value) throws JSONException {
put(index, new JSONArray(value));
return this;
}
/**
* Put or replace a double value. If the index is greater than the length of
* the JSONArray, then null elements will be added as necessary to pad
* it out.
* @param index The subscript.
* @param value A double value.
* @return this.
* @throws JSONException If the index is negative or if the value is
* not finite.
*/
public JSONArray put(int index, double value) throws JSONException {
put(index, new Double(value));
return this;
}
/**
* Put or replace an int value. If the index is greater than the length of
* the JSONArray, then null elements will be added as necessary to pad
* it out.
* @param index The subscript.
* @param value An int value.
* @return this.
* @throws JSONException If the index is negative.
*/
public JSONArray put(int index, int value) throws JSONException {
put(index, Integer.valueOf(value));
return this;
}
/**
* Put or replace a long value. If the index is greater than the length of
* the JSONArray, then null elements will be added as necessary to pad
* it out.
* @param index The subscript.
* @param value A long value.
* @return this.
* @throws JSONException If the index is negative.
*/
public JSONArray put(int index, long value) throws JSONException {
put(index, Long.valueOf(value));
return this;
}
/**
* Put a value in the JSONArray, where the value will be a
* JSONObject which is produced from a Map.
* @param index The subscript.
* @param value The Map value.
* @return this.
* @throws JSONException If the index is negative or if the the value is
* an invalid number.
*/
public JSONArray put(int index, Map value) throws JSONException {
put(index, new JSONObject(value));
return this;
}
/**
* Put or replace an object value in the JSONArray. If the index is greater
* than the length of the JSONArray, then null elements will be added as
* necessary to pad it out.
* @param index The subscript.
* @param value The value to put into the array. The value should be a
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
* JSONObject.NULL object.
* @return this.
* @throws JSONException If the index is negative or if the the value is
* an invalid number.
*/
public JSONArray put(int index, Object value) throws JSONException {
JSONObject.testValidity(value);
if (index < 0) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
if (index < length()) {
this.myArrayList.set(index, value);
} else {
while (index != length()) {
put(JSONObject.NULL);
}
put(value);
}
return this;
}
/**
* Produce a JSONObject by combining a JSONArray of names with the values
* of this JSONArray.
* @param names A JSONArray containing a list of key strings. These will be
* paired with the values.
* @return A JSONObject, or null if there are no names or if this JSONArray
* has no values.
* @throws JSONException If any of the names are null.
*/
public JSONObject toJSONObject(JSONArray names) throws JSONException {
if (names == null || names.length() == 0 || length() == 0) {
return null;
}
JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1) {
jo.put(names.getString(i), this.opt(i));
}
return jo;
}
/**
* Make a JSON text of this JSONArray. For compactness, no
* unnecessary whitespace is added. If it is not possible to produce a
* syntactically correct JSON text then null will be returned instead. This
* could occur if the array contains an invalid number.
*
* Warning: This method assumes that the data structure is acyclical.
*
* @return a printable, displayable, transmittable
* representation of the array.
*/
public String toString() {
try {
return '[' + join(",") + ']';
} catch (Exception e) {
return null;
}
}
/**
* Make a prettyprinted JSON text of this JSONArray.
* Warning: This method assumes that the data structure is acyclical.
* @param indentFactor The number of spaces to add to each level of
* indentation.
* @return a printable, displayable, transmittable
* representation of the object, beginning
* with [ (left bracket) and ending
* with ] (right bracket).
* @throws JSONException JSONException
*/
public String toString(int indentFactor) throws JSONException {
return toString(indentFactor, 0);
}
/**
* Make a prettyprinted JSON text of this JSONArray.
* Warning: This method assumes that the data structure is acyclical.
* @param indentFactor The number of spaces to add to each level of
* indentation.
* @param indent The indention of the top level.
* @return a printable, displayable, transmittable
* representation of the array.
* @throws JSONException JSONException
*/
String toString(int indentFactor, int indent) throws JSONException {
int len = length();
if (len == 0) {
return "[]";
}
int i;
StringBuilder sb = new StringBuilder("[");
if (len == 1) {
sb.append(JSONObject.valueToString(this.myArrayList.get(0),
indentFactor, indent, escapeForwardSlashAlways));
} else {
int newindent = indent + indentFactor;
sb.append('\n');
for (i = 0; i < len; i += 1) {
if (i > 0) {
sb.append(",\n");
}
for (int j = 0; j < newindent; j += 1) {
sb.append(' ');
}
sb.append(JSONObject.valueToString(this.myArrayList.get(i),
indentFactor, newindent, escapeForwardSlashAlways));
}
sb.append('\n');
for (i = 0; i < indent; i += 1) {
sb.append(' ');
}
}
sb.append(']');
return sb.toString();
}
@Override
public int hashCode() {
return myArrayList.hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof JSONArray) {
return myArrayList.equals(((JSONArray)obj).myArrayList);
} else {
return false;
}
}
/**
* Write the contents of the JSONArray as JSON text to a writer.
* For compactness, no whitespace is added.
*
* Warning: This method assumes that the data structure is acyclical.
*
* @param writer The writer.
* @return The writer.
* @throws JSONException JSONException
*/
public Writer write(Writer writer) throws JSONException {
try {
boolean b = false;
int len = length();
writer.write('[');
for (int i = 0; i < len; i += 1) {
if (b) {
writer.write(',');
}
Object v = this.myArrayList.get(i);
if (v instanceof JSONObject) {
((JSONObject)v).write(writer);
} else if (v instanceof JSONArray) {
((JSONArray)v).write(writer);
} else {
writer.write(JSONObject.valueToString(v, escapeForwardSlashAlways));
}
b = true;
}
writer.write(']');
return writer;
} catch (IOException e) {
throw new JSONException(e);
}
}
} jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/json/JSONException.java 0000664 0000000 0000000 00000002525 14404057722 0030347 0 ustar 00root root 0000000 0000000 /*
Copyright (c) 2002 JSON.org
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.codehaus.jettison.json;
/**
* The JSONException is thrown by the JSON.org classes then things are amiss.
* @author JSON.org
* @version 2
*/
public class JSONException extends Exception {
private int line = -1;
private int column = -1;
/**
* Constructs a JSONException with an explanatory message.
* @param message Detail about the reason for the exception.
*/
public JSONException(String message) {
super(message);
}
public JSONException(String message, int line, int column) {
super(message);
this.line = line;
this.column = column;
}
public JSONException(Throwable t) {
super(t.getMessage(), t);
}
public int getColumn() {
return column;
}
public int getLine() {
return line;
}
}
jettison-jettison-1.5.4/src/main/java/org/codehaus/jettison/json/JSONObject.java 0000664 0000000 0000000 00000136013 14404057722 0027617 0 ustar 00root root 0000000 0000000 /*
Copyright (c) 2002 JSON.org
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.codehaus.jettison.json;
import java.io.IOException;
import java.io.Serializable;
import java.io.Writer;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.codehaus.jettison.JSONSequenceTooLargeException;
/**
* A JSONObject is an unordered collection of name/value pairs. Its
* external form is a string wrapped in curly braces with colons between the
* names and values, and commas between the values and names. The internal form
* is an object having get and opt methods for
* accessing the values by name, and put methods for adding or
* replacing values by name. The values can be any of these types:
* Boolean, JSONArray, JSONObject,
* Number, String, or the JSONObject.NULL
* object. A JSONObject constructor can be used to convert an external form
* JSON text into an internal form whose values can be retrieved with the
* get and opt methods, or to convert values into a
* JSON text using the put and toString methods.
* A get method returns a value if one can be found, and throws an
* exception if one cannot be found. An opt method returns a
* default value instead of throwing an exception, and so is useful for
* obtaining optional values.
*
* The generic get() and opt() methods return an
* object, which you can cast or query for type. There are also typed
* get and opt methods that do type checking and type
* coersion for you.
*
* The put methods adds values to an object. For example,
* myString = new JSONObject().put("JSON", "Hello, World!").toString();
* produces the string {"JSON": "Hello, World"}.
*
* The texts produced by the toString methods strictly conform to
* the JSON sysntax rules.
* The constructors are more forgiving in the texts they will accept:
*
*
An extra , (comma) may appear just
* before the closing brace.
*
Strings may be quoted with ' (single
* quote).
*
Strings do not need to be quoted at all if they do not begin with a quote
* or single quote, and if they do not contain leading or trailing spaces,
* and if they do not contain any of these characters:
* { } [ ] / \ : , = ; # and if they do not look like numbers
* and if they are not the reserved words true,
* false, or null.
*
Keys can be followed by = or => as well as
* by :.
*
Values can be followed by ; (semicolon) as
* well as by , (comma).
*
Numbers may have the 0- (octal) or
* 0x- (hex) prefix.
*
Comments written in the slashshlash, slashstar, and hash conventions
* will be ignored.
*
* @author JSON.org
* @version 2
*/
public class JSONObject implements Serializable {
/**
* The default recursion depth limit to prevent stack overflow issues on deeply nested structures.
*/
final static int DEFAULT_RECURSION_DEPTH_LIMIT = 500;
static int RECURSION_DEPTH_LIMIT = DEFAULT_RECURSION_DEPTH_LIMIT;
/**
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
* whilst Java's null is equivalent to the value that JavaScript calls
* undefined.
*/
private static final class Null {
boolean explicitNull;
public Null() {
}
public Null(boolean explicitNull) {
this.explicitNull = explicitNull;
}
/**
* There is only intended to be a single instance of the NULL object,
* so the clone method returns itself.
* @return NULL.
*/
protected final Object clone() {
return this;
}
/**
* A Null object is equal to the null value and to itself.
* @param object An object to test for nullness.
* @return true if the object parameter is the JSONObject.NULL object
* or null.
*/
public boolean equals(Object object) {
return object == null || object == this;
}
/**
* Get the "null" string value.
* @return The string "null".
*/
public String toString() {
return isExplicitNull() ? null : "null";
}
public boolean isExplicitNull() {
return explicitNull;
}
}
/**
* The hash map where the JSONObject's properties are kept.
*/
private LinkedHashMap