예제 #1
0
  /**
   * Returns the contents of a file as a string
   *
   * @param file the file to be read
   * @return the contents as a string
   */
  public static String getContents(final File file) {
    StringBuilder contents = new StringBuilder();
    BufferedReader input = null;
    try {
      // XXX TODO Replace with FileUtils
      input = new BufferedReader(new FileReader(file));

      String line = null;
      while ((line = input.readLine()) != null) {
        contents.append(line);
        contents.append(eol);
      }
    } catch (FileNotFoundException ex) {
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(XMLHelper.class, ex);
      ex.printStackTrace();

    } catch (IOException ex) {
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(XMLHelper.class, ex);
      ex.printStackTrace();

    } finally {
      try {
        if (input != null) {
          input.close();
        }
      } catch (IOException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(XMLHelper.class, ex);
        ex.printStackTrace();
      }
    }
    return contents.toString();
  }
예제 #2
0
 /* (non-Javadoc)
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(ActionEvent evt) {
   isSearchDown = true;
   Object source = evt.getSource();
   TableSearcher tableSearcher = createTableSearcher();
   if (source == nextButton) {
     log.debug("nextButton --------------------------------------------------------");
     isSearchDown = true;
   } else if (source == previousButton) {
     log.debug("previousButton --------------------------------------------------------");
     isSearchDown = false;
   }
   int replacementCount = 0;
   UsageTracker.incrUsageCount("WB.FindButton");
   setCheckAndSetWrapOption();
   log.debug("action performed");
   final String findValue = getFindFieldValue();
   int curRow = foundCell == null ? table.getSelectedRow() : foundCell.getRow();
   int curCol = foundCell == null ? table.getSelectedColumn() - 1 : foundCell.getColumn();
   TableSearcherCell cell =
       tableSearcher.findNext(
           findValue,
           curRow,
           curCol,
           isSearchDown(),
           getWrapSearchFlag(),
           getMatchCaseFlag(),
           isSearchSelection());
   if (cell.isFound()) {
     replacementCount++;
     foundCell = cell;
   } else {
     // foundCell = null;
   }
   updateTableUiForFoundValue(cell, replacementCount, false);
 }
  /* (non-Javadoc)
   * @see edu.ku.brc.af.ui.forms.validation.TypeSearchForQueryFactory#getDOMFromResource(java.lang.String, java.lang.String)
   */
  public Element getDOMFromResource(final String name, final String localPath) {
    SpecifyAppContextMgr acMgr = (SpecifyAppContextMgr) AppContextMgr.getInstance();
    DataProviderSessionIFace session = null;
    try {
      session = DataProviderFactory.getInstance().createSession();

      String[] dirs = {SpecifyAppContextMgr.COMMONDIR, SpecifyAppContextMgr.BACKSTOPDIR};
      for (String dirName : dirs) {
        SpAppResourceDir appResDir = acMgr.getSpAppResourceDirByName(dirName);
        if (appResDir != null) {
          SpAppResource appRes = appResDir.getResourceByName(name);
          if (appRes != null) {
            session.close();
            session = null;

            return AppContextMgr.getInstance().getResourceAsDOM(appRes);
          }
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance()
          .capture(SpecifyUIFieldFormatterMgr.class, ex);

    } finally {
      if (session != null) {
        session.close();
      }
    }

    return XMLHelper.readDOMFromConfigDir(localPath); // $NON-NLS-1$
  }
예제 #4
0
  /** Setup output directory and get template etc. */
  protected void createIndexFile() {
    String fName = outputDir.getAbsolutePath() + File.separator + "index.html"; // $NON-NLS-1$
    try {
      File html = new File(fName);
      BufferedWriter output = new BufferedWriter(new FileWriter(html));

      int inx = mapTemplate.indexOf(contentTag);
      String subContent = mapTemplate.substring(0, inx);
      output.write(
          StringUtils.replace(
              subContent,
              "<!-- Title -->",
              getResourceString("FormDisplayer.FORM_INDEX"))); // $NON-NLS-1$ //$NON-NLS-2$
      output.write("<UL>"); // $NON-NLS-1$

      Collections.sort(
          entries,
          new Comparator<Pair<String, File>>() {
            public int compare(Pair<String, File> o1, Pair<String, File> o2) {
              return o1.first.compareTo(o2.first);
            }
          });
      int cnt = 0;
      for (Pair<String, File> p : entries) {
        output.write(
            "<LI><a href=\""
                + FilenameUtils.getBaseName(p.second.getName())
                + ".html\">"
                + p.first
                + "</a></LI>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        String prvName =
            cnt == 0
                ? null
                : FilenameUtils.getBaseName(entries.get(cnt - 1).second.getName())
                    + ".html"; //$NON-NLS-1$
        String nxtName =
            cnt == entries.size() - 1
                ? null
                : FilenameUtils.getBaseName(entries.get(cnt + 1).second.getName())
                    + ".html"; //$NON-NLS-1$
        writeImageFile(p.first, p.second.getName(), prvName, nxtName);
        cnt++;
      }
      output.write("</UL>"); // $NON-NLS-1$
      output.write(mapTemplate.substring(inx + contentTag.length() + 1, mapTemplate.length()));

      output.close();

    } catch (Exception e) {
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, e);
      e.printStackTrace();
    }

    createFormImagesIndexFile();

    JOptionPane.showMessageDialog(
        getTopWindow(),
        String.format(getResourceString("FormDisplayer.OUTPUT"), outputDir.getAbsoluteFile()));
  }
예제 #5
0
 /**
  * @param shouldShow - flag noting whether the panel should be visible
  * @return the find/replace panel to be displayed
  */
 protected JPanel showFindAndReplacePanel(boolean shouldShow) {
   if (!shouldShow) {
     this.setVisible(false);
   } else {
     stopTableEditing();
     this.setVisible(true);
     findField.requestFocusInWindow();
     UsageTracker.incrUsageCount("WB.ShowFindReplace");
   }
   return this;
 }
예제 #6
0
  /**
   * @param fileName
   * @param title
   */
  protected void createHTMLFile(final String fileName, final String title) {
    try {
      file = new File(fileName);
      pw = new PrintWriter(file);
      pw.print(
          "<html><head><title>" + title + "</title></head><body>"); // $NON-NLS-1$ //$NON-NLS-2$

    } catch (IOException ex) {
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, ex);
      ex.printStackTrace();
    }
  }
예제 #7
0
 /*
  * (non-Javadoc)
  *
  * @see javax.swing.SwingWorker#doInBackground()
  */
 @Override
 public Boolean doInBackground() {
   traversalSession = DataProviderFactory.getInstance().createSession();
   try {
     buildVerificationQueries();
     T root = getTreeRoot();
     LinkedList<Integer> parentIds = new LinkedList<Integer>();
     initProgress();
     verifyNodes(root.getTreeId(), root.getNodeNumber(), parentIds);
     return true;
   } catch (Exception e) {
     edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
     edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(NodeNumberer.class, e);
     return false;
   } finally {
     traversalSession.close();
   }
 }
예제 #8
0
  /**
   * @param title
   * @param fileName
   * @param prevName
   * @param nxtName
   */
  protected void writeImageFile(
      final String title, final String fileName, final String prevName, final String nxtName) {
    String fName =
        outputDir.getAbsolutePath()
            + File.separator
            + FilenameUtils.getBaseName(fileName)
            + ".html"; //$NON-NLS-1$
    try {
      File html = new File(fName);
      BufferedWriter output = new BufferedWriter(new FileWriter(html));

      int inx = mapTemplate.indexOf(contentTag);
      String subContent = mapTemplate.substring(0, inx);
      output.write(StringUtils.replace(subContent, "<!-- Title -->", title)); // $NON-NLS-1$
      output.write("<br>"); // $NON-NLS-1$
      if (prevName != null) {
        output.write("<a href=\"" + prevName + "\">Previous</a>"); // $NON-NLS-1$ //$NON-NLS-2$
      } else {
        output.write(getResourceString("FormDisplayer.PREV")); // $NON-NLS-1$
      }
      output.write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"); // $NON-NLS-1$
      if (nxtName != null) {
        output.write("<a href=\"" + nxtName + "\">Next</a>"); // $NON-NLS-1$ //$NON-NLS-2$
      } else {
        output.write(getResourceString("FormDisplayer.NEXT")); // $NON-NLS-1$
      }
      output.write(
          "<center><br><img src=\""
              + fileName
              + "\"><br><br>"
              + title); //$NON-NLS-1$ //$NON-NLS-2$
      output.write("</center>"); // $NON-NLS-1$
      output.write(mapTemplate.substring(inx + contentTag.length() + 1, mapTemplate.length()));

      output.close();

    } catch (Exception e) {
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, e);
      e.printStackTrace();
    }
  }
예제 #9
0
  /** Create the UI for the panel */
  protected void createUI() {
    createForm("Preferences", "LoansPrefs");
    AppPreferences prefs = AppPreferences.getRemote();

    Integer dueInMonths = prefs.getInt(DUEINMONTHS, 6);
    String shippingMethod = prefs.get(LoanGiftShipmentBusRules.SHIPMETHOD, null);
    Integer shippedByAgentId = prefs.getInt(LoanGiftShipmentBusRules.SHIPPEDBY, null);

    FormViewObj fvo = (FormViewObj) form;

    ValSpinner dueSpinner = fvo.getCompById("OVERDUETIME");
    if (dueSpinner != null) {
      dueSpinner.setValue(dueInMonths);
    }

    ValComboBox shipMeth = fvo.getCompById("SHIPMETH");
    if (shipMeth != null) {
      shipMeth.setValue(shippingMethod, null);
    }

    ValComboBoxFromQuery shippedBy = fvo.getCompById("SHIPPEDBY");
    if (shippedBy != null && shippedByAgentId != null) {
      DataProviderSessionIFace session = null;
      try {
        session = DataProviderFactory.getInstance().createSession();
        Agent agent = session.get(Agent.class, shippedByAgentId);
        shippedBy.setValue(agent, null);

      } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance()
            .capture(ValComboBoxFromQuery.class, ex);
        ex.printStackTrace();

      } finally {
        if (session != null) {
          session.close();
        }
      }
    }
  }
예제 #10
0
  /** Generates an Image for the View. */
  protected void generateViewImage(final ViewIFace view) {
    Rectangle rect = frame.getContentPane().getBounds();
    if (rect.width == 0 || rect.height == 0) {
      return;
    }

    BufferedImage bufImage =
        new BufferedImage(
            rect.width,
            rect.height,
            (doPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB));
    Graphics2D g2 = bufImage.createGraphics();
    if (!doPNG) {
      g2.setColor(Color.WHITE);
      g2.fillRect(0, 0, rect.width, rect.height);
    }
    g2.setRenderingHints(ERDVisualizer.createTextRenderingHints());
    frame.getContentPane().paint(g2);

    g2.dispose();

    String baseFileName =
        outputDir.getAbsoluteFile()
            + "/"
            + view.getName()
            + "_"
            + viewInx; //$NON-NLS-1$ //$NON-NLS-2$
    File imgFile = new File(baseFileName + (doPNG ? ".png" : ".jpg")); // $NON-NLS-1$ //$NON-NLS-2$
    System.out.println(imgFile.getAbsolutePath());
    try {
      ImageIO.write(bufImage, "PNG", imgFile); // $NON-NLS-1$

      entries.add(new Pair<String, File>(view.getName(), imgFile));

    } catch (Exception ex) {
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, ex);
      ex.printStackTrace();
    }
  }
예제 #11
0
  /**
   * Reads in a file of HTML, primarily from the Help directory and fixes up the images to have an
   * absolute path. Plus it strip everything before and including the 'body' tag and strips the
   * '</body>' to the end.
   *
   * @param file the html file to be read.
   * @return the file as a string
   */
  @SuppressWarnings("deprecation") // $NON-NLS-1$
  public static String fixUpHTML(final File file) {
    String path = FilenameUtils.getFullPath(file.getAbsolutePath());

    StringBuilder sb = new StringBuilder();
    try {
      List<?> lines = FileUtils.readLines(file);
      boolean fndBegin = false;

      for (Object lineObj : lines) {
        String line = (String) lineObj;
        if (!fndBegin) {
          if (line.indexOf("<body") > -1) // $NON-NLS-1$
          {
            fndBegin = true;
          }
          continue;
        }
        int inx = line.indexOf("<img"); // $NON-NLS-1$
        if (inx > -1) {
          inx = line.indexOf("src=\"", inx); // $NON-NLS-1$

          sb.append(line.substring(0, inx + 5));
          File f = new File(path);
          sb.append(f.toURL()); // needed for 1.5
          sb.append(line.substring(inx + 5, line.length()));
        } else {
          sb.append(line + "\n"); // $NON-NLS-1$
        }
      }
    } catch (IOException ex) {
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(XMLHelper.class, ex);
      log.error(ex);
    }
    return sb.toString();
  }
