Example #1
0
 private void initializeTimestamp() throws IOException {
   IWTimestamp timestamp = null;
   // try to get timestamp from origin file
   File originFile =
       FileUtil.getFileRelativeToFile(this.projectFile, ManagerConstants.ORIGIN_FILE);
   if (originFile.exists()) {
     BufferedReader fileReader = null;
     try {
       fileReader = new BufferedReader(new FileReader(originFile));
       String orignFileName = fileReader.readLine();
       timestamp = getTimestampFromFileName(orignFileName);
     } finally {
       try {
         if (fileReader != null) {
           fileReader.close();
         }
       } catch (IOException io) {
         // do not hide an existing exception
       }
     }
   }
   if (timestamp == null) {
     // failed?  try to get timestamp from corresponding MANIFEST_FILE
     File manifestFile = FileUtil.getFileRelativeToFile(this.projectFile, MANIFEST_PATH);
     if (manifestFile.exists()) {
       long dateValue = manifestFile.lastModified();
       Date date = new Date(dateValue);
       timestamp = new IWTimestamp(date);
     }
   }
   setTimestamp(timestamp);
 }
  private void init(IWApplicationContext iwac, Application application, Locale locale)
      throws RemoteException {
    Map<String, Object> props = new HashMap<String, Object>();
    Company company = ((CompanyApplication) application).getCompany();
    Commune commune = company.getWorkingArea();
    if (commune == null) {
      commune = getCommuneBusiness(iwac).getDefaultCommune();
    }

    props.put(PrintingContext.IW_BUNDLE_ROPERTY_NAME, getBundle(iwac));
    props.put("iwrb", getResourceBundle(iwac, locale));

    props.put("name", company.getName());
    props.put("personalID", company.getPersonalID());

    setFileName(
        getResourceBundle(iwac, locale).getLocalizedString("contract.file_name", "contract")
            + "_"
            + String.valueOf(application.getPrimaryKey()));
    addDocumentProperties(props);

    String baseDirectory = getResourceRealPath(getBundle(iwac), locale);
    try {
      setResourceDirectory(FileUtil.getFileAndCreateRecursiveIfNotExists(baseDirectory));
      File file = FileUtil.getFileFromWorkspace(baseDirectory + "company_contract_template.xml");
      setTemplateStream(new FileInputStream(file));
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #3
0
 public static XMLData createXMLData(File projectFile) throws IOException {
   XMLData pomData = XMLData.getInstanceForFile(projectFile);
   // handle extensions
   String superPom = pomData.getDocument().getRootElement().getTextTrim(EXTEND);
   // TODO thi: where can I fetch the value of the variable?
   if (superPom != null) {
     // replace if variable exists
     superPom = StringHandler.replace(superPom, BASE_PROJECT_VARIABLE, BASE_PROJECT_PATH);
     File superPomFile = FileUtil.getFileRelativeToFile(projectFile, superPom);
     if (superPomFile.exists()) {
       XMLData superPomData = createXMLData(superPomFile);
       // concat pomData and superPomData
       pomData.add(superPomData);
     }
   }
   return pomData;
 }
  private void log(String msg) {

    Handler fh = null;

    try {
      Logger logger = Logger.getLogger(this.getClass().getName());
      fh =
          new FileHandler(
              this.bundle.getPropertiesRealPath()
                  + FileUtil.getFileSeparator()
                  + "kortathjonustan.log");
      logger.addHandler(fh);
      logger.setLevel(Level.ALL);
      logger.info(msg);
      fh.close();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (fh != null) {
        fh.close();
      }
    }
  }