diff --git a/ResultGenerator/HtmlResultGenerator.cpp b/ResultGenerator/HtmlResultGenerator.cpp
index 50c1b6a066..78df7b2d8d 100644
--- a/ResultGenerator/HtmlResultGenerator.cpp
+++ b/ResultGenerator/HtmlResultGenerator.cpp
@@ -30,26 +30,26 @@
#include
-#include
+#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
using namespace triagens::basics;
diff --git a/ResultGenerator/Initialise.cpp b/ResultGenerator/Initialise.cpp
new file mode 100644
index 0000000000..69a434d1ec
--- /dev/null
+++ b/ResultGenerator/Initialise.cpp
@@ -0,0 +1,55 @@
+////////////////////////////////////////////////////////////////////////////////
+/// @brief force symbols into programm
+///
+/// @file
+///
+/// DISCLAIMER
+///
+/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
+///
+/// Licensed under the Apache License, Version 2.0 (the "License");
+/// you may not use this file except in compliance with the License.
+/// You may obtain a copy of the License at
+///
+/// http://www.apache.org/licenses/LICENSE-2.0
+///
+/// Unless required by applicable law or agreed to in writing, software
+/// distributed under the License is distributed on an "AS IS" BASIS,
+/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+/// See the License for the specific language governing permissions and
+/// limitations under the License.
+///
+/// Copyright holder is triAGENS GmbH, Cologne, Germany
+///
+/// @author Dr. Frank Celler
+/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany
+////////////////////////////////////////////////////////////////////////////////
+
+#include "Initialise.h"
+
+#include
+
+#include "ResultGenerator/HtmlResultGenerator.h"
+#include "ResultGenerator/JsonResultGenerator.h"
+#include "ResultGenerator/JsonXResultGenerator.h"
+#include "ResultGenerator/PhpResultGenerator.h"
+#include "ResultGenerator/XmlResultGenerator.h"
+
+namespace triagens {
+ namespace rest {
+ void InitialiseResultGenerator () {
+ TRIAGENS_REST_INITIALISE;
+
+ HtmlResultGenerator::initialise();
+ JsonResultGenerator::initialise();
+ JsonXResultGenerator::initialise();
+ PhpResultGenerator::initialise();
+ XmlResultGenerator::initialise();
+ }
+
+
+ void ShutdownResultGenerator () {
+ TRIAGENS_REST_SHUTDOWN;
+ }
+ }
+}
diff --git a/ResultGenerator/Initialise.h b/ResultGenerator/Initialise.h
new file mode 100644
index 0000000000..db9bd5dcf9
--- /dev/null
+++ b/ResultGenerator/Initialise.h
@@ -0,0 +1,99 @@
+////////////////////////////////////////////////////////////////////////////////
+/// @brief force symbols into programm
+///
+/// @file
+///
+/// DISCLAIMER
+///
+/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
+///
+/// Licensed under the Apache License, Version 2.0 (the "License");
+/// you may not use this file except in compliance with the License.
+/// You may obtain a copy of the License at
+///
+/// http://www.apache.org/licenses/LICENSE-2.0
+///
+/// Unless required by applicable law or agreed to in writing, software
+/// distributed under the License is distributed on an "AS IS" BASIS,
+/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+/// See the License for the specific language governing permissions and
+/// limitations under the License.
+///
+/// Copyright holder is triAGENS GmbH, Cologne, Germany
+///
+/// @author Dr. Frank Celler
+/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef TRIAGENS_FYN_REST_INITIALISE2_H
+#define TRIAGENS_FYN_REST_INITIALISE2_H 1
+
+#include
+
+// -----------------------------------------------------------------------------
+// --SECTION-- public macros
+// -----------------------------------------------------------------------------
+
+////////////////////////////////////////////////////////////////////////////////
+/// @addtogroup ResultGenerator
+/// @{
+////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief initialise
+////////////////////////////////////////////////////////////////////////////////
+
+#define TRIAGENS_RESULT_GENERATOR_INITIALISE \
+ do { \
+ triagens::rest::InitialiseResultGenerator(); \
+ } while (0)
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief shutdown
+////////////////////////////////////////////////////////////////////////////////
+
+#define TRIAGENS_RESULT_GENERATOR_SHUTDOWN \
+ do { \
+ triagens::rest::ShutdownResultGenerator(); \
+ } while (0)
+
+////////////////////////////////////////////////////////////////////////////////
+/// @}
+////////////////////////////////////////////////////////////////////////////////
+
+// -----------------------------------------------------------------------------
+// --SECTION-- private functions
+// -----------------------------------------------------------------------------
+
+////////////////////////////////////////////////////////////////////////////////
+/// @addtogroup ResultGenerator
+/// @{
+////////////////////////////////////////////////////////////////////////////////
+
+namespace triagens {
+ namespace rest {
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief initialise function
+////////////////////////////////////////////////////////////////////////////////
+
+ extern void InitialiseResultGenerator ();
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief shutdown function
+////////////////////////////////////////////////////////////////////////////////
+
+ extern void ShutdownResultGenerator ();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// @}
+////////////////////////////////////////////////////////////////////////////////
+
+#endif
+
+// Local Variables:
+// mode: outline-minor
+// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
+// End:
diff --git a/ResultGenerator/JsonResultGenerator.cpp b/ResultGenerator/JsonResultGenerator.cpp
index f6e5cd8ebe..3fbf7d614f 100644
--- a/ResultGenerator/JsonResultGenerator.cpp
+++ b/ResultGenerator/JsonResultGenerator.cpp
@@ -30,26 +30,26 @@
#include
-#include
+#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
using namespace triagens::basics;
diff --git a/ResultGenerator/JsonXResultGenerator.cpp b/ResultGenerator/JsonXResultGenerator.cpp
index 2fcff08e56..13bd5bedc9 100644
--- a/ResultGenerator/JsonXResultGenerator.cpp
+++ b/ResultGenerator/JsonXResultGenerator.cpp
@@ -28,10 +28,10 @@
#include "JsonXResultGenerator.h"
-#include
+#include
#include
#include
-#include
+#include
using namespace triagens::basics;
diff --git a/ResultGenerator/OutputGenerator.cpp b/ResultGenerator/OutputGenerator.cpp
new file mode 100644
index 0000000000..c1ca7940a8
--- /dev/null
+++ b/ResultGenerator/OutputGenerator.cpp
@@ -0,0 +1,114 @@
+////////////////////////////////////////////////////////////////////////////////
+/// @brief output generators
+///
+/// @file
+///
+/// DISCLAIMER
+///
+/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
+///
+/// Licensed under the Apache License, Version 2.0 (the "License");
+/// you may not use this file except in compliance with the License.
+/// You may obtain a copy of the License at
+///
+/// http://www.apache.org/licenses/LICENSE-2.0
+///
+/// Unless required by applicable law or agreed to in writing, software
+/// distributed under the License is distributed on an "AS IS" BASIS,
+/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+/// See the License for the specific language governing permissions and
+/// limitations under the License.
+///
+/// Copyright holder is triAGENS GmbH, Cologne, Germany
+///
+/// @author Dr. Frank Celler
+/// @author Copyright 2010-2011, triAGENS GmbH, Cologne, Germany
+////////////////////////////////////////////////////////////////////////////////
+
+#include "OutputGenerator.h"
+
+#include
+#include
+
+#include "ResultGenerator/HtmlResultGenerator.h"
+#include "ResultGenerator/JsonResultGenerator.h"
+#include "ResultGenerator/JsonXResultGenerator.h"
+#include "ResultGenerator/PhpResultGenerator.h"
+#include "ResultGenerator/XmlResultGenerator.h"
+
+using namespace triagens::basics;
+
+namespace triagens {
+ namespace rest {
+ namespace OutputGenerator {
+ ResultGenerator* resultGenerator (string const& name) {
+ static PhpResultGenerator php;
+ static HtmlResultGenerator html;
+ static JsonResultGenerator json;
+ static JsonXResultGenerator jsonx;
+ static XmlResultGenerator xml;
+
+ if (name == "application/json" || name == "json") {
+ LOGGER_TRACE << "using json result generator";
+ return &json;
+ }
+ else if (name == "application/jsonx" || name == "jsonx") {
+ LOGGER_TRACE << "using json result generator";
+ return &jsonx;
+ }
+ else if (name == "application/php" || name == "php") {
+ LOGGER_TRACE << "using php result generator";
+ return &php;
+ }
+ else if (name == "application/xml" || name == "xml") {
+ LOGGER_TRACE << "using xml result generator";
+ return &xml;
+ }
+ else if (name == "text/html" || name == "html") {
+ LOGGER_TRACE << "using html result generator";
+ return &html;
+ }
+ else {
+ LOGGER_TRACE << "using json result generator per default (accept: '" << name << "')";
+ return &json;
+ }
+ }
+
+
+
+ bool output (string const& format, StringBuffer& buffer, VariantObject* object, string& contentType) {
+ ResultGenerator* generator = resultGenerator(format);
+
+ if (generator == 0) {
+ return false;
+ }
+
+ generator->generate(buffer, object);
+ contentType = generator->contentType();
+
+ return true;
+ }
+
+
+
+ string json (VariantObject* object) {
+ StringBuffer buffer;
+ buffer.initialise();
+
+ string contentType;
+
+ bool ok = output("json", buffer, object, contentType);
+
+ string result;
+
+ if (ok) {
+ result = buffer.c_str();
+ }
+
+ buffer.free();
+
+ return result;
+ }
+ }
+ }
+}
diff --git a/ResultGenerator/OutputGenerator.h b/ResultGenerator/OutputGenerator.h
new file mode 100644
index 0000000000..24ae0b9a11
--- /dev/null
+++ b/ResultGenerator/OutputGenerator.h
@@ -0,0 +1,68 @@
+////////////////////////////////////////////////////////////////////////////////
+/// @brief output generators
+///
+/// @file
+///
+/// DISCLAIMER
+///
+/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
+///
+/// Licensed under the Apache License, Version 2.0 (the "License");
+/// you may not use this file except in compliance with the License.
+/// You may obtain a copy of the License at
+///
+/// http://www.apache.org/licenses/LICENSE-2.0
+///
+/// Unless required by applicable law or agreed to in writing, software
+/// distributed under the License is distributed on an "AS IS" BASIS,
+/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+/// See the License for the specific language governing permissions and
+/// limitations under the License.
+///
+/// Copyright holder is triAGENS GmbH, Cologne, Germany
+///
+/// @author Dr. Frank Celler
+/// @author Copyright 2010-2011, triAGENS GmbH, Cologne, Germany
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef TRIAGENS_FYN_REST_OUTPUT_GENERATOR_H
+#define TRIAGENS_FYN_REST_OUTPUT_GENERATOR_H 1
+
+#include
+
+namespace triagens {
+ namespace basics {
+ class VariantObject;
+ struct StringBuffer;
+ }
+
+ namespace rest {
+ class ResultGenerator;
+
+ namespace OutputGenerator {
+
+ ////////////////////////////////////////////////////////////////////////////////
+ /// @ingroup Utilities
+ /// @brief returns a static result generator
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ResultGenerator* resultGenerator (string const& name);
+
+ ////////////////////////////////////////////////////////////////////////////////
+ /// @ingroup Utilities
+ /// @brief generates output given a format and object
+ ////////////////////////////////////////////////////////////////////////////////
+
+ bool output (string const& format, basics::StringBuffer& buffer, basics::VariantObject*, string& contentType);
+
+ ////////////////////////////////////////////////////////////////////////////////
+ /// @ingroup Utilities
+ /// @brief generates output as json given an object
+ ////////////////////////////////////////////////////////////////////////////////
+
+ string json (basics::VariantObject*);
+ }
+ }
+}
+
+#endif
diff --git a/ResultGenerator/PhpResultGenerator.cpp b/ResultGenerator/PhpResultGenerator.cpp
index 7cc04d142b..9b82bea0c7 100644
--- a/ResultGenerator/PhpResultGenerator.cpp
+++ b/ResultGenerator/PhpResultGenerator.cpp
@@ -30,26 +30,26 @@
#include
-#include
+#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
using namespace triagens::basics;
diff --git a/ResultGenerator/ResultGenerator.cpp b/ResultGenerator/ResultGenerator.cpp
index a236721f37..b57ffbe33d 100644
--- a/ResultGenerator/ResultGenerator.cpp
+++ b/ResultGenerator/ResultGenerator.cpp
@@ -30,23 +30,23 @@
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
using namespace triagens::basics;
diff --git a/ResultGenerator/ResultGenerator.h b/ResultGenerator/ResultGenerator.h
index b1fea21d6f..64fa41a400 100644
--- a/ResultGenerator/ResultGenerator.h
+++ b/ResultGenerator/ResultGenerator.h
@@ -29,7 +29,7 @@
#ifndef TRIAGENS_FYN_RESULT_GENERATOR_RESULT_GENERATOR_H
#define TRIAGENS_FYN_RESULT_GENERATOR_RESULT_GENERATOR_H 1
-#include
+#include
#include
namespace triagens {
diff --git a/ResultGenerator/XmlResultGenerator.cpp b/ResultGenerator/XmlResultGenerator.cpp
index f78b041a51..865256b5da 100644
--- a/ResultGenerator/XmlResultGenerator.cpp
+++ b/ResultGenerator/XmlResultGenerator.cpp
@@ -30,26 +30,26 @@
#include
-#include
+#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
using namespace triagens::basics;