Stage one validation of the file, returning the converted document or
{@code null}.

@param file XBEL file
@return Document
422149
private Document stage1(final File file) {
        beginStage(PHASE1_STAGE1_HDR, "1", NUM_PHASES);
        final StringBuilder bldr = new StringBuilder();

        stageOutput("Validating " + file);
        long t1 = currentTimeMillis();

        final Stage1Output output;
        if (isBELScript(file)) {
            output = p1.stage1BELValidation(file);
        } else {
            output = p1.stage1XBELValidation(file);
        }

        if (output.hasValidationErrors()) {
            for (final ValidationError error : output.getValidationErrors()) {
                stageError(error.getUserFacingMessage());
            }
            return null;
        }

        if (output.hasConversionError()) {
            stageError(output.getConversionError().getUserFacingMessage());
            return null;
        }

        if (output.getSymbolWarning() != null) {
            stageWarning(output.getSymbolWarning().getUserFacingMessage());
        }

        long t2 = currentTimeMillis();
        markTime(bldr, t1, t2);
        markEndStage(bldr);
        stageOutput(bldr.toString());
        return output.getDocument();
    }
711268
public boolean isValid(File file, CycloneDxSchema.Version schemaVersion) {
        return validate(file, schemaVersion).isEmpty();
    }
285866
public Result<String> extractRawText(File file) throws IOException {
        return new InternalDocumentConverter(options).extractRawText(file).toResult();
    }
887546
public ResourceFormatParser getParserForFileExtension(final File file) throws UnsupportedFormatException {
        String extension = getFileExtension(file.getName());
        if (null != extension) {
            return getParserForFileExtension(extension);
        } else {
            throw new UnsupportedFormatException("Could not determine format for file: " + file.getAbsolutePath());
        }
    }
390997
public static InputStream asInputStream(File file) throws IOException {
		Validate.notNull(file, "file is null");
		return asInputStream(file.toPath());
	}
943031
public static DocumentBuilder getValidatingXmlParser(File schemaFile) {
    DocumentBuilder db = null;
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      Schema schema = factory.newSchema(schemaFile);
      dbf.setSchema(schema);

      db = dbf.newDocumentBuilder();
      db.setErrorHandler(new SAXErrorHandler());

    } catch (ParserConfigurationException e) {
      System.err.printf("%s: Unable to create XML parser\n", XMLUtils.class.getName());
      e.printStackTrace();

    } catch (SAXException e) {
      System.err.printf("%s: XML parsing exception while loading schema %s\n", XMLUtils.class.getName(),schemaFile.getPath());
      e.printStackTrace();

    } catch(UnsupportedOperationException e) {
      System.err.printf("%s: API error while setting up XML parser. Check your JAXP version\n", XMLUtils.class.getName());
      e.printStackTrace();
    }

    return db;
  }
464844
public static FileObject toFileObject(File file) {
        if (file == null) {
            return null;
        }
        try {
            return getFileSystemManager().toFileObject(file);
        } catch (FileSystemException e) {
            throw new IllegalStateException(e);
        }
    }
226242
public Object deserialise(final File file)
	{
		if (file == null)
			throw new IllegalArgumentException("Null argument passed to deserialise!");
		if (!file.exists())
			throw new IllegalArgumentException("File does not exist: " + file);

		final Unmarshaller unmarshaller = getUnmarshaller();

		try
		{
			final Object obj = unmarshaller.unmarshal(file);

			if (obj == null)
				throw new RuntimeException("Malformed XML from " + file);
			else
				return obj;
		}
		catch (JAXBException e)
		{
			throw new JAXBRuntimeException("deserialisation", e);
		}
	}
1214521
private IChemFile readChemFile(IChemFile file) throws CDKException {
        logger.debug("Started parsing from input...");
        try {
            parser.setFeature("http://xml.org/sax/features/validation", false);
            logger.info("Deactivated validation");
        } catch (SAXException e) {
            logger.warn("Cannot deactivate validation.");
            return null;
        }
        CMLHandler handler = new CMLHandler(file);
        // copy the manually added conventions
        for (String conv : userConventions.keySet()) {
            handler.registerConvention(conv, userConventions.get(conv));
        }
        parser.setContentHandler(handler);
        parser.setEntityResolver(new CMLResolver());
        parser.setErrorHandler(new CMLErrorHandler());
        try {
            if (input == null) {
                logger.debug("Parsing from URL: ", url);
                parser.parse(url);
            } else {
                logger.debug("Parsing from Reader");
                parser.parse(new InputSource(input));
            }
        } catch (IOException e) {
            String error = "Error while reading file: " + e.getMessage();
            logger.error(error);
            logger.debug(e);
            throw new CDKException(error, e);
        } catch (SAXParseException saxe) {
            SAXParseException spe = (SAXParseException) saxe;
            String error = "Found well-formedness error in line " + spe.getLineNumber();
            logger.error(error);
            logger.debug(saxe);
            throw new CDKException(error, saxe);
        } catch (SAXException saxe) {
            String error = "Error while parsing XML: " + saxe.getMessage();
            logger.error(error);
            logger.debug(saxe);
            throw new CDKException(error, saxe);
        }
        return file;
    }
