Preliminary study on the import process of the OpenCMS file

zhaozj2021-02-16  58

Preliminary study on the import process of the OpenCMS file

There is a file import process during the installation of OpenCMS. Due to work reasons, I have done this import process. A little harvest is written out and share it.

The installation process in the system is triggered by run_import.jsp files (this file is located in sourcpath1 / opencms_src_5.0.1 / opencms / web / ocsetup). She used in this page.

Such a structure to complete the import and display function. Seeing Name is easy to guess if he is used to display the result of the processing to the user. This is just a conjecture, how can I have to confirm. Let's take a look at DISPLAY_IMPORT.JSP this file.

On the display_import.jsp server, there is basically no processing, and the client's processing is quite. This sentence is important to this > is important. Let's take a look at the enable () function.

/ * indeicates if the document has been loading * /

Function enable () {

enabled = true;

Parent.data.location.href = "data_import.jsp";

Document.Forms [0] .info.value = message;

}

There is a parent.data.location.href = "data_import.jsp" in this function; this sentence. He puts Name to Data's Location.href to "Data_Import.jsp". From the file name, it should be an imported work of the file processing file. Is it, let's go in and see.

In addition to the session range of the session range in the Data_Import.jsp page, there is a JavaBean for the session range of com.opencms.boot.cmssetupthread. So what is this cmssetupthread in the end. Go to the source code!

Package com.opencms.boot;

Import java.io.file;

Import java.io.ioException;

Import java.io.pipedocutstream;

Import Java.io.printStream;

// CMSSetupThread is a thread.

Public class cmssetupthread extends thread {

Public void run () {

/ * Save the Original Out and Err Stream * /

M_Tempout = system.out;

m_temperr = system.err;

/ * Redirect the streams * /

System.setOut (New PrintStream (m_pipedout));

System.seterr (New PrintStream (m_pipedout));

/ * START the logging thread * /

m_lt.start (); / * start importing the workplace * /

CMSMain.StartSetup (Basepath "Web-INF / OCSETUP / CMSSETUP.TXT", Basepath "Web-INF /");

/ * stop the logging thread * /

Try {

Sleep (1000);

m_lt.stopthread ();

m_pipedout.close ();

}

Catch (InterruptedException E) {

m_lt.stopthread ();

E.PrintStackTrace (M_Temperr);

}

Catch (IOException E) {

m_lt.stopthread ();

E.PrintStackTrace (M_Temperr);

}

/ * Restore to the old streams * /

System.setout (M_Tempout);

System.seterr (M_Temperr);

}

...... ...... ......

}

It can be seen from the Public Void Run () method in the previous code to handle the work of file import. It is mainly divided into several steps to complete. Here, verify that the previous name of the DISPLAY is displayed to the user to display the result of the processing result, and Name is a conjecture for the DATA to process the file import. .

1. The standard output and system error output of the backup system

M_Tempout = system.out;

m_temperr = system.err;

2. Redirect the system output to a PiPedoutputStream instance (Instance)

System.setOut (New PrintStream (m_pipedout));

System.seterr (New PrintStream (m_pipedout));

In this way, some system outputs are oriented to m_pipedout to this object. To display processing information, you only need to handle it with system.out.println (). You can read M_Pipedout in front. This is not true to be confirmed.

3, start the CMSSETUPLOGGINGTHREAD thread;

4, start introducing work. Code is evidence

/ * START IMPORTING THE WORKPLACE * /

CMSMain.StartSetup (Basepath "Web-INF / OCSETUP / CMSSETUP.TXT", Basepath "Web-INF /");

5. Stop the CMSsetupLoggingThread thread.

6. Refractive system standard output and system error output.

Here is what you don't know what CMSSETUPLOGGINGTHREAD is. By viewing the source code, you can find that he is used to collect the processing information of the CMSSetupThread thread. Also, the communication of these two threads is accompanied by pipedocutstream. This can be known from his constructor.

Public cmssetuploggingthread (PiPedoutputStream Piped) {

Messages = new vector ();

m_stopthread = false;

Try {

m_pipedin = new pipedinputstream ();

m_pipedin.connect (pipedout);

M_LineReader = New LineNumberReader (New InputStreamReader);

}

Catch (Exception E) {

Messages.addelement (e.tostring ());

}

}

To facilitate the convenience of the JSP page, these information CMSsetupLoggingThread also provides a private static vector message; and a static getMess () method to process him. This is in Data_Import.jsp

Messages = com.netMarch.infopub.pubservletcon.logginthread.getMess (); statement can be verified. Finally, Messages passed