Re: [opencms-dev] Cron task of static export doesn´ t work
Juan David Ayllón Burguillo
jdayllon at gmail.com
Mon May 16 16:04:32 CEST 2005
Poblemillas con openseemeese?
Yo estube haciendo una tarea cron para eso... pero al final lo deje por
imposible, lo del jsp rulaba mucho mejor
2005/5/16, Salvador Santander Gutiérrez <
salvador.santander at juntadeandalucia.es>:
>
> Hello, list.
> We've developed a cron task for import certain resources from other
> opencms server. We've got this developing a java class and calling it from
> the Cron tasks in OpenCMS Administration View.
> All goes well, the task import the resources, publish them, but they're
> not exported to html pages (static export). When we login in opencms, we
> check that the new resources has been updated.
> If we call the class of the cron task in a jsp page, the resources are
> exported, but not when the class is called from the cron scheduler of
> OpenCMS.
> Anybody can tell us how to get this?
> Thanks very much.
> The code of the class:
> package epsa.admin;
> import java.util.*;
> import java.sql.*;
> import com.opencms.flex.jsp.*;
> import com.opencms.file.*;
> import com.opencms.workplace.*;
> import com.opencms.report.*;
> import com.opencms.core.*;
> import com.opencms.file.*;
> import epsa.admin.*;
> import java.io.*;
> /**
> * Clase que realiza la exportacion de contenidos de internet
> * @author Salvador Santander Gutiérrez
> * @company dominion
> */
> public class CronInternetContentImport implements I_CmsCronJob {
>
> /**
> * Nombre del fichero de exportacion
> */
> String nombreFichero =
> "/var/tomcat4/webapps/epsa/WEB-INF/export/internetContentExport.zip";
> String nombreFicheroLog =
> "/var/tomcat4/webapps/epsa/WEB-INF/export/internetContentImported.html";
>
> private void writeFile( String fileName, String scriptSQL )
> throws FileNotFoundException, IOException
> {
> FileOutputStream file = new FileOutputStream( fileName.trim() );
> file.write( scriptSQL.getBytes() );
> file.flush();
> file.close();
> }
>
> /**
> * Método que ejecuta el gestor de tareas de opencms y que
> * lanzará la exportación de contenidos de internet
> * @param CmsObject cms object.
> * @param String Parametros
> * @throws Exception Excepcion.
> */
> public String launch (CmsObject cms, String params)
> throws Exception
> {
> StringBuffer mensajeResultado; // Mensaje que se escribirá en el log
>
> mensajeResultado = new StringBuffer();
>
> try
> {
> mensajeResultado.append( " \n----- IMPORTACION DE CONTENIDOS DE INTERNET
> ------ \n" );
>
> // Comenzamos la importacion
> int projectOfflineId = 4;
> int projectOnlineId = 1;
> cms.getRequestContext().setCurrentProject( projectOfflineId );
> EpsaAdminDatabaseImportThread hiloImportacion = new
> EpsaAdminDatabaseImportThread( cms, nombreFichero );
> hiloImportacion.run();
> writeFile( nombreFicheroLog , hiloImportacion.getReportUpdate() );
>
> cms.lockResource("/eintranet/", true);
> cms.lockResource("/system/modules/", true);
> cms.lockResource("/system/galleries/", true);
> cms.touch("/eintranet/", new java.util.Date().getTime(), true);
> cms.touch("/system/modules/", new java.util.Date().getTime(), true);
> cms.touch("/system/galleries/", new java.util.Date().getTime(), true);
> cms.unlockResource("/eintranet/");
> cms.unlockResource("/system/modules/");
> cms.unlockResource("/system/galleries/");
> cms.publishResource("/eintranet/");
> cms.publishResource("/system/modules/");
> cms.publishResource("/system/galleries/");
>
> cms.unlockProject( projectOfflineId );
> cms.publishProject( projectOfflineId );
>
> cms.getRequestContext().setCurrentProject( projectOnlineId );
>
> Vector linksToExport = new Vector();
> linksToExport.add("/");
> cms.exportStaticResources(linksToExport);
>
> }
> catch( Exception ex )
> {
> mensajeResultado.append( "\nERROR!!!:\n" );
> mensajeResultado.append( "Mensaje: " + ex.getMessage() + "\n" );
> mensajeResultado.append( "Localizacion: " + ex.getLocalizedMessage() +
> "\n" );
> mensajeResultado.append( "StackTrace: " +
> com.opencms.util.Utils.getStackTrace(ex) + "\n");
>
> OpenCms.log(OpenCms.C_OPENCMS_CRITICAL, mensajeResultado.toString() );
>
> }
>
> mensajeResultado.append( " \n----- FIN DE EXPORTACIÓN DE CONTENIDOS DE
> INTERNET ------ \n" );
>
> return mensajeResultado.toString();
> }
> }
> package epsa.admin;
> import com.opencms.boot.I_CmsLogChannels;
> import com.opencms.core.A_OpenCms;
> import com.opencms.core.CmsException;
> import com.opencms.core.I_CmsConstants;
> import com.opencms.file.CmsObject;
> import com.opencms.report.A_CmsReportThread;
> import com.opencms.report.CmsHtmlReport;
> import com.opencms.report.I_CmsReport;
>
> public class EpsaAdminDatabaseImportThread extends A_CmsReportThread {
> private String m_existingFile;
> private CmsObject m_cms;
> private I_CmsReport m_report;
> /**
> * Imports the database.<p>
> */
> public EpsaAdminDatabaseImportThread(
> CmsObject cms,
> String existingFile
> ) {
> m_cms = cms;
> m_cms.getRequestContext().setUpdateSessionEnabled(false);
> m_existingFile = existingFile;
> m_report = new CmsHtmlReport("es");
> }
> /**
> * @see java.lang.Runnable#run()
> */
> public void run() {
> try {
> m_report.println(m_report.key("report.import_db_begin"),
> I_CmsReport.C_FORMAT_HEADLINE);
> m_cms.importResources(m_existingFile, I_CmsConstants.C_ROOT, m_report);
> m_report.println(m_report.key("report.import_db_end"),
> I_CmsReport.C_FORMAT_HEADLINE);
> }
> catch(CmsException e) {
> m_report.println(e);
> if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
> A_OpenCms.log(A_OpenCms.C_OPENCMS_CRITICAL, e.getMessage());
> }
> }
> }
> /**
> * Returns the part of the report that is ready.<p>
> */
> public String getReportUpdate()
> {
> return m_report.getReportUpdate();
> }
> }
>
>
>
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
>
>
--
Juan David Ayllón Burguillo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20050516/0606a2ac/attachment.htm>
More information about the opencms-dev
mailing list