示例#1
0
文件: Macro.java 项目: bramk/bnd
  String ls(String args[], boolean relative) {
    if (args.length < 2)
      throw new IllegalArgumentException(
          "the ${ls} macro must at least have a directory as parameter");

    File dir = domain.getFile(args[1]);
    if (!dir.isAbsolute())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter is not absolute: " + dir);

    if (!dir.exists())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter does not exist: " + dir);

    if (!dir.isDirectory())
      throw new IllegalArgumentException(
          "the ${ls} macro directory parameter points to a file instead of a directory: " + dir);

    Collection<File> files = new ArrayList<File>(new SortedList<File>(dir.listFiles()));

    for (int i = 2; i < args.length; i++) {
      Instructions filters = new Instructions(args[i]);
      files = filters.select(files, true);
    }

    List<String> result = new ArrayList<String>();
    for (File file : files) result.add(relative ? file.getName() : file.getAbsolutePath());

    return Processor.join(result, ",");
  }
  /**
   * Finds all files in folder and in it's sub-tree of specified depth.
   *
   * @param file Starting folder
   * @param maxDepth Depth of the tree. If 1 - just look in the folder, no sub-folders.
   * @param filter file filter.
   * @return List of found files.
   */
  public static List<VisorLogFile> fileTree(File file, int maxDepth, @Nullable FileFilter filter) {
    if (file.isDirectory()) {
      File[] files = (filter == null) ? file.listFiles() : file.listFiles(filter);

      if (files == null) return Collections.emptyList();

      List<VisorLogFile> res = new ArrayList<>(files.length);

      for (File f : files) {
        if (f.isFile() && f.length() > 0) res.add(new VisorLogFile(f));
        else if (maxDepth > 1) res.addAll(fileTree(f, maxDepth - 1, filter));
      }

      return res;
    }

    return F.asList(new VisorLogFile(file));
  }
  /**
   * Garbage collect repository
   *
   * @throws Exception
   */
  public void gc() throws Exception {
    HashSet<byte[]> deps = new HashSet<byte[]>();

    // deps.add(SERVICE_JAR_FILE);

    for (File cmd : commandDir.listFiles()) {
      CommandData data = getData(CommandData.class, cmd);
      addDependencies(deps, data);
    }

    for (File service : serviceDir.listFiles()) {
      File dataFile = new File(service, "data");
      ServiceData data = getData(ServiceData.class, dataFile);
      addDependencies(deps, data);
    }

    int count = 0;
    for (File f : repoDir.listFiles()) {
      String name = f.getName();
      if (!deps.contains(name)) {
        if (!name.endsWith(".json")
            || !deps.contains(name.substring(0, name.length() - ".json".length()))) { // Remove
          // json
          // files
          // only
          // if
          // the
          // bin
          // is
          // going
          // as
          // well
          f.delete();
          count++;
        } else {

        }
      }
    }
    System.out.format("Garbage collection done (%d file(s) removed)%n", count);
  }
  public List<CommandData> getCommands(File commandDir) throws Exception {
    List<CommandData> result = new ArrayList<CommandData>();

    if (!commandDir.exists()) {
      return result;
    }

    for (File f : commandDir.listFiles()) {
      CommandData data = getData(CommandData.class, f);
      if (data != null) result.add(data);
    }
    return result;
  }
示例#5
0
  private ArrayList GetFolderTree(String s_Dir, String s_Flag, int n_Indent, int n_TreeIndex) {
    String s_List = "";
    ArrayList aSubFolders = new ArrayList();

    File file = new File(s_Dir);
    File[] filelist = file.listFiles();

    if (filelist != null && filelist.length > 0) {
      for (int i = 0; i < filelist.length; i++) {
        if (filelist[i].isDirectory()) {
          aSubFolders.add(filelist[i].getName());
        }
      }

      int n_Count = aSubFolders.size();
      String s_LastFlag = "";
      String s_Folder = "";
      for (int i = 1; i <= n_Count; i++) {
        if (i < n_Count) {
          s_LastFlag = "0";
        } else {
          s_LastFlag = "1";
        }

        s_Folder = aSubFolders.get(i - 1).toString();
        s_List =
            s_List
                + "arr"
                + s_Flag
                + "["
                + String.valueOf(n_TreeIndex)
                + "]=new Array(\""
                + s_Folder
                + "\","
                + String.valueOf(n_Indent)
                + ", "
                + s_LastFlag
                + ");\n";
        n_TreeIndex = n_TreeIndex + 1;
        ArrayList a_Temp =
            GetFolderTree(s_Dir + s_Folder + sFileSeparator, s_Flag, n_Indent + 1, n_TreeIndex);
        s_List = s_List + a_Temp.get(0).toString();
        n_TreeIndex = Integer.valueOf(a_Temp.get(1).toString()).intValue();
      }
    }

    ArrayList a_Return = new ArrayList();
    a_Return.add(s_List);
    a_Return.add(String.valueOf(n_TreeIndex));
    return a_Return;
  }
  public List<ServiceData> getServices(File serviceDir) throws Exception {
    List<ServiceData> result = new ArrayList<ServiceData>();

    if (!serviceDir.exists()) {
      return result;
    }

    for (File sdir : serviceDir.listFiles()) {
      File dataFile = new File(sdir, "data");
      ServiceData data = getData(ServiceData.class, dataFile);
      result.add(data);
    }
    return result;
  }
 public static boolean deleteRecursive(File dir) {
   boolean result = true;
   File files[] = dir.listFiles();
   if (files != null) {
     for (int i = 0; i < files.length; i++) {
       if (files[i].isDirectory()) {
         result = result && deleteRecursive(files[i]);
       } else {
         result = result && files[i].delete();
       }
     }
   }
   result = result && dir.delete();
   return result;
 }
示例#8
0
 public static Vector expandFileList(String[] files, boolean inclDirs) {
   Vector v = new Vector();
   if (files == null) return v;
   for (int i = 0; i < files.length; i++) v.add(new File(URLDecoder.decode(files[i])));
   for (int i = 0; i < v.size(); i++) {
     File f = (File) v.get(i);
     if (f.isDirectory()) {
       File[] fs = f.listFiles();
       for (int n = 0; n < fs.length; n++) v.add(fs[n]);
       if (!inclDirs) {
         v.remove(i);
         i--;
       }
     }
   }
   return v;
 }
  private void populateList() {
    try {
      String path = ".";
      fileList.setText(" ");

      String files;
      File folder = new File(path);
      File[] listOfFiles = folder.listFiles();

      for (int i = 0; i < listOfFiles.length; i++) {

        if (listOfFiles[i].isFile()) {
          files = listOfFiles[i].getName();
          // if(files.endsWith(".dat"))
          fileList.append(files + "\n");
        }
      }
    } catch (java.security.AccessControlException k) {
    }
  }
