예제 #1
0
파일: PEPConfig.cpp 프로젝트: auldale/pep
void PEPConfig::initialize(string& configFile) throw (std::runtime_error) {

	Lock initLock(m_lock);

	if (m_initCount == INT_MAX) {
		Category::getInstance("PEPConfig").crit("library initialized too many times");
		return;
	}

	if (m_initCount >= 1) {
		++m_initCount;
		return;
	}

	const char* logconf = getenv("SHIBSP_LOGGING");

	string logpath = configFile.substr(0, configFile.find_last_of('/'));
	if (!logconf || !*logconf) {
		if (isEnabled(PEPConfig::OutOfProcess) && !isEnabled(PEPConfig::InProcess))
			logconf = logpath.append("/pepd.logger").c_str();
		else if (isEnabled(PEPConfig::InProcess) && !isEnabled(PEPConfig::OutOfProcess))
			logconf = logpath.append("/mod_pep.logger").c_str();
		else
			logconf = logpath.append("/pepd.logger").c_str();
	}

	XMLToolingConfig::getConfig().log_config(logconf);

	Category& log = Category::getInstance("Config");
	log.debug("library initialization started");

	XMLToolingConfig::getConfig().user_agent = string("PEP");

	if (!XMLToolingConfig::getConfig().init()) {
		log.fatal("failed to initialize XMLTooling library");
		throw(std::runtime_error("failed to initialize XMLTooling library"));
	}

	if (m_PEPInstance) {
		delete m_PEPInstance;
	}
	m_PEPInstance = new PEP();

	statConfigFile(configFile);

	// register listener service factories
	registerListenerServices();

	// Configure DOM parser.
	m_ConfigFileParser->setValidationScheme(XercesDOMParser::Val_Never);
	m_ConfigFileParser->setDoNamespaces(false);
	m_ConfigFileParser->setDoSchema(false);
	m_ConfigFileParser->setLoadExternalDTD(false);

	try {
		m_ConfigFileParser->parse(configFile.c_str());

		// no need to free this pointer - owned by the parent parser object
		DOMDocument* xmlDoc = m_ConfigFileParser->getDocument();

		// Get the top-level element: NAme is "root". No attributes for "root"

		DOMElement* elementRoot = xmlDoc->getDocumentElement();
		if (!elementRoot)
			throw(std::runtime_error("empty XML document"));

		// Parse XML file for tags of interest: "ApplicationSettings"
		// Look one level nested within "root". (child of root)

		DOMNodeList* children = elementRoot->getChildNodes();
		const XMLSize_t nodeCount = children->getLength();

		// For all nodes, children of "root" in the XML tree.

		for (XMLSize_t xx = 0; xx < nodeCount; ++xx) {

			DOMNode* currentNode = children->item(xx);

			if (currentNode->getNodeType() && currentNode->getNodeType() == DOMNode::ELEMENT_NODE) { // is element

			// Found node which is an Element. Re-cast node as element
				DOMElement* currentElement = dynamic_cast<xercesc::DOMElement*>(currentNode);

				if (XMLString::equals(currentElement->getTagName(), APPLICATION_DEFAULTS_ELEM)) {
					parseApplicationConfig(currentElement);
				} else if (XMLString::equals(currentElement->getTagName(), LISTENER_ELEM)) {
					parseListenerServiceConfig(currentElement);
				}
			}
		}
	} catch (xercesc::XMLException& e) {
		char* message = xercesc::XMLString::transcode(e.getMessage());
		ostringstream errBuf;
		errBuf << "Error parsing file: " << message << flush;
		XMLString::release(&message);
	}
	++m_initCount;
}
예제 #2
0
com::typesafe::config::Config* com::typesafe::config::ConfigFactory::defaultApplication(ConfigParseOptions* options)
{
    clinit();
    return parseApplicationConfig(ensureClassLoader(options, u"defaultApplication"_j));
}