910ab9ebb5ba11bbe3e22229aa2e647612510fbf.svn-base 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package xin.glue.ui.Z;
  2. import com.posdata.glue.biz.activity.PosActivity;
  3. import com.posdata.glue.biz.constants.PosBizControlConstants;
  4. import com.posdata.glue.context.PosContext;
  5. import com.posdata.glue.dao.PosGenericDao;
  6. import com.posdata.glue.dao.vo.PosParameter;
  7. import com.posdata.glue.dao.vo.PosRow;
  8. import com.posdata.glue.dao.vo.PosRowSet;
  9. import com.posdata.glue.util.PosFileResourceUtil;
  10. import java.io.File;
  11. import java.net.URL;
  12. import java.util.Map;
  13. import xin.glue.ui.common.component.PosSiteConfig;
  14. public class PosUIFileManager extends PosActivity {
  15. private PosGenericDao getDao() {
  16. String testdao = getProperty("dao");
  17. if (testdao == null)
  18. testdao = "mesdao";
  19. else
  20. testdao = testdao.trim();
  21. return getDao(testdao);
  22. }
  23. public String runActivity(PosContext ctx) {
  24. if (!PosSiteConfig.isDebug())
  25. return PosBizControlConstants.SUCCESS;
  26. URL url = PosFileResourceUtil.getResource("/");
  27. // xgmes3/WEB-INF/classes/ => xgmes3
  28. String dir = url.getPath();
  29. //System.out.println(dir);
  30. String xrwFiles = getListOfFiles((new File(dir)).getParentFile().getParentFile());
  31. //System.out.println(xrwFiles);
  32. if ("".equals(xrwFiles)) return PosBizControlConstants.SUCCESS;
  33. PosGenericDao dao = getDao();
  34. PosParameter param = new PosParameter();
  35. param.setWhereClauseParameter(0, xrwFiles);
  36. PosRowSet rowset = dao.find("FileManager.select", param);
  37. while (rowset.hasNext()) {
  38. PosRow row = rowset.next();
  39. Map rowData = row.getAttributes();
  40. searchMNSCR((String)rowData.get("MNSCR_ID"), dao);
  41. }
  42. if (PosSiteConfig.isBeta()) { // ²âÊÔ½×¶Î
  43. dao.delete("FileManager.SCRFN.delete", param);
  44. dao.delete("FileManager.MNSCR.delete", param);
  45. }
  46. return PosBizControlConstants.SUCCESS;
  47. }
  48. private String getListOfFiles(File file) {
  49. String xrwFiles = "";
  50. File afile[] = file.isFile()? (new File[] {file}) : file.listFiles();
  51. if(afile == null || afile.length == 0) return xrwFiles;
  52. for(int i = 0; i < afile.length; i++) {
  53. if(afile[i].isDirectory()) {
  54. if (";css;images;js;META-INF;WEB-INF;".indexOf(";"+afile[i].getName()+";") == -1)
  55. xrwFiles += "," + getListOfFiles(afile[i]);
  56. } else if(afile[i].isFile()) {
  57. String fileName = afile[i].getName();
  58. if (fileName.startsWith("UI") && fileName.endsWith(".xrw")
  59. && fileName.length() == 13)
  60. xrwFiles += "," + fileName.substring(0, 9);
  61. }
  62. }
  63. if (!"".equals(xrwFiles)) {
  64. xrwFiles = xrwFiles.replaceAll("[,]+", ",");
  65. xrwFiles = xrwFiles.replaceAll("^[,]+", "");
  66. xrwFiles = xrwFiles.replaceAll("[,]+$", "");
  67. }
  68. return xrwFiles;
  69. }
  70. private void searchMNSCR(String MNSCR_ID, PosGenericDao dao) {
  71. int len = MNSCR_ID.length();
  72. if (len == 9)
  73. searchMNSCR(MNSCR_ID.substring(2, 5), dao);
  74. else {
  75. PosParameter param = new PosParameter();
  76. param.setWhereClauseParameter(0, MNSCR_ID);
  77. PosRowSet rowset = dao.find("FileManager.select.single", param);
  78. if (rowset.hasNext()) return;
  79. if (len == 3)
  80. searchMNSCR(MNSCR_ID.substring(0, 1), dao);
  81. }
  82. PosParameter param = new PosParameter();
  83. param.setValueParamter(0, MNSCR_ID);
  84. param.setValueParamter(1, MNSCR_ID);
  85. if (len == 9) {
  86. param.setValueParamter(2, MNSCR_ID.substring(2, 5));
  87. param.setValueParamter(3, "S");
  88. param.setValueParamter(4, MNSCR_ID.substring(5, 9));
  89. } else if (len == 3) {
  90. param.setValueParamter(2, MNSCR_ID.substring(0, 1));
  91. param.setValueParamter(3, "M");
  92. param.setValueParamter(4, MNSCR_ID.substring(1, 3));
  93. } else {
  94. param.setValueParamter(2, "*");
  95. param.setValueParamter(3, "M");
  96. param.setValueParamter(4, "100");
  97. }
  98. dao.insert("FileManager.insert", param);
  99. }
  100. }