All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juneau.xml.XmlParser Maven / Gradle / Ivy

There is a newer version: 9.0.1
Show newest version
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
// * to you 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.apache.juneau.xml;

import javax.xml.stream.*;
import javax.xml.stream.util.*;

import org.apache.juneau.*;
import org.apache.juneau.parser.*;

/**
 * Parses text generated by the {@link XmlSerializer} class back into a POJO model.
 *
 * 
Media types:
* * Handles Content-Type types: text/xml * *
Description:
* * See the {@link XmlSerializer} class for a description of Juneau-generated XML. */ public class XmlParser extends ReaderParser { //------------------------------------------------------------------------------------------------------------------- // Configurable properties //------------------------------------------------------------------------------------------------------------------- private static final String PREFIX = "XmlParser."; /** * Configuration property: Enable validation. * *
    *
  • Name: "XmlParser.validating" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: true *
* *

* If true, XML document will be validated. * See {@link XMLInputFactory#IS_VALIDATING} for more info. */ public static final String XML_validating = PREFIX + "validating"; /** * Configuration property: XML reporter. * *

    *
  • Name: "XmlParser.reporter" *
  • Data type: {@link XMLReporter} *
  • Default: null *
  • Session-overridable: true *
* *

* Associates an {@link XMLReporter} with this parser. * *

Notes:
*
    *
  • Reporters are not copied to new parsers during a clone. *
*/ public static final String XML_reporter = PREFIX + "reporter"; /** * Configuration property: XML resolver. * *
    *
  • Name: "XmlParser.resolver" *
  • Data type: {@link XMLResolver} *
  • Default: null *
  • Session-overridable: true *
* *

* Associates an {@link XMLResolver} with this parser. */ public static final String XML_resolver = PREFIX + "resolver"; /** * Configuration property: XML event allocator. * *

    *
  • Name: "XmlParser.eventAllocator" *
  • Data type: {@link XMLEventAllocator} *
  • Default: null *
  • Session-overridable: true *
* *

* Associates an {@link XMLEventAllocator} with this parser. */ public static final String XML_eventAllocator = PREFIX + "eventAllocator"; /** * Configuration property: Preserve root element during generalized parsing. * *

    *
  • Name: "XmlParser.preserveRootElement" *
  • Data type: Boolean *
  • Default: false *
  • Session-overridable: true *
* *

* If true, when parsing into a generic {@link ObjectMap}, the map will contain a single entry whose key * is the root element name. * *

* Example: *

* * * * * * * * * * *
XMLObjectMap.toString(), preserveRootElement==falseObjectMap.toString(), preserveRootElement==true
<root><a>foobar</a></root>{ a:'foobar' }{ root: { a:'foobar' }}
*/ public static final String XML_preserveRootElement = PREFIX + "preserveRootElement"; //------------------------------------------------------------------------------------------------------------------- // Predefined instances //------------------------------------------------------------------------------------------------------------------- /** Default parser, all default settings.*/ public static final XmlParser DEFAULT = new XmlParser(PropertyStore.create()); //------------------------------------------------------------------------------------------------------------------- // Instance //------------------------------------------------------------------------------------------------------------------- private final XmlParserContext ctx; /** * Constructor. * * @param propertyStore * The property store containing all the settings for this object. */ public XmlParser(PropertyStore propertyStore) { this(propertyStore, "text/xml", "application/xml"); } /** * Constructor. * * @param propertyStore * The property store containing all the settings for this object. * @param consumes * The list of media types that this parser consumes (e.g. "application/json", "*​/json"). */ public XmlParser(PropertyStore propertyStore, String...consumes) { super(propertyStore, consumes); this.ctx = createContext(XmlParserContext.class); } @Override /* CoreObject */ public XmlParserBuilder builder() { return new XmlParserBuilder(propertyStore); } @Override /* Parser */ public ReaderParserSession createSession(ParserSessionArgs args) { return new XmlParserSession(ctx, args); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy