I'm looking for Java framework like libconfig. I like its simple human readable configuration files and also that I can create complex setting values composed from arrays, lists, groups.
Is there anything similar for Java (not XML) ?
Looks like a simple JSON-esque format; why not just use JSON?
Commons Configuration supports a similarly-formatted config using PropertyListConfiguration.
A Groovy-based ConfigSlurper might be suitable if you're considering JVM, rather than Java-the-language, solutions. JRuby and JavaScript etc. has similar implementations.
Related
Starting to digg into java, coming from c++. I am calling some functions in java from c++ (qt / Android). I miss a way to predefine some tags shareable between both languages avoiding having to define them twice or using strings.
Something like
define OPERATION_START 0X01
in c that would be compilable/readable in java.
Does something like this exists or you know some trick to achieve it?
Edit: How about something like this:
A java file stuff.java with
public enum Stuff{
Table, Apple, Beach, Eye };
and in Cpp+
'#define public
'#include "stuff.java"
'#undef public
Would that work? java would enumerate from 0 as does c, right?
You need something that can read one of the definitions and export the other.
There are a bunch of things that can do this.
Two that I know of are:
SWIG and protocol buffers.
SWIG will read the C++ declarations and generate code with the same things in other languages.
Protocol buffers will read some proprietary declaration and generate code for all the languages you need.
There are probably others as well, and I don't know of anything that is lighter weight than those. BTW, those are also good for defining more complex structures that you want to pass between C++ and java (and other languages).
You could model the shared definitions/enumerations in UML or maybe a DSL and use code generation from there to create matching definitions in Java and C++.
Or you could probably also define them in Java classes and build a generator which uses reflection to generate matching C++ headers from that.
I have a requirement where I need to traverse a hierarchy of Java beans and the hierarchy is different based on the starting point. What would be ideal is if I would be able to use the "dot operator" from JSTL in my Java class.
Then I can have a static map of Strings to describe my hierarchy..something like:
clazz1=attribute1.attribute2
clazz2=attribute3.attribute4
I look up which class and which attributes I need to drill down and go to the root object.
I am coding for it anyway, just checking if BeanUtils etc had such a facility already since seems to me like it can be an useful feature.
You could write some of your code in groovy - it compiles to java bytecode so interoperates perfectly.
This question has almost certainly been asked before, but I ask it anyway because I couldn't find an answer.
Generally, is there a utility class of some sort that assists in common String manipulations associated with URL/URIs?
I'm thinking something like Java SE's URL Class, but maybe a little beefier. I'm looking for something that will let you do simple things, like:
Get a List of query string parameters
An "addParameter" method to add a
query string parameter, and it will
take care of adding "&", "?", and "="
where necessary
Also, encoding
parameter values would be ideal...
Let me know, thanks!
There isn't really (oddly enough) any standard that does it all. There are some bits and pieces, usually buried in various util packages:
I've used http://java.net/projects/urlencodedquerystring/pages/Home to decent effect (for extraction of parameters).
Atlassian's JIRA has http://docs.atlassian.com/jira/4.2/index.html?com/atlassian/jira/util/UrlBuilder.html, which I've actually extracted from the jar and used.
On Android, http://developer.android.com/reference/android/net/Uri.Builder.html is a Uri builder that works pretty well as far as building a url with ease.
And finally, in a classic case of history repeating itself: A good library to do URL Query String manipulation in Java.
I'd really just rip out the android.net.Uri.Builder class and pair that with the urlencodedquerystring class and then carry those around with you, but this does seem like a good candidate for an Apache commons package.
I personnaly like UriBuilder from jax-rs
This does not answer OP's question directly (i.e. it's not a generic, all-around library for URL manipulation), but: if you're going to be using Spring anyway, you might as well consider the ServletUriComponentsBuilder and UriComponentsBuilder classes (see here and here for javadocs).
I believe they are bundled with the spring-web dependency. IMHO, these offer quite a few convenient utility methods for working with URIs, URLs and query parameters.
I was wondering if there was a way to parse XML using E4X, or something similar to E4X.
Does such a framework / library exist?
Thanks!
You can use JavaScript engine Rahino with Java which can handle E4X.
http://blogs.oracle.com/sundararajan/entry/desktop_scripting_applications_with_netbeans
http://www.ibm.com/developerworks/library/ws-ajax1/
Java cannot support dynamically defined members, as JavaScript can.
However, with design-time generation, you can get Java whose members reflect the XML. E.g., JAXB
E4X is a language extension, XML is treated like a primitive. E4X is not just for parsing XML, it's using XML as real types.
This can't be simulated or done with a Java 'framework', it would require a language extension for Java.
There is no parsing XML with E4X. It is a specification that makes XML a native data type. Among browsers, only Firefox supports it as of now.
Here's a list of all known implementations of the spec.
A framework can only mimic making XML access easier, but will not fundamentally change the way we use XML. For example, the SimpleXML extension in PHP simplifies things a lot, but under the hood it converts elements to objects using reflection.
So to have something like E4X, it has to be implemented in the language itself and there is no other non-ECMAScript based language that has this as of now.
Freemarker has the ability to do text escaping using something like this:
<#escape x as x?html>
Foo: ${someVal}
Bar: ${someOtherVal}
</#escape>
xml, xhtml, and html are all built in escapers. Is there a way to register a custom written escaper? I want to generate CSV and have each individual element escaped and that seems like a good mechanism.
I'm trying to do this in Struts 2 if that matters as well.
You seem to be confusing two concepts here. ?xml, ?xhtml and ?html are string built-ins.
<#escape> OTOH is syntax sugar to save you from typing the same expression over and over again. It can be used with any expression, it's not limited to built-ins.
That said, there's unfortunately no built-in for csv string escaping and there's no way to write your own without modifying FreeMarker source (though if you do want to go this way it's pretty straightforward - take a look at freemarker.core.BuiltIn). Perhaps you can by with ?replace using regex or just write / expose an appropriate method and invoke it in your template.
The Javadoc for HtmlEscaper indicates how to instantiate/register that in code (see the header), so I suspect if you implement your own TemplateTransformModel, and register it in a similar fashion then that should work.