Exemple #1
0
  /**
   * 方法名: </br> 详述: </br>修改应用名称 开发人员:谭明</br> 创建时间:Apr 1, 2014</br>
   *
   * @param appName
   * @param project_path
   * @throws Exception
   */
  public static void update_system_config_xml(String project_path, String enterpriseId)
      throws Exception {
    String url =
        ResourceBundle.getBundle("config").getString("filePath")
            + "/"
            + enterpriseId
            + "/page/index.html";
    String filepath =
        project_path
            + File.separator
            + "res"
            + File.separator
            + "values"
            + File.separator
            + "system_config.xml";
    logger.info("strings.xml路径为:" + filepath);
    File file = new File(filepath);
    if (!file.exists()) {
      throw new Exception("项目/res/values/system_config.xml文件不存在!");
    }
    // 修改/res/values/strings.xml appname内容
    org.w3c.dom.Document document = XmlUtil.getDom(filepath);

    try {
      NodeList list = document.getElementsByTagName("string");
      for (int i = 0; i < list.getLength(); i++) {
        org.w3c.dom.Element brandElement = (org.w3c.dom.Element) list.item(i);
        brandElement.getFirstChild().setNodeValue(url);
      }
      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      Transformer transformer = transformerFactory.newTransformer();
      DOMSource domSource = new DOMSource(document);
      // 设置编码类型
      transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
      transformer.setOutputProperty("standalone", "no");
      StreamResult result = new StreamResult(new FileOutputStream(filepath));
      // 把DOM树转换为xml文件
      transformer.transform(domSource, result);

    } catch (Exception e) {
      throw new Exception("输出项目/res/values/system_config.xml文件出错!");
    }
  }
Exemple #2
0
  /**
   * 方法名: </br> 详述: </br>修改应用名称 开发人员:谭明</br> 创建时间:Apr 1, 2014</br>
   *
   * @param appName
   * @param project_path
   * @throws Exception
   */
  public static void update_strings_xml(
      String project_path,
      String appName,
      String phoneNumber,
      String versionCode,
      String enterpriseId)
      throws Exception {
    String filepath =
        project_path
            + File.separator
            + "res"
            + File.separator
            + "values"
            + File.separator
            + "strings.xml";
    logger.info("strings.xml路径为:" + filepath);
    File file = new File(filepath);
    if (!file.exists()) {
      throw new Exception("项目/res/values/strings.xml文件不存在!");
    }
    // 修改/res/values/strings.xml appname内容
    org.w3c.dom.Document document = XmlUtil.getDom(filepath);

    try {
      NodeList list = document.getElementsByTagName("string");
      for (int i = 0; i < list.getLength(); i++) {
        org.w3c.dom.Element brandElement = (org.w3c.dom.Element) list.item(i);
        String name = brandElement.getAttribute("name");
        if ("app_name".equals(name)) {
          brandElement.getFirstChild().setNodeValue(appName);
        } else if ("server_ip".equals(name)) {
          String serverIp = ResourceBundle.getBundle("config").getString("server_ip");
          String url = "";
          if (serverIp.lastIndexOf(":80") > 0) {
            url =
                serverIp.substring(0, serverIp.lastIndexOf(":80"))
                    + "/"
                    + ResourceBundle.getBundle("config").getString("server_name")
                    + "/file/"
                    + phoneNumber
                    + "/page/index.html";
          } else {
            url =
                ResourceBundle.getBundle("config").getString("filePath")
                    + "/"
                    + phoneNumber
                    + "/page/index.html";
          }
          brandElement.getFirstChild().setNodeValue(url);
        } else if ("update_url".equals(name)) {
          String url =
              ResourceBundle.getBundle("config").getString("server_ip")
                  + "/"
                  + ResourceBundle.getBundle("config").getString("server_name")
                  + "/action/app/getClient";
          brandElement.getFirstChild().setNodeValue(url);
        } else if ("curVersion".equals(name)) {
          brandElement.getFirstChild().setNodeValue(versionCode);
        } else if ("id".equals(name)) {
          brandElement.getFirstChild().setNodeValue(enterpriseId);
        }
      }
      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      Transformer transformer = transformerFactory.newTransformer();
      DOMSource domSource = new DOMSource(document);
      // 设置编码类型
      transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
      transformer.setOutputProperty("standalone", "no");
      StreamResult result = new StreamResult(new FileOutputStream(filepath));
      // 把DOM树转换为xml文件
      transformer.transform(domSource, result);

    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception("输出项目/res/values/strings.xml文件出错!");
    }
  }