Java源码示例:com.google.appengine.repackaged.com.google.common.io.Files
示例1
/**
* Validates a given XML document against a given schema.
*
* @param xmlFilename filename with XML document.
* @param schema XSD schema to validate with.
*
* @throws AppEngineConfigException for malformed XML, or IO errors
*/
public static void validateXml(String xmlFilename, File schema) {
File xml = new File(xmlFilename);
if (!xml.exists()) {
throw new AppEngineConfigException("Xml file: " + xml.getPath() + " does not exist.");
}
if (!schema.exists()) {
throw new AppEngineConfigException("Schema file: " + schema.getPath() + " does not exist.");
}
try {
validateXmlContent(Files.toString(xml, StandardCharsets.UTF_8), schema);
} catch (IOException ex) {
throw new AppEngineConfigException(
"IO error validating " + xmlFilename + " against " + schema.getPath(), ex);
}
}
示例2
public void updateWebXml(List<String> services, String webXmlPath)
throws ParserConfigurationException, SAXException, IOException,
TransformerFactoryConfigurationError, TransformerException {
boolean saveRequired;
String spc = " ";
String delimiter = "\n";
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document document = docBuilder.parse(webXmlPath);
Node systemServiceServletNode = findSystemServiceServlet(document);
if (systemServiceServletNode == null) {
getLog().info("Not a valid web.xml document");
return;
}
if (isElementAndNamed(systemServiceServletNode, WEB_APP)) {
systemServiceServletNode = insertSystemServiceServlet(document,
systemServiceServletNode, spc, delimiter);
saveRequired = true;
}
saveRequired = updateSystemServiceServletParam(document,
systemServiceServletNode, services);
String generatedWebInf = outputDirectory + "/WEB-INF";
new File(generatedWebInf).mkdirs();
saveFile(document, generatedWebInf + "/web.xml");
Files.copy(
new File(new File(webXmlPath).getParentFile(), "appengine-web.xml"),
new File(generatedWebInf, "appengine-web.xml"));
}
示例3
public void updateWebXml(List<String> services, String webXmlPath)
throws ParserConfigurationException, SAXException, IOException,
TransformerFactoryConfigurationError, TransformerException {
boolean saveRequired;
String spc = " ";
String delimiter = "\n";
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document document = docBuilder.parse(webXmlPath);
Node systemServiceServletNode = findSystemServiceServlet(document);
if (systemServiceServletNode == null) {
getLog().info("Not a valid web.xml document");
return;
}
if (isElementAndNamed(systemServiceServletNode, WEB_APP)) {
systemServiceServletNode = insertSystemServiceServlet(document,
systemServiceServletNode, spc, delimiter);
saveRequired = true;
}
saveRequired = updateSystemServiceServletParam(document,
systemServiceServletNode, services);
String generatedWebInf = outputDirectory + "/WEB-INF";
new File(generatedWebInf).mkdirs();
saveFile(document, generatedWebInf + "/web.xml");
Files.copy(
new File(new File(webXmlPath).getParentFile(), "appengine-web.xml"),
new File(generatedWebInf, "appengine-web.xml"));
}