File: CS.java

package info (click to toggle)
clearsilver 0.10.5-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,304 kB
  • sloc: ansic: 24,586; python: 4,233; sh: 2,502; cs: 1,429; ruby: 819; java: 735; makefile: 589; perl: 120; lisp: 34; sql: 21
file content (120 lines) | stat: -rw-r--r-- 2,769 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package org.clearsilver;

import java.io.*;
import java.util.*;

public class CS {
  public int csptr;

  protected HDF globalHDF;
  protected HDF localHDF;

  static {
    JNI.loadLibrary();
  }

  public CS(HDF ho) {
    this.globalHDF = null;
    this.localHDF = ho;
    csptr = _init(ho.hdfptr);
  }

  // Construct with global HDF to search if local HDF returns null
  public CS(HDF ho, HDF global) {
    this(ho);

    this.globalHDF = global;
    if (global != null) {
      _setGlobalHdf(csptr,global.hdfptr);
    }
  }

  // Specify a new/different global HDF
  public void setGlobalHDF(HDF global) {
    _setGlobalHdf(csptr,global.hdfptr);
    this.globalHDF = global;
  }

  // Return global hdf in use
  public HDF getGlobalHDF() {
    return this.globalHDF;
  }

  public void close() {
    if (csptr != 0) {
      _dealloc(csptr);
      csptr = 0;
    }
  }

  public void finalize() {
    close();
  }

  public void parseFile(String filename) {
    if (csptr == 0) {
      throw new NullPointerException("CS is closed.");
    }
    _parseFile(csptr, filename, fileLoader != null);
  }

  public void parseStr(String content) {
    if (csptr == 0) {
      throw new NullPointerException("CS is closed.");
    }
    _parseStr(csptr,content);
  }

  public String render() {
    if (csptr == 0) {
      throw new NullPointerException("CS is closed.");
    }
    return _render(csptr);
  }


  protected String fileLoad(String filename) throws IOException,
            FileNotFoundException {
    if (csptr == 0) {
      throw new NullPointerException("CS is closed.");
    }
    CSFileLoader aFileLoader = fileLoader;
    if (aFileLoader == null) {
      throw new NullPointerException("No fileLoader specified.");
    } else {
      String result = aFileLoader.load(localHDF, filename);
      if (result == null) {
        throw new NullPointerException("CSFileLoader.load() returned null");
      }
      return result;
    }
  }

  // The optional CS file loader to use to read in files
  private CSFileLoader fileLoader = null;

  /**
   * Get the file loader in use, if any.
   * @return the file loader in use.
   */
  public CSFileLoader getFileLoader() {
    return fileLoader;
  }

  /**
   * Set the CS file loader to use
   * @param fileLoader the file loader that should be used.
   */
  public void setFileLoader(CSFileLoader fileLoader) {
    this.fileLoader = fileLoader;
  }


  private native int    _init(int ptr);
  private native void   _dealloc(int ptr);
  private native void   _parseFile(int ptr, String filename,
                                   boolean use_cb);
  private native void   _parseStr(int ptr, String content);
  private native String _render(int ptr);
  private native void   _setGlobalHdf(int csptr, int hdfptr);
};