1316214
public static String getFileExtension(File file) {
        if (file == null) {
            return null;
        }

        String fileName = file.getName();
        int dotPos = fileName.lastIndexOf('.');
        return dotPos == -1 ? null : fileName.substring(dotPos + 1);
    }
648078
public static String readTextFile(File file) {
        try {
            return readTextFile(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
990201
public static boolean isBELDocument(final String path) {
        if (path == null) {
            return false;
        }
        if (path.endsWith(BEL_SCRIPT_EXTENSION)) {
            return true;
        }
        if (path.endsWith(XBEL_EXTENSION)) {
            return true;
        }
        return false;
    }
1108027
public static Document getDocument(File file) {
		SAXReader reader = new SAXReader();
		Document document = null;
		try {
			document = reader.read(file);
		} catch (DocumentException e) {
			throw new RuntimeException(e);
		}
		return document;
	}
856518
static Document loadDocument(Resource xmlFile) throws SAXException, IOException {
	InputStream is = null;
	try {
	    return _loadDocument(is = IOUtil.toBufferedInputStream(xmlFile.getInputStream()));
	}
	finally {
	    IOUtil.closeEL(is);
	}
    }
713421
public static @Nullable FileBinaryResource createOrNull(File file) {
    return (file != null) ? new FileBinaryResource(file) : null;
  }
284782
public static String extension(String file) {
      if (StringUtils.isNullOrBlank(file)) {
         return StringUtils.EMPTY;
      }
      file = StringUtils.trim(file);
      int index = indexOfFileExtension(file);
      if (index == -1) {
         return StringUtils.EMPTY;
      }
      return file.substring(index + 1);
   }
203659
private void loadXMLResource(final File file) {

		final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
		// Ignore comments in the XML file
		docBuilderFactory.setIgnoringComments(true);
		docBuilderFactory.setNamespaceAware(true);

		try {

			final DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
			Document doc = null;
			Element root = null;

			doc = builder.parse(file);

			if (doc == null) {
				LOG.warn("Cannot load configuration: doc is null");
				return;
			}

			root = doc.getDocumentElement();
			if (root == null) {
				LOG.warn("Cannot load configuration: root is null");
				return;
			}

			if (!"configuration".equals(root.getNodeName())) {
				LOG.warn("Cannot load configuration: unknown element " + root.getNodeName());
				return;
			}

			final NodeList props = root.getChildNodes();
			int propNumber = -1;

			synchronized (this.confData) {

				for (int i = 0; i < props.getLength(); i++) {

					final Node propNode = props.item(i);
					String key = null;
					String value = null;

					// Ignore text at this point
					if (propNode instanceof Text) {
						continue;
					}

					if (!(propNode instanceof Element)) {
						LOG.warn("Error while reading configuration: " + propNode.getNodeName()
							+ " is not of type element");
						continue;
					}

					Element property = (Element) propNode;
					if (!"property".equals(property.getNodeName())) {
						LOG.warn("Error while reading configuration: unknown element " + property.getNodeName());
						continue;
					}

					propNumber++;
					final NodeList propChildren = property.getChildNodes();
					if (propChildren == null) {
						LOG.warn("Error while reading configuration: property has no children, skipping...");
						continue;
					}

					for (int j = 0; j < propChildren.getLength(); j++) {

						final Node propChild = propChildren.item(j);
						if (propChild instanceof Element) {
							if ("key".equals(propChild.getNodeName())) {
								if (propChild.getChildNodes() != null) {
									if (propChild.getChildNodes().getLength() == 1) {
										if (propChild.getChildNodes().item(0) instanceof Text) {
											final Text t = (Text) propChild.getChildNodes().item(0);
											key = t.getTextContent();
										}
									}
								}
							}

							if ("value".equals(propChild.getNodeName())) {
								if (propChild.getChildNodes() != null) {
									if (propChild.getChildNodes().getLength() == 1) {
										if (propChild.getChildNodes().item(0) instanceof Text) {
											final Text t = (Text) propChild.getChildNodes().item(0);
											value = t.getTextContent();
										}
									}
								}
							}
						}
					}

					if (key != null && value != null) {
						// Put key, value pair into the map
						LOG.debug("Loading configuration property: " + key + ", " + value);
						this.confData.put(key, value);
					} else {
						LOG.warn("Error while reading configuration: Cannot read property " + propNumber);
						continue;
					}
				}
			}

		} catch (ParserConfigurationException e) {
			LOG.warn("Cannot load configuration: " + StringUtils.stringifyException(e));
		} catch (IOException e) {
			LOG.warn("Cannot load configuration: " + StringUtils.stringifyException(e));
		} catch (SAXException e) {
			LOG.warn("Cannot load configuration: " + StringUtils.stringifyException(e));
		}
	}