Exemple #1
0
 public static void main(String[] args) {
   try {
     GenConfig config = getConfig();
     System.out.println(config);
     System.out.println(JaxbMapper.toXml(config));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemple #2
0
 /**
  * XML文件转换为对象
  *
  * @param fileName
  * @param clazz
  * @return
  */
 @SuppressWarnings("unchecked")
 public static <T> T fileToObject(String fileName, Class<?> clazz) {
   try {
     String pathName = "/templates/modules/gen/" + fileName;
     //			logger.debug("File to object: {}", pathName);
     Resource resource = new ClassPathResource(pathName);
     InputStream is = resource.getInputStream();
     BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
     StringBuilder sb = new StringBuilder();
     while (true) {
       String line = br.readLine();
       if (line == null) {
         break;
       }
       sb.append(line).append("\r\n");
     }
     if (is != null) {
       is.close();
     }
     if (br != null) {
       br.close();
     }
     //			logger.debug("Read file content: {}", sb.toString());
     return (T) JaxbMapper.fromXml(sb.toString(), clazz);
   } catch (IOException e) {
     logger.warn("Error file convert: {}", e.getMessage());
   }
   //		String pathName = StringUtils.replace(getTemplatePath() + "/" + fileName, "/",
   // File.separator);
   //		logger.debug("file to object: {}", pathName);
   //		String content = "";
   //		try {
   //			content = FileUtils.readFileToString(new File(pathName), "utf-8");
   ////			logger.debug("read config content: {}", content);
   //			return (T) JaxbMapper.fromXml(content, clazz);
   //		} catch (IOException e) {
   //			logger.warn("error convert: {}", e.getMessage());
   //		}
   return null;
 }