예제 #12
0
    /* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent evt) {
      Object source = evt.getSource();
      setCheckAndSetWrapOption();
      final String replaceValue = getRepalceFieldValue();
      final String findValue = getFindFieldValue();
      TableSearcherCell cell = null;
      if (source == replaceAllButton) {
        log.debug("replaceAllButton --------------------------------------------------------");
        TableSearcher tableSearcher = createTableSearcher();
        int selectedCol = 0;
        int selectedRow = 0;
        int rowCount = table.getModel().getRowCount();
        int colCount = table.getModel().getColumnCount();
        boolean found = false;
        boolean oldBatchMode = table.getModel().isBatchMode();
        cell =
            tableSearcher.checkCell(
                getFindFieldValue(),
                selectedRow,
                selectedCol,
                getMatchCaseFlag(),
                isSearchSelection());
        try {
          table.getModel().setBatchMode(true);
          while ((selectedRow > -1)
              && (selectedCol > -1)
              && (selectedRow <= rowCount - 1)
              && (selectedCol <= colCount - 1)) {
            found = cell.isFound();
            if (found) {
              tableSearcher.replace(
                  cell, findValue, replaceValue, getMatchCaseFlag(), isSearchSelection());
            }
            cell =
                tableSearcher.findNext(
                    findValue,
                    selectedRow,
                    selectedCol,
                    true,
                    false,
                    getMatchCaseFlag(),
                    isSearchSelection());
            selectedCol = cell.getColumn();
            selectedRow = cell.getRow();
          }
        } finally {
          table.getModel().setBatchMode(oldBatchMode);
        }
        tableSearcher.replacementCleanup();
        updateTableUiForFoundValue(cell, tableSearcher.getReplacementCount(), true);
        UsageTracker.incrUsageCount("WB.ReplaceAllButton");
      } else if (source == replaceButton) {
        if (!canReplace()) {
          if (isSearchSelection()) {
            UIRegistry.displayInfoMsgDlgLocalized("SearchReplacePanel.UnableToReplaceSelection");
          } else {
            UIRegistry.displayInfoMsgDlgLocalized("SearchReplacePanel.UnableToReplace");
          }
          return;
        }
        log.debug("replaceButton --------------------------------------------------------");
        TableSearcher tableSearcher = createTableSearcher();
        int selectedCol = foundCell == null ? table.getSelectedColumn() - 1 : foundCell.getColumn();
        int selectedRow = foundCell == null ? table.getSelectedRow() : foundCell.getRow();

        cell =
            tableSearcher.checkCell(
                getFindFieldValue(),
                selectedRow,
                selectedCol,
                getMatchCaseFlag(),
                isSearchSelection());
        if (cell.isFound()) {
          tableSearcher.replace(
              cell, findValue, replaceValue, getMatchCaseFlag(), isSearchSelection());
          tableSearcher.replacementCleanup();
          selectedCol = cell.getColumn();
          selectedRow = cell.getRow();

          cell =
              tableSearcher.findNext(
                  findValue,
                  selectedRow,
                  selectedCol,
                  isSearchDown(),
                  getWrapSearchFlag(),
                  getMatchCaseFlag(),
                  isSearchSelection());
          if (cell.isFound()) {
            foundCell = cell;
            updateTableUiForFoundValue(foundCell, tableSearcher.getReplacementCount(), true);
          } else {
            foundCell = null;
          }
        } else {
          setStatusLabelWithFailedFind();
        }
        UsageTracker.incrUsageCount("WB.ReplaceButton");
      }
    }
  /**
   * Saves an Discipline level XML document to a Database Resource.
   *
   * @param resName the name of the resource
   * @param xml the XML to be saved.
   */
  public void saveResource(final String resName, final String xml) {
    // System.out.println("Saved");
    // System.out.println(xml);
    // System.out.println();

    SpecifyAppContextMgr acMgr = (SpecifyAppContextMgr) AppContextMgr.getInstance();
    DataProviderSessionIFace session = null;
    try {
      session = DataProviderFactory.getInstance().createSession();

      SpAppResource appRes = null;
      SpAppResourceDir commonResDir =
          acMgr.getSpAppResourceDirByName(SpecifyAppContextMgr.COMMONDIR);
      if (commonResDir != null) {
        appRes = commonResDir.getResourceByName(resName);
        if (appRes == null) {
          SpAppResourceDir backStopResDir =
              acMgr.getSpAppResourceDirByName(SpecifyAppContextMgr.BACKSTOPDIR);
          appRes = backStopResDir.getResourceByName(resName);
          if (appRes != null) {
            backStopResDir.getSpAppResources().remove(appRes);
            commonResDir.getSpAppResources().add(appRes);
            appRes.setSpAppResourceDir(commonResDir);
          } else {
            // major error
            UIRegistry.showError("Major Error");
          }
        }

        if (appRes != null) {
          session.close();
          session = null;

          appRes.setDataAsString(xml);
          AppContextMgr.getInstance().saveResource(appRes);

        } else {
          UIRegistry.showError("Major Error #2");
        }
      }

      /*if (appRes == null)
      {
          SpAppResource backStopDir = acMgr.getSpAppResourceDirByName(BACKSTOPDIR).getResourceByName(resName);
          if (appResDir != null)
          {
              SpAppResource newAppRes  = new SpAppResource();
              newAppRes.initialize();
              if (diskAppRes != null)
              {
                  newAppRes.setMetaData(diskAppRes.getMetaData());
                  newAppRes.setDescription(diskAppRes.getDescription());
                  newAppRes.setFileName(diskAppRes.getFileName());
                  newAppRes.setMimeType(diskAppRes.getMimeType());
                  newAppRes.setName(diskAppRes.getName());

                  newAppRes.setLevel(diskAppRes.getLevel());
              } else
              {
                  newAppRes.setName(resName);
                  newAppRes.setLevel((short)0);
                  newAppRes.setMimeType("text/xml");
              }

              Agent agent = AppContextMgr.getInstance().getClassObject(Agent.class);
              newAppRes.setCreatedByAgent(agent);
              newAppRes.setSpecifyUser(user);

              newAppRes.setSpAppResourceDir(appResDir);
              appResDir.getSpAppResources().add(newAppRes);
              newAppRes.setDataAsString(xml);

              session.close();
              session = null;
              ((SpecifyAppContextMgr) AppContextMgr.getInstance()).saveResource(newAppRes);

          } else
          {
              AppContextMgr.getInstance().putResourceAsXML(resName, xml); //$NON-NLS-1$
          }
      }*/

    } catch (Exception ex) {
      ex.printStackTrace();
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance()
          .capture(SpecifyUIFieldFormatterMgr.class, ex);

    } finally {
      if (session != null) {
        session.close();
      }
    }
  }
예제 #14
0
  protected boolean setup() {
    String pathStr =
        AppContextMgr.getInstance().getClassObject(Discipline.class) != null
            ? AppContextMgr.getInstance().getClassObject(Discipline.class).getType()
            : ""; //$NON-NLS-1$
    pathStr +=
        "_"
            + UIHelper.getOSType().toString()
            + "_"
            + (doAll ? "all" : "user"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    baseDir = new File(getUserHomeDir() + File.separator + "FormImages"); // $NON-NLS-1$
    outputDir = new File(baseDir.getAbsoluteFile() + File.separator + pathStr);

    if (!baseDir.exists()) {
      if (!baseDir.mkdir()) {
        UIRegistry.showError(
            String.format(
                getResourceString("FormDisplayer.OUTPUT_ERROR"), baseDir.getAbsoluteFile()));
      }
    }

    if (!outputDir.exists()) {
      if (!outputDir.mkdir()) {
        UIRegistry.showError(
            String.format(
                getResourceString("FormDisplayer.OUTPUT_ERROR"), outputDir.getAbsoluteFile()));
      }
    } else {
      try {
        FileUtils.cleanDirectory(outputDir);

      } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, ex);
        ex.printStackTrace();
      }
    }

    String dstDirPath = UIRegistry.getDefaultUserHomeDir() + File.separator + "Specify/site";
    try {
      File tmplateFile = checkForTemplateFiles(dstDirPath);
      mapTemplate = FileUtils.readFileToString(tmplateFile);
      mapTemplate =
          StringUtils.replace(
              mapTemplate,
              "Database Schema",
              getResourceString("FormDisplayer.FORMS")); // $NON-NLS-1$ //$NON-NLS-2$

    } catch (IOException ex) {
      ex.printStackTrace();
      JOptionPane.showMessageDialog(
          null, "You are missing the template that is needed to run this tool.");
      return false;
    }

    if (StringUtils.isEmpty(mapTemplate)) {
      System.err.println("The template file is empty!"); // $NON-NLS-1$
    }

    try {
      File srcDir = new File(dstDirPath); // $NON-NLS-1$
      for (File f : srcDir.listFiles()) {
        if (!f.getName().startsWith(".")) // $NON-NLS-1$
        {
          File dst =
              new File(outputDir.getAbsolutePath() + File.separator + f.getName()); // $NON-NLS-1$
          if (!FilenameUtils.getExtension(f.getName()).toLowerCase().equals("html")) // $NON-NLS-1$
          {
            FileUtils.copyFile(f, dst);
          }

          dst = new File(baseDir.getAbsolutePath() + File.separator + f.getName()); // $NON-NLS-1$
          if (!FilenameUtils.getExtension(f.getName()).toLowerCase().equals("html")) // $NON-NLS-1$
          {
            FileUtils.copyFile(f, dst);
          }
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, ex);
      ex.printStackTrace();
      return false;
    }
    return true;
  }
예제 #15
0
  /** Setup output directory and get template etc. */
  protected void createFormImagesIndexFile() {
    String fName = baseDir.getAbsolutePath() + File.separator + "index.html"; // $NON-NLS-1$
    try {
      File html = new File(fName);
      BufferedWriter output = new BufferedWriter(new FileWriter(html));

      int inx = mapTemplate.indexOf(contentTag);
      String subContent = mapTemplate.substring(0, inx);
      output.write(
          StringUtils.replace(
              subContent,
              "<!-- Title -->",
              getResourceString("FormDisplayer.FORM_INDEX"))); // $NON-NLS-1$ //$NON-NLS-2$
      output.write("<UL>\n"); // $NON-NLS-1$

      List<File> files = new Vector<File>();
      for (File f : baseDir.listFiles()) {
        String nm = f.getName();
        if (nm.endsWith("_all") || nm.endsWith("_user")) // $NON-NLS-1$ //$NON-NLS-2$
        {
          files.add(f);
        }
      }

      Collections.sort(
          files,
          new Comparator<File>() {
            public int compare(File o1, File o2) {
              return o1.getName().compareTo(o2.getName());
            }
          });

      String currDiscipline = "";
      for (File f : files) {
        String[] segments = StringUtils.split(f.getName(), "_"); // $NON-NLS-1$
        if (segments != null && segments.length == 3) {
          DisciplineType dt = DisciplineType.getDisciplineHash().get(segments[0]);
          if (!dt.getName().equals(currDiscipline)) {
            if (currDiscipline.length() > 0) output.write("</UL>\n"); // $NON-NLS-1$
            output.write("<LI>" + dt.getTitle() + "</LI>\n"); // $NON-NLS-1$ //$NON-NLS-2$
            output.write("<UL>\n"); // $NON-NLS-1$
            currDiscipline = dt.getName();
          }
          String title =
              String.format(
                  "%s %s",
                  segments[1],
                  (segments[2].equals("all")
                      ? "All"
                      : "User")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          output.write(
              "<LI><a href=\""
                  + f.getName()
                  + File.separator
                  + "index.html\">"
                  + title
                  + "</a></LI>\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
      }
      output.write("</UL>\n"); // $NON-NLS-1$
      output.write("</UL>\n"); // $NON-NLS-1$
      output.write(mapTemplate.substring(inx + contentTag.length() + 1, mapTemplate.length()));

      output.close();

    } catch (Exception e) {
      edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
      edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormDisplayer.class, e);
      e.printStackTrace();
    }
  }