org.ow2.petals.binding.rest.utils.JsonXMLConfigBuilder Maven / Gradle / Ivy
/**
* Copyright (c) 2018-2020 Linagora
*
* This program/library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at your
* option) any later version.
*
* This program/library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program/library; If not, see http://www.gnu.org/licenses/
* for the GNU Lesser General Public License version 2.1.
*/
package org.ow2.petals.binding.rest.utils;
import javax.xml.XMLConstants;
import org.ow2.petals.binding.rest.RESTConstants.CommonServicesParameter;
import org.ow2.petals.component.framework.api.exception.PEtALSCDKException;
import org.w3c.dom.Element;
import de.odysseus.staxon.json.JsonXMLConfig;
public class JsonXMLConfigBuilder {
private JsonXMLConfigBuilder() {
// Utility class --> No constructor
}
public static JsonXMLConfig build(final Element parentElt) throws PEtALSCDKException {
final de.odysseus.staxon.json.JsonXMLConfigBuilder config = new de.odysseus.staxon.json.JsonXMLConfigBuilder();
final String virtRoot = DOMUtils.getSubElementTextContent(parentElt,
CommonServicesParameter.HTTP_BODY_TO_JSON_VIRTUAL_ROOT, false);
if (virtRoot != null) {
// we don't want to use the namespace of the jbi document!
config.virtualRoot(DOMUtils.getStringAsQName(parentElt, virtRoot, XMLConstants.NULL_NS_URI));
}
final String multiplePi = DOMUtils.getSubElementTextContent(parentElt,
CommonServicesParameter.HTTP_BODY_TO_JSON_MULTIPLE_PI, false);
if (multiplePi != null) {
config.multiplePI(Boolean.parseBoolean(multiplePi));
} else {
config.multiplePI(true);
}
final String autoArray = DOMUtils.getSubElementTextContent(parentElt,
CommonServicesParameter.HTTP_BODY_TO_JSON_AUTO_ARRAY, false);
if (autoArray != null) {
config.autoArray(Boolean.parseBoolean(autoArray));
} else {
config.autoArray(false);
}
final String autoPrimitive = DOMUtils.getSubElementTextContent(parentElt,
CommonServicesParameter.HTTP_BODY_TO_JSON_AUTO_PRIMITIVE, false);
if (autoPrimitive != null) {
config.autoPrimitive(Boolean.parseBoolean(autoPrimitive));
} else {
config.autoPrimitive(false);
}
final String prettyPrint = DOMUtils.getSubElementTextContent(parentElt,
CommonServicesParameter.HTTP_BODY_TO_JSON_PRETTY_PRINT, false);
if (prettyPrint != null) {
config.prettyPrint(Boolean.parseBoolean(prettyPrint));
} else {
config.prettyPrint(false);
}
final String nsDecl = DOMUtils.getSubElementTextContent(parentElt,
CommonServicesParameter.HTTP_BODY_TO_JSON_NS_DECL, false);
if (nsDecl != null) {
config.namespaceDeclarations(Boolean.parseBoolean(nsDecl));
} else {
config.namespaceDeclarations(false);
}
return config.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy