Package com.knowgate.dfs

Examples of com.knowgate.dfs.FileSystem


   * @param oConn Database Connection
   * @throws SQLException
   */
  public boolean delete(JDCConnection oConn) throws SQLException {
    boolean bRetVal;
    FileSystem oFS = new FileSystem();

    if (DebugFile.trace) {
      DebugFile.writeln("Begin ProductLocation.delete(" + getString(DB.gu_location) + ")" );
      DebugFile.incIdent();
    }

    try {
      if (getInt(DB.id_cont_type)==ProductLocation.CONTAINER_FILE || getInt(DB.id_cont_type)==ProductLocation.CONTAINER_FTP) {

        oFS.delete(getURL());
      } // fi(CONTAINER_*)
    }
    catch (IOException ioe) {
      if (ioe.getMessage().indexOf("No such file or directory")<0)
        throw new SQLException(ioe.getMessage());
View Full Code Here


      DebugFile.writeln(")");
    } // fi (trace)
    // ***************************************************
    // Load file with properties about the mail to be sent
    FileSystem oFS = new FileSystem();
    FileInputStream oInStrm = new FileInputStream(oPropsFile);
    Properties oProps = new Properties();
    oProps.load(oInStrm);
   
    System.out.println("Running job "+oProps.getProperty("job"));

    // *************************************************************************
    // Recipients list must be an ASCII encoded file with one recipient per line
   
    String sRecipientsFile = oProps.getProperty("recipients");

    if (null==sRecipientsFile) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new NullPointerException("Recipients file path is required");
    } else {
      if (DebugFile.trace) DebugFile.writeln("recipients="+sRecipientsFile);
    }

    String sRecipientsList = oFS.readfilestr(sRecipientsFile, "ASCII");
    if (sRecipientsList.length()==0) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new NullPointerException("Recipients file is empty");
    }

    // ***********************************
    // Load Black List into a sorted array

    String[] aBlackList = null;
    String sBlackListFile = oProps.getProperty("blacklist");
    if (null!=sRecipientsFile) {
      if (sRecipientsFile.trim().length()>0) {
        String sBlackList = oFS.readfilestr(sBlackListFile, "ASCII");
        if (sBlackList.length()>0) {
          aBlackList = Gadgets.split(sBlackList, "\n");
          final int nBlackList = aBlackList.length;
          for (int b=0; b<nBlackList; b++) {
            aBlackList[b] = aBlackList[b].toLowerCase();
          } // next
          Arrays.sort(aBlackList, String.CASE_INSENSITIVE_ORDER);
        }
      } // fi
    } // fi
   
    String aRecipients[] = Gadgets.split(sRecipientsList, "\n");

      System.out.println("total recipients count is "+String.valueOf(aRecipients.length));
    if (DebugFile.trace) DebugFile.writeln("total recipients count is "+String.valueOf(aRecipients.length));

    AdHocMailing oAdHoc = new AdHocMailing();
    if (oProps.getProperty("allow")!=null) oAdHoc.setAllowPattern(oProps.getProperty("allow"));
    if (oProps.getProperty("deny")!=null) oAdHoc.setDenyPattern(oProps.getProperty("deny"));
    oAdHoc.addBlackList (aBlackList );
    oAdHoc.addRecipients(aRecipients);
    aRecipients = oAdHoc.getRecipients();

    System.out.println("unique and allowed recipients count is"+String.valueOf(aRecipients.length));
    if (DebugFile.trace) DebugFile.writeln("unique and allowed recipients count is"+String.valueOf(aRecipients.length));
   
    // ******************
    // Get Mail enconding
   
    String sEncoding = oProps.getProperty("encoding","UTF-8");
   
    // ******************************************************
    // Get base directory where mail source files are located
   
    String sUserDir = oProps.getProperty("userdir",System.getProperty("user.dir"));
   
    // ********************
    // Get mail source HTML
   
    String sTextHtml = null;
    String sHtmlFilePath = oProps.getProperty("texthtml","");
    if (sHtmlFilePath.length()>0) {
      if (!sHtmlFilePath.startsWith(sUserDir)) sHtmlFilePath = sUserDir+sHtmlFilePath;
        sTextHtml = oFS.readfilestr(sHtmlFilePath, sEncoding);
    }

    // **************************
    // Get mail source plain text

    String sTextPlain = null;
    String sTextFilePath = oProps.getProperty("textplain","");
    if (sTextFilePath.length()>0) {
      if (!sTextFilePath.startsWith(sUserDir)) sTextFilePath = sUserDir+sTextFilePath;
    sTextPlain = oFS.readfilestr(sTextFilePath, sEncoding);
    }
       
    // Get mail subject
    String sSubject = oProps.getProperty("subject", "");

View Full Code Here

      DebugFile.incIdent();
    }

    final int iMaxRecent = 10;

    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 sNewsGrp = req.getProperty("newsgrp");
    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 = "recentpoststab_" + req.getWindowState().toString() + ".xhtm";

    // New for v4.0
    String sOrderBy = req.getProperty("orderby");
    if (null==sOrderBy) sOrderBy = DB.dt_published;
    if (sOrderBy.length()==0) sOrderBy = DB.dt_published;

    if (DebugFile.trace) {
      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 (oCached.lastModified()>oDtModified.getTime()) {
          sOutput = new String(oFS.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 RecentPosts.render()");
          }

          return sOutput;
        }
      }
      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 iPosts = 0;

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

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

      JDCConnection oCon = null;

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

        NewsGroup oGrp = new NewsGroup(sNewsGrp);
        DBSubset  oPosts = oGrp.getTopLevelMessages(oCon, iMaxRecent, sOrderBy);
        iPosts = oPosts.getRowCount();

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

        Date dtPub;
        int iDtPubColPos = oPosts.getColumnPosition(DB.dt_published);
        for (int p=0; p<iPosts; p++) {
          dtPub = oPosts.getDate(iDtPubColPos,p);
          oPosts.setElementAt(Gadgets.leftPad(String.valueOf(dtPub.getMonth()+1),'0',2)+"-"+Gadgets.leftPad(String.valueOf(dtPub.getDate()),'0',2)+" "+Gadgets.leftPad(String.valueOf(dtPub.getHours()),'0',2)+":"+Gadgets.leftPad(String.valueOf(dtPub.getMinutes()),'0',2), 5,p);
        }

        sXML += "<posts>\n"+oPosts.toXML("","newsmsg")+"</posts>";
      }
      catch (SQLException e) {
        sXML += "<posts/>";

        try {
          if (null != oCon)
            if (!oCon.isClosed())
              oCon.close("PostsForGroup");
        } 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

      DebugFile.incIdent();
    }

    if (null==oFS) {
      if (DebugFile.trace) DebugFile.writeln("new com.knowgate.dfs.FileSystem()");
      oFS = new FileSystem();
    }

    // Crea la ruta base quitando el file:// de por delante
    sBasePath = sSourcePath.substring(sSourcePath.indexOf("://")+3);
