com.google.appengine.repackaged.com.google.common.io.Files Java Examples

The following examples show how to use com.google.appengine.repackaged.com.google.common.io.Files. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlUtils.java    From appengine-java-vm-runtime with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example #2
Source File: WebXmlProcessing.java    From appengine-maven-plugin with Apache License 2.0 5 votes vote down vote up
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"));
}
 
Example #3
Source File: WebXmlProcessing.java    From gcloud-maven-plugin with Apache License 2.0 5 votes vote down vote up
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"));
}