summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am8
-rw-r--r--configure.ac7
-rw-r--r--src/render_xml.cc31
-rw-r--r--src/xsl_processor.cc76
-rw-r--r--src/xsl_processor.hh28
5 files changed, 150 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index ac4aa61..fdde7e6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,6 +19,14 @@ bin_sudo_users_SCRIPTS = scripts/vyatta-show-log
bin_sudo_users_SCRIPTS += scripts/vyatta-show-log-all
bin_sudo_users_SCRIPTS += scripts/vyatta-show-log-file
+sbin_PROGRAMS = src/render_xml
+
+src_render_xml_SOURCES = src/render_xml.cc
+src_render_xml_SOURCES += src/xsl_processor.cc
+src_render_xml_SOURCES += src/xsl_processor.hh
+src_render_xml_CPPFLAGS = -I$(srcdir)/src
+src_render_xml_LDADD = -lsablot
+
cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \
cpio -0pd
diff --git a/configure.ac b/configure.ac
index 30d16dd..c47e093 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,6 +15,13 @@ AC_CONFIG_AUX_DIR([config])
AM_INIT_AUTOMAKE([gnu no-dist-gzip dist-bzip2 subdir-objects])
AC_PREFIX_DEFAULT([/opt/vyatta])
+AC_PROG_CC
+AM_PROG_AS
+AM_PROG_CC_C_O
+AC_PROG_LIBTOOL
+AC_PROG_LEX
+AC_PROG_YACC
+
AC_ARG_ENABLE([nostrip],
AC_HELP_STRING([--enable-nostrip],
[include -nostrip option during packaging]),
diff --git a/src/render_xml.cc b/src/render_xml.cc
new file mode 100644
index 0000000..a213387
--- /dev/null
+++ b/src/render_xml.cc
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <iostream>
+#include <string>
+
+#include "xsl_processor.hh"
+
+using namespace std;
+
+int
+main(int argc, char* argv[])
+{
+ if (argc < 2) {
+ printf("usage: %s <xsl_file>\n", argv[0]);
+ printf(" (takes XML from stdin)\n");
+ exit(1);
+ }
+
+ char buf[2048];
+ string xml_str = "";
+ while (fgets(buf, 2048, stdin) != NULL) {
+ xml_str += buf;
+ }
+
+ string xsl_file(argv[1]);
+ list<pair<string,string> > listParams;
+ XSLProcessor xsl_processor(false);
+ cout << xsl_processor.transform(xml_str, xsl_file, listParams) << endl;
+
+ exit(0);
+}
diff --git a/src/xsl_processor.cc b/src/xsl_processor.cc
new file mode 100644
index 0000000..f40b611
--- /dev/null
+++ b/src/xsl_processor.cc
@@ -0,0 +1,76 @@
+/**
+ * Module: xsl_processor.cc
+ *
+ * Author: Michael Larson
+ * Date: 2005
+ */
+#include <string>
+#include <iostream>
+#include <sablot.h>
+#include "xsl_processor.hh"
+
+using namespace std;
+
+/**
+ *
+ **/
+XSLProcessor::XSLProcessor(bool debug) : _debug(debug)
+{
+
+}
+
+/**
+ *
+ **/
+XSLProcessor::~XSLProcessor()
+{
+
+}
+
+/**
+ *
+ **/
+std::string
+XSLProcessor::transform(const string &input, const string &xsl, const list<pair<string,string> > & listParams)
+{
+ if (_debug) {
+ cout << "input to xsl processor: " << endl << input << endl << xsl << endl;
+ }
+
+ //for now we'll dump this into a file, but this will have to change soon.
+ string formatted_output;
+
+ //example below from http://www.gingerall.org/ga/html/sablot/sparse-frameset.html
+ SablotSituation S;
+ SablotHandle proc;
+ SDOM_Document xml;
+
+ SablotCreateSituation(&S);
+
+ SablotParseBuffer(S, input.c_str(), &xml);
+
+ SablotCreateProcessorForSituation(S, &proc);
+ SablotAddArgTree(S, proc, "data", xml);
+ list<pair<string, string> >::const_iterator i = listParams.begin();
+ list<pair<string, string> >::const_iterator iEnd = listParams.end();
+ while (i != iEnd) {
+ SablotAddParam(S, proc, i->first.c_str(), i->second.c_str());
+ i++;
+ }
+ SablotRunProcessorGen(S, proc, xsl.c_str(), "arg:/data", "arg:/out");
+
+ char *result;
+ SablotGetResultArg(proc, "arg:/out", &result);
+
+ formatted_output = result;
+
+ //now strip away the first line
+ int pos = formatted_output.find("\n");
+ formatted_output = formatted_output.substr(pos + 1, formatted_output.length() - pos - 1);
+
+ SablotFree(result);
+ SablotDestroyProcessor(proc);
+ SablotDestroySituation(S);
+
+ return formatted_output;
+}
diff --git a/src/xsl_processor.hh b/src/xsl_processor.hh
new file mode 100644
index 0000000..ac9b047
--- /dev/null
+++ b/src/xsl_processor.hh
@@ -0,0 +1,28 @@
+/**
+ * Module: xsl_processor.hh
+ *
+ * Author: Michael Larson
+ * Date: 2005
+ */
+#ifndef __XSL_PROCESSOR_HH__
+#define __XSL_PROCESSOR_HH__
+
+#include <list>
+#include <string>
+#include <utility>
+
+
+class XSLProcessor
+{
+public:
+ XSLProcessor(bool debug);
+ ~XSLProcessor();
+
+ std::string
+ transform(const std::string &input, const std::string &xsl, const std::list<std::pair<std::string, std::string> > & listParams);
+
+private:
+ bool _debug;
+};
+
+#endif //__XSL_PROCESSOR_HH__