Load a XWiki document from its XML representation.

@param file the file to parse.
@return the loaded document object or null if the document cannot be parsed
15821
protected XWikiDocument getDocFromXML(File file) throws MojoExecutionException
    {
        XWikiDocument doc;

        try {
            doc = new XWikiDocument();
            doc.fromXML(file);
        } catch (Exception e) {
            throw new MojoExecutionException(String.format("Failed to parse [%s].", file.getAbsolutePath()), e);
        }

        return doc;
    }
285866
public Result<String> extractRawText(File file) throws IOException {
        return new InternalDocumentConverter(options).extractRawText(file).toResult();
    }
250145
public static byte[] loadBytesFromFile(File file) {

		byte[] bytes = null;
		try {
			bytes = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bytes;
	}
1082940
private Document loadDocument(String file) {
		Document doc = null;
		URL url = null;
		File f = new File(file);
		if (f.exists()) {
			try {
				url = f.toURI().toURL();
			} catch (MalformedURLException e) {
				throw new ConfigurationException("Unable to load " + file, e);
			}
		}
		if (url == null) {
			url = ClassLoader.getSystemResource(file);
		}
		InputStream is = null;
		if (url == null) {
			if (errorIfMissing) {
				throw new ConfigurationException("Could not open files of the name " + file);
			} else {
				LOG.info("Unable to locate configuration files of the name " + file + ", skipping");
				return doc;
			}
		}
		try {
			is = url.openStream();
			InputSource in = new InputSource(is);
			in.setSystemId(url.toString());
			doc = DomHelper.parse(in, dtdMappings);
		} catch (Exception e) {
			throw new ConfigurationException("Unable to load " + file, e);
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				LOG.error("Unable to close input stream", e);
			}
		}
		if (doc != null) {
			LOG.debug("Wallmod configuration parsed");
		}
		return doc;
	}
1024554
public Document getDocument(String xmlFilename) throws CmsXmlException {

        // try to get it from the cache
        Document document = m_cache.get(xmlFilename);

        if (document == null) {
            try {
                document = CmsXmlUtils.unmarshalHelper(
                    new InputSource(new FileReader(getFile(xmlFilename))),
                    NO_ENTITY_RESOLVER);
            } catch (FileNotFoundException e) {
                LOG.error("Could not read file " + xmlFilename, e);
                throw new CmsXmlException(new CmsMessageContainer(null, e.toString()));

            } catch (Exception e) {
                LOG.error("Could not parse file " + xmlFilename, e);
                throw new CmsXmlException(
                    Messages.get().container(Messages.ERR_XML_COULD_NOT_PARSE_FILE_1, xmlFilename),
                    e);
            }
            // cache the doc
            m_cache.put(xmlFilename, document);
        }
        return document;
    }
1177118
public static Document readDocument( File file) throws SAXException, IOException {
		InputStream in = new FileInputStream( file);
		Document result = readDocument( in);
		in.close();
		return result;
	}
648078
public static String readTextFile(File file) {
        try {
            return readTextFile(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
1203441
public static Properties loadFile(File file) throws IOException {
		InputStream input = new FileInputStream(file);
		Properties prop = null;
		try {
			prop = load(input);
		} finally {
			IOUtils.close(input);
		}
		return prop;
	}
102488
public static Document readXML(File file) {
		Assert.notNull(file, "Xml file is null !");
		if (false == file.exists()) {
			throw new UtilException("File [{}] not a exist!", file.getAbsolutePath());
		}
		if (false == file.isFile()) {
			throw new UtilException("[{}] not a file!", file.getAbsolutePath());
		}

		try {
			file = file.getCanonicalFile();
		} catch (IOException e) {
			// ignore
		}

		BufferedInputStream in = null;
		try {
			in = FileUtil.getInputStream(file);
			return readXML(in);
		} finally {
			IoUtil.close(in);
		}
	}
199008
public static XmlReport parse( File file ) throws Exception
	{
		Reader in = BOMUtil.newReader( file );

		try
		{
			return parse( in );
		}
		finally
		{
			IOUtil.closeQuietly( in );
		}
	}
1050072
public void load() {
        try {
            setPersistFile();
            XMLObjectReader reader = XMLObjectReader.newInstance(new FileInputStream(persistFile.toString()));
            reader.setBinding(binding);
            load(reader);
        } catch (XMLStreamException | FileNotFoundException e) {
            System.err.println(String.format("Error while load the MAP Resource state from file=%s", persistFile.toString()));
            e.printStackTrace();
        }
    }
456265
public static BufferedImage loadImage(File file){
		try {
			BufferedImage bimg = ImageIO.read(file);
			if(bimg == null){
				throw new ImageLoaderException("Could not load Image! ImageIO.read() returned null.");
			}
			return bimg;
		} catch (IOException e) {
			throw new ImageLoaderException(e);
		}
	}
569611
public void loadTagMappingFile(String file) {
        if (file != null) {
            File f = new File(file);
            if (!f.exists()) {
                throw new IllegalArgumentException("tag mapping file parameter points to a file that does not exist");
            }
            if (f.isDirectory()) {
                throw new IllegalArgumentException("tag mapping file parameter points to a directory, must be a file");
            } else if (!f.canRead()) {
                throw new IllegalArgumentException(
                        "tag mapping file parameter points to a file we have no read permissions");
            }

            try {
                this.tagMapping = f.toURI().toURL();
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        } else {
            this.tagMapping = PoiWriterTask.class.getClassLoader().getResource("poi-mapping.xml");
        }
    }
505838
private Document loadValidating(File file) {
		try {
			return getDOMObject(file.getAbsolutePath(), true);
		} catch (SAXException e) {
			e.printStackTrace();
			System.out.println("Error parsing digital document from nitf file "
					+ file + ".");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Error parsing digital document from nitf file "
					+ file + ".");
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
			System.out.println("Error parsing digital document from nitf file "
					+ file + ".");
		}
		return null;
	}
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);
	}
    }
1338097
public static Document load(File in, String charsetName, String baseUri) throws IOException {
        return parseInputStream(new FileInputStream(in), charsetName, baseUri, Parser.htmlParser());
    }