Wish 10187 fulfilled: Add a function to test the existence of a XML object 40/5340/2
Calixte DENIZET [Wed, 2 Nov 2011 14:04:25 +0000 (15:04 +0100)]
Change-Id: I00a8b2d94b2a13b79e4945a2d960d598de4a85d3

scilab/CHANGES_5.4.X
scilab/modules/xml/Makefile.am
scilab/modules/xml/Makefile.in
scilab/modules/xml/help/en_US/xmlIsValidObject.xml [new file with mode: 0644]
scilab/modules/xml/includes/gw_xml.h
scilab/modules/xml/sci_gateway/c/gw_xml.c
scilab/modules/xml/sci_gateway/cpp/sci_xmlIsValidObject.cpp [new file with mode: 0644]
scilab/modules/xml/sci_gateway/xml_gateway.xml
scilab/modules/xml/xml.vcxproj
scilab/modules/xml/xml.vcxproj.filters

index 546396a..a013da8 100644 (file)
@@ -8,9 +8,9 @@ Scilab Desktop:
 * Thanks to this new feature, Scilab confirms its usuability and its strong
 user-oriented approach. Scilab Desktop is the new concept behind Scilab
 window management taking advantage of advanced Flexdock features.
-Out of the box, Scilab is now able to save all windows layouts including the 
+Out of the box, Scilab is now able to save all windows layouts including the
 help browser, the variable browser, the command history, Scinotes and Xcos.
-Through this major improvement, position and size of all the windows will 
+Through this major improvement, position and size of all the windows will
 be preserved from a session to an other.
 
 In this context, a file browser component has been developped and fully
@@ -51,6 +51,7 @@ XML files, validation and writing.
  - xmlValidate - Validate a document in using a DTD, a Relax NG or a Schema.
  - xmlWrite - Write a XML document in a file
  - xmlXPath - Make an XPath query on a XML document
+ - xmlIsValidObject - Test the existence of an XML object
 
 These features have been developped in the context of the OASIS R&D project.
 
@@ -136,7 +137,7 @@ Xcos:
 * bug 8742 fixed - On the Modelica initialization GUI, the error reporting did
                    not work.
 
-* Bug 8743 fixed - On the Modelica initialization GUI, it was impossible to 
+* Bug 8743 fixed - On the Modelica initialization GUI, it was impossible to
                    re-fix the states after a derivatives fix.
 
 * bug 9301 fixed - Exception when one tried to paste a column to replace a
@@ -213,7 +214,7 @@ File input/output:
 * bug 9917 fixed - 'mputl' function crashed with a wrong second parameter.
 
 * bug 10055 fixed - findfiles had a wrong default filter under GNU/Linux
-                    & Mac OS X 
+                    & Mac OS X
 
 New functions
 =============
index 066b927..abeb981 100644 (file)
@@ -75,7 +75,8 @@ GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
                      sci_gateway/cpp/sci_xmlWrite.cpp \
                      sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp \
                      sci_gateway/cpp/sci_xmlValidationFile.cpp \
-                     sci_gateway/cpp/sci_xmlValidate.cpp
+                     sci_gateway/cpp/sci_xmlValidate.cpp \
+                     sci_gateway/cpp/sci_xmlIsValidObject.cpp
 
 libscixml_la_CFLAGS= -I$(srcdir)/includes/ \
                     -I$(top_srcdir)/libs/MALLOC/includes/ \
index ef302c8..97a1274 100644 (file)
@@ -156,7 +156,8 @@ am__objects_5 = libscixml_la-sci_xmlRead.lo \
        libscixml_la-sci_xmlWrite.lo \
        libscixml_la-sci_percent_foo_i_XMLList.lo \
        libscixml_la-sci_xmlValidationFile.lo \
-       libscixml_la-sci_xmlValidate.lo
+       libscixml_la-sci_xmlValidate.lo \
+       libscixml_la-sci_xmlIsValidObject.lo
 am_libscixml_la_OBJECTS = $(am__objects_4) $(am__objects_5)
 libscixml_la_OBJECTS = $(am_libscixml_la_OBJECTS)
 libscixml_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
@@ -561,7 +562,8 @@ GATEWAY_CPP_SOURCES = sci_gateway/cpp/sci_xmlRead.cpp \
                      sci_gateway/cpp/sci_xmlWrite.cpp \
                      sci_gateway/cpp/sci_percent_foo_i_XMLList.cpp \
                      sci_gateway/cpp/sci_xmlValidationFile.cpp \
-                     sci_gateway/cpp/sci_xmlValidate.cpp
+                     sci_gateway/cpp/sci_xmlValidate.cpp \
+                     sci_gateway/cpp/sci_xmlIsValidObject.cpp
 
 libscixml_la_CFLAGS = -I$(srcdir)/includes/ \
                     -I$(top_srcdir)/libs/MALLOC/includes/ \
@@ -717,6 +719,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlGetNsByHref.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlGetNsByPrefix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlGetOpenStreams.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlIsValidObject.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlNs.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlRead.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscixml_la-sci_xmlReadStr.Plo@am__quote@
@@ -1082,6 +1085,13 @@ libscixml_la-sci_xmlValidate.lo: sci_gateway/cpp/sci_xmlValidate.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_la-sci_xmlValidate.lo `test -f 'sci_gateway/cpp/sci_xmlValidate.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlValidate.cpp
 
+libscixml_la-sci_xmlIsValidObject.lo: sci_gateway/cpp/sci_xmlIsValidObject.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libscixml_la-sci_xmlIsValidObject.lo -MD -MP -MF $(DEPDIR)/libscixml_la-sci_xmlIsValidObject.Tpo -c -o libscixml_la-sci_xmlIsValidObject.lo `test -f 'sci_gateway/cpp/sci_xmlIsValidObject.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlIsValidObject.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libscixml_la-sci_xmlIsValidObject.Tpo $(DEPDIR)/libscixml_la-sci_xmlIsValidObject.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_xmlIsValidObject.cpp' object='libscixml_la-sci_xmlIsValidObject.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixml_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libscixml_la-sci_xmlIsValidObject.lo `test -f 'sci_gateway/cpp/sci_xmlIsValidObject.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xmlIsValidObject.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
diff --git a/scilab/modules/xml/help/en_US/xmlIsValidObject.xml b/scilab/modules/xml/help/en_US/xmlIsValidObject.xml
new file mode 100644 (file)
index 0000000..686e0df
--- /dev/null
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="xmlIsValidObject" xml:lang="en">
+  <info>
+    <pubdate>$LastChangedDate$</pubdate>
+  </info>
+  <refnamediv>
+    <refname>xmlIsValidObject</refname>
+    <refpurpose>Test the existence of an XML object</refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>
+      exists = xmlIsValidObject(obj)
+    </synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Arguments</title>
+    <variablelist>
+      <varlistentry>
+        <term>obj</term>
+        <listitem>
+          <para>a XML object or a matrix of strings containing the variables names</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>exists</term>
+        <listitem>
+          <para>a boolean or a matrix of booleans to indicate if the XML objects exist or not</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Description</title>
+    <para>When a XML stream has been closed all the attached objects are destroyed, but on the Scilab side the objects are still alive. So this function is useful to know if an object on the Scilab side is valid or not.</para>
+  </refsection>
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    doc = xmlRead("http://www.w3.org/TR/2009/REC-xml-names-20091208/xml-names-10-3e.xml");
+    r = doc.root
+    // must return %T
+    xmlIsValidObject(r)
+
+    // We close the doc
+    xmlClose(doc);
+
+    // must return [%F %F]
+    xmlIsValidObject(["doc" "r"])
+    ]]></programlisting>
+  </refsection>
+  <refsection role="see also">
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="XMLObjects">XML Objects</link>
+      </member>
+      <member>
+        <link linkend="xmlClose">xmlClose</link>
+      </member>
+    </simplelist>
+  </refsection>
+  <refsection>
+    <title>Author</title>
+    <para>Calixte DENIZET</para>
+  </refsection>
+  <refsection>
+    <title>History</title>
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+        <revremark>XML module introduced.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
index f257bda..2956ffc 100644 (file)
@@ -66,6 +66,7 @@ int sci_xmlSchema(char *fname, unsigned long fname_len);
 int sci_xmlRelaxNG(char *fname, unsigned long fname_len);
 int sci_xmlValidate(char *fname, unsigned long fname_len);
 int sci_percent_XMLValid_p(char *fname, unsigned long fname_len);
+int sci_xmlIsValidObject(char *fname, unsigned long fname_len);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_XML_H__ */
 /*--------------------------------------------------------------------------*/
index 43f7d05..acff650 100644 (file)
@@ -92,7 +92,8 @@ static gw_generic_table Tab[] =
     {sci_xmlSchema, "xmlSchema"},
     {sci_xmlRelaxNG, "xmlRelaxNG"},
     {sci_xmlValidate, "xmlValidate"},
-    {sci_percent_XMLValid_p, "%XMLValid_p"}
+    {sci_percent_XMLValid_p, "%XMLValid_p"},
+    {sci_xmlIsValidObject, "xmlIsValidObject"}
 };
 /*--------------------------------------------------------------------------*/
 int gw_xml(void)
diff --git a/scilab/modules/xml/sci_gateway/cpp/sci_xmlIsValidObject.cpp b/scilab/modules/xml/sci_gateway/cpp/sci_xmlIsValidObject.cpp
new file mode 100644 (file)
index 0000000..c372bd1
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - DIGITEO - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "XMLObject.hxx"
+#include "XMLDocument.hxx"
+#include "XMLElement.hxx"
+#include "XMLNs.hxx"
+#include "XMLAttr.hxx"
+#include "XMLNodeList.hxx"
+
+extern "C"
+{
+#include "gw_xml.h"
+#include "stack-c.h"
+#include "Scierror.h"
+#include "api_scilab.h"
+#include "sciprint.h"
+#include "xml_mlist.h"
+#include "localization.h"
+}
+
+using namespace org_modules_xml;
+
+/*--------------------------------------------------------------------------*/
+int sci_xmlIsValidObject(char * fname, unsigned long fname_len)
+{
+    XMLObject * obj = 0;
+    int id;
+    SciErr err;
+    int * addr = 0;
+    int row = 1;
+    int col = 1;
+    char ** vars = 0;
+    int * exists = 0;
+
+    CheckLhs(1, 1);
+    CheckRhs(1, 1);
+
+    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
+    if (err.iErr)
+    {
+        printError(&err, 0);
+        return 0;
+    }
+
+    if (isStringType(pvApiCtx, addr))
+    {
+        getAllocatedMatrixOfString(pvApiCtx, addr, &row, &col, &vars);
+        exists = new int[row * col];
+        for (int i = 0; i < row * col; i++)
+        {
+            err = getVarAddressFromName(pvApiCtx, const_cast<const char *>(vars[i]), &addr);
+            if (err.iErr)
+            {
+                delete[] exists;
+                freeAllocatedMatrixOfString(row, col, vars);
+                printError(&err, 0);
+                return 0;
+            }
+
+            id = getXMLObjectId(addr, pvApiCtx);
+            exists[i] = XMLObject::getFromId<XMLObject>(id) != 0;
+        }
+
+        freeAllocatedMatrixOfString(row, col, vars);
+    }
+    else
+    {
+        exists = new int[1];
+        id = getXMLObjectId(addr, pvApiCtx);
+        exists[0] = XMLObject::getFromId<XMLObject>(id) != 0;
+    }
+
+    err = createMatrixOfBoolean(pvApiCtx, Rhs + 1, row, col, exists);
+    delete[] exists;
+    if (err.iErr)
+    {
+        printError(&err, 0);
+        return 0;
+    }
+
+    LhsVar(1) = Rhs + 1;
+    PutLhsVar();
+
+    return 0;
+}
index d702645..8c6c97f 100644 (file)
 <PRIMITIVE gatewayId="68" primitiveId="71" primitiveName="xmlRelaxNG" />
 <PRIMITIVE gatewayId="68" primitiveId="72" primitiveName="xmlValidate" />
 <PRIMITIVE gatewayId="68" primitiveId="73" primitiveName="%XMLValid_p" />
+<PRIMITIVE gatewayId="68" primitiveId="74" primitiveName="xmlIsValidObject" />
 </GATEWAY>
index c45ec29..a410363 100644 (file)
     <ClCompile Include="sci_gateway\cpp\sci_xmlGetNsByHref.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlGetNsByPrefix.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlGetOpenStreams.cpp" />
+    <ClCompile Include="sci_gateway\cpp\sci_xmlIsValidObject.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlNs.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlRead.cpp" />
     <ClCompile Include="sci_gateway\cpp\sci_xmlReadStr.cpp" />
index ce41783..645711f 100644 (file)
     <ClCompile Include="src\cpp\XMLValidationSchema.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_gateway\cpp\sci_xmlIsValidObject.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file