1*650b9f74SAndroid Build Coastguard Worker /* 2*650b9f74SAndroid Build Coastguard Worker * Copyright (C) 2010 Google Inc. 3*650b9f74SAndroid Build Coastguard Worker * 4*650b9f74SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*650b9f74SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*650b9f74SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*650b9f74SAndroid Build Coastguard Worker * 8*650b9f74SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*650b9f74SAndroid Build Coastguard Worker * 10*650b9f74SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*650b9f74SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*650b9f74SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*650b9f74SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*650b9f74SAndroid Build Coastguard Worker * limitations under the License. 15*650b9f74SAndroid Build Coastguard Worker */ 16*650b9f74SAndroid Build Coastguard Worker 17*650b9f74SAndroid Build Coastguard Worker package org.clearsilver; 18*650b9f74SAndroid Build Coastguard Worker 19*650b9f74SAndroid Build Coastguard Worker import java.io.Closeable; 20*650b9f74SAndroid Build Coastguard Worker import java.io.IOException; 21*650b9f74SAndroid Build Coastguard Worker import java.util.Date; 22*650b9f74SAndroid Build Coastguard Worker import java.util.TimeZone; 23*650b9f74SAndroid Build Coastguard Worker 24*650b9f74SAndroid Build Coastguard Worker /** 25*650b9f74SAndroid Build Coastguard Worker * This interface establishes the API for an HDF data structure used by 26*650b9f74SAndroid Build Coastguard Worker * Clearsilver templates when rendering content. 27*650b9f74SAndroid Build Coastguard Worker */ 28*650b9f74SAndroid Build Coastguard Worker public interface HDF extends Closeable { 29*650b9f74SAndroid Build Coastguard Worker 30*650b9f74SAndroid Build Coastguard Worker /** 31*650b9f74SAndroid Build Coastguard Worker * Clean up CS object state. 32*650b9f74SAndroid Build Coastguard Worker */ close()33*650b9f74SAndroid Build Coastguard Worker void close(); 34*650b9f74SAndroid Build Coastguard Worker 35*650b9f74SAndroid Build Coastguard Worker /** 36*650b9f74SAndroid Build Coastguard Worker * Loads the contents of the specified HDF file from disk into the current 37*650b9f74SAndroid Build Coastguard Worker * HDF object. The loaded contents are merged with the existing contents. 38*650b9f74SAndroid Build Coastguard Worker */ readFile(String filename)39*650b9f74SAndroid Build Coastguard Worker boolean readFile(String filename) throws IOException; 40*650b9f74SAndroid Build Coastguard Worker 41*650b9f74SAndroid Build Coastguard Worker /** 42*650b9f74SAndroid Build Coastguard Worker * Get the file loader in use, if any. 43*650b9f74SAndroid Build Coastguard Worker * @return the file loader in use. 44*650b9f74SAndroid Build Coastguard Worker */ getFileLoader()45*650b9f74SAndroid Build Coastguard Worker CSFileLoader getFileLoader(); 46*650b9f74SAndroid Build Coastguard Worker 47*650b9f74SAndroid Build Coastguard Worker /** 48*650b9f74SAndroid Build Coastguard Worker * Set the CS file loader to use 49*650b9f74SAndroid Build Coastguard Worker * @param fileLoader the file loader that should be used. 50*650b9f74SAndroid Build Coastguard Worker */ setFileLoader(CSFileLoader fileLoader)51*650b9f74SAndroid Build Coastguard Worker void setFileLoader(CSFileLoader fileLoader); 52*650b9f74SAndroid Build Coastguard Worker 53*650b9f74SAndroid Build Coastguard Worker /** 54*650b9f74SAndroid Build Coastguard Worker * Serializes HDF contents to a file (readable by readFile) 55*650b9f74SAndroid Build Coastguard Worker */ writeFile(String filename)56*650b9f74SAndroid Build Coastguard Worker boolean writeFile(String filename) throws IOException; 57*650b9f74SAndroid Build Coastguard Worker 58*650b9f74SAndroid Build Coastguard Worker /** 59*650b9f74SAndroid Build Coastguard Worker * Parses/loads the contents of the given string as HDF into the current 60*650b9f74SAndroid Build Coastguard Worker * HDF object. The loaded contents are merged with the existing contents. 61*650b9f74SAndroid Build Coastguard Worker */ readString(String data)62*650b9f74SAndroid Build Coastguard Worker boolean readString(String data); 63*650b9f74SAndroid Build Coastguard Worker 64*650b9f74SAndroid Build Coastguard Worker /** 65*650b9f74SAndroid Build Coastguard Worker * Serializes HDF contents to a string (readable by readString) 66*650b9f74SAndroid Build Coastguard Worker */ writeString()67*650b9f74SAndroid Build Coastguard Worker String writeString(); 68*650b9f74SAndroid Build Coastguard Worker 69*650b9f74SAndroid Build Coastguard Worker /** 70*650b9f74SAndroid Build Coastguard Worker * Retrieves the integer value at the specified path in this HDF node's 71*650b9f74SAndroid Build Coastguard Worker * subtree. If the value does not exist, or cannot be converted to an 72*650b9f74SAndroid Build Coastguard Worker * integer, default_value will be returned. 73*650b9f74SAndroid Build Coastguard Worker */ getIntValue(String hdfName, int defaultValue)74*650b9f74SAndroid Build Coastguard Worker int getIntValue(String hdfName, int defaultValue); 75*650b9f74SAndroid Build Coastguard Worker 76*650b9f74SAndroid Build Coastguard Worker /** 77*650b9f74SAndroid Build Coastguard Worker * Retrieves the value at the specified path in this HDF node's subtree. 78*650b9f74SAndroid Build Coastguard Worker */ getValue(String hdfName, String defaultValue)79*650b9f74SAndroid Build Coastguard Worker String getValue(String hdfName, String defaultValue); 80*650b9f74SAndroid Build Coastguard Worker 81*650b9f74SAndroid Build Coastguard Worker /** 82*650b9f74SAndroid Build Coastguard Worker * Sets the value at the specified path in this HDF node's subtree. 83*650b9f74SAndroid Build Coastguard Worker */ setValue(String hdfName, String value)84*650b9f74SAndroid Build Coastguard Worker void setValue(String hdfName, String value); 85*650b9f74SAndroid Build Coastguard Worker 86*650b9f74SAndroid Build Coastguard Worker /** 87*650b9f74SAndroid Build Coastguard Worker * Remove the specified subtree. 88*650b9f74SAndroid Build Coastguard Worker */ removeTree(String hdfName)89*650b9f74SAndroid Build Coastguard Worker void removeTree(String hdfName); 90*650b9f74SAndroid Build Coastguard Worker 91*650b9f74SAndroid Build Coastguard Worker /** 92*650b9f74SAndroid Build Coastguard Worker * Links the src hdf name to the dest. 93*650b9f74SAndroid Build Coastguard Worker */ setSymLink(String hdfNameSrc, String hdfNameDest)94*650b9f74SAndroid Build Coastguard Worker void setSymLink(String hdfNameSrc, String hdfNameDest); 95*650b9f74SAndroid Build Coastguard Worker 96*650b9f74SAndroid Build Coastguard Worker /** 97*650b9f74SAndroid Build Coastguard Worker * Export a date to a clearsilver tree using a specified timezone 98*650b9f74SAndroid Build Coastguard Worker */ exportDate(String hdfName, TimeZone timeZone, Date date)99*650b9f74SAndroid Build Coastguard Worker void exportDate(String hdfName, TimeZone timeZone, Date date); 100*650b9f74SAndroid Build Coastguard Worker 101*650b9f74SAndroid Build Coastguard Worker /** 102*650b9f74SAndroid Build Coastguard Worker * Export a date to a clearsilver tree using a specified timezone 103*650b9f74SAndroid Build Coastguard Worker */ exportDate(String hdfName, String tz, int tt)104*650b9f74SAndroid Build Coastguard Worker void exportDate(String hdfName, String tz, int tt); 105*650b9f74SAndroid Build Coastguard Worker 106*650b9f74SAndroid Build Coastguard Worker /** 107*650b9f74SAndroid Build Coastguard Worker * Retrieves the HDF object that is the root of the subtree at hdfpath, or 108*650b9f74SAndroid Build Coastguard Worker * null if no object exists at that path. 109*650b9f74SAndroid Build Coastguard Worker */ getObj(String hdfpath)110*650b9f74SAndroid Build Coastguard Worker HDF getObj(String hdfpath); 111*650b9f74SAndroid Build Coastguard Worker 112*650b9f74SAndroid Build Coastguard Worker /** 113*650b9f74SAndroid Build Coastguard Worker * Retrieves the HDF for the first child of the root of the subtree 114*650b9f74SAndroid Build Coastguard Worker * at hdfpath, or null if no child exists of that path or if the 115*650b9f74SAndroid Build Coastguard Worker * path doesn't exist. 116*650b9f74SAndroid Build Coastguard Worker */ getChild(String hdfpath)117*650b9f74SAndroid Build Coastguard Worker HDF getChild(String hdfpath); 118*650b9f74SAndroid Build Coastguard Worker 119*650b9f74SAndroid Build Coastguard Worker /** 120*650b9f74SAndroid Build Coastguard Worker * Return the root of the tree where the current node lies. If the 121*650b9f74SAndroid Build Coastguard Worker * current node is the root, return this. Implementations may not 122*650b9f74SAndroid Build Coastguard Worker * necessarily return the same instance of {@code HDF} every time. 123*650b9f74SAndroid Build Coastguard Worker * Use {@link #belongsToSameRoot(HDF)} to check if two {@code HDF}s 124*650b9f74SAndroid Build Coastguard Worker * belong to the same root. 125*650b9f74SAndroid Build Coastguard Worker */ getRootObj()126*650b9f74SAndroid Build Coastguard Worker HDF getRootObj(); 127*650b9f74SAndroid Build Coastguard Worker 128*650b9f74SAndroid Build Coastguard Worker /** 129*650b9f74SAndroid Build Coastguard Worker * Checks if the given hdf object belongs to the same root HDF object 130*650b9f74SAndroid Build Coastguard Worker * as this one. 131*650b9f74SAndroid Build Coastguard Worker * 132*650b9f74SAndroid Build Coastguard Worker * @param hdf The hdf object to compare to. 133*650b9f74SAndroid Build Coastguard Worker * @throws IllegalArgumentException If the supplied hdf object is from 134*650b9f74SAndroid Build Coastguard Worker * a different implementation (e.g. mixing JNI and jsilver). 135*650b9f74SAndroid Build Coastguard Worker */ belongsToSameRoot(HDF hdf)136*650b9f74SAndroid Build Coastguard Worker boolean belongsToSameRoot(HDF hdf); 137*650b9f74SAndroid Build Coastguard Worker 138*650b9f74SAndroid Build Coastguard Worker /** 139*650b9f74SAndroid Build Coastguard Worker * Retrieves the HDF object that is the root of the subtree at 140*650b9f74SAndroid Build Coastguard Worker * hdfpath, create the subtree if it doesn't exist 141*650b9f74SAndroid Build Coastguard Worker */ getOrCreateObj(String hdfpath)142*650b9f74SAndroid Build Coastguard Worker HDF getOrCreateObj(String hdfpath); 143*650b9f74SAndroid Build Coastguard Worker 144*650b9f74SAndroid Build Coastguard Worker /** 145*650b9f74SAndroid Build Coastguard Worker * Returns the name of this HDF node. The root node has no name, so 146*650b9f74SAndroid Build Coastguard Worker * calling this on the root node will return null. 147*650b9f74SAndroid Build Coastguard Worker */ objName()148*650b9f74SAndroid Build Coastguard Worker String objName(); 149*650b9f74SAndroid Build Coastguard Worker 150*650b9f74SAndroid Build Coastguard Worker /** 151*650b9f74SAndroid Build Coastguard Worker * Returns the value of this HDF node, or null if this node has no value. 152*650b9f74SAndroid Build Coastguard Worker * Every node in the tree can have a value, a child, and a next peer. 153*650b9f74SAndroid Build Coastguard Worker */ objValue()154*650b9f74SAndroid Build Coastguard Worker String objValue(); 155*650b9f74SAndroid Build Coastguard Worker 156*650b9f74SAndroid Build Coastguard Worker /** 157*650b9f74SAndroid Build Coastguard Worker * Returns the child of this HDF node, or null if there is no child. 158*650b9f74SAndroid Build Coastguard Worker * Use this in conjunction with objNext to walk the HDF tree. Every node 159*650b9f74SAndroid Build Coastguard Worker * in the tree can have a value, a child, and a next peer. 160*650b9f74SAndroid Build Coastguard Worker */ objChild()161*650b9f74SAndroid Build Coastguard Worker HDF objChild(); 162*650b9f74SAndroid Build Coastguard Worker 163*650b9f74SAndroid Build Coastguard Worker /** 164*650b9f74SAndroid Build Coastguard Worker * Returns the child of this HDF node, or null if there is no child. 165*650b9f74SAndroid Build Coastguard Worker * Use this in conjunction with objNext to walk the HDF tree. Every node 166*650b9f74SAndroid Build Coastguard Worker * in the tree can have a value, a child, and a next peer. 167*650b9f74SAndroid Build Coastguard Worker */ objNext()168*650b9f74SAndroid Build Coastguard Worker HDF objNext(); 169*650b9f74SAndroid Build Coastguard Worker 170*650b9f74SAndroid Build Coastguard Worker /** 171*650b9f74SAndroid Build Coastguard Worker * Deep copy of the contents of the source HDF structure to this HDF 172*650b9f74SAndroid Build Coastguard Worker * starting at the specified HDF path node. 173*650b9f74SAndroid Build Coastguard Worker * <p> 174*650b9f74SAndroid Build Coastguard Worker * This method copies over the attributes and value of the node and recurses 175*650b9f74SAndroid Build Coastguard Worker * through all the children of the source node. Any symlink in the source 176*650b9f74SAndroid Build Coastguard Worker * node becomes a symlink in the copy. 177*650b9f74SAndroid Build Coastguard Worker * <p> 178*650b9f74SAndroid Build Coastguard Worker * @param hdfpath the node within this HDF where the source structure should 179*650b9f74SAndroid Build Coastguard Worker * be copied to. 180*650b9f74SAndroid Build Coastguard Worker * @param src the source HDF to copy over. 181*650b9f74SAndroid Build Coastguard Worker */ copy(String hdfpath, HDF src)182*650b9f74SAndroid Build Coastguard Worker void copy(String hdfpath, HDF src); 183*650b9f74SAndroid Build Coastguard Worker 184*650b9f74SAndroid Build Coastguard Worker /** 185*650b9f74SAndroid Build Coastguard Worker * Generates a string representing the content of the HDF tree rooted at 186*650b9f74SAndroid Build Coastguard Worker * this node. 187*650b9f74SAndroid Build Coastguard Worker */ dump()188*650b9f74SAndroid Build Coastguard Worker String dump(); 189*650b9f74SAndroid Build Coastguard Worker } 190*650b9f74SAndroid Build Coastguard Worker 191