示例#10
0
  public static void generateMainPage(File mainFile, File sourceProjDir)
      throws IOException, ProjectFileParsingException, NeuroMLException {
    SimpleXMLElement root = new SimpleXMLElement("document");
    SimpleXMLElement header = new SimpleXMLElement("header");
    root.addChildElement(header);

    SimpleXMLElement title = new SimpleXMLElement("title");
    header.addChildElement(title);

    SimpleXMLElement body = new SimpleXMLElement("body");
    root.addChildElement(body);
    SimpleXMLElement intro = new SimpleXMLElement("p");
    body.addChildElement(intro);

    if (!mainFile.getParentFile().exists()) mainFile.getParentFile().mkdir();

    File targetDownloadDir = new File(mainFile.getParentFile(), "downloads");
    if (!targetDownloadDir.exists()) targetDownloadDir.mkdir();

    if (sourceProjDir.getName().indexOf("examples") >= 0) {
      title.addContent("neuroConstruct example projects");

      intro.addContent(
          "Downloadable neuroConstruct example projects. These <strong>illustrate the core "
              + "functionality of neuroConstruct</strong>, as opposed to providing electrophysiologically accurate "
              + "models. Projects based on published conductance based models can be found <a href=\"../models/index.html\">here</a>");
    }
    if (sourceProjDir.getName().indexOf("models") >= 0) {
      title.addContent("neuroConstruct projects based on published neuronal and network models");

      intro.addContent(
          "Downloadable neuroConstruct projects <strong>based on published conductance based models</strong>. "
              + "Some examples to illustrate the core functionality of neuroConstruct, as opposed to "
              + "providing electrophysiologically accurate models can be found <a href=\"../samples/index.html\">here</a>."
              + "<p>Note: These models are currently being moved to a repository to allow open source, collaborative development of NeuroML models.</p>"
              + "<p>See the <a href=\"http://www.opensourcebrain.org\">Open Source Brain</a> website for full details.&nbsp;&nbsp;&nbsp;&nbsp;"
              + "<img alt=\"Open Source Brain\" src=\"http://www.opensourcebrain.org/images/logo.png\"/></p>");
    }
    File[] fileArray = sourceProjDir.listFiles();

    fileArray = GeneralUtils.reorderAlphabetically(fileArray, true);

    ArrayList<File> files = GeneralUtils.toArrayList(fileArray);
    // if (files.contains(""))

    ArrayList<String> toIgnore = new ArrayList<String>();
    // toIgnore.add("Thalamocortical"); // temporarily
    // toIgnore.add("CA1PyramidalCell"); // temporarily
    // toIgnore.add("SolinasEtAl-GolgiCell"); // temporarily

    for (File exProjDir : files) {
      File morphDir = new File(exProjDir, "cellMechanisms");

      if (morphDir.isDirectory() && !toIgnore.contains(exProjDir.getName())) {
        String projName = exProjDir.getName();
        SimpleXMLElement section = new SimpleXMLElement("section");
        body.addChildElement(section);

        SimpleXMLElement secTitle = new SimpleXMLElement("title");
        section.addChildElement(secTitle);
        secTitle.addContent(projName);

        SimpleXMLElement anchor = new SimpleXMLElement("anchor");
        section.addChildElement(anchor);
        anchor.addAttribute("id", projName);

        SimpleXMLElement table = new SimpleXMLElement("table");

        section.addChildElement(table);

        SimpleXMLElement row = new SimpleXMLElement("tr");
        table.addChildElement(row);

        String largeImg = "large.png";
        String smallImg = "small.png";

        File targetImageDir = new File(mainFile.getParentFile(), "images");
        if (!targetImageDir.exists()) targetImageDir.mkdir();

        File targetProjImageDir = new File(targetImageDir, projName);

        if (!targetProjImageDir.exists()) targetProjImageDir.mkdir();

        File smallImgFile = new File(exProjDir, "images/" + smallImg);
        File largeImgFile = new File(exProjDir, "images/" + largeImg);

        if (smallImgFile.exists()) {
          GeneralUtils.copyFileIntoDir(smallImgFile, targetProjImageDir);

          SimpleXMLElement col2 = new SimpleXMLElement("td");
          row.addChildElement(col2);
          col2.addAttribute("width", "120");

          SimpleXMLElement secImg = new SimpleXMLElement("p");
          col2.addChildElement(secImg);

          SimpleXMLElement img = new SimpleXMLElement("img");
          img.addAttribute("src", "images/" + projName + "/small.png");
          img.addAttribute("alt", "Screenshot of " + projName);

          if (largeImgFile.exists()) {
            GeneralUtils.copyFileIntoDir(largeImgFile, targetProjImageDir);

            SimpleXMLElement imgRef = new SimpleXMLElement("a");
            img.addAttribute("title", "Click to enlarge");
            imgRef.addAttribute("href", "images/" + projName + "/" + largeImg);
            imgRef.addChildElement(img);
            secImg.addChildElement(imgRef);
          } else {
            secImg.addChildElement(img);
          }
        }

        SimpleXMLElement secIntro = new SimpleXMLElement("p");
        SimpleXMLElement colMid = new SimpleXMLElement("td");
        SimpleXMLElement colRight = new SimpleXMLElement("td");
        row.addChildElement(colMid);
        row.addChildElement(colRight);
        colRight.addAttribute("width", "150");
        colMid.addChildElement(secIntro);
        secIntro.addContent("Project name: <strong>" + projName + "</strong>");

        File projFile = ProjectStructure.findProjectFile(exProjDir);

        Project project = Project.loadProject(projFile, null);
        String descFull = project.getProjectDescription();
        String breakpoint = "\n\n";
        String descShort = new String(descFull);

        if (descFull.indexOf(breakpoint) > 0) {
          descShort = descFull.substring(0, descFull.indexOf(breakpoint));
        }

        SimpleXMLElement desc = new SimpleXMLElement("p");
        colMid.addChildElement(desc);
        desc.addContent(GeneralUtils.parseForHyperlinks(descShort));

        SimpleXMLElement modified = new SimpleXMLElement("p");
        colMid.addChildElement(modified);

        SimpleDateFormat formatter = new SimpleDateFormat("EEEE MMMM d, yyyy");

        java.util.Date date = new java.util.Date(projFile.lastModified());

        modified.addContent("Project last modified: " + formatter.format(date));

        File zipFile = null;
        String zipFileName =
            targetDownloadDir.getAbsolutePath()
                + "/"
                + projName
                + ProjectStructure.getNewProjectZipFileExtension();

        ArrayList<String> ignore = new ArrayList<String>();
        ArrayList<String> ignoreNone = new ArrayList<String>();
        ArrayList<String> ignoreExtns = new ArrayList<String>();

        ignore.add("i686");
        ignore.add("x86_64");
        ignore.add(".svn");
        ignore.add("simulations");
        ignore.add("generatedNEURON");
        ignore.add("generatedNeuroML");
        ignore.add("generatedGENESIS");
        ignore.add("generatedMOOSE");
        ignore.add("generatedPyNN");
        ignore.add("generatedPSICS");
        ignore.add("dataSets");
        ignoreExtns.add("bak");

        zipFile = ZipUtils.zipUp(exProjDir, zipFileName, ignore, ignoreExtns);

        logger.logComment(
            "The zip file: "
                + zipFile.getAbsolutePath()
                + " ("
                + zipFile.length()
                + " bytes)  contains all of the project files");

        SimpleXMLElement downloads = new SimpleXMLElement("p");
        colRight.addChildElement(downloads);
        downloads.addContent("Downloads<a href=\"#downloadInfo\">*</a>:");

        SimpleXMLElement downloadProj = new SimpleXMLElement("p");
        colRight.addChildElement(downloadProj);

        SimpleXMLElement link = new SimpleXMLElement("a");
        link.addAttribute("href", "downloads/" + zipFile.getName());
        link.addContent("neuroConstruct project");
        link.addAttribute("title", "Download full project for loading into neuroConstruct");
        downloadProj.addChildElement(link);

        ArrayList<String> noNeuroML = new ArrayList<String>();
        noNeuroML.add("Ex3_Morphology");
        noNeuroML.add("DentateGyrus");
        noNeuroML.add("RothmanEtAl_KoleEtAl_PyrCell");

        if (!noNeuroML.contains(projName)) {
          project.neuromlFileManager.generateNeuroMLFiles(
              null, new OriginalCompartmentalisation(), 1234, false);

          File neuroMLDir = ProjectStructure.getNeuroML1Dir(project.getProjectMainDirectory());

          String nmlZipFileName =
              targetDownloadDir.getAbsolutePath() + "/" + projName + "_NeuroML.zip";

          zipFile = ZipUtils.zipUp(neuroMLDir, nmlZipFileName, ignoreNone, ignoreNone);

          SimpleXMLElement downloadNml = new SimpleXMLElement("p");
          colRight.addChildElement(downloadNml);
          // downloadNml.addContent("Download project as pure NeuroML: ");

          SimpleXMLElement img = new SimpleXMLElement("img");
          img.addAttribute("src", "../images/NeuroMLSmall.png");
          String info = "Download core project elements in NeuroML format";
          img.addAttribute("alt", info);

          SimpleXMLElement imgRef = new SimpleXMLElement("a");
          img.addAttribute("title", info);
          imgRef.addAttribute("href", "downloads/" + zipFile.getName());
          imgRef.addChildElement(img);

          downloadNml.addChildElement(imgRef);
        }
      }
    }

    SimpleXMLElement end = new SimpleXMLElement("p");
    body.addChildElement(end);
    end.addContent("&nbsp;");

    SimpleXMLElement infoDlanchor = new SimpleXMLElement("anchor");
    body.addChildElement(infoDlanchor);
    end.addAttribute("id", "downloadInfo");

    SimpleXMLElement infoDl = new SimpleXMLElement("p");
    body.addChildElement(infoDl);
    end.addContent(
        "* Note: neuroConstruct project downloads (most of which are included with the standard software distribution) "
            + "can be loaded directly into neuroConstruct to generate cell and network scripts for NEURON, GENESIS, etc.,"
            + " but NeuroML downloads just consist of the core elements of the project"
            + " (morphologies, channels, etc.) which have been exported in NeuroML format. The latter can be useful for testing NeuroML compliant applications. "
            + "If no NeuroML download link is present, this usually indicates that the model is mainly implemented using channel/synapse mechanisms in a simulator's "
            + "native language (e.g. mod files) which have not fully been converted to ChannelML yet.");

    SimpleXMLElement end2 = new SimpleXMLElement("p");
    body.addChildElement(end2);
    end2.addContent("&nbsp;");

    FileWriter fw = null;
    try {

      fw = new FileWriter(mainFile);
      fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); // quick hack, todo: add to
      // SimpleXMLDoc...

      fw.write(
          "<!DOCTYPE document PUBLIC \"-//APACHE//DTD Documentation V2.0//EN\" \"http://forrest.apache.org/dtd/document-v20.dtd\">\n\n");
      fw.write(root.getXMLString("", false));

      fw.flush();
      fw.close();

    } catch (IOException ex) {
      logger.logError("Problem: ", ex);
      fw.close();
    }

    /*
             <header>
      <title>Examples of neuroConstruct in use</title>
    </header>
    <body>
        <p>Some screenshots of neuroConstruct in action are given below.
        Click on the thumbnails to see a full size version of the screenshots</p>

      <section>
        <title>Examples included with distribution</title>*/

  }
