/* * * ProLinga-Validate * * Copyright (C) 2002-2008 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Validate. * * ProLinga-Validate is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Validate is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Validate. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "ValCommon.h" #include "VCValidateCommand.hpp" #include #include #include "ValConfig.hpp" #include "VCDocumentParse.hpp" #include "ValMain.hpp" #include #include /* Make sure global handles keep their value */ static PlRepositoryPtr repValStaticPtr; static xmlDocPtr docSyntaxStaticPtr; /* Global handles */ PlRepositoryPtr repValPtr = repValStaticPtr; xmlDocPtr docSyntax = docSyntaxStaticPtr; xmlDocPtr VCProcessError(char *errorString) { xmlDocPtr docValidateResponse; char *validateResponse; /* Generate generic error */ validateResponse = new char[1024]; strcpy(validateResponse, "\n\t\n\t\t\n\t\t\t\n\t\t\t\tError\n\t\t\t\tCan not process Repository Command\n\t\t\t\t"); strcat(validateResponse, errorString); strcat(validateResponse, "\n\t\t\t\n\t\t\n\t\n"); /* Load response into xml doc */ docValidateResponse = xmlParseMemory(validateResponse, strlen(validateResponse)); /* Clean up */ delete validateResponse; /* Return */ return docValidateResponse; } PlValidate::PlValidate() { /* Init */ isValidateOpen = false; } PlValidate::~PlValidate() { /* free */ } void PlValidate::validateOpen(const char *configFileName) { char *confName, *syntaxFile; ConfigValPtr confValPtr; /* Return if already open */ if (isValidateOpen == true) return; /* Get Config */ if (configFileName == NULL) confName = DEF_CONFIG_FILE; else confName = (char *)configFileName; /* Get Config */ confValPtr = new ConfigVal(confName); /* Set RepositoryEndPoint */ //repositoryConfigFile = confValPtr->getStringValue("RepositoryConfigurationFile", DEF_REP_CONFIG_FILE); /* Set Global value */ repValPtr = new PlRepository; repValStaticPtr = repValPtr; /* Open Repository */ repValPtr->repositoryOpen(confName); /* Load Syntax Document */ syntaxFile = confValPtr->getStringValue("LanguageValidationFile", DEF_SYNTAX_FILE); docSyntax = VCParseSyntaxDoc(syntaxFile); docSyntaxStaticPtr = docSyntax; /* Set status */ isValidateOpen = true; /* Free */ delete confValPtr; } void PlValidate::validateClose(void) { /* Return if already closed */ if (isValidateOpen == false) return; /* Set status */ isValidateOpen = false; /* Close Repository */ repValPtr->repositoryClose(); /* Free */ delete repValPtr; xmlFreeDoc(docSyntax); } xmlDocPtr PlValidate::executeCommand(const xmlDocPtr validateRequest) { xmlDocPtr validateResponse; /* Return if validate not open or process command */ if (isValidateOpen == false) validateResponse = VCProcessError("Validate not opened."); else validateResponse = VCValidateCommand(validateRequest); /* Return */ return validateResponse; }