Changeset 3456
- Timestamp:
- 08/22/13 12:26:32 (11 years ago)
- Location:
- cats/shared/mod-SLOOT/trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cats/shared/mod-SLOOT/trunk/module.xml
r2029 r3456 51 51 </rewrite> 52 52 <rewrite> 53 <match>active:sloot.dbx-cache\+(.*)</match> 54 <to>active:sloot.accessor+operand@ffcpl:/tools/dbx-cache.acc+$1</to> 55 </rewrite> 56 <rewrite> 53 57 <match>active:sloot.dbx(.*)\+operator@([^+]*)(.*)</match> 54 58 <to>active:javascript+operator@ffcpl:/tools/dbx.js+_operator@$2$1$3</to> -
cats/shared/mod-SLOOT/trunk/nk/src/DBXEngine.java
r2029 r3456 90 90 engine.setStrict(strict); 91 91 92 // determine cache directory 93 String cache = "file:///tmp/sloot-dbx-cache"; 94 if (nkreq.argumentExists("cache")) { 95 String val = "" + cache; 96 String paramURI = nkreq.getArgument("cache"); 97 if (paramURI.startsWith("data:text/plain,")) 98 val = paramURI.substring(("data:text/plain,").length(),paramURI.length()); 99 else { 100 IXAspect param = (IXAspect)nk.sourceAspect(paramURI, IXAspect.class); 101 val = param.getXDA().getText(".",true); 102 } 103 cache = (val.equals("")?cache:val); 104 } 105 engine.setCacheDirectory(cache); 106 92 107 // get the DBX guide document 93 108 IXAspect optxa = (IXAspect)nk.sourceAspect("this:param:operator", IXAspect.class); -
cats/shared/mod-SLOOT/trunk/nk/src/dbx/Engine.java
r2029 r3456 3 3 import com.ten60.netkernel.urii.*; 4 4 import com.ten60.netkernel.urii.aspect.IAspectBoolean; 5 import com.ten60.netkernel.urii.aspect.IAspectReadableBinaryStream; 5 6 import org.ten60.netkernel.xml.xahelper.*; 6 7 import org.ten60.netkernel.xml.xda.*; … … 47 48 protected boolean strict = true; 48 49 50 // cache directory 51 protected String cacheDir = "file:///tmp/sloot-dbx-cache"; 52 49 53 // profile hashmap 50 54 protected SortedMap profiles = new TreeMap(); … … 114 118 } 115 119 120 public void setCacheDirectory(String cacheDir) { 121 this.cacheDir = cacheDir; 122 } 123 116 124 public IURAspect run() throws Exception { 117 125 long start = System.currentTimeMillis(); … … 276 284 // silently move on 277 285 evalChildren(); 286 } else if (action.equals("cache")) { 287 cache(); 278 288 } else 279 289 fatal(guide,"unknown DBX element!"); … … 734 744 735 745 evalChildren(template); 746 } 747 748 /** cache the result */ 749 protected void cache() throws Exception { 750 // check if there is a when attribute 751 String when = guide.getAttributeValue(new QName("when")); 752 if ((when!=null) && (!when.trim().equals(""))) { 753 if (!xpath2boolean(sxdoc.wrap(result),when.trim())) { 754 debug("dbx:cache@when eval["+when.trim()+"][false]"); 755 // no caching 756 evalChildren(); 757 return; 758 } else { 759 debug("dbx:cache@when eval["+when.trim()+"][true]"); 760 } 761 } 762 // get cache id 763 String id = guide.getAttributeValue(new QName("id")); 764 if (id!=null) 765 id = avt(id); 766 if ((id == null) || id.trim().equals("")) 767 fatal(guide,"<dbx:cache/> without a id attribute, or it's empty!"); 768 // lookup the id in the cache 769 String cacheFile = cacheDir+id; 770 try { 771 InputSource is = new InputSource(((IAspectReadableBinaryStream)nk.sourceAspect(cacheFile,IAspectReadableBinaryStream.class)).getInputStream()); 772 XdmNode node = sxdoc.build(new SAXSource(is)); 773 debug("dbx:cache@file["+cacheFile+"][loaded]"); 774 deepCopy(result,node); 775 node=null; 776 is=null; 777 } catch(Exception e) { 778 // TODO: check if its a not found exception, if not throw the exception 779 debug("dbx:cache@file["+cacheFile+"][failed]["+e+"]"); 780 int children = result.getChildNodes().getLength(); 781 evalChildren(); 782 if (result.getChildNodes().getLength() == (children + 1)) { 783 // now cache the result 784 // DOMAspect dom = new DOMAspect(result.getLastChild()); 785 Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); 786 Node root = doc.importNode(result.getLastChild(),true); 787 doc.appendChild(root); 788 DOMAspect dom = new DOMAspect(doc); 789 nk.sinkAspect(cacheFile,dom); 790 debug("dbx:cache@file["+cacheFile+"][saved]"); 791 } else if (result.getChildNodes().getLength() > (children + 1)) { 792 warn(guide,"dbx:cache: more then one new child node has been created, this can't be cached!"); 793 }// else nothing to cache 794 } 736 795 } 737 796
Note: See TracChangeset
for help on using the changeset viewer.