Build doc into modules/helptools/{jar,ps,html} now
Sylvestre Ledru [Thu, 11 Sep 2008 13:52:56 +0000 (13:52 +0000)]
scilab/modules/helptools/sci_gateway/cpp/sci_buildDoc.cpp
scilab/modules/helptools/src/java/org/scilab/modules/helptools/BuildDocObject.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/BuildJavaHelp.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/BuildPDF.java
scilab/modules/helptools/src/jni/BuildDocObject.cpp
scilab/modules/helptools/src/jni/BuildDocObject.giws.xml
scilab/modules/helptools/src/jni/BuildDocObject.hxx

index 217712b..62b2adf 100644 (file)
@@ -52,6 +52,7 @@ static void __slashToAntislash(std::string *in)
     static int l2 = 0,n2 = 0,m2 = 0;
     static int l3 = 0,n3 = 0,m3 = 0;
     static int l4 = 0,n4 = 0,m4 = 0;
+       //      static int Row_Output = 0, Col_Output = 0;
     std::string exportFormat;
     std::string SciPath = getSCIpath(); /* Scilab path */
     std::string masterXML; /* Which file contains all the doc stuff */
@@ -60,6 +61,7 @@ static void __slashToAntislash(std::string *in)
     std::string outputDirectoryTMP;
     std::string language;
     std::string styleSheet; /* the CSS */
+       //      std::string pathToGenerated;
     org_scilab_modules_helptools::BuildDocObject *doc = NULL;
 
     CheckRhs(0,4);
@@ -129,14 +131,14 @@ static void __slashToAntislash(std::string *in)
           }
         else
           {
-           Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n"),fname,4);
-           return FALSE;
+                         Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n"),fname,4);
+                         return FALSE;
           }
       }
     else /* Scilab help */
       {
         /* Update the path with the localization */
-        outputDirectoryTMP = std::string("/modules/helptools/build/doc/scilab_")+language+std::string("_help/");
+        outputDirectoryTMP = std::string("/modules/helptools/")+std::string(exportFormat)+std::string("/scilab_")+language+std::string("_help/");
 
         outputDirectory = SciPath+outputDirectoryTMP;
       }
@@ -151,11 +153,18 @@ static void __slashToAntislash(std::string *in)
        __slashToAntislash(&masterXML);
 #endif
 
+
        if (doc->setOutputDirectory((char *) outputDirectory.c_str()))
          {
            doc->setWorkingLanguage((char *) language.c_str());
            doc->setExportFormat((char *) exportFormat.c_str());
-           doc->process((char *) masterXML.c_str(), (char *) styleSheet.c_str());
+
+               doc->process((char *) masterXML.c_str(), (char *) styleSheet.c_str());
+               /*              Row_Output = 1;
+               Col_Output = 1;
+               CreateVarFromPtr( Rhs+1,MATRIX_OF_STRING_DATATYPE, &Row_Output, &Col_Output, &pathToGenerated.c_str() );
+               */
+
          }
        else
          {
@@ -170,8 +179,7 @@ static void __slashToAntislash(std::string *in)
       }
 
     if (doc != NULL) delete doc;
-
-    LhsVar(1) = 0;
+       LhsVar(1) = 0 ;
     C2F(putlhsvar)();
     return 0;
   }
index 8dde638..1e589f7 100644 (file)
@@ -182,7 +182,9 @@ public class BuildDocObject extends StyleSheet {
                /* Create the output file which will be created by copyconvert.run into the working directory  */
                File masterXMLTransformed = new File(this.outputDirectory 
                                + File.separator + filename.substring(0, filename.lastIndexOf(".")) + "-processed.xml");
+               /* Where it will be stored */
                String out = this.outputDirectory + File.separator + (String) new File(styleSheet).getName();
+
                try {
                        Helpers.copyFile(new File(styleSheet), new File(out));
                } catch (java.io.FileNotFoundException e) {
@@ -190,6 +192,7 @@ public class BuildDocObject extends StyleSheet {
                } catch (java.io.IOException e) {
                        System.err.println(ERROR_WHILE_COPYING + styleSheet + TO + out + COLON + e.getMessage());                       
                }
+
         CopyConvert copyConvert = new CopyConvert();
         copyConvert.setVerbose(true);
         copyConvert.setPrintFormat(this.format);
@@ -210,15 +213,16 @@ public class BuildDocObject extends StyleSheet {
 
     /**
      * Private method which manages the post processing
-     *
+     * @return The path to the file/directory created.
      */
-       private void postProcess() {
+       private String postProcess() {
                if (this.format.equalsIgnoreCase(JH_FORMAT) || format.equalsIgnoreCase(JAVAHELP_FORMAT)) {
-                       BuildJavaHelp.buildJavaHelp(this.outputDirectory, this.language);
+                       return BuildJavaHelp.buildJavaHelp(this.outputDirectory, this.language);
                }
                if (format.equalsIgnoreCase(PDF_FORMAT) || format.equalsIgnoreCase(POSTSCRIPT_FORMAT)) {
-                       BuildPDF.buildPDF(this.outputDirectory, this.language, format);
+                       return BuildPDF.buildPDF(this.outputDirectory, this.language, format);
                }
+               return null;
        }
 
 
@@ -227,9 +231,10 @@ public class BuildDocObject extends StyleSheet {
      *
      * @param sourceDoc Path to the XML master document
      * @param styleSheet Path to the CSS stylesheet
+        * @return The path to the file/directory created.
         * @throws FileNotFoundException Raises an exception if no file/dir found
         */
-       public void process(String sourceDoc, String styleSheet) throws FileNotFoundException {
+       public String process(String sourceDoc, String styleSheet) throws FileNotFoundException {
                ArrayList<String> args = new ArrayList<String>();
 
                if (!new File(sourceDoc).isFile()) {
@@ -273,7 +278,7 @@ public class BuildDocObject extends StyleSheet {
                        new File(sourceDocProcessed).delete();
                }
 
-               this.postProcess();
+               return this.postProcess();
 
        }
        
index 31cedde..307322c 100644 (file)
@@ -72,6 +72,7 @@ public final class BuildJavaHelp {
                JarOutputStream jarFile = null;
                FileOutputStream fileOutputStream = null;
                final int compressionLevel = 5;
+               /* Stored into SCI/modules/helptools/jar */
                String fileName = outputDirectory + "/../../../jar/" + baseName + ".jar";
 
                try {
@@ -132,7 +133,7 @@ public final class BuildJavaHelp {
      * @param language In which language (for the file name)
      * @return The result of the process
         */
-       public static boolean buildJavaHelp(String outputDirectory, String language) {
+       public static String buildJavaHelp(String outputDirectory, String language) {
         
                String outputJavaHelp = new String(outputDirectory + JAVAHELPSEARCH_DIR);
         
@@ -148,12 +149,12 @@ public final class BuildJavaHelp {
                        indexer.compile(args);
                } catch (Exception e) {
                        System.err.println("buildDoc: Error building search index: " + e.getLocalizedMessage());
-                       return false;
+                       return null;
                }
 
                BuildJavaHelp.buildJar(outputDirectory, language);
                        
-               return true;
+               return outputDirectory;
        }
 
 }
index 4a7e3ca..39e0948 100644 (file)
@@ -55,10 +55,12 @@ public final class BuildPDF {
      * @param language In which language (for the file name)
      * @return The result of the process
         */
-       public static boolean buildPDF(String outputDirectory, String language, String format) {
+       public static String buildPDF(String outputDirectory, String language, String format) {
 
                String baseName = Helpers.getBaseName(language);
-               String fileName = outputDirectory + "/" + baseName;
+               /* the following '..' is used because we are in the current working
+                  directory with all the tmp stuff in it */
+               String fileName = outputDirectory + "/../" + baseName; 
                if (format.equalsIgnoreCase("PS")) {
                         fileName+= ".ps";
                }else{
@@ -105,7 +107,7 @@ public final class BuildPDF {
                        System.out.println(e.getLocalizedMessage());
                }
                        
-               return true;
+               return fileName;
        }
 
 }
index 6cd52a3..f0f1b33 100644 (file)
@@ -102,7 +102,7 @@ curEnv->DeleteLocalRef(localInstance);
 jbooleansetOutputDirectoryjstringID=NULL; 
 voidsetWorkingLanguagejstringID=NULL; 
 voidsetExportFormatjstringID=NULL; 
-voidprocessjstringjstringID=NULL; 
+jstringprocessjstringjstringID=NULL; 
 
 
 }
@@ -128,7 +128,7 @@ throw GiwsException::JniObjectCreationException(curEnv, this->className());
         jbooleansetOutputDirectoryjstringID=NULL; 
 voidsetWorkingLanguagejstringID=NULL; 
 voidsetExportFormatjstringID=NULL; 
-voidprocessjstringjstringID=NULL; 
+jstringprocessjstringjstringID=NULL; 
 
 
 }
@@ -206,12 +206,12 @@ throw GiwsException::JniCallMethodException(curEnv);
 }
 }
 
-void BuildDocObject::process (char * sourceDoc, char * styleSheet){
+char * BuildDocObject::process (char * sourceDoc, char * styleSheet){
 
 JNIEnv * curEnv = getCurrentEnv();
 
-if (voidprocessjstringjstringID==NULL) { /* Use the cache Luke */ voidprocessjstringjstringID = curEnv->GetMethodID(this->instanceClass, "process", "(Ljava/lang/String;Ljava/lang/String;)V" ) ;
-if (voidprocessjstringjstringID == NULL) {
+if (jstringprocessjstringjstringID==NULL) { /* Use the cache Luke */ jstringprocessjstringjstringID = curEnv->GetMethodID(this->instanceClass, "process", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;" ) ;
+if (jstringprocessjstringjstringID == NULL) {
 throw GiwsException::JniMethodNotFoundException(curEnv, "process");
 }
 }
@@ -219,10 +219,19 @@ jstring sourceDoc_ = curEnv->NewStringUTF( sourceDoc );
 
 jstring styleSheet_ = curEnv->NewStringUTF( styleSheet );
 
-                         curEnv->CallVoidMethod( this->instance, voidprocessjstringjstringID ,sourceDoc_, styleSheet_);
-                        if (curEnv->ExceptionCheck()) {
+                        jstring res =  (jstring) curEnv->CallObjectMethod( this->instance, jstringprocessjstringjstringID ,sourceDoc_, styleSheet_);
+                        
+
+const char *tempString = curEnv->GetStringUTFChars(res, 0);
+char * myStringBuffer = new char[strlen(tempString) + 1];
+strcpy(myStringBuffer, tempString);
+curEnv->ReleaseStringUTFChars(res, tempString);
+curEnv->DeleteLocalRef(res);
+if (curEnv->ExceptionCheck()) {
 throw GiwsException::JniCallMethodException(curEnv);
 }
+return myStringBuffer;
+
 }
 
 }
index 4ebd609..c97cadc 100644 (file)
@@ -13,7 +13,7 @@
       <param type="String" name="format" />
        </method>
 
-    <method name="process" returnType="void">
+    <method name="process" returnType="String">
       <param type="String" name="sourceDoc" />
       <param type="String" name="styleSheet" />
     </method>
index 2a011cd..d60e13d 100644 (file)
@@ -57,7 +57,7 @@ jclass instanceClass; // cache class
 jmethodID jbooleansetOutputDirectoryjstringID; // cache method id
 jmethodID voidsetWorkingLanguagejstringID; // cache method id
 jmethodID voidsetExportFormatjstringID; // cache method id
-jmethodID voidprocessjstringjstringID; // cache method id
+jmethodID jstringprocessjstringjstringID; // cache method id
 
 
 /**
@@ -105,7 +105,7 @@ void setWorkingLanguage(char * language);
 
 void setExportFormat(char * format);
 
-void process(char * sourceDoc, char * styleSheet);
+char * process(char * sourceDoc, char * styleSheet);
 
 
                         /**