Examples of FileSystem


Examples of com.knowgate.dfs.FileSystem

    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

Examples of com.knowgate.dfs.FileSystem

      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

Examples of com.knowgate.dfs.FileSystem

    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

Examples of com.knowgate.dfs.FileSystem

    !sTargetUri.startsWith("ftp://" ) && !sTargetUri.startsWith("ftps://" ) &&
    !sTargetUri.startsWith("http://") && !sTargetUri.startsWith("https://")) {
    sTargetUri = "file://" + sTargetUri;
  }
 
    FileSystem oFs = new FileSystem();
  if (!oFs.exists(sSourceUri)) {
    throw new FileNotFoundException("PageDB.publish() file not found "+getString(DB.path_page));
  }
  return oFs.copy(sSourceUri, sTargetUri);
  } // publish
View Full Code Here

Examples of com.knowgate.dfs.FileSystem

      DebugFile.writeln("Begin Pageset.buildPageForEdit(" + sBasePath + "," + sOutputPath + "," + sCtrlPath + "," + sMenuPath + ")");
      DebugFile.incIdent();
    }

    FileSystem oFS = new FileSystem();

    if (!sBasePath.endsWith(sSep)) sBasePath += sSep;

    String sWebServer = oEnvironmentProps.getProperty("webserver", "");

    if (DebugFile.trace && sWebServer.length()==0) DebugFile.writeln("WARNING: webserver property not set at EnvironmentProperties");

    if (!sWebServer.endsWith("/")) sWebServer+="/";


    // Posicionarse en el nodo de contenedores
    Node oContainers = oMSite.seekChildByName(oMSite.getRootNode().getFirstChild(), "containers");

    if (oContainers==null) {
      if (DebugFile.trace)
        DebugFile.writeln("ERROR: <containers> node not found.");

      throw new DOMException(DOMException.NOT_FOUND_ERR, "<containers> node not found");
    }

    // Cagar el stream de datos XML una sola vez
    if (DebugFile.trace)
      DebugFile.writeln("new FileInputStream(" + (sURI.startsWith("file://") ? sURI.substring(7) : sURI) + ")");

    // Para cada contenedor (página) realizar la transformación XSLT

      oCurrentPage = this.page(sPageGUID);

    oXMLFile = new File (sURI.startsWith("file://") ? sURI.substring(7) : sURI);
    if (!oXMLFile.exists()) {
        if (DebugFile.trace) DebugFile.decIdent();
      throw new FileNotFoundException("PageSet.buildPageForEdit() File not found "+sURI);
    }

      oXMLStream = new FileInputStream(oXMLFile);
      oStreamSrcXML = new StreamSource(oXMLStream);

      // Asignar cada stream de salida a su stream temporal
      oStrWritter = new StringWriter();
      oStreamResult = new StreamResult(oStrWritter);

      // Transformacion XSLT
      try {

        // Obtener la hoja de estilo desde el cache
        sXSLFile = sBasePath + "xslt" + sSep + "templates" + sSep + oMSite.name() + sSep + oCurrentPage.template();
      oXSLFile = new File (sXSLFile);
      if (!oXSLFile.exists()) {
          if (DebugFile.trace) DebugFile.decIdent();
        throw new FileNotFoundException("PageSet.buildPageForEdit() File not found "+sXSLFile+" maybe there is a mismatch between the microsite name and the directory name where it is placed, or between the template name and the actual .xsl file name");
      }

        oTransformer = StylesheetCache.newTransformer(sXSLFile);

        sMedia = oTransformer.getOutputProperty(OutputKeys.MEDIA_TYPE);

        if (DebugFile.trace) DebugFile.writeln(OutputKeys.MEDIA_TYPE + "=" + sMedia);

        if (null==sMedia)
          sMedia = "html";
        else
          sMedia = sMedia.substring(sMedia.indexOf('/')+1);

        if (null==oCurrentPage.getTitle())
          throw new NullPointerException("Page title is null");

        if (DebugFile.trace)
          DebugFile.writeln("Page.filePath(" + sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia + ")");

        oCurrentPage.filePath(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia);

        // Set environment parameters for stylesheet
        StylesheetCache.setParameters (oTransformer, oEnvironmentProps);

        // Set user defined parameters for stylesheet
        StylesheetCache.setParameters (oTransformer, oUserProps);

        // Paso el title de la pagina como parametro
        oTransformer.setParameter ("param_page", oCurrentPage.getTitle());

        // Realizar la transformación
        oTransformer.transform (oStreamSrcXML, oStreamResult);

      }
      catch (TransformerConfigurationException e) {
         oLastXcpt = e;
         sMedia = null;

         SourceLocator sl = e.getLocator();

         if (DebugFile.trace) {
           if (sl == null) {
             DebugFile.writeln("ERROR TransformerConfigurationException " + e.getMessage());
           }
           else {
             DebugFile.writeln("ERROR TransformerConfigurationException " + e.getMessage() + " line=" + String.valueOf(sl.getLineNumber()) + " column=" + String.valueOf(sl.getColumnNumber()));
           }
         }
      }
      catch (TransformerException e) {
        oLastXcpt = e;
        sMedia = null;

        if (DebugFile.trace) DebugFile.writeln("ERROR TransformerException " + e.getMessageAndLocation());
      }

      oTransformer = null;
      oStreamResult = null;

      // Asignar un String con el fuente XML transformado
      sTransformed = oStrWritter.toString();

      if (DebugFile.trace) DebugFile.writeln("transformation length=" + String.valueOf(sTransformed.length()));

      // Buscar el fin de tag </head>
      if (sTransformed.length()>0) {
        iCloseHead = sTransformed.indexOf("</head");
        if (iCloseHead<0) iCloseHead = sTransformed.indexOf("</HEAD");

    if (iCloseHead<0) {
          if (DebugFile.trace) {
            DebugFile.writeln("Stylesheet lacks </head> tag");
            DebugFile.decIdent();
          }     
      throw new TransformerException("Stylesheet lacks </head> tag");
    } // fi

        // Buscar el inicio de tag <body>
        iOpenBody = sTransformed.indexOf("<body", iCloseHead);
        if (iOpenBody<0) iOpenBody = sTransformed.indexOf("<BODY", iCloseHead);

    if (iOpenBody<0) {
          if (DebugFile.trace) {
            DebugFile.writeln("Stylesheet lacks <body> tag");
            DebugFile.decIdent();
          }     
      throw new TransformerException("Stylesheet lacks <body> tag");
    } // fi
   
        iCloseBody = sTransformed.indexOf(">", iOpenBody+5);
        for (char s = sTransformed.charAt(iCloseBody+1); s=='\r' || s=='\n' || s==' ' || s=='\t'; s = sTransformed.charAt(++iCloseBody)) ;

        // Crear un buffer intermedio para mayor velocidad de concatenado
        oPostTransform = new StringBuffer(sTransformed.length()+4096);

        // Incrustar las llamadas al Integrador en el lugar apropiado del fuente
        oPostTransform.append(sTransformed.substring(0, iCloseHead));
        oPostTransform.append("\n<script language=\"JavaScript\" type=\"text/javascript\" src=\"" + sMenuPath + "\"></script>");
        oPostTransform.append("\n<script language=\"JavaScript\" type=\"text/javascript\" src=\"" + sIntegradorPath + "\"></script>\n");
        oPostTransform.append(sTransformed.substring(iCloseHead, iCloseHead+7));
        oPostTransform.append(sTransformed.substring(iOpenBody, iCloseBody));

        // Cargar el código fuente del control de visulización del Integrador
        try {
          sCharBuffer = oFS.readfilestr(sCtrlPath, "UTF-8");

          if (DebugFile.trace) DebugFile.writeln(String.valueOf(sCharBuffer.length()) + " characters readed");
        }
        catch (com.enterprisedt.net.ftp.FTPException ftpe) {
          throw new IOException (ftpe.getMessage());
        }

        try {
          if (DebugFile.trace) DebugFile.writeln("Gadgets.replace(" + sCtrlPath + ",http://demo.hipergate.com/," + sWebServer + ")");

          Gadgets.replace(sCharBuffer, "http://demo.hipergate.com/", sWebServer);

        } catch (org.apache.oro.text.regex.MalformedPatternException e) { }

        oPostTransform.append("<!--Begin " + sCtrlPath + "-->\n");

        oPostTransform.append(sCharBuffer);
        sCharBuffer = null;

        oPostTransform.append("\n<!--End " + sCtrlPath + "-->\n");

        oPostTransform.append(sTransformed.substring(iCloseBody));
      }
      else {
        oPostTransform = new StringBuffer("Page " + oCurrentPage.getTitle() + " could not be rendered.");
        if (oLastXcpt!=null) oPostTransform.append("<BR>" + oLastXcpt.getMessageAndLocation());
      }

      // Escribir el resultado con las llamadas incrustadas en el archivo de salida

      if (sSelPageOptions.length()==0)
        oFS.writefilestr(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia, oPostTransform.toString(), "UTF-8");
      else
        try {

          oFS.writefilestr(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia, Gadgets.replace(oPostTransform.toString(), ":selPageOptions", sSelPageOptions), "UTF-8");

        } catch (Exception e) {/* Ignore MalformedPatternException, is never thrown */ }

      // Desreferenciar los buffers intermedios para liberar memoria lo antes posible
      oPostTransform = null;
View Full Code Here

Examples of com.knowgate.dfs.FileSystem

      DebugFile.writeln("Begin Pageset.buildSiteForEdit(" + sBasePath + "," + sOutputPath + "," + sCtrlPath + "," + sMenuPath + ")");
      DebugFile.incIdent();
    }

    FileSystem oFS = new FileSystem();

    Vector vPages = pages();

    if (!sBasePath.endsWith(sSep)) sBasePath += sSep;

    String sWebServer = oEnvironmentProps.getProperty("webserver", "");

    if (DebugFile.trace && sWebServer.length()==0) DebugFile.writeln("WARNING: webserver property not set at EnvironmentProperties");

    if (!sWebServer.endsWith("/")) sWebServer+="/";


    // Posicionarse en el nodo de contenedores
    Node oContainers = oMSite.seekChildByName(oMSite.getRootNode().getFirstChild(), "containers");

    if (oContainers==null) {
      if (DebugFile.trace)
        DebugFile.writeln("ERROR: <containers> node not found.");

      throw new DOMException(DOMException.NOT_FOUND_ERR, "<containers> node not found");
    }

    // Cagar el stream de datos XML una sola vez
    if (DebugFile.trace)
      DebugFile.writeln("new FileInputStream(" + (sURI.startsWith("file://") ? sURI.substring(7) : sURI) + ")");


    // Para cada contenedor (página) realizar la transformación XSLT
    for (int c=0; c<vPages.size(); c++) {

      oCurrentPage = (Page) vPages.get(c);

      oXMLStream = new FileInputStream(sURI.startsWith("file://") ? sURI.substring(7) : sURI);
      oStreamSrcXML = new StreamSource(oXMLStream);

      // Asignar cada stream de salida a su stream temporal
      oStrWritter = new StringWriter();
      oStreamResult = new StreamResult(oStrWritter);

      // Transformacion XSLT
      try {

        // Obtener la hoja de estilo desde el cache
        oTransformer = StylesheetCache.newTransformer(sBasePath + "xslt" + sSep + "templates" + sSep + oMSite.name() + sSep + oCurrentPage.template());

        sMedia = oTransformer.getOutputProperty(OutputKeys.MEDIA_TYPE);

        if (DebugFile.trace) DebugFile.writeln(OutputKeys.MEDIA_TYPE + "=" + sMedia);

        if (null==sMedia)
          sMedia = "html";
        else
          sMedia = sMedia.substring(sMedia.indexOf('/')+1);

        if (null==oCurrentPage.getTitle())
          throw new NullPointerException("Page " + String.valueOf(c) + " title is null");

        if (DebugFile.trace)
          DebugFile.writeln("Page.filePath(" + sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia + ")");

        oCurrentPage.filePath(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia);

        // Set environment parameters for stylesheet
        StylesheetCache.setParameters (oTransformer, oEnvironmentProps);

        // Set user defined parameters for stylesheet
        StylesheetCache.setParameters (oTransformer, oUserProps);

        // Paso el title de la pagina como parametro
        oTransformer.setParameter ("param_page", ((Page)(vPages.get(c))).getTitle());

        // Realizar la transformación
        oTransformer.transform (oStreamSrcXML, oStreamResult);

      }
      catch (TransformerConfigurationException e) {
         oLastXcpt = e;
         sMedia = null;

         SourceLocator sl = e.getLocator();

         if (DebugFile.trace) {
           if (sl == null) {
             DebugFile.writeln("ERROR TransformerConfigurationException " + e.getMessage());
           }
           else {
             DebugFile.writeln("ERROR TransformerConfigurationException " + e.getMessage() + " line=" + String.valueOf(sl.getLineNumber()) + " column=" + String.valueOf(sl.getColumnNumber()));
           }
         }
      }
      catch (TransformerException e) {
        oLastXcpt = e;
        sMedia = null;

        if (DebugFile.trace) DebugFile.writeln("ERROR TransformerException " + e.getMessageAndLocation());
      }

      oTransformer = null;
      oStreamResult = null;

      // Asignar un String con el fuente XML transformado
      sTransformed = oStrWritter.toString();

      if (DebugFile.trace) DebugFile.writeln("transformation length=" + String.valueOf(sTransformed.length()));

      // Buscar el fin de tag </head>
      if (sTransformed.length()>0) {
        iCloseHead = sTransformed.indexOf("</head");
        if (iCloseHead<0) iCloseHead = sTransformed.indexOf("</HEAD");

        // Buscar el inicio de tag <body>
        iOpenBody = sTransformed.indexOf("<body", iCloseHead);
        if (iOpenBody<0) iOpenBody = sTransformed.indexOf("<BODY", iCloseHead);

        iCloseBody = sTransformed.indexOf(">", iOpenBody+5);
        for (char s = sTransformed.charAt(iCloseBody+1); s=='\r' || s=='\n' || s==' ' || s=='\t'; s = sTransformed.charAt(++iCloseBody)) ;

        // Crear un buffer intermedio para mayor velocidad de concatenado
        oPostTransform = new StringBuffer(sTransformed.length()+4096);

        // Incrustar las llamadas al Integrador en el lugar apropiado del fuente
        oPostTransform.append(sTransformed.substring(0, iCloseHead));
        oPostTransform.append("\n<script language=\"JavaScript\" src=\"" + sMenuPath + "\"></script>");
        oPostTransform.append("\n<script language=\"JavaScript\" src=\"" + sIntegradorPath + "\"></script>\n");
        oPostTransform.append(sTransformed.substring(iCloseHead, iCloseHead+7));
        oPostTransform.append(sTransformed.substring(iOpenBody, iCloseBody));

        // Cargar el código fuente del control de visulización del Integrador
        try {
          sCharBuffer = oFS.readfilestr(sCtrlPath, "UTF-8");

          if (DebugFile.trace) DebugFile.writeln(String.valueOf(sCharBuffer.length()) + " characters readed");
        }
        catch (com.enterprisedt.net.ftp.FTPException ftpe) {
          throw new IOException (ftpe.getMessage());
        }

        try {
          if (DebugFile.trace) DebugFile.writeln("Gadgets.replace(" + sCtrlPath + ",http://demo.hipergate.com/," + sWebServer + ")");

          Gadgets.replace(sCharBuffer, "http://demo.hipergate.com/", sWebServer);
        } catch (org.apache.oro.text.regex.MalformedPatternException e) { }

        oPostTransform.append("<!--Begin " + sCtrlPath + "-->\n");

        oPostTransform.append(sCharBuffer);
        sCharBuffer = null;

        oPostTransform.append("\n<!--End " + sCtrlPath + "-->\n");

        oPostTransform.append(sTransformed.substring(iCloseBody));
      }
      else {
        oPostTransform = new StringBuffer("Page " + ((Page)vPages.get(c)).getTitle() + " could not be rendered.");
        if (oLastXcpt!=null) oPostTransform.append("<BR>" + oLastXcpt.getMessageAndLocation());
      }

      // Escribir el resultado con las llamadas incrustadas en el archivo de salida
      if (DebugFile.trace) DebugFile.writeln("new FileWriter(" + sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia + ")");


      if (sSelPageOptions.length()==0)
        oFS.writefilestr(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia, oPostTransform.toString(), "UTF-8");
      else
        try {
          oFS.writefilestr(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "_." + sMedia, Gadgets.replace(oPostTransform.toString(), ":selPageOptions", sSelPageOptions), "UTF-8");

        } catch (Exception e) {/* Ignore MalformedPatternException, is never thrown */ }

      // Desreferenciar los buffers intermedios para liberar memoria lo antes posible
      oPostTransform = null;
View Full Code Here

Examples of com.knowgate.dfs.FileSystem

    if (DebugFile.trace) {
      DebugFile.writeln("Begin PasswordRecordTemplate.load("+sFilePath+")");
      DebugFile.incIdent();
    }

    FileSystem oFs = new FileSystem();
    if (!sFilePath.startsWith("file://") && !sFilePath.startsWith("ftp://") &&
      !sFilePath.startsWith("ftps://") && !sFilePath.startsWith("https://") &&
      !sFilePath.startsWith("http://") && !sFilePath.startsWith("file://"))
      sFilePath = "file://" + sFilePath;

  if (!oFs.exists(sFilePath)) {
      if (DebugFile.trace) {
        DebugFile.writeln("FileNotFoundException: PasswordRecordTemplate.load() "+sFilePath);
        DebugFile.decIdent();
      }
      throw new FileNotFoundException("PasswordRecordTemplate.load() "+sFilePath);
  }

    String sTemplate = oFs.readfilestr(sFilePath, "UTF-8");

  oMasterRecord.lines().clear();

  if (sTemplate!=null) {
    if (sTemplate.length()>0) {
View Full Code Here

Examples of com.knowgate.dfs.FileSystem

    if (!sFilePath.startsWith("file://") && !sFilePath.startsWith("ftp://") &&
      !sFilePath.startsWith("ftps://") && !sFilePath.startsWith("https://") &&
      !sFilePath.startsWith("http://") && !sFilePath.startsWith("file://"))
      sFilePath = "file://" + sFilePath;

    FileSystem oFs = new FileSystem();

  oFs.writefilestr(sFilePath, oTemplate.toString(), "UTF-8");
 
  } // store
View Full Code Here

Examples of com.knowgate.dfs.FileSystem

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

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

View Full Code Here

Examples of com.knowgate.dfs.FileSystem

    if (DebugFile.trace) DebugFile.writeln("index directory is " + sDirectory);

    File oDir = new File(sDirectory);
  boolean bNewIndex = !oDir.exists();
    if (bNewIndex) {
    FileSystem oFs = new FileSystem();
    try {
      oFs.mkdirs("file://"+sDirectory);
    } catch (Exception xcpt) {
        if (DebugFile.trace) DebugFile.writeln(xcpt.getClass()+" "+xcpt.getMessage());
        throw new FileNotFoundException ("Could not create directory "+sDirectory+" "+xcpt.getMessage());
    }
    } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.