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

com.hazelcast.config.AbstractXmlConfigHelper Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
 *
 * 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 com.hazelcast.config;

import com.hazelcast.config.AbstractXmlConfigBuilder.ConfigType;
import com.hazelcast.instance.BuildInfo;
import com.hazelcast.instance.BuildInfoProvider;
import com.hazelcast.logging.ILogger;
import com.hazelcast.logging.Logger;
import com.hazelcast.internal.util.StringUtil;
import com.hazelcast.internal.util.XmlUtil;
import com.hazelcast.spi.annotation.PrivateApi;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;

import static com.hazelcast.internal.nio.IOUtil.closeResource;

/**
 * Contains Hazelcast XML Configuration helper methods and variables.
 */
@SuppressWarnings("checkstyle:methodcount")
public abstract class AbstractXmlConfigHelper extends AbstractConfigBuilder {

    private static final ILogger LOGGER = Logger.getLogger(AbstractXmlConfigHelper.class);

    protected boolean domLevel3 = true;

    final String xmlns = "http://www.hazelcast.com/schema/" + getNamespaceType();

    private final String hazelcastSchemaLocation = getConfigType().name + "-config-" + getReleaseVersion() + ".xsd";

    public String getNamespaceType() {
        return getConfigType().name.equals("hazelcast") ? "config" : "client-config";
    }

    protected ConfigType getConfigType() {
        return ConfigType.SERVER;
    }

    protected void schemaValidation(Document doc) throws Exception {
        ArrayList schemas = new ArrayList<>();
        InputStream inputStream = null;
        String schemaLocation = doc.getDocumentElement().getAttribute("xsi:schemaLocation");
        schemaLocation = schemaLocation.replaceAll("^ +| +$| (?= )", "");

        // get every two pair. every pair includes namespace and uri
        String[] xsdLocations = schemaLocation.split("(?




© 2015 - 2025 Weber Informatics LLC | Privacy Policy