void ATemplateNodeHandler_DADA::_loadStaticData() { AXmlElement::CONST_CONTAINER nodes; m_Services.useConfiguration().getConfigRoot().find("AOS_DadaData/dataset", nodes); AXmlElement::CONST_CONTAINER::iterator it; for (it = nodes.begin(); it != nodes.end(); ++it) { AString strSet; (*it)->getAttributes().get(ASW("name",4), strSet); if (strSet.isEmpty()) ATHROW_EX(*it, AException::InvalidData, ASWNL("AOS_DadaData/dataset missing 'name' parameter")); ADadaDataHolder *pddh = new ADadaDataHolder(); pddh->readData(m_Services, *it); m_Objects.insert(strSet, pddh, true); } nodes.clear(); m_Services.useConfiguration().getConfigRoot().find(ASW("AOS_DadaData/template",21), nodes); it = nodes.begin(); while (it != nodes.end()) { AString str; (*it)->emitContent(str); AString strName; if ((*it)->getAttributes().get(ASW("name",4), strName)) { AFilename filename(m_Services.useConfiguration().getAosBaseDataDirectory(), str, false); if (AFileSystem::exists(filename)) { AFile_Physical file(filename, ASW("r", 1)); file.open(); str.clear(); while (AConstant::npos != file.readLine(str)) { if ('#' != str.at(0, '\x0')) { m_Templates[strName].push_back(str); } str.clear(); } } else m_Services.useLog().add(ARope("AOS_DadaData: Missing file: ")+filename, ALog::EVENT_WARNING); } else m_Services.useLog().add(ASWNL("AOS_DadaData: AOS_DadaData/template missing 'name' attribute"), ALog::EVENT_FAILURE); ++it; } }
AOSContext::ReturnCode AOSOutput_Template::execute(AOSContext& context) { //a_See if extension for mime type set for the template(s) AString ext; if (context.getOutputParams().emitContentFromPath(AOS_BaseModules_Constants::MIME_EXTENSION, ext)) { m_Services.useConfiguration().setMimeTypeFromExt(ext, context); } else { //a_Set content type based on request URL extension m_Services.useConfiguration().setMimeTypeFromExt(context.useRequestUrl().getExtension(), context); } // Iterate parameters and build the template const AXmlElement::CONTAINER& container = context.getOutputParams().getContentContainer(); for (AXmlElement::CONTAINER::const_iterator cit = container.begin(); cit != container.end(); ++cit) { //a_Check "if" condition AString ifElement; if ((*cit)->getAttributes().get(ASW("if",2), ifElement)) { if (ifElement.getSize() > 0) { //a_Check condition, if not met continue with next template if (!context.useModel().exists(ifElement)) { if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG)) context.useEventVisitor().startEvent(ARope("Skipping conditional file template IF ")+ifElement, AEventVisitor::EL_DEBUG); continue; } } } //a_Check "ifnot" condition ifElement.clear(); if ((*cit)->getAttributes().get(ASW("ifnot",5), ifElement)) { if (ifElement.getSize() > 0) { //a_Check condition, if not met continue with next template if (context.useModel().exists(ifElement)) { if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG)) context.useEventVisitor().startEvent(ARope("Skipping conditional file template IFNOT ")+ifElement, AEventVisitor::EL_DEBUG); continue; } } } // // Now we check if this is inlined or filename // AString str(1024, 512); if ((*cit)->getName().equals(AOS_BaseModules_Constants::TEMPLATE)) { if (context.useEventVisitor().isLoggingDebug()) { context.useEventVisitor().startEvent(getClass() + ": Creating new inline template", AEventVisitor::EL_DEBUG); } // Create a new template AAutoPtr<ATemplate> pTemplate(m_Services.createTemplate(), true); // Add inline template str.clear(); (*cit)->emitContent(str); AFile_AString strfile(str); pTemplate->clear(); pTemplate->fromAFile(strfile); pTemplate->process(context.useLuaTemplateContext(), context.useOutputBuffer()); } else if ((*cit)->getName().equals(AOS_BaseModules_Constants::FILENAME)) { // Add filename based template AFilename filename(m_Services.useConfiguration().getAosBaseDataDirectory()); str.clear(); (*cit)->emitContent(str); filename.join(str, false); if (context.useEventVisitor().isLoggingDebug()) { context.useEventVisitor().startEvent(getClass()+": Fetching/parsing template for: "+filename, AEventVisitor::EL_DEBUG); } AAutoPtr<ATemplate> pT(NULL, false); if (ACacheInterface::NOT_FOUND == m_Services.useCacheManager().getTemplate(context, filename, pT)) { //a_Not found add error and continue if (context.useEventVisitor().isLogging(AEventVisitor::EL_WARN)) context.useEventVisitor().startEvent(ARope(getClass())+ASWNL(": Unable to find a template file: ")+filename+ASWNL(", ignoring and continuing"), AEventVisitor::EL_WARN); continue; } //a_Parse template if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG)) { context.useEventVisitor().startEvent(getClass()+"Processing template file: "+filename, AEventVisitor::EL_DEBUG); } AASSERT(this, pT.isNotNull()); pT->process(context.useLuaTemplateContext(), context.useOutputBuffer()); } } return AOSContext::RETURN_OK; }