// // PageCompiler.cpp // // A compiler that compiler HTML pages containing JSP directives into C++ classes. // // Copyright (c) 2008, Applied Informatics Software Engineering GmbH. // and Contributors. // // SPDX-License-Identifier: BSL-1.0 // #include "Poco/Util/Application.h" #include "Poco/Util/Option.h" #include "Poco/Util/OptionSet.h" #include "Poco/Util/HelpFormatter.h" #include "Poco/Util/AbstractConfiguration.h" #include "Poco/AutoPtr.h" #include "Poco/FileStream.h" #include "Poco/Path.h" #include "Poco/DateTime.h" #include "Poco/DateTimeFormatter.h" #include "Poco/DateTimeFormat.h" #include "Poco/StringTokenizer.h" #include "Poco/LineEndingConverter.h" #include "Poco/Ascii.h" #include "Page.h" #include "PageReader.h" #include "CodeWriter.h" #include "ApacheCodeWriter.h" #include "OSPCodeWriter.h" #include #include #include using Poco::Util::Application; using Poco::Util::Option; using Poco::Util::OptionSet; using Poco::Util::HelpFormatter; using Poco::Util::AbstractConfiguration; using Poco::Util::OptionCallback; using Poco::AutoPtr; using Poco::FileInputStream; using Poco::FileOutputStream; using Poco::Path; using Poco::DateTime; using Poco::DateTimeFormatter; using Poco::DateTimeFormat; using Poco::StringTokenizer; using Poco::OutputLineEndingConverter; class CompilerApp: public Application { public: CompilerApp(): _helpRequested(false), _generateOSPCode(false), _generateApacheCode(false), _emitLineDirectives(true), _escape(false) { } protected: void initialize(Application& self) { loadConfiguration(); // load default configuration files, if present Application::initialize(self); } void defineOptions(OptionSet& options) { Application::defineOptions(options); options.addOption( Option("help", "h", "Display help information on command line arguments.") .required(false) .repeatable(false) .callback(OptionCallback(this, &CompilerApp::handleHelp))); options.addOption( Option("define", "D", "Define a configuration property. A configuration property " "defined with this option can be referenced in the input " "page file, using the following syntax: ${}.") .required(false) .repeatable(true) .argument("=") .callback(OptionCallback(this, &CompilerApp::handleDefine))); options.addOption( Option("config-file", "f", "Load configuration data from the given file.") .required(false) .repeatable(true) .argument("") .callback(OptionCallback(this, &CompilerApp::handleConfig))); options.addOption( Option("output-dir", "o", "Write output files to directory .") .required(false) .repeatable(false) .argument("") .callback(OptionCallback(this, &CompilerApp::handleOutputDir))); options.addOption( Option("header-output-dir", "H", "Write header file to directory .") .required(false) .repeatable(false) .argument("") .callback(OptionCallback(this, &CompilerApp::handleHeaderOutputDir))); options.addOption( Option("header-prefix", "P", "Prepend the given to the header file name in the generated #include directive.") .required(false) .repeatable(false) .argument("") .callback(OptionCallback(this, &CompilerApp::handleHeaderPrefix))); options.addOption( Option("base-file-name", "b", "Use instead of the class name for the output file name.") .required(false) .repeatable(false) .argument("") .callback(OptionCallback(this, &CompilerApp::handleBase))); options.addOption( Option("osp", "O", "Add factory class definition and implementation for use with the Open Service Platform.") .required(false) .repeatable(false) .callback(OptionCallback(this, &CompilerApp::handleOSP))); options.addOption( Option("apache", "A", "Add factory class definition and implementation, and shared library manifest for use with ApacheConnector.") .required(false) .repeatable(false) .callback(OptionCallback(this, &CompilerApp::handleApache))); options.addOption( Option("noline", "N", "Do not include #line directives in generated code.") .required(false) .repeatable(false) .callback(OptionCallback(this, &CompilerApp::handleNoLine))); options.addOption( Option("escape", "e", "Escape special HTML characters (<, >, \", &) in <%= %> expressions.") .required(false) .repeatable(false) .callback(OptionCallback(this, &CompilerApp::handleEscape))); } void handleHelp(const std::string& name, const std::string& value) { _helpRequested = true; stopOptionsProcessing(); } void handleDefine(const std::string& name, const std::string& value) { defineProperty(value); } void handleConfig(const std::string& name, const std::string& value) { loadConfiguration(value); } void handleOutputDir(const std::string& name, const std::string& value) { _outputDir = value; } void handleHeaderOutputDir(const std::string& name, const std::string& value) { _headerOutputDir = value; } void handleHeaderPrefix(const std::string& name, const std::string& value) { _headerPrefix = value; if (!_headerPrefix.empty() && _headerPrefix[_headerPrefix.size() - 1] != '/') _headerPrefix += '/'; } void handleBase(const std::string& name, const std::string& value) { _base = value; } void handleOSP(const std::string& name, const std::string& value) { _generateOSPCode = true; } void handleApache(const std::string& name, const std::string& value) { _generateApacheCode = true; } void handleNoLine(const std::string& name, const std::string& value) { _emitLineDirectives = false; } void handleEscape(const std::string& name, const std::string& value) { _escape = true; } void displayHelp() { HelpFormatter helpFormatter(options()); helpFormatter.setCommand(commandName()); helpFormatter.setUsage("[