
net.sf.okapi.lib.xliff2.reader.LocationValidator Maven / Gradle / Ivy
/*===========================================================================
Copyright (C) 2013-2014 by the Okapi Framework contributors
-----------------------------------------------------------------------------
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 net.sf.okapi.lib.xliff2.reader;
import java.io.InputStream;
import java.util.HashMap;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import net.sf.okapi.lib.xliff2.Const;
import net.sf.okapi.lib.xliff2.XLIFFException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* Performs the validation of the names and location of the modules in the extension points
* that the schema-based validation cannot do because the core schema does not have references
* to the modules.
*/
class LocationValidator {
/**
* The attribute or element for the module is allowed at the given location.
*/
public static final int ALLOWED = 0;
/**
* No module is defined at the given location.
*/
public static final int NO_MODULES = 1;
/**
* The attribute or element for the module is invalid or not allowed at the given location.
*/
public static final int NOT_ALLOWED = 2;
/**
* The given location does not allow more than one of the given element.
*/
public static final int TOO_MANY = 3;
private HashMap map;
/**
* Loads the file containing the definitions of what module's elements and attributes are
* allowed in what extension points.
* @param inputStream the input stream of the file to load.
*/
public void load (InputStream inputStream) {
try {
map = new HashMap<>();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(inputStream);
NodeList list1 = doc.getDocumentElement().getElementsByTagName("location");
if (( list1 == null ) || ( list1.getLength() == 0 )) return;
for ( int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy