浏览代码

ISSUE #80: Support custom result display via workunit resources Edit

Updated with suggestions from code review.

Signed-off-by: Anthony Fishbeck Anthony.Fishbeck@lexisnexis.com
Anthony Fishbeck 13 年之前
父节点
当前提交
512725d2ac
共有 4 个文件被更改,包括 40 次插入41 次删除
  1. 26 32
      common/wuwebview/wuwebview.cpp
  2. 8 0
      system/jlib/jfile.cpp
  3. 2 1
      system/jlib/jfile.hpp
  4. 4 8
      system/xmllib/xslprocessor.ipp

+ 26 - 32
common/wuwebview/wuwebview.cpp

@@ -84,10 +84,15 @@ public:
             const void *data = NULL;
             if (loadedDll.getResource(len, data, "RESULT_XSD", (unsigned) id) && len>0)
             {
-                StringBuffer decompressed;
-                decompressResource(len, data, decompressed);
                 buffer.append("<XmlSchema name=\"").append(res.queryProp("@name")).append("\">");
-                buffer.append(decompressed.str());
+                if (res.getPropBool("@compressed"))
+                {
+                    StringBuffer decompressed;
+                    decompressResource(len, data, decompressed);
+                    buffer.append(decompressed.str());
+                }
+                else
+                    buffer.append(len, (const char *)data);
                 buffer.append("</XmlSchema>");
             }
         }
@@ -104,14 +109,10 @@ public:
     void appendManifestResultSchema(IPropertyTree &manifest, const char *resultname, ILoadedDllEntry &loadedDll)
     {
         assertex(!finalized);
-        VStringBuffer xpath("Resource[@name='%s']", resultname);
-        Owned<IPropertyTreeIterator> iter = manifest.getElements(xpath.str());
-        ForEach(*iter)
-        {
-            const char *type=iter->query().queryProp("@type");
-            if (type && strieq(type, "RESULT_XSD"))
-                appendSchemaResource(iter->query(), loadedDll);
-        }
+        VStringBuffer xpath("Resource[@name='%s'][@type='RESULT_XSD']", resultname);
+        IPropertyTree *res=manifest.queryPropTree(xpath.str());
+        if (res)
+            appendSchemaResource(*res, loadedDll);
     }
 
     virtual void beginNode(const char *tag, offset_t startOffset)
@@ -177,13 +178,6 @@ private:
     int datasetLevel;
 };
 
-inline bool isAbsoluteXalanPath(const char *path)
-{
-    if (!path||!*path)
-        return false;
-    return isPathSepChar(path[0])||((path[1]==':')&&(isPathSepChar(path[2])));
-}
-
 class WuWebView : public CInterface,
     implements IWuWebView,
     implements IIncludeHandler
@@ -216,7 +210,7 @@ public:
     virtual void applyResultsXSLT(const char *filename, StringBuffer &out);
     virtual StringBuffer &aggregateResources(const char *type, StringBuffer &content);
 
-    void renderExpandedResults(const char *viewName, StringBuffer &expanded, StringBuffer &out);
+    void renderExpandedResults(const char *viewName, const StringBuffer &expanded, StringBuffer &out);
 
     void appendResultSchemas(WuExpandedResultBuffer &buffer);
     void getResultXSLT(const char *viewName, StringBuffer &xslt, StringBuffer &abspath);
@@ -255,17 +249,8 @@ void WuWebView::calculateResourceIncludePaths()
         Owned<IPropertyTreeIterator> iter = ensureManifest()->getElements("Resource[@filename]");
         ForEach(*iter)
         {
-            const char *filename = iter->query().queryProp("@filename");
             StringBuffer abspath;
-            if (isAbsoluteXalanPath(filename))
-                abspath.append(filename);
-            else
-            {
-                StringBuffer relpath(dir.get());
-                relpath.append(filename);
-                makeAbsolutePath(relpath.str(), abspath);
-            }
-            iter->query().setProp("@res_include_path", abspath.str());
+            iter->query().setProp("@res_include_path", makeAbsolutePath(iter->query().queryProp("@filename"), dir.get(), abspath).str());
         }
         manifestIncludePathsSet=true;
     }
@@ -334,7 +319,16 @@ void WuWebView::getResource(IPropertyTree *res, StringBuffer &content)
         size32_t len = 0;
         const void *data = NULL;
         if (loadedDll->getResource(len, data, res->queryProp("@type"), (unsigned) id) && len>0)
-            decompressResource(len, data, content);
+        {
+            if (res->getPropBool("@compressed"))
+            {
+                StringBuffer decompressed;
+                decompressResource(len, data, content);
+                content.append(decompressed.str());
+            }
+            else
+                content.append(len, (const char *)data);
+        }
     }
 }
 
@@ -353,7 +347,7 @@ StringBuffer &WuWebView::aggregateResources(const char *type, StringBuffer &cont
     VStringBuffer xpath("Resource[@type='%s']", type);
     Owned<IPropertyTreeIterator> iter = ensureManifest()->getElements(xpath.str());
     ForEach(*iter)
-    getResource(&iter->query(), content);
+        getResource(&iter->query(), content);
     return content;
 }
 
@@ -365,7 +359,7 @@ void WuWebView::getResultXSLT(const char *viewName, StringBuffer &xslt, StringBu
         getResource(resource, xslt, abspath);
 }
 
-void WuWebView::renderExpandedResults(const char *viewName, StringBuffer &expanded, StringBuffer &out)
+void WuWebView::renderExpandedResults(const char *viewName, const StringBuffer &expanded, StringBuffer &out)
 {
     StringBuffer xslt;
     StringBuffer rootpath;

+ 8 - 0
system/jlib/jfile.cpp

@@ -4857,6 +4857,14 @@ StringBuffer &makeAbsolutePath(const char *relpath,StringBuffer &out)
     return out.append(path);
 }
 
+StringBuffer &makeAbsolutePath(const char *relpath, const char *basedir, StringBuffer &out)
+{
+    StringBuffer combined;
+    if (basedir && !isAbsolutePath(relpath))
+        relpath = combined.append(basedir).append(relpath);
+    return makeAbsolutePath(relpath, out);
+}
+
 const char *splitRelativePath(const char *full,const char *basedir,StringBuffer &reldir)
 {
     if (basedir&&*basedir) {

+ 2 - 1
system/jlib/jfile.hpp

@@ -529,12 +529,13 @@ inline bool isAbsolutePath(const char *path)
 {   
     if (!path||!*path)
         return false;
-    return isPathSepChar(path[0])||((path[1]==':')&&(path[2]=='\\'));
+    return isPathSepChar(path[0])||((path[1]==':')&&(isPathSepChar(path[2])));
 }
 
 
 
 extern jlib_decl StringBuffer &makeAbsolutePath(const char *relpath,StringBuffer &out);
+extern jlib_decl StringBuffer &makeAbsolutePath(const char *relpath, const char *basedir, StringBuffer &out);
 extern jlib_decl const char *splitRelativePath(const char *full,const char *basedir,StringBuffer &reldir); // removes basedir if matches, returns tail and relative dir
 extern jlib_decl const char *splitDirMultiTail(const char *multipath,StringBuffer &dir,StringBuffer &tail);
 extern jlib_decl StringBuffer &mergeDirMultiTail(const char *dir,const char *tail, StringBuffer &multipath);

+ 4 - 8
system/xmllib/xslprocessor.ipp

@@ -250,17 +250,13 @@ public:
                     std::istringstream theXSLStream(m_xsltext.str());
                     XSLTInputSource xslinput(&theXSLStream);
                     
-                    char baseurl[1031];
-                    strcpy(baseurl, URLPREFIX);
+                    StringBuffer baseurl(URLPREFIX);
                     if (m_rootpath)
-                        strcpy(baseurl, m_rootpath.sget());
+                        baseurl.append(m_rootpath.get());
                     else
-                    {
-                        GetCurrentDirectory(1024, baseurl + strlen(URLPREFIX));
-                        strcpy(baseurl+strlen(baseurl), PATHSEPSTR);
-                    }
+                        appendCurrentDirectory(baseurl, true).append(PATHSEPCHAR);
 
-                    xslinput.setSystemId(XalanDOMString(baseurl).c_str());
+                    xslinput.setSystemId(XalanDOMString(baseurl.str()).c_str());
                     m_XalanTransformer.compileStylesheet((const XSLTInputSource&)xslinput, (const XalanCompiledStylesheet*&)m_CompiledStylesheet);
                 }
             }