I am trying to integrate Minitemplator (http://www.source-code.biz/MiniTemplator/) to an application of android but i am little lost.
I can access to the template file, the template file is in asset directory and i try to get the file at this way:
Uri path = Uri.parse("file:///android_asset/index.html");
and instantiate the object at this way:
MiniTemplator t = new MiniTemplator(path.getPath());
but it send me an io exception that file or folder doesn't exists.
how is the correct way to send the file to instantiate my minitemplator object?
This is the complete code:
package com.kentverger.minitemplator;
import java.io.File;
import java.io.IOException;
import biz.source_code.miniTemplator.MiniTemplator;
import biz.source_code.miniTemplator.MiniTemplator.TemplateSyntaxException;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.webkit.WebView;
public class Template extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_template);
WebView index = (WebView) findViewById(R.id.indexWebView);
Uri path = Uri.parse("file:///android_asset/index.html");
try {
MiniTemplator t = new MiniTemplator(path.getPath());
t.setVariable("titulo", "Hola mundo generado desde java");
String html_code = t.generateOutput();
index.loadData(html_code, "text/html", null);
} catch (TemplateSyntaxException e) {
Log.d("ERROR 1", e.getMessage());
} catch (IOException e) {
Log.d("ERROR 2", e.getMessage());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_template, menu);
return true;
}
}