I'm having some trouble figuring out how to migrate my code to use org.stringtemplate.v4 . I have a single template file in a 'templates' folder under src/main/resources. Nothing fancy going on. I just need to load the template, set a few attributes, and pass it along in my html response. The problem is, the template is getting bundled into the deployed jar, which means I can't do a normal classpath lookup. Usually in a case like this, I would use an InputStream, but I can't find any way of doing that with the available constructors for ST and STGroup. Does anyone know how to do this? is there an easier way I'm just overlooking?
Here is what my code looks like:
STGroup group = new STGroupDir("templates");
ST template = group.getInstanceOf("smartSubmitResponse");
template.add("errors", results.exceptions.asMap());
template.add("plannedDates", results.plannedDates);
return Response.status(Response.Status.OK).header("smartSubmitFileUrl", url)
.header("errors", errorHeaders.toString()).entity(template.toString()).build();
Currently, it is failing with a null pointer exception since template is not being set correctly.
I finally figured it out. I needed to use org.stringtemplate.v4.STRawGroupDir since my template was using the older format with no wrapping characters. My result ended up looking like this:
STGroup group = new STRawGroupDir("templates",'$','$');
ST template = group.getInstanceOf("smartSubmitResponse");
Related
Hi can somebody help me fix this.
My texture on item is not loading.
I'm modding in eclipse on minecraft 1.9.4
Here is a github page with source code :
Github page
Here is a gist with a console log :
Console log
I hope somebody knows more than me :)
You have a few problems with your code:
Your file is named ItemSlome, it would only search for itemslome, because (Model)ResourceLocations will be turned to lower-case.
The ModelResourceLocation you created is for slome not itemslome.
Your file is in the "ktm" domain, but you did not provide this to the ModelResourceLocation causing it to search in the "minecraft" domain.
Solutions:
Make the model file's name all lower-case
Make the model file's name match your code
Prepend the model name by your domain "ktm:" the ":" is the seperator for the domain part and the resource part or use a ResourceLocation instead of the String.
Additional Hints:
You may want to use ModelLoader.setCustomModelResourceLocation(...) to register your ModelResourceLocation.
Examples for a correct ModelResourceLocation:
new ModelResourceLocation("ktm:slome", "inventory"))
new ModelResourceLocation(new ResourceLocation("ktm","slome"),"inventory")
Both of the above examples will lead to the model being searched at resource_root/ktm/models/item/slome.json
This is how you set the texture of a block you have to put a colon after The Mod Name instead of comma
YourItemName = new Item().setUnlocalizedName("YourItemName")
.setTextureName("ModName:PutTextureNameHere")
.setCreativeTab(TheTabYouWantItToBeIn);
Hey, all! I have a class method who's primary function is to get a Map object, which works fine; however, it's an expensive operation that doesn't need to be done every time, so I'd like to have the results stored in an XML file using JAXB, to be read from for the majority of calls and updated infrequently.
When I run a class that calls it out of NetBeans the file is created no problem with exactly what I want -- but when I have my JSP call the method nothing happens whatsoever, even though the rest of the information is passed normally. I have the feeling it's somehow lacking write privileges, but the file is just in the root directory so I'm not sure what I'm missing. Thanks for the help!
The code looks roughly like this:
public class DataHandler() {
...
public void config() {
MapHolder bucket = new MapHolder();
MapExporter exp = new MapExporter();
Map map = makeMap();
bucket.setMap(map);
exp.exportMap(bucket);
}
}
And then the JSP has a javabean of Datahandler, and this line:
databean.config();
It's probably a tad more fragmented than it needs to be; the whole bucket rigamarole was because I was stumbling trying to learn how to write a map to an xml file. Mapholder is just a class that I wrap around the map, and MapExporter just uses a JAXB marshaller, and it all does work properly when run from NetBeans.
OK turns out I'm just dumb; everything was working fine, the file was just being stored in a folder at the localhost location. Whoops! That'd be my inexperience with web development at work.
I have a json file with data for all the tiles in my game that I store in the assets folder. I try to access and parse it using TileList dataList = json.fromJson(TileList.class, Gdx.file.internal("map-elements/tiles/tiles.json")). This works fine for the desktop version but on the html version, after converting with gwt, I get these errors:
GwtApplication: exception: Error reading file: map-elements/tiles/tiles.json
Error reading file: map-elements/tiles/tiles.json
Couldn't find Type for class 'net.vediogames.archipelo.world.tiles.TileList'
TileList is a simple object that contains an array of TileData which can then be converted into Tile objects. I did it this way to make the json parsing easy.
The solution to the json error is simple. Instead of passing the FileHandle into the json parser, pass the string from the file like this:
TileList dataList = json.fromJson(TileList.class, Gdx.file.internal("map-elements/tiles/tiles.json").readString());
In the end, all I needed to do to solve that issue is add .readString(). As for the Couldn't find Type for class 'net.vediogames.archipelo.world.tiles.TileList' error, I also found a solution but it is more complicated.
JavaScript handles class references differently than Java. So I was not able to use TileList.class without first registering it so LibGDX can generate a Reflection. What I needed to do was add this line into my *.gwt.xml files:
<extend-configuration-property name="gdx.reflect.include" value="net.vediogames.archipelo.world.tiles.TileList" />
If you want a full tutorial about how reflection works and how to include packages or exclude, please view the official LibGDX tutorial here.
Your solution was not working for me, I still got the same error. After some hours of testing I got it to work, using your suggestions and by using the ClassReflection instead of referencing the class itself.
Your example:
TileList dataList = json.fromJson(TileList.class, Gdx.file.internal("map-elements/tiles/tiles.json").readString());
looks in my working code like:
TileList dataList = (TileList) json.fromJson(ClassReflection.forName(TileList.class.getName()), Gdx.file.internal("map-elements/tiles/tiles.json").readString());
This is quite a pain in the a.. but I'm glad it is finally working now.
Stupid problem, but I can't solve it. Java server - glassfish 4. I have in WEB-INF tiles**.xml files. For example I have tiles.xml, tiles2.xml (I can have more in future) and I need to get them. I use the following code
Collection<ApplicationResource> webINFSet =
applicationContext.getResources("/WEB-INF/tiles*.xml")
However it this code returns only one.
System.out.println("Size:"+webINFSet.size());//out Size:1
Where is my mistake?
Looking at org.apache.tiles.request.servlet.ServletApplicationContext at GrepCode, which I assume is the implemenation you get, it seems as if the error (if there is any) is not on your side. The implementation looks like this:
public Collection<ApplicationResource> getResources(String path) {
ArrayList<ApplicationResource> resources = new ArrayList<ApplicationResource>();
resources.add(getResource(path));
return resources;
}
Depending on what you need, you could try and look for the files on the classpath. There is, however, no standard way of searching for resources by name pattern, but you could have a look here: Get a list of resources from classpath directory
I'm attempting to provide a StreamingResponse for files stored under Lifts resources/toserve directory, in order to authorize access for different users.
I can access an image for example with:
localhost:8080/classpath/images/test.jpg
But when I try and actually read the file using scala I keep getting file not found exceptions:
val file = new java.io.FileInputStream("/classpath/images/test.jpg")
Is there a specific method to reading files located on classpath?
Thanks in advance, much appreciated :)
To read resources from the toserve-directory you need to do a call like
LiftRules.getResource("/toserve/images/test.jpg")
If you try to use 'classpath' instead of 'toserve' you will receive an empty box.
By default, Lift uses two different path-prefixes to locate resources either programmatically within the server or through a link-element from HTML. For the former, you will use the 'toserve'-prefix, for the latter the 'classpath'-prefix.
This behavior is specified in the objects net.liftweb.http.LiftRules and net.liftweb.http.ResourceServer. In particular, you can there specify (i.e. replace) the path to the resources. The relevant code is:
/** (from net.liftweb.http.ResourceServer)
* The base package for serving resources. This way, resource names can't be spoofed
*/
var baseResourceLocation = "toserve"
You might also want to look at the following method in LiftRules, which allows you to redefine the name used to serve resources through the server:
/** (from net.liftweb.http.LiftRules)
* The path to handle served resources
*/
#volatile var resourceServerPath = "classpath"
If you wish to use the same prefix to refer both to resources you can use either (or both) of these settings to achieve your purpose.
Have you tried:
LiftRules.getResource("/classpath/images/test.jpg")
That should return a java.net.URL to the item you are looking for.
This may also have more information on what you are looking to do: http://exploring.liftweb.net/master/index-9.html#lst:streaming-download