void CFileSpraySoapBindingEx::xsltTransform(const char* xml, const char* sheet, IProperties *params, StringBuffer& ret) { StringBuffer xsl; if (!checkFileExists(sheet)) throw MakeStringException(ECLWATCH_FILE_NOT_EXIST, "Cannot open stylesheet %s",sheet); Owned<IXslProcessor> proc = getXslProcessor(); Owned<IXslTransform> trans = proc->createXslTransform(); trans->setXmlSource(xml, strlen(xml)); trans->loadXslFromFile(sheet); if (params) { Owned<IPropertyIterator> it = params->getIterator(); for (it->first(); it->isValid(); it->next()) { const char *key = it->getPropKey(); //set parameter in the XSL transform skipping over the @ prefix, if any const char* paramName = *key == '@' ? key+1 : key; trans->setParameter(paramName, StringBuffer().append('\'').append(params->queryProp(key)).append('\'').str()); } } trans->transform(ret); }
static void xsltTransform(const char* xml, const char* sheet, IProperties *params, StringBuffer& ret) { if(!checkFileExists(sheet)) throw MakeStringException(-1, "Could not find stylesheet %s.",sheet); Owned<IXslProcessor> proc = getXslProcessor(); Owned<IXslTransform> trans = proc->createXslTransform(); trans->setXmlSource(xml, strlen(xml)); trans->loadXslFromFile(sheet); trans->copyParameters(params); trans->transform(ret); }
bool addResult(const char *res) { if (resultoverflow) return false; StringBuffer t; size32_t reslen = strlen(res); if (xslt&&xslt.length()) { #ifndef NO_XLS if (!xslproc) xslproc.setown(getXslProcessor()); if (!xsltrans&&xslproc) { xsltrans.setown(xslproc->createXslTransform()); if (!xsltrans) return false; xsltrans->setXslSource(xslt.get(), xslt.length()); } xsltrans->setXmlSource(res, reslen); try { xsltrans->transform(t); res = t.str(); reslen = t.length(); } catch (IException *e) { EXCLOG(e,"CSashaCommand::addResult"); e->Release(); return false; } #endif } if (resultsize&&(resultsize+reslen>MAX_RESULT_SIZE)) resultoverflow = true; else { results.append(*new StringAttrItem(res,reslen)); resultsize += reslen; } return !resultoverflow; }
int CFileSpraySoapBindingEx::onGetInstantQuery(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method) { bool permission = true; bool bDownloadFile = false; bool bProcess; StringBuffer sourceLogicalFile; StringBuffer methodbuf; StringBuffer submethod; StringBuffer xsltFileName(getCFD()); xsltFileName.append("smc_xslt/"); if (stricmp(method, "SprayFixedInput")==0) { if (!context.validateFeatureAccess(FILE_SPRAY_URL, SecAccess_Write, false)) permission = false; bProcess = true; xsltFileName.append("fs_sprayForm.xslt"); methodbuf.append("SprayFixed"); } else if(stricmp(method, "SprayVariableInput")==0) { if (!context.validateFeatureAccess(FILE_SPRAY_URL, SecAccess_Write, false)) permission = false; bProcess = true; xsltFileName.append("fs_sprayForm.xslt"); methodbuf.append("SprayVariable"); request->getParameter("submethod", submethod); } else if (stricmp(method, "DesprayInput")==0) { if (!context.validateFeatureAccess(FILE_DESPRAY_URL, SecAccess_Write, false)) permission = false; request->getParameter("sourceLogicalName", sourceLogicalFile); xsltFileName.append("fs_desprayCopyForm.xslt"); methodbuf.append("Despray"); bProcess = true; } else if (stricmp(method, "CopyInput") == 0) { if (!context.validateFeatureAccess(FILE_SPRAY_URL, SecAccess_Write, false)) permission = false; request->getParameter("sourceLogicalName", sourceLogicalFile); xsltFileName.append("fs_desprayCopyForm.xslt"); methodbuf.append("Copy"); bProcess = true; } else if (stricmp(method, "RenameInput") == 0) { if (!context.validateFeatureAccess(FILE_SPRAY_URL, SecAccess_Write, false)) permission = false; request->getParameter("sourceLogicalName", sourceLogicalFile); xsltFileName.append("fs_renameForm.xslt"); methodbuf.append("Rename"); bProcess = true; } else if (stricmp(method, "DownloadFile") == 0) { if (!context.validateFeatureAccess(FILE_SPRAY_URL, SecAccess_Full, false)) permission = false; downloadFile(context, request, response); bDownloadFile = true; bProcess = true; } else bProcess = false; if (bProcess) { if (bDownloadFile) return 0; StringBuffer xml; Owned<IProperties> params(createProperties()); if (!permission) { params->setProp("@method", methodbuf.str()); xml.append("<Environment><ErrorMessage>Permission denied.</ErrorMessage></Environment>"); } else { if(submethod.length() > 0) params->setProp("@submethod", submethod.str()); params->setProp("@method", methodbuf.str()); if (*sourceLogicalFile.str()) { params->setProp("@sourceLogicalName", sourceLogicalFile.str()); Owned<IUserDescriptor> userdesc; StringBuffer username; context.getUserID(username); if(username.length() > 0) { const char* passwd = context.queryPassword(); userdesc.setown(createUserDescriptor()); userdesc->set(username.str(), passwd); try { if (stricmp(method, "CopyInput") == 0) { Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(sourceLogicalFile.str(), userdesc.get()); if(!df) { throw MakeStringException(ECLWATCH_FILE_NOT_EXIST,"Could not find file %s.",sourceLogicalFile.str()); } const char *kind = df->queryAttributes().queryProp("@kind"); if (kind && strcmp(kind,"key")==0) { params->setProp("@compressflag", 0); } else if(df->isCompressed()) { params->setProp("@compressflag", 2); } else { params->setProp("@compressflag", 1); } } } catch (IException *E) { Owned<IXslProcessor> xslp = getXslProcessor(); if (!xslp) throw E; Owned<IMultiException> me = MakeMultiException(); me->append(*E); response->handleExceptions(xslp, me, "FileSpray", method, StringBuffer(getCFD()).append("./smc_xslt/exceptions.xslt").str()); return 0; } } } else { params->setProp("@compressflag", 1); } StringBuffer wuid; request->getParameter("wuid", wuid); Owned<IPropertyTree> pTree = createPTreeForXslt(method, wuid.str()); toXML(pTree, xml, false); } IProperties* requestparams = request->queryParameters(); if(requestparams && requestparams->hasProp("rawxml_")) { response->setContent(xml.str()); response->setContentType(HTTP_TYPE_APPLICATION_XML); } else{ StringBuffer htmlbuf; xsltTransform(xml.str(), xsltFileName.str(), params, htmlbuf); response->setContent(htmlbuf.str()); response->setContentType(HTTP_TYPE_TEXT_HTML_UTF8); } response->send(); return 0; } else return CFileSpraySoapBinding::onGetInstantQuery(context, request, response, service, method); }