示例#11
0
  private void InitUpload() throws ServletException, IOException {
    String sConfig = myUtil.ReadFile(myUtil.getConfigFileRealPath(m_request.getServletPath()));
    ArrayList aStyle = myUtil.getConfigArray("Style", sConfig);

    String sAllowExt, sUploadDir, sBaseUrl, sContentPath;
    String sCurrDir, sDir;
    int nAllowBrowse;
    String sPathShareImage, sPathShareFlash, sPathShareMedia, sPathShareOther;

    // param
    String sType = myUtil.dealNull(m_request.getParameter("type")).toUpperCase();
    String sStyleName = myUtil.dealNull(m_request.getParameter("style"));
    String sCusDir = myUtil.dealNull(m_request.getParameter("cusdir"));
    String sAction = myUtil.dealNull(m_request.getParameter("action")).toUpperCase();

    String s_SKey = myUtil.dealNull(m_request.getParameter("skey"));

    // InitUpload

    String[] aStyleConfig = new String[1];
    boolean bValidStyle = false;

    for (int i = 0; i < aStyle.size(); i++) {
      aStyleConfig = myUtil.split(aStyle.get(i).toString(), "|||");
      if (sStyleName.toLowerCase().equals(aStyleConfig[0].toLowerCase())) {
        bValidStyle = true;
        break;
      }
    }

    if (!bValidStyle) {
      out.print(getOutScript("alert('Invalid Style!')"));
      out.close();
      return;
    }

    if (!aStyleConfig[61].equals("1")) {
      sCusDir = "";
    }

    String ss_FileSize = "",
        ss_FileBrowse = "",
        ss_SpaceSize = "",
        ss_SpacePath = "",
        ss_PathMode = "",
        ss_PathUpload = "",
        ss_PathCusDir = "",
        ss_PathCode = "",
        ss_PathView = "";
    if ((aStyleConfig[61].equals("2")) && (!s_SKey.equals(""))) {
      ss_FileSize =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileSize"));
      ss_FileBrowse =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileBrowse"));
      ss_SpaceSize =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpaceSize"));
      ss_SpacePath =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpacePath"));
      ss_PathMode =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathMode"));
      ss_PathUpload =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathUpload"));
      ss_PathCusDir =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCusDir"));
      ss_PathCode =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCode"));
      ss_PathView =
          (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathView"));

      if (myUtil.IsInt(ss_FileSize)) {
        aStyleConfig[11] = ss_FileSize;
        aStyleConfig[12] = ss_FileSize;
        aStyleConfig[13] = ss_FileSize;
        aStyleConfig[14] = ss_FileSize;
        aStyleConfig[15] = ss_FileSize;
        aStyleConfig[45] = ss_FileSize;
      } else {
        ss_FileSize = "";
      }
      if (ss_FileBrowse.equals("0") || ss_FileBrowse.equals("1")) {
        aStyleConfig[43] = ss_FileBrowse;
      } else {
        ss_FileBrowse = "";
      }
      if (myUtil.IsInt(ss_SpaceSize)) {
        aStyleConfig[78] = ss_SpaceSize;
      } else {
        ss_SpaceSize = "";
      }
      if (!ss_PathMode.equals("")) {
        aStyleConfig[19] = ss_PathMode;
      }
      if (!ss_PathUpload.equals("")) {
        aStyleConfig[3] = ss_PathUpload;
      }
      if (!ss_PathCode.equals("")) {
        aStyleConfig[23] = ss_PathCode;
      }
      if (!ss_PathView.equals("")) {
        aStyleConfig[22] = ss_PathView;
      }

      sCusDir = ss_PathCusDir;
    }

    sBaseUrl = aStyleConfig[19];
    nAllowBrowse = Integer.valueOf(aStyleConfig[43]).intValue();

    if (nAllowBrowse != 1) {
      out.print(getOutScript("alert('Do not allow browse!')"));
      out.close();
      return;
    }

    if (!sCusDir.equals("")) {
      sCusDir = myUtil.replace(sCusDir, "\\", "/");
      if ((sCusDir.startsWith("/"))
          || (sCusDir.startsWith("."))
          || (sCusDir.endsWith("."))
          || (sCusDir.indexOf("./") >= 0)
          || (sCusDir.indexOf("/.") >= 0)
          || (sCusDir.indexOf("//") >= 0)
          || (sCusDir.indexOf("..") >= 0)) {
        sCusDir = "";
      } else {
        if (!sCusDir.endsWith("/")) {
          sCusDir = sCusDir + "/";
        }
      }
    }

    sUploadDir = aStyleConfig[3];
    if (!sBaseUrl.equals("3")) {
      sUploadDir = myUtil.getRealPathFromRelative(m_request.getServletPath(), sUploadDir);
    }
    sUploadDir = GetSlashPath(sUploadDir);
    sUploadDir =
        sUploadDir
            + myUtil.replace(myUtil.replace(sCusDir, "/", sFileSeparator), "\\", sFileSeparator);

    if (sType.equals("FILE")) {
      sAllowExt = aStyleConfig[6];
    } else if (sType.equals("MEDIA")) {
      sAllowExt = aStyleConfig[9];
    } else if (sType.equals("FLASH")) {
      sAllowExt = aStyleConfig[7];
    } else {
      sAllowExt = aStyleConfig[8];
    }

    sPathShareImage =
        GetSlashPath(
            myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/image/"));
    sPathShareFlash =
        GetSlashPath(
            myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/flash/"));
    sPathShareMedia =
        GetSlashPath(
            myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/media/"));
    sPathShareOther =
        GetSlashPath(
            myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/other/"));

    String s_Out = "";
    if (sAction.equals("FILE")) {

      String s_ReturnFlag = myUtil.dealNull(m_request.getParameter("returnflag"));
      String s_FolderType = myUtil.dealNull(m_request.getParameter("foldertype"));
      String s_Dir = myUtil.dealNull(m_request.getParameter("dir"));
      s_Dir = java.net.URLDecoder.decode(s_Dir, "UTF-" + "8");

      String s_CurrDir = "";
      if (s_FolderType.equals("upload")) {
        s_CurrDir = sUploadDir;
      } else if (s_FolderType.equals("shareimage")) {
        sAllowExt = "";
        s_CurrDir = sPathShareImage;
      } else if (s_FolderType.equals("shareflash")) {
        sAllowExt = "";
        s_CurrDir = sPathShareFlash;
      } else if (s_FolderType.equals("sharemedia")) {
        sAllowExt = "";
        s_CurrDir = sPathShareMedia;
      } else {
        s_FolderType = "shareother";
        sAllowExt = "";
        s_CurrDir = sPathShareOther;
      }

      s_Dir = myUtil.replace(s_Dir, "\\", "/");
      if ((s_Dir.startsWith("/"))
          || (s_Dir.startsWith("."))
          || (s_Dir.endsWith("."))
          || (s_Dir.indexOf("./") >= 0)
          || (s_Dir.indexOf("/.") >= 0)
          || (s_Dir.indexOf("//") >= 0)
          || (s_Dir.indexOf("..") >= 0)) {
        s_Dir = "";
      }

      String s_Dir2 = myUtil.replace(s_Dir, "/", sFileSeparator);
      s_Dir2 = myUtil.replace(s_Dir2, "\\", sFileSeparator);

      if (!s_Dir.equals("")) {
        if (CheckValidDir(s_CurrDir + s_Dir2)) {
          s_CurrDir += s_Dir2;
        } else {
          s_Dir = "";
        }
      }

      if (CheckValidDir(s_CurrDir)) {
        File file = new File(s_CurrDir);
        File[] filelist = file.listFiles();
        if (filelist != null && filelist.length > 0) {
          int n = -1;
          for (int i = 0; i < filelist.length; i++) {
            if (filelist[i].isFile()) {
              String s_FileName = filelist[i].getName();
              String s_FileExt = s_FileName.substring(s_FileName.lastIndexOf(".") + 1);
              s_FileExt = s_FileExt.toLowerCase();
              if (CheckValidExt(sAllowExt, s_FileExt)) {
                n++;
                s_Out =
                    s_Out
                        + "arr["
                        + String.valueOf(n)
                        + "]=new Array(\""
                        + s_FileName
                        + "\", \""
                        + String.valueOf(convertFileSize(filelist[i].length()))
                        + "\",\""
                        + formatDate(new Date(filelist[i].lastModified()))
                        + "\");\n";
              }
            }
          }
        }
      }

      s_Out =
          "var arr = new Array();\n"
              + s_Out
              + "parent.setFileList('"
              + s_ReturnFlag
              + "', '"
              + s_FolderType
              + "', '"
              + s_Dir
              + "', arr);";
      out.print(getOutScript(s_Out));

    } else {

      s_Out = "var arrUpload = new Array();\n";
      s_Out += "var arrShareImage = new Array();\n";
      s_Out += "var arrShareFlash = new Array();\n";
      s_Out += "var arrShareMedia = new Array();\n";
      s_Out += "var arrShareOther = new Array();\n";

      s_Out += GetFolderTree(sUploadDir, "Upload", 1, 0).get(0).toString();

      sAllowExt = "";
      if (sType.equals("FILE")) {
        s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString();
        s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString();
        s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString();
        s_Out += GetFolderTree(sPathShareOther, "ShareOther", 1, 0).get(0).toString();
      } else if (sType.equals("MEDIA")) {
        s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString();
      } else if (sType.equals("FLASH")) {
        s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString();
      } else {
        s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString();
      }

      s_Out +=
          "parent.setFolderList(arrUpload, arrShareImage, arrShareFlash, arrShareMedia, arrShareOther);";
      out.print(getOutScript(s_Out));
    }
  }