View Full Code Here

        if (id_disposition.equals("reference")) {
          if (DebugFile.trace) DebugFile.writeln("content disposition is reference");
          sFilePath = oRSet.getString(4);

          FileSystem oFS = new FileSystem();
          byte[] byData = oFS.readfilebin(sFilePath);
          String sContentType = oRSet.getString(7);
          if (DebugFile.trace) DebugFile.writeln("new ByteArrayDataSource("+sFilePath+", "+sContentType+")");
          ByteArrayDataSource baDataSrc = new ByteArrayDataSource(byData, sContentType);

          oMimeBody = new MimeBodyPart();
View Full Code Here

    if (DebugFile.trace) {
      DebugFile.writeln("Begin CalendarTab.render()");
      DebugFile.incIdent();
    }

    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 sTemplatePath = req.getProperty("template");
    String sStorage = req.getProperty("storage");
    String sZone = req.getProperty("zone");
    String sMaxRows = req.getProperty("maxrows");
    if (null==sMaxRows) sMaxRows = "10";
    String sFileDir = "file://" + sStorage + "domains" + File.separator + sDomainId + File.separator + "workareas" + File.separator + sWorkAreaId + File.separator + "cache" + File.separator + sUserId;
    String sCachedFile = "calendartab_" + sZone + "_" + 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 {
      if (DebugFile.trace) DebugFile.writeln ("new File("+sFileDir.substring(7)+File.separator+sCachedFile+")");
       
        File oCached = new File(sFileDir.substring(7)+File.separator+sCachedFile);

        if (!oCached.exists()) {
          oFS.mkdirs(sFileDir);
        }
        else 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 CalendarTab.render()");
          }

          return sOutput;
        }
      }
      catch (Exception xcpt) {
        DebugFile.writeln(xcpt.getClass().getName() + " " + xcpt.getMessage());
      }
    }

    String sXML;

    int iToDo = 0, iMeetings = 0;

    if (req.getWindowState().equals(WindowState.MINIMIZED)) {
      if (DebugFile.trace) DebugFile.writeln ("WindowState.MINIMIZED");
      sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type=\"text/xsl\"?><calendar><todo/><today/></calendar>";
    }
    else {
      if (DebugFile.trace) DebugFile.writeln ("WindowState.NORMAL");

      String sTodayXML, sToDoXML;

      Date dt00 = new Date();
      Date dt23 = new Date();

      dt00.setHours(0);
      dt00.setMinutes(0);
      dt00.setSeconds(0);

      dt23.setHours(23);
      dt23.setMinutes(59);
      dt23.setSeconds(59);

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

      DBSubset oToDo = new DBSubset (DB.k_to_do, DB.gu_to_do + "," + DB.od_priority + "," + DB.tl_to_do,
                                     DB.gu_user + "=? AND (" + DB.tx_status + "='PENDING' OR " + DB.tx_status + " IS NULL) ORDER BY 2 DESC", 10);

      DBSubset oMeetings = new DBSubset (DB.k_meetings + " m," + DB.k_x_meeting_fellow + " f",
                                         "m." + DB.gu_meeting + ",m." + DB.gu_fellow + ",m." + DB.tp_meeting + ",m." + DB.tx_meeting + ", m." + DB.dt_start + ",m." + DB.dt_end,
                                         "m." + DB.gu_meeting + "=f." + DB.gu_meeting + " AND f." + DB.gu_fellow + "=? AND m." + DB.dt_start + " BETWEEN ? AND ? ORDER BY m." + DB.dt_start, 10);

      JDCConnection oCon = null;

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

        oToDo.setMaxRows(Integer.parseInt(sMaxRows));
        iToDo = oToDo.load (oCon, new Object[]{sUserId});

        for (int a=0; a<iToDo; a++) {
          if (oToDo.getStringNull(2, a,"").length()>40)
            oToDo.setElementAt(oToDo.getString(2, a).substring(0, 40) +"...", 2,a);
        }

        sToDoXML = oToDo.toXML("", "activity");

        iMeetings = oMeetings.load(oCon, new Object[]{sUserId, new Timestamp(dt00.getTime()), new Timestamp(dt23.getTime())});

        for (int m=0; m<iMeetings; m++) {

          if (oMeetings.isNull(3,m)) oMeetings.setElementAt("untitled", 3,m);

          Date oFrom = oMeetings.getDate(4,m);
          oMeetings.setElementAt(String.valueOf(oFrom.getHours())+":"+Gadgets.leftPad(String.valueOf(oFrom.getMinutes()),'0',2), 4, m);

          Date oTo = oMeetings.getDate(5,m);
          oMeetings.setElementAt(String.valueOf(oTo.getHours())+":"+Gadgets.leftPad(String.valueOf(oTo.getMinutes()),'0',2), 5, m);
        }

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

        sTodayXML = oMeetings.toXML("","meeting");
      }
      catch (SQLException e) {
        sToDoXML = "<todo></todo>";
        sTodayXML = "<today></today>";

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

      sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/xsl\"?>\n<calendar>\n";
      if (iToDo>0)
        sXML += "<todo>\n"+sToDoXML+"</todo>\n";
      else
        sXML += "<todo/>\n";

      if (iMeetings>0)
        sXML += "<today>\n"+sTodayXML+"</today>\n</calendar>";
      else
        sXML += "<today/>\n</calendar>";
     }

     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();
         if (null!=req.getProperty(sKey)) {
           if (DebugFile.trace) DebugFile.writeln("setProperty("+sKey+","+req.getProperty(sKey)+")");
           oProps.setProperty(sKey, req.getProperty(sKey));
         }
       } // wend

     if (req.getWindowState()==null)
         oProps.setProperty("windowstate", "NORMAL");
       else 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 sOutput;
    ByteArrayInputStream oInStream;
    ByteArrayOutputStream oOutStream;

    FileSystem oFS = new FileSystem(FileSystem.OS_PUREJAVA);

  // ****************************************************************************
  // These are the properties passed to this portlet from desktop.jsp page

    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 sStorage    = req.getProperty("storage");
    String sTemplatePath  = req.getProperty("template");
    String sCacheFilesDir = sStorage+"domains"+File.separator+
                          sDomainId+File.separator+"workareas"+File.separator+
                          sWorkAreaId+File.separator+"cache"+File.separator+sUserId;
    String sCachedFile = getClass().getName() + "." + req.getWindowState().toString() + ".xhtm";

    // No more properties
  // ****************************************************************************

  // ****************************************************************************
  // Portlets are cached for reducing database accesses and improving performance

    Date oDtModified = (Date) req.getAttribute("modified");
 
    if (null!=oDtModified) {
      try {

        File oCached = new File(sCacheFilesDir+File.separator+sCachedFile);

        if (!oCached.exists())
          oFS.mkdirs(sCacheFilesDir);
        else if (oCached.lastModified()>oDtModified.getTime())
          return oFS.readfilestr("file://"+sCacheFilesDir+File.separator+sCachedFile,
                                 sEncoding==null ? "ISO8859_1" : sEncoding);
      } catch (Exception xcpt) {
        System.err.println(xcpt.getClass().getName() + " " + xcpt.getMessage());
      }
    } // fi (oDtModified)

  // ****************************************************************************

    String sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type=\"text/xsl\"?>";
 
    if (req.getWindowState().equals(WindowState.MINIMIZED)) {
     
      // If portlet state is minimized then there is no need to do any database access
     
      sXML += "<FullName/>";
    }
    else {

      // Get database connection from desktop.jsp page

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

      JDCConnection oCon = null;

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

      String sFullName = DBCommand.queryStr(oCon, "SELECT "+DB.nm_user+",' ',"+DB.tx_surname1+" FROM "+DB.k_users+" WHERE '"+DB.gu_user+"='"+sUserId+"'");

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

        sXML += "<FullName>"+sFullName+"</FullName>";
      }
      catch (SQLException e) {
        sXML += "<FullName/>";

        try {
          if (null != oCon)
            if (!oCon.isClosed())
              oCon.close("HelloWorld");
        } catch (SQLException ignore) { }
      }
    } // fi (WindowState)

    try {

     // ******************************************
     // Set input parameters for XSL StyleSheet
    
       Properties oProps = new Properties();
       Enumeration oKeys = req.getPropertyNames();
       while (oKeys.hasMoreElements()) {
         String sKey = (String) oKeys.nextElement();
         oProps.setProperty(sKey, req.getProperty(sKey));
       } // wend

       oProps.setProperty("windowstate",
                          req.getWindowState().equals(WindowState.MINIMIZED) ?
                          "MINIMIZED" : "NORMAL");

     // ******************************************

     // ******************************************
     // Perform XSLT Transformation for generating
     // portlet XHTML code fragment.

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

       oOutStream = new ByteArrayOutputStream(4000);

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

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

       oOutStream.close();

       oInStream.close();
       oInStream = null;

     // **************************************
     // Cache generated XHTML code into a file

       oFS.writefilestr ("file://"+sCacheFilesDir+File.separator+sCachedFile, sOutput,
                         sEncoding==null ? "ISO8859_1" : sEncoding);
     }
     catch (Exception xcpt) {
       throw new PortletException(xcpt.getClass().getName() + " " + xcpt.getMessage(), xcpt);
     }
View Full Code Here

    String sOutput;
    ByteArrayInputStream oInStream;
    ByteArrayOutputStream oOutStream;

    FileSystem oFS = new FileSystem(FileSystem.OS_PUREJAVA);

  // ****************************************************************************
  // These are the properties passed to this portlet from desktop.jsp page

    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 sStorage    = req.getProperty("storage");
    String sTemplatePath  = req.getProperty("template");
    String sCacheFilesDir = sStorage+"domains"+File.separator+
                          sDomainId+File.separator+"workareas"+File.separator+
                          sWorkAreaId+File.separator+"cache"+File.separator+sUserId;
    String sCachedFile = getClass().getName() + "." + req.getWindowState().toString() + ".xhtm";

    // No more properties
  // ****************************************************************************

  // ****************************************************************************
  // Portlets are cached for reducing database accesses and improving performance

    Date oDtModified = (Date) req.getAttribute("modified");
 
    if (null!=oDtModified) {
      try {

        File oCached = new File(sCacheFilesDir+File.separator+sCachedFile);

        if (!oCached.exists())
          oFS.mkdirs(sCacheFilesDir);
        else if (oCached.lastModified()>oDtModified.getTime())
          return oFS.readfilestr("file://"+sCacheFilesDir+File.separator+sCachedFile,
                                 sEncoding==null ? "ISO8859_1" : sEncoding);
      } catch (Exception xcpt) {
        System.err.println(xcpt.getClass().getName() + " " + xcpt.getMessage());
      }
    } // fi (oDtModified)

  // ****************************************************************************

    String sXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type=\"text/xsl\"?>";
 
    if (req.getWindowState().equals(WindowState.MINIMIZED)) {
     
      // If portlet state is minimized then there is no need to do any database access
     
      sXML += "<Nodes/>";
    }
    else {

      // Get database connection from desktop.jsp page

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

      JDCConnection oCon = null;

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

    // *** Place database access code here

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

        sXML += "<Nodes></Nodes>";
      }
      catch (SQLException e) {
        sXML += "<Nodes/>";

        try {
          if (null != oCon)
            if (!oCon.isClosed())
              oCon.close("Invoicing");
        } catch (SQLException ignore) { }
      }
    } // fi (WindowState)

    try {

     // ******************************************
     // Set input parameters for XSL StyleSheet
    
       Properties oProps = new Properties();
       Enumeration oKeys = req.getPropertyNames();
       while (oKeys.hasMoreElements()) {
         String sKey = (String) oKeys.nextElement();
         oProps.setProperty(sKey, req.getProperty(sKey));
       } // wend

       oProps.setProperty("windowstate",
                          req.getWindowState().equals(WindowState.MINIMIZED) ?
                          "MINIMIZED" : "NORMAL");

     // ******************************************

     // ******************************************
     // Perform XSLT Transformation for generating
     // portlet XHTML code fragment.

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

       oOutStream = new ByteArrayOutputStream(4000);

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

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

       oOutStream.close();

       oInStream.close();
       oInStream = null;

     // **************************************
     // Cache generated XHTML code into a file

       oFS.writefilestr ("file://"+sCacheFilesDir+File.separator+sCachedFile, sOutput,
                         sEncoding==null ? "ISO8859_1" : sEncoding);
     }
     catch (Exception xcpt) {
       sOutput = "";
       String sTrace = "";
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 = "oportunitiestab_" + 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 (oCached.lastModified()>oDtModified.getTime()) {
          sOutput = new String(oFS.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 OportunitiesTab.render()");
          }

          return sOutput;
        }
      }
      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 += "<oportunities/>";
    }
    else {

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

      JDCConnection oCon = null;
      PreparedStatement oStm = null;
      String sSQL, sInterval;

      try  {
        int iOprtnCount = 0;
        StringBuffer oXML = new StringBuffer();
        String[][] aOprtns = new String[6][iMaxRecent];

        oCon = oDBB.getConnection("OportunitiesTab");

        if (oCon.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL)
          sInterval = "interval '10 years'";
        else
          sInterval = "3650";

        sSQL = "SELECT "+
               DB.gu_oportunity+","+DB.tl_oportunity+","+DB.gu_company+","+DB.gu_contact+","+DB.tx_company+","+DB.tx_contact+","+DB.dt_modified+","+DB.dt_next_action+","+
               DBBind.Functions.GETDATE+"-"+DB.dt_modified+ " AS nu_elapsed FROM "+DB.k_oportunities+" WHERE "+DB.id_status+" NOT IN ('PERDIDA','GANADA','ABANDONADA') AND "+
               DB.dt_modified+" IS NOT NULL AND " + DB.gu_workarea+"=? AND "+DB.gu_writer+"=? UNION SELECT "+
               DB.gu_oportunity+","+DB.tl_oportunity+","+DB.gu_company+","+DB.gu_contact+","+DB.tx_company+","+DB.tx_contact+","+DB.dt_modified+","+DB.dt_next_action+","+
               DBBind.Functions.ISNULL+"("+DB.dt_next_action+","+DBBind.Functions.GETDATE+"+" + sInterval + ")-"+DBBind.Functions.GETDATE+" AS nu_elapsed "+
               "FROM "+DB.k_oportunities+" WHERE "+DB.id_status+" NOT IN ('PERDIDA','GANADA','ABANDONADA') AND "+
               DB.gu_workarea+"=? AND "+DB.gu_writer+"=?";

        if (oCon.getDataBaseProduct()!=JDCConnection.DBMS_MYSQL) {
          sSQL = "(" + sSQL + ")";
        }
        sSQL += " ORDER BY "+DB.nu_elapsed;

        if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+")");

        oStm = oCon.prepareStatement(sSQL,ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

        oStm.setString (1,sWorkAreaId);
        oStm.setString (2,sUserId);
        oStm.setString (3,sWorkAreaId);
        oStm.setString (4,sUserId);

        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeQuery()");

        ResultSet oRSet = oStm.executeQuery();

        while (oRSet.next() && iOprtnCount<iMaxRecent) {

          boolean bListed = false;
          for (int n=0; n<iOprtnCount && !bListed; n++)
            bListed = oRSet.getString(1).equals(aOprtns[0][n]);

          if (!bListed) {
            aOprtns[0][iOprtnCount] = oRSet.getString(1);
            aOprtns[1][iOprtnCount] = oRSet.getString(2);
            aOprtns[2][iOprtnCount] = oRSet.getString(3);
            aOprtns[3][iOprtnCount] = oRSet.getString(4);
            aOprtns[4][iOprtnCount] = oRSet.getString(5);
            aOprtns[5][iOprtnCount] = oRSet.getString(6);

            iOprtnCount++;
          }
        } // wend

        oRSet.close();
        oRSet = null;

        oStm.close();
        oStm = null;

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

        for (int o=0; o<iOprtnCount; o++)
          for (int f=0; f<6; f++)
            if (aOprtns[f][o]==null) aOprtns[f][o]="";

        oXML.append("<oportunities>\n");
        for (int q=0; q<iOprtnCount; q++) {
          oXML.append("<oportunity>\n");

          oXML.append("<gu_oportunity>"+aOprtns[0][q]+"</gu_oportunity>");
          oXML.append("<tl_oportunity><![CDATA["+aOprtns[1][q]+"]]></tl_oportunity>");
          oXML.append("<gu_company>"+aOprtns[2][q]+"</gu_company>");
          oXML.append("<gu_contact>"+aOprtns[3][q]+"</gu_contact>");
          oXML.append("<tx_company><![CDATA["+aOprtns[4][q]+"]]></tx_company>");
          oXML.append("<tx_contact><![CDATA["+aOprtns[5][q]+"]]></tx_contact>");
          oXML.append("<tx_contact_esc><![CDATA["+Gadgets.URLEncode(aOprtns[5][q])+"]]></tx_contact_esc>");
          oXML.append("<where><![CDATA["+Gadgets.URLEncode(" AND gu_contact='" + aOprtns[3][q] + "'")+"]]></where>");

          oXML.append("</oportunity>\n");
        }

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

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

        if (DebugFile.trace) DebugFile.writeln("SQLException " + e.getMessage());
        try {
          if (null != oStm)
              oStm.close();
        } catch (SQLException ignore) { }

        try {
          if (null != oCon)
            if (!oCon.isClosed())
              oCon.close("OportunitiesTab");
        } 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

    if (DebugFile.trace) {
      DebugFile.writeln("Begin PageSetDB.clone([Connection], [PageSetDB])");
      DebugFile.incIdent();
    }

  FileSystem oFS = new FileSystem();
  if (sProtocol==null) sProtocol = "file://";
 
  sStorage = Gadgets.chomp(sStorage, File.separator);

  SimpleDateFormat oFmt = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
  int iLastSlash, iParenthesis;

  String sPathMetadata = DBCommand.queryStr(oConn, "SELECT "+DB.path_metadata+" FROM "+DB.k_microsites+" WHERE "+DB.gu_microsite+"='"+oSource.getString(DB.gu_microsite)+"'");

  super.clone(oSource);
 
  replace(DB.gu_pageset, Gadgets.generateUUID());
  remove(DB.dt_modified);
  remove(DB.id_status);

  if (getStringNull(DB.id_language,"").equals("es"))
    replace(DB.nm_pageset, Gadgets.left("Copia de "+oSource.getString(DB.nm_pageset),100));
  else 
    replace(DB.nm_pageset, Gadgets.left("Copy of "+oSource.getString(DB.nm_pageset),100));

  String sPathData = getString(DB.path_data);
  iLastSlash = sPathData.lastIndexOf('/');
  if (-1==iLastSlash) iLastSlash = sPathData.lastIndexOf('\\');
  sPathData = sPathData.substring(0, iLastSlash+1);
  Date dtCreated = new Date();
  String sXmlFileName = oSource.getString(DB.nm_pageset);
  iParenthesis = sXmlFileName.indexOf('(');
  if (iParenthesis>0) sXmlFileName = sXmlFileName.substring(0, iParenthesis)
  sXmlFileName = Gadgets.ASCIIEncode(sXmlFileName).toLowerCase();

    if (DebugFile.trace) DebugFile.writeln("path_data="+sPathData+sXmlFileName+" ("+oFmt.format(dtCreated)+").xml");

  replace(DB.path_data, sPathData+sXmlFileName+" ("+oFmt.format(dtCreated)+").xml");

  store(oConn);
  setCreationDate(oConn, dtCreated);

  PageSet oPSet = null;
 
  try {
    oPSet = new PageSet(sStorage+sPathMetadata, sStorage+oSource.getString(DB.path_data), false);
  } catch (Exception xcpt) {
    throw new IOException(xcpt.getMessage(), xcpt);
  }

  Node oRoot = oPSet.getRootNode();   
  Node oPgst = oPSet.seekChildByName(oRoot, "pageset");
  if (DebugFile.trace) DebugFile.writeln("PageSet.setAttribute("+oPgst+",\"guid\",\""+getString(DB.gu_pageset)+"\")");
    oPSet.setAttribute(oPgst, "guid", getString(DB.gu_pageset));     

  PageDB[] aPags = oSource.getPages(oConn);

  if (aPags!=null) {
    if (DebugFile.trace) DebugFile.writeln("PageSet.seekChildByName("+oPgst+",\"pages\")");
    Node oPags = oPSet.seekChildByName(oPgst,"pages");
    if (DebugFile.trace) DebugFile.writeln("PageSet.filterChildsByName("+oPags+",\"page\")");
    Vector<DOMSubDocument> vPags = oPSet.filterChildsByName((Element) oPags, "page");

    for (int p=0; p<aPags.length; p++) {
      PageDB oPage = aPags[p];
      oPage.replace(DB.gu_page, Gadgets.generateUUID());
      oPage.replace(DB.gu_pageset, getString(DB.gu_pageset));
    oPage.remove(DB.dt_modified);
      String sTlPage = oPage.getString(DB.tl_page);
    iParenthesis = sTlPage.indexOf('(');
    if (iParenthesis>0) sTlPage = sTlPage.substring(0, iParenthesis)+" ("+oFmt.format(dtCreated)+").html";
    if (DebugFile.trace) DebugFile.writeln("PageDB.replace(DB.tl_page, \""+sTlPage+"\")");
    oPage.replace(DB.tl_page, sTlPage);
   
    final String sSrcPathPage = oPage.getString(DB.path_page);
      String sPathPage = sSrcPathPage;
      iLastSlash = sPathPage.indexOf("/"+oSource.getString(DB.gu_pageset)+"/");
      if (-1==iLastSlash) iLastSlash = sPathPage.indexOf("\\"+oSource.getString(DB.gu_pageset)+"\\");
      char cSep = sPathPage.charAt(iLastSlash);
      String sPathPages = sPathPage.substring(0, ++iLastSlash)+getString(DB.gu_pageset);
      sPathPage = sPathPages+cSep+sTlPage.replace(' ','_');     
      if (DebugFile.trace) DebugFile.writeln("Page.replace(DB.path_page, \""+sPathPages+cSep+sTlPage.replace(' ','_')+"\")");
      oPage.replace(DB.path_page, sPathPages+cSep+sTlPage.replace(' ','_'));
       
      oPage.store(oConn);
    oPage.setCreationDate(oConn, dtCreated);

        oPSet.setAttribute(vPags.get(p).getNode(), "guid", oPage.getString(DB.gu_page));

        try {
          oFS.mkdirs(sProtocol+sPathPages);
          if (oFS.exists(sProtocol+sSrcPathPage))
            oFS.copy(sProtocol+sSrcPathPage, sProtocol+sPathPage);       
        } catch (Exception xcpt) {
          throw new IOException(xcpt.getMessage(), xcpt);
        }
    } // next
  } // fi (aPags)
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.