Package com.knowgate.dfs

Examples of com.knowgate.dfs.FileSystem


    if (null!=url.getFile()) {
      File oDir = new File(url.getFile());

      if (!oDir.exists()) {
        FileSystem oFS = new FileSystem();
        try {
          oFS.mkdirs(url.getFile());
        } catch (Exception e) {
          if (DebugFile.trace) DebugFile.writeln(e.getClass().getName() + " " + e.getMessage());
          throw new MessagingException(e.getMessage(), e);
        }
      }
View Full Code Here


    final long lRefreshEvery = 60000l// 1 minute

    ByteArrayInputStream oInStream;
    ByteArrayOutputStream oOutStream;

    FileSystem oFS = new FileSystem(FileSystem.OS_PUREJAVA);
    String sOutput;
    String sDomainId = req.getProperty("domain");
    String sWorkAreaId = req.getProperty("workarea");
    String sUserId = req.getProperty("user");
    String sMailAccount = req.getProperty("account");
    String sZone = req.getProperty("zone");
    String sLang = req.getProperty("language");
    String sTemplatePath = req.getProperty("template");
    String sStorage = req.getProperty("storage");
    String sFileDir = "file://" + sStorage + "domains" + File.separator + sDomainId + File.separator + "workareas" + File.separator + sWorkAreaId + File.separator + "cache" + File.separator + sUserId;
    String sCachedFile = "newmails_" + req.getWindowState().toString() + ".xhtm";

    boolean bFetch;

    File oCached = new File(sFileDir.substring(7)+File.separator+sCachedFile);

    if (!oCached.exists()) {
      bFetch = true;
      try {
        oFS.mkdirs(sFileDir);
      } catch (Exception xcpt) {
        throw new PortletException(xcpt.getMessage(), xcpt);
      }
    } else {
      bFetch = (new Date().getTime()-oCached.lastModified()>lRefreshEvery);
    }
     
  if (bFetch) {

      String sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type=\"text/xsl\"?>\n<folder account=\""+(null==sMailAccount ? "" : sMailAccount)+"\" name=\"inbox\">";
   
      if (req.getWindowState().equals(WindowState.MINIMIZED) || null==sMailAccount) {
        sXML += "<messages total=\"0\" skip=\"0\"/></folder>";
      } else {
        JDCConnection oCon = null;
        try {
       
        SessionHandler oHnr;

          DBBind oDBB = (DBBind) getPortletContext().getAttribute("GlobalDBBind");
       
        oCon = oDBB.getConnection("NewMail");
       
        MailAccount oMacc = new MailAccount(oCon, sMailAccount);
       
        if (oMacc.load(oCon, sMailAccount))
          oHnr = new SessionHandler(oMacc);
      else
        oHnr = null;

      oCon.close("NewMail");
      oCon=null;
     
      if (null!=oHnr) {
        String[] aRecentXML = oHnr.listRecentMessages("INBOX", iMaxNew);
          if (null!=aRecentXML) {
          int nRecentXML = aRecentXML.length;
          sXML += "<messages total=\""+String.valueOf(nRecentXML)+"\" skip=\"0\">";
          for (int r=0; r<nRecentXML; r++)
              sXML += aRecentXML[r];
            sXML += "</messages>";
          } else {
            sXML += "<messages total=\"0\" skip=\"0\"/>";
          }// fi
      } else {
         if (DebugFile.trace) {
             DebugFile.writeln("Mail Account "+sMailAccount+" not found");
         }
          sXML += "<messages total=\"0\" skip=\"0\" />";
      }
        } catch (SQLException sqle) {
          if (oCon!=null) { try { oCon.close("NewMail"); oCon=null; } catch (SQLException ignore) {} }
          throw new PortletException(sqle.getMessage(), sqle);
        } catch (AuthenticationFailedException afe) {
          if (oCon!=null) { try { oCon.close("NewMail"); oCon=null; } catch (SQLException ignore) {} }
          throw new PortletException(afe.getMessage(), afe);
        } catch (NoSuchProviderException nspe) {
          if (oCon!=null) { try { oCon.close("NewMail"); oCon=null; } catch (SQLException ignore) {} }
          throw new PortletException(nspe.getMessage(), nspe);
        } catch (MessagingException jmme) {
          if (oCon!=null) { try { oCon.close("NewMail"); oCon=null; } catch (SQLException ignore) {} }
          throw new PortletException(jmme.getMessage(), jmme);
        }
        sXML += "</folder>";
      } // fi

    DebugFile.writeln(sXML);

      try {
       if (DebugFile.trace) DebugFile.writeln("new ByteArrayInputStream(" + String.valueOf(sXML.length()) + ")");

       if (sEncoding==null)
         oInStream = new ByteArrayInputStream(sXML.getBytes());
       else
         oInStream = new ByteArrayInputStream(sXML.getBytes(sEncoding));

       oOutStream = new ByteArrayOutputStream(4000);

       Properties oProps = new Properties();

       Enumeration oKeys = req.getPropertyNames();
       while (oKeys.hasMoreElements()) {
         String sKey = (String) oKeys.nextElement();
         oProps.setProperty(sKey, req.getProperty(sKey));
       } // wend

       if (req.getWindowState().equals(WindowState.MINIMIZED))
         oProps.setProperty("windowstate", "MINIMIZED");
       else
         oProps.setProperty("windowstate", "NORMAL");

       StylesheetCache.transform (sTemplatePath, oInStream, oOutStream, oProps);

       if (sEncoding==null)
         sOutput = oOutStream.toString();
       else
         sOutput = oOutStream.toString("UTF-8");

       oOutStream.close();

       oInStream.close();
       oInStream = null;

       oFS.writefilestr (sFileDir+File.separator+sCachedFile, sOutput, sEncoding==null ? "ISO8859_1" : sEncoding);
      }
      catch (TransformerConfigurationException tce) {
       if (DebugFile.trace) {
         DebugFile.writeln("TransformerConfigurationException " + tce.getMessageAndLocation());
         try {
           DebugFile.write("--------------------------------------------------------------------------------\n");
           DebugFile.write(FileSystem.readfile(sTemplatePath));
           DebugFile.write("\n--------------------------------------------------------------------------------\n");
           DebugFile.write(sXML);
           DebugFile.write("\n--------------------------------------------------------------------------------\n");
         }
         catch (java.io.IOException ignore) { }
         catch (com.enterprisedt.net.ftp.FTPException ignore) { }

         DebugFile.decIdent();
       }
       throw new PortletException("TransformerConfigurationException " + tce.getMessage(), tce);
      }
      catch (TransformerException tex) {
       if (DebugFile.trace) {
         DebugFile.writeln("TransformerException " + tex.getMessageAndLocation());

         try {
           DebugFile.write("--------------------------------------------------------------------------------\n");
           DebugFile.write(FileSystem.readfile(sTemplatePath));
           DebugFile.write("\n--------------------------------------------------------------------------------\n");
           DebugFile.write(sXML);
           DebugFile.write("\n--------------------------------------------------------------------------------\n");
         }
         catch (java.io.IOException ignore) { }
         catch (com.enterprisedt.net.ftp.FTPException ignore) { }

         DebugFile.decIdent();
       }
       throw new PortletException("TransformerException " + tex.getMessage(), tex);
      }
  } else {
      try {
        sOutput = new String(oFS.readfile(sFileDir+File.separator+sCachedFile, sEncoding==null ? "ISO8859_1" : sEncoding));
      } catch (Exception xcpt) {
        throw new PortletException(xcpt.getClass().getName()+" "+xcpt.getMessage(), xcpt);
      }
  } // fi (bFetch)
 
View Full Code Here

          int iDeleted = oReader.deleteDocuments(new Term("workarea", sWorkArea));
          oReader.close();
        }
      }
    } else {
      FileSystem oFS = new FileSystem();
      try { oFS.mkdirs(sDirectory); } catch (Exception e) { throw new IOException(e.getClass().getName()+" "+e.getMessage()); }
    }
    // *********************************************************************

    if (DebugFile.trace) DebugFile.writeln("new IndexWriter("+sDirectory+",[Analyzer], true)");

View Full Code Here

    if (null==sDirectory)
      throw new NoSuchFieldException ("Cannot find luceneindex property");

    File oDir = new File(sDirectory);
    if (!oDir.exists()) {
      FileSystem oFS = new FileSystem();
      try { oFS.mkdirs(sDirectory); } catch (Exception e) { throw new IOException(e.getClass().getName()+" "+e.getMessage()); }
    }

    Class oAnalyzer = Class.forName((sAnalyzer==null) ? DEFAULT_ANALYZER : sAnalyzer);

    IndexWriter oIWrt = new IndexWriter(sDirectory, (Analyzer) oAnalyzer.newInstance(), true);
View Full Code Here

      DebugFile.incIdent();
    }

    final int iMaxRecent = 8;

    FileSystem oFS = new FileSystem(FileSystem.OS_PUREJAVA);

    String sOutput;
    String sDomainId = req.getProperty("domain");
    String sWorkAreaId = req.getProperty("workarea");
    String sUserId = req.getProperty("user");
    String sZone = req.getProperty("zone");
    String sLang = req.getProperty("language");
    String sTemplatePath = req.getProperty("template");
    String sStorage = req.getProperty("storage");
    String sFileDir = "file://" + sStorage + "domains" + File.separator + sDomainId + File.separator + "workareas" + File.separator + sWorkAreaId + File.separator + "cache" + File.separator + sUserId;
    String sCachedFile = "recentcontactstab_" + req.getWindowState().toString() + ".xhtm";

    if (DebugFile.trace) {
      DebugFile.writeln ("user=" + sUserId);
      DebugFile.writeln ("template=" + sTemplatePath);
      DebugFile.writeln ("cache dir=" + sFileDir);
      DebugFile.writeln ("modified=" + req.getAttribute("modified"));
      DebugFile.writeln ("encoding=" + sEncoding);
    }

    Date oDtModified = (Date) req.getAttribute("modified");

    if (null!=oDtModified) {

      try {

        File oCached = new File(sFileDir.substring(7)+File.separator+sCachedFile);

        if (!oCached.exists()) {
          oFS.mkdirs(sFileDir);
        }
        else {
          if (DebugFile.trace) {
            DebugFile.writeln ("file modified " + new Date(oCached.lastModified()).toString());
            DebugFile.writeln ("last modified " + new Date(oDtModified.getTime()).toString());
          }
          if (oCached.lastModified()>oDtModified.getTime()) {
            sOutput = new String(FileSystem.readfile(sFileDir+File.separator+sCachedFile, sEncoding==null ? "ISO8859_1" : sEncoding));

            if (DebugFile.trace) {
              DebugFile.writeln("cache hit " + sFileDir+File.separator+sCachedFile);
              DebugFile.decIdent();
              DebugFile.writeln("End RecentContactsTab.render()");
            }

            return sOutput;
          } // fi (oCached.lastModified()>oDtModified.getTime())
        } // fi (!oCached.exists())
      }
      catch (Exception xcpt) {
        DebugFile.writeln(xcpt.getClass().getName() + " " + xcpt.getMessage());
      }
    }

    String sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type=\"text/xsl\"?>";

    int iCalls = 0;

    if (req.getWindowState().equals(WindowState.MINIMIZED)) {
      sXML += "<contacts/>";
    }
    else {

      DBBind oDBB = (DBBind) getPortletContext().getAttribute("GlobalDBBind");

      JDCConnection oCon = null;

      try  {
        oCon = oDBB.getConnection("RecentContactsTab");

        PreparedStatement oStm = oCon.prepareStatement("(SELECT dt_last_visit,gu_company,NULL AS gu_contact,nm_company,'' AS full_name,work_phone,tx_email FROM k_companies_recent WHERE gu_user=? UNION SELECT dt_last_visit,NULL AS gu_company,gu_contact,nm_company,full_name,work_phone,tx_email FROM k_contacts_recent WHERE gu_user=?) ORDER BY dt_last_visit DESC", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        oStm.setString (1, sUserId);
        oStm.setString (2, sUserId);
        ResultSet oRSet = oStm.executeQuery();

        int iRecentCount = 0;
        StringBuffer oXML = new StringBuffer();
        String sStr;

        while (oRSet.next() && iRecentCount<iMaxRecent) {
          oXML.append("<contact>");

          sStr = oRSet.getString(2);
          if (oRSet.wasNull()) oXML.append("<gu_company/>"); else oXML.append("<gu_company>"+oRSet.getString(2)+"</gu_company>");

          sStr = oRSet.getString(3);
          if (oRSet.wasNull()) oXML.append("<gu_contact/>"); else oXML.append("<gu_contact>"+oRSet.getString(3)+"</gu_contact>");

          sStr = oRSet.getString(4);
          if (oRSet.wasNull()) oXML.append("<nm_company/>"); else oXML.append("<nm_company><![CDATA["+oRSet.getString(4)+"]]></nm_company>");

          sStr = oRSet.getString(5);
          if (oRSet.wasNull()) oXML.append("<full_name/>"); else oXML.append("<full_name><![CDATA["+oRSet.getString(5)+"]]></full_name>");

          sStr = oRSet.getString(6);
          if (oRSet.wasNull()) oXML.append("<work_phone/>"); else oXML.append("<work_phone><![CDATA["+oRSet.getString(6)+"]]></work_phone>");

          sStr = oRSet.getString(7);
          if (oRSet.wasNull()) oXML.append("<tx_email/>"); else oXML.append("<tx_email>"+oRSet.getString(7)+"</tx_email>");

          oXML.append("</contact>");

          iRecentCount++;
        } // wend

        oCon.close("RecentContactsTab");
        oCon = null;

        sXML += "<contacts>\n"+oXML.toString()+"</contacts>";
      }
      catch (SQLException e) {
        sXML += "<contacts/>";

        try {
          if (null != oCon)
            if (!oCon.isClosed())
              oCon.close("RecentContactsTab");
        } catch (SQLException ignore) { }
      }
    }

    try {
       if (DebugFile.trace) DebugFile.writeln("new ByteArrayInputStream(" + String.valueOf(sXML.length()) + ")");

       if (sEncoding==null)
         oInStream = new ByteArrayInputStream(sXML.getBytes());
       else
         oInStream = new ByteArrayInputStream(sXML.getBytes(sEncoding));

       oOutStream = new ByteArrayOutputStream(4000);

       Properties oProps = new Properties();

       Enumeration oKeys = req.getPropertyNames();
       while (oKeys.hasMoreElements()) {
         String sKey = (String) oKeys.nextElement();
         oProps.setProperty(sKey, req.getProperty(sKey));
       } // wend

       if (req.getWindowState().equals(WindowState.MINIMIZED))
         oProps.setProperty("windowstate", "MINIMIZED");
       else
         oProps.setProperty("windowstate", "NORMAL");

       StylesheetCache.transform (sTemplatePath, oInStream, oOutStream, oProps);

       if (sEncoding==null)
         sOutput = oOutStream.toString();
       else
         sOutput = oOutStream.toString("UTF-8");

       oOutStream.close();

       oInStream.close();
       oInStream = null;

       oFS.writefilestr (sFileDir+File.separator+sCachedFile, sOutput, sEncoding==null ? "ISO8859_1" : sEncoding);
     }
     catch (TransformerConfigurationException tce) {
       if (DebugFile.trace) {
         DebugFile.writeln("TransformerConfigurationException " + tce.getMessageAndLocation());
         try {
View Full Code Here

 
  String sXmlProlog = "<?xml version=\"1.0\" encoding=\""+getEncoding()+"\"?>\n";
  String sNewsGrpXml = oNewsGrp.toXML(oConn);
  String sMonthsWithPosts = Forums.XMLListMonthsWithPosts(oConn, getGuid(), getLanguage());

  FileSystem oFs = new FileSystem();
  try { oFs.mkdirs("file://"+getOutputPath()+"archives"); } catch (Exception ignore) { }

    Properties oProps = new Properties();
  oProps.put("language", getLanguage());
  oProps.put("basehref", getBaseHref());

    ArrayList<Boolean> aDaysWithPosts = Forums.getDaysWithPosts(oConn, getGuid(), null, null);

  DBSubset oLastModified = new DBSubset(DB.k_newsmsgs+" m,"+DB.k_x_cat_objs+" x",
                      "MAX(m."+DB.dt_modified+")",
                                      "m."+DB.gu_msg+"=x."+DB.gu_object+" AND "+
                                      "x."+DB.gu_category+"=? AND "+
                                      "m."+DB.dt_published+" BETWEEN ? AND ?", 1);
 
  for (NewsGroupJournalPage t : templates) {

      if (DebugFile.trace) {
        DebugFile.writeln("Processing "+t.getFilter()+" template");
      }

    if (t.getFilter().equalsIgnoreCase("main")) {

        dtLastModified =  DBCommand.queryMaxDate(oConn, "m."+DB.dt_modified,
                                             DB.k_newsmsgs+" m,"+DB.k_x_cat_objs+" x",
                                             "m."+DB.gu_msg+"=x."+DB.gu_object+" AND "+
                                             "x."+DB.gu_category+"='"+getGuid()+"'");
    if (null==dtLastModified) dtLastModified = new Date();

        if (DebugFile.trace) {
          DebugFile.writeln("Last modified message date is "+dtLastModified.toString());
        }

      sFilePath = getOutputPath()+"main.html";

      oOut = new File(sFilePath);
      if (oOut.exists()) {
        dtFileModified = new Date(oOut.lastModified());
          if (DebugFile.trace) {
            DebugFile.writeln("Output file path is "+sFilePath+" last modified at "+dtFileModified.toString());
          }
        bNeedsRebuild = (dtLastModified.compareTo(dtFileModified)>0) || (new File(getBlogPath()+t.getInputFilePath()).lastModified()>dtFileModified.getTime());
        if (bNeedsRebuild || bFullRebuild) oOut.delete();
      } else {
          if (DebugFile.trace) {
            DebugFile.writeln("Output file "+sFilePath+" does not exist");
          }
        bNeedsRebuild = true;
      }
     
    if (bNeedsRebuild || bFullRebuild) {
        sMessageList = Forums.XMLListTopLevelMessagesForGroup(oConn, t.getLimit(), 0, getGuid(), DB.dt_published);
        sXMLDataSource = sXmlProlog + "<Journal guid=\""+getGuid()+"\">\n" + sNewsGrpXml + "\n" + sMonthsWithPosts + "\n" + sMessageList + "</Journal>";

      if (DebugFile.trace) {
        oFs.delete(getOutputPath()+"main.xml");
        oFs.writefilestr(getOutputPath()+"main.xml", sXMLDataSource, getEncoding());
      }

        oFs.writefilestr(sFilePath,
                         StylesheetCache.transform(getBlogPath()+t.getInputFilePath(), sXMLDataSource, oProps), getEncoding());
    } // fi (bNeedsRebuild)

      } else if (t.getFilter().equalsIgnoreCase("rss2")) {

        dtLastModified =  DBCommand.queryMaxDate(oConn, "m."+DB.dt_modified,
                                             DB.k_newsmsgs+" m,"+DB.k_x_cat_objs+" x",
                                             "m."+DB.gu_msg+"=x."+DB.gu_object+" AND "+
                                             "x."+DB.gu_category+"='"+getGuid()+"' AND "+
                                             "m."+DB.gu_parent_msg+" IS NULL");
    if (null==dtLastModified) dtLastModified = new Date();

        if (DebugFile.trace) {
          DebugFile.writeln("Last modified message date is "+dtLastModified.toString());
        }

      sFilePath = getOutputPath()+"rss2.xml";

      oOut = new File(sFilePath);
      if (oOut.exists()) {
        dtFileModified = new Date(oOut.lastModified());
          if (DebugFile.trace) {
            DebugFile.writeln("Output file path is "+sFilePath+" last modified at "+dtFileModified.toString());
          }
        bNeedsRebuild = (dtLastModified.compareTo(dtFileModified)>0) || (new File(getBlogPath()+t.getInputFilePath()).lastModified()>dtFileModified.getTime());
        if (bNeedsRebuild || bFullRebuild) oOut.delete();
      } else {
          if (DebugFile.trace) {
            DebugFile.writeln("Output file "+sFilePath+" does not exist");
          }
        bNeedsRebuild = true;
      }
     
    if (bNeedsRebuild || bFullRebuild) {
     
        sMessageList = Forums.XMLListTopLevelMessagesForGroup(oConn, t.getLimit(), 0, getGuid(), DB.dt_published, "yyyy-MM-dd'T'hh:mm:ss");
        try {
          sMessageList = Gadgets.replace(sMessageList,"<((IMG)|img) +((SRC)|(src))=\"/", "<img src=\""+getBaseHref()+"/");
        } catch (org.apache.oro.text.regex.MalformedPatternException neverthrown) { }
        sXMLDataSource = sXmlProlog + "<Journal guid=\""+getGuid()+"\">\n" + sNewsGrpXml + "\n" + sMessageList + "</Journal>";

        oFs.writefilestr(sFilePath,
                         StylesheetCache.transform(getBlogPath()+t.getInputFilePath(), sXMLDataSource, oProps), getEncoding());
      if (DebugFile.trace) {
          oFs.writefilestr(sFilePath+".source.xml", sXMLDataSource, getEncoding());
      }
    } // fi (bNeedsRebuild)

    } else if (t.getFilter().equalsIgnoreCase("monthly")) {

      ArrayList<Month> aMonthsWithPosts = Forums.getMonthsWithPosts(oConn, getGuid());

      for (Month m : aMonthsWithPosts) {

      oProps.put("year", String.valueOf(m.getYear()));
      oProps.put("month", String.valueOf(m.getMonth()));

        if (oLastModified.load(oConn, new Object[]{getGuid(), new Timestamp(m.firstDay().getTime()), new Timestamp(m.lastDay().getTime())})>0) {
          if (oLastModified.isNull(0,0))
            dtLastModified = new Date();
          else
            dtLastModified = oLastModified.getDate(0,0);
        } else {
          dtLastModified = new Date();
        }
     
            if (DebugFile.trace) {
              DebugFile.writeln("Last modified message date is "+dtLastModified.toString());
            }

          sFilePath = getOutputPath()+"archives"+File.separator+m.toString()+".html";
          oOut = new File(sFilePath);
          if (oOut.exists()) {
            dtFileModified = new Date(oOut.lastModified());
              if (DebugFile.trace) {
                DebugFile.writeln("Output file path is "+sFilePath+" last modified at "+dtFileModified.toString());
              }
            bNeedsRebuild = (dtLastModified.compareTo(dtFileModified)>0);
            if (bNeedsRebuild || bFullRebuild) oOut.delete();
          } else {
              if (DebugFile.trace) {
                DebugFile.writeln("Output file "+sFilePath+" does not exist");
              }
            bNeedsRebuild = true;
          }
     
        if (bNeedsRebuild || bFullRebuild) {
        sMessageList = Forums.XMLListTopLevelMessagesForGroup(oConn, m.firstDay(), m.lastDay(), getGuid(), DB.dt_published);
            sXMLDataSource = sXmlProlog + "<Journal guid=\""+getGuid()+"\">\n" + sNewsGrpXml + "\n" + sMonthsWithPosts + "\n" + sMessageList + "</Journal>";

          if (DebugFile.trace) {
            oFs.delete(Gadgets.dechomp(sFilePath,"html")+"xml");
            oFs.writefilestr(Gadgets.dechomp(sFilePath,"html")+"xml", sXMLDataSource, getEncoding());
          }

            oFs.writefilestr(sFilePath,
                             StylesheetCache.transform(getBlogPath()+t.getInputFilePath(), sXMLDataSource, oProps), getEncoding());
        } // fi
       
      } // next     
      } else if (t.getFilter().equalsIgnoreCase("daily")) {

        Date dt1stPost = DBCommand.queryMinDate(oConn, "m."+DB.dt_published,
                                              DB.k_newsmsgs+" m,"+DB.k_x_cat_objs+" x",
                                              "m."+DB.gu_msg+"=x."+DB.gu_object+" AND "+
                                              "x."+DB.gu_category+"='"+getGuid()+"' AND "+
                                              "m."+DB.id_status+"="+String.valueOf(NewsMessage.STATUS_VALIDATED));
      if (dt1stPost!=null) {

          Date dtDay00 = new Date(dt1stPost.getYear(), dt1stPost.getMonth(), dt1stPost.getDate()000);
          Date dtDay23 = new Date(dt1stPost.getYear(), dt1stPost.getMonth(), dt1stPost.getDate(), 23, 59, 59);

        for (Boolean b : aDaysWithPosts) {
       
          if (b.booleanValue()) {

          oProps.put("year", String.valueOf(dtDay00.getYear()));
          oProps.put("month", String.valueOf(dtDay00.getMonth()));

            if (oLastModified.load(oConn, new Object[]{getGuid(), new Timestamp(dtDay00.getTime()), new Timestamp(dtDay23.getTime())})>0) {
              if (oLastModified.isNull(0,0))
                dtLastModified = new Date();
              else
                dtLastModified = oLastModified.getDate(0,0);
            } else {
              dtLastModified = new Date();
            }

                if (DebugFile.trace) {
                  DebugFile.writeln("Last modified message date is "+dtLastModified.toString());
                }

              sFilePath = getOutputPath()+"archives"+File.separator+oFmt.format(dtDay00)+".html";
              oOut = new File(sFilePath);
              if (oOut.exists()) {
                dtFileModified = new Date(oOut.lastModified());
                  if (DebugFile.trace) {
                    DebugFile.writeln("Output file path is "+sFilePath+" last modified at "+dtFileModified.toString());
                  }
                bNeedsRebuild = (dtLastModified.compareTo(dtFileModified)>0);
                if (bNeedsRebuild || bFullRebuild) oOut.delete();
              } else {
                  if (DebugFile.trace) {
                    DebugFile.writeln("Output file "+sFilePath+" does not exist");
                  }
                bNeedsRebuild = true;
              }

            if (bNeedsRebuild || bFullRebuild) {
            sMessageList = Forums.XMLListTopLevelMessagesForGroup(oConn, dtDay00, dtDay23, getGuid(), DB.dt_published);
                sXMLDataSource = sXmlProlog + "<Journal guid=\""+getGuid()+"\">\n" + sNewsGrpXml + "\n" + sMonthsWithPosts + "\n" + sMessageList + "</Journal>";
                oFs.writefilestr(sFilePath,
                                 StylesheetCache.transform(getBlogPath()+t.getInputFilePath(), sXMLDataSource, oProps), getEncoding());
            } // fi

          } // fi (DaysWithPosts)
        dtDay00 = new Date(dtDay00.getTime()+86400000l);
        dtDay23 = new Date(dtDay23.getTime()+86400000l);
        } // next
      } else {
            if (DebugFile.trace)
              DebugFile.writeln("No date for first post found rebuilding daily template");
      } // fi

      } else if (t.getFilter().equalsIgnoreCase("single")) {

        DBSubset  oPostsModified = new DBSubset (
            DB.k_newsmsgs + " m," + DB.k_x_cat_objs + " x," + DB.k_newsgroups + " g," + DB.k_categories + " c",
            "MAX(m." + DB.dt_modified + "),m."+DB.gu_thread_msg,
            "m." + DB.id_status + "="+String.valueOf(NewsMessage.STATUS_VALIDATED)+" AND x." + DB.gu_category + "=" + "g." + DB.gu_newsgrp + " AND " +
            "c." + DB.gu_category + "=g." + DB.gu_newsgrp + " AND " +
            "m." + DB.gu_msg + "=x." + DB.gu_object + " AND g." + DB.gu_newsgrp + "=? GROUP BY m."+DB.gu_thread_msg, 100);
      int nPosts = oPostsModified.load(oConn, new Object[]{getGuid()});

      for (int p=0; p<nPosts; p++) {
        dtLastModified = oPostsModified.getDate(0,0);
        if (null==dtLastModified) dtLastModified = new Date();

            if (DebugFile.trace) {
              DebugFile.writeln("Last modified message date is "+dtLastModified.toString());
            }
       
          sFilePath = getOutputPath()+"archives"+File.separator+oPostsModified.getString(1,p)+".html";
          oOut = new File(sFilePath);
          if (oOut.exists()) {
            dtFileModified = new Date(oOut.lastModified());
              if (DebugFile.trace) {
                DebugFile.writeln("Output file path is "+sFilePath+" last modified at "+dtFileModified.toString());
              }
            bNeedsRebuild = (dtLastModified.compareTo(dtFileModified)>0);
            if (bNeedsRebuild || bFullRebuild) oOut.delete();
          } else {
              if (DebugFile.trace) {
                DebugFile.writeln("Output file "+sFilePath+" does not exist");
              }
            bNeedsRebuild = true;
          }

        if (bNeedsRebuild || bFullRebuild) {

        sMessageList = Forums.XMLListMessagesForThread(oConn, oPostsModified.getString(1,p));
            sXMLDataSource = sXmlProlog + "<Journal guid=\""+getGuid()+"\">\n" + sNewsGrpXml + "\n" + sMonthsWithPosts + "\n" + sMessageList + "</Journal>";
            oFs.writefilestr(sFilePath,
                             StylesheetCache.transform(getBlogPath()+t.getInputFilePath(), sXMLDataSource, oProps), getEncoding());
          if (DebugFile.trace) {
            oFs.writefilestr(Gadgets.dechomp(sFilePath,"html")+"xml", sXMLDataSource, getEncoding());
          }
        } // fi
       
      } //next

      } else if (t.getFilter().equalsIgnoreCase("bytag")) {

          DBSubset oTags = Forums.getNewsGroupTags(oConn, getGuid());
          int nTags = oTags.getRowCount();

          for (int g=0; g<nTags; g++) {
           
            if (DebugFile.trace) {
                DebugFile.writeln("Rebuilding archive for tag "+oTags.getString(3,g));
            }

          oProps.put("tag", oTags.getString(4,g));

          sFilePath = getOutputPath()+"archives"+File.separator+oTags.getString(4,g)+".html";
          oOut = new File(sFilePath);
          if (oOut.exists()) {
            dtFileModified = new Date(oOut.lastModified());
              if (DebugFile.trace) {
                DebugFile.writeln("Output file path is "+sFilePath+" last modified at "+dtFileModified.toString());
              }
            oOut.delete();
          } else {
              if (DebugFile.trace) {
                DebugFile.writeln("Output file "+sFilePath+" does not exist");
              }
          }

      sMessageList = Forums.XMLListTopLevelMessagesForTag(oConn, 32767, 0, getGuid(), oTags.getString(0,g), DB.dt_published);
          sXMLDataSource = sXmlProlog + "<Journal guid=\""+getGuid()+"\">\n" + sNewsGrpXml + "\n" + sMonthsWithPosts + "\n" + sMessageList + "</Journal>";
          oFs.writefilestr(sFilePath,
                           StylesheetCache.transform(getBlogPath()+t.getInputFilePath(), sXMLDataSource, oProps), getEncoding());

        if (DebugFile.trace) {
          oFs.delete(Gadgets.dechomp(sFilePath,"html")+"xml");
          oFs.writefilestr(Gadgets.dechomp(sFilePath,"html")+"xml", sXMLDataSource, getEncoding());
        }
      } //next     
       } // fi     

    } // next (template)
View Full Code Here

  public EmailSender() {
    bHasReplacements = true;
    oFileStr = null;
    oHTMLStr = null;
    oFS = new FileSystem();
    oReplacer = new FastStreamReplacer();
    oDocumentImages = new HashMap<String,String>();
    oMailSession = null;
    oMailTransport = null;
  }
View Full Code Here

  private FileSystem oFileSys;

  public FTPPublisher() {
    oReplacer = new FastStreamReplacer();
    oFileSys = new FileSystem();
  }
View Full Code Here

      String sLinkCSS = oMatcher.getMatch().group(0);
    if (DebugFile.trace) DebugFile.writeln("Matched a CSS <link> regular expression "+sLinkCSS);
      String sLinkHref = oMatcher.getMatch().group(1);
      if (!oLinksSrc.containsKey(sLinkHref)) {
        try {
          FileSystem oFls = new FileSystem();
          String sLinkSrc = oFls.readfilestr(sLinkHref,"ISO8859_1");
          if (null!=sLinkSrc) {
            oLinksSrc.put(sLinkHref,"<style type=\"text/css\">\n"+sLinkSrc+"\n</style>\n");
            if (sLinkSrc.length()>0) {
              sInlinedBody = Util.substitute(oMatcher, oLinkCSS, new Perl5Substitution(oLinksSrc.get(sLinkHref), Perl5Substitution.INTERPOLATE_ALL), sSBody, Util.SUBSTITUTE_ALL);
            } else {
View Full Code Here

  * @throws SQLException
  **/
public static void main(String[] args) throws IOException,SQLException {
   int nSent = 0;
   int nErrs = 0;
   FileSystem oFs = new FileSystem();
   DBBind oDbb = null;
   JDCConnection oCon = null;
   PreparedStatement oStm = null;
   ResultSet oRst = null;
   MimeSender oSnd = null;
   SessionHandler oHnl = null;
   DBStore  oSto = null;
   DBFolder oFld = null;
   DBSubset oLists = new DBSubset(DB.k_lists,DB.gu_list,DB.gu_list+"=? OR "+DB.de_list+"=?",1);
   DBSubset oMaccs = new DBSubset(DB.k_user_mail,DB.gu_account,DB.gu_account+"=? OR "+DB.tl_account+"=?",1);
     
   if (args==null) {
     System.out.println("Mail batch descriptor is required");
   } else if (args.length==0) {
     System.out.println("Mail batch descriptor is required")
   } else {
      try {
        System.out.println("Connecting to database...");
        oDbb = new DBBind(args[0]);
        System.out.println("Database connection was successfull");
        if (oDbb.getProperty("storage")==null) {
         System.out.println("storage property is required but not found at "+args[0]+".cnf file");
         nErrs++;       
        } else {

        if (oDbb.getProperty("mail.list")==null) {
         System.out.println("mail.list property is required but not found at "+args[0]+".cnf file");  
         nErrs++;       
        } else {
           String sMailingDir = Gadgets.chomp(oDbb.getProperty("storage"), File.separator)+"mailing"+File.separator+oDbb.getProperty("mail.list");
     String sBody = null;
     String sType = null;
     String sBodyFile = sMailingDir+File.separator+"body.htm";
    
     if (new File(sMailingDir+File.separator+"body.htm").exists()) {
           System.out.println("Trying to read file "+sMailingDir+File.separator+"body.htm");
       sBody = oFs.readfilestr("file://"+sMailingDir+File.separator+"body.htm","UTF-8");
       sType = "html";      
     } else if (new File("file://"+sMailingDir+File.separator+"body.txt").exists()) {
           System.out.println("Trying to read file "+sMailingDir+File.separator+"body.txt");
       sBody = oFs.readfilestr("file://"+sMailingDir+File.separator+"body.txt","UTF-8");
       sType = "plain";      
     }
     if (null==sBody) {
           System.out.println("Could not find body.htm nor body.txt files at directory "+sMailingDir);
           nErrs++;
View Full Code Here

TOP

Related Classes of com.knowgate.dfs.FileSystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.