Java String externalization key missing - java

I used the Eclipse string externalisation wizard to extract strings which are then stored in a configuration file.
Although when I run it I keep getting an NPE whenever a resource or a System.getProperty() is called.
I can't seem to find documentation on this, is there a reason for this?
Many thanks.

You won't find your externalized through System.getProperty().
From the docs of System.getProperty():
Gets the system property indicated by the specified key.
When I run the String externalization wizzard I get a class called Messages on which I can call a .getString method like this:
Messages.getString("Test.STR0")

Related

Spring Boot: Is there a similar way to hold an XML resource of strings and reference them like in Androids framework?

Been browsing around and can't find a simple solution to this.
I have just started using Spring Boot and was trying to see if I can do something similar like in Android's getResources().getString(R.string.mystring)
I may have a changing list of say references to API docs, error code descriptions and many other "static strings" and would like to hold them in once place (i.e. in the res folder as an XML resource) for the same reasons it is recommended in Android (easy changes and easier for translation).
So far I have seen ways to say get an InputStream from a file in the resource folder...but that isn't quite what I want.
I am probably a little late to the party, but once possible solution is to still use a properties file and get the values using org.springframework.core.env.Environment, like this:
#Autowired
Environment env;
Then, you can get the value of an entry in the properties file like this:
env.getProperty("foo.bar");
For a small subset of properties you can store the string in the application.properties use
Application.properties:
my.string.in.properties=test
Inside your bean:
#Value("${my.string.in.properties:my_default_value}")
String myString;
This will load the value "test" in myString. If the key is not present in the properties file, it'll load whatever you place after the :.

How to get method name in Android?

I've been using this instruction to get the name of a method which is currently being used.
currentThread().getStackTrace()[1].getMethodName()
It works fine when I developed Spring Framework or other simple programmings.
However, It seems it works differently in Android Studio. I get time instead of the name of a method.
The reason why I try to use this instruction is for debugging. I used to use
Log.d(TAG, "Method()");
However, The problem when I use this... I should type its method name each. So, To implement this instruction in all the different methods with the same instruction. I found out using currentTrace(). But when I use this on Android Studio. I just get 'geStackTrace' instead of the current method name.
Is there any way to implement it correctly or better way for debugging?
Try this
StackTraceElement[] stacktraceObj = Thread.currentThread().getStackTrace();
stacktraceObj[1].getMethodName();
For further reference, checkout the links
https://www.badprog.com/android-api-getting-the-current-method-name-with-stacktraceelement
https://developer.android.com/reference/java/lang/Throwable.html#getStackTrace()
If typing it out every-time is the issue use the default live templates for log statements.
Use cmd+j(ctrl + j in windows) and look for logd, logi, logw or loge.
By default it prints the method and a colon. You can customize it in preferences.
There's logt for creating a TAG too.

Is there a way to get the IJavaElementDelta object from IResourceDelta?

I'm working on an Eclipse plugin that enables traceability. I am implementing a notification system that tells the user whenever a traced item changes (is removed, renamed or edited) and for that purpose I implemented an IResourceChangeListener, but that doesn't give me all the support that I want for Java elements.
For example, when I rename a Java method inside a .java file, it only tells me which file has been edited, but I would like to have the info about the method as well. I know that this can be achieved with implementing the IElementChangedListener, but is there any way around it? Do I really have to implement two listeners (ResourceListener for other files and ElementChangedListener just for java elements) or can I somehow get the IJavaElementDelta (normally obtained from the ElementChangedListener) from the IResourceDelta? Thanks!
These two deltas are completely unrelated. You need to use both listeners.
Try to check this link example 5. There is some method with this description:
Converts an IResourceDelta and its children into
the corresponding IJavaElementDeltas.
Return whether the delta corresponds to a resource on the classpath.
If it is not a resource on the classpath, it will be added as a non-java
resource by the sender of this method.
So I suppose it could be possible.
The links leads here which should you check ass well. Method public void processJavaDelta(IJavaElementDelta delta)

How to data-bind WTK component in child bxml file

I am using Apache Pivot 2.0.2 and I am trying to build a DesktopApplication.
My problem is that I have a ListView or really - whatever object in my application, defined in bxml file. I can give it an ID or anything - no problem.
But now, how should I obtain this object in Java and affect changes I make to it?
Since my bxml are including other bxml files; after
this.window.open(display);
I have tried to obtain a certain object with:
bxmlSerializer.getNamespace().get("musicPanel");
And i can have the object with everything I put in BXML. I can even change its properties BUT
its not being reflected on the GUI! Nothing changes!
So I thought I could find my object in the
window.getContent();
but I cannot find a method to get an object with ID.
Any help appreciated!
Its hard to explain, but mainly I had to restructure my application and use my own namespace as in the example:
Stock Tracker Example
And it was useful to get the full sourcecode of these examples:
Sourcecode

Java Spring #Value annotation, and parameters

So, I have an environment property that is supposed to reflect what environment my app is running in.
#Value("${environment}")
private String environmentName; //This will be set as sandbox, staging, production
I also have a feature flag (feature is called 'superFeature.enable') that should be set based on what environment the app has been deployed in.
//Config file
superFeature.enable.sandbox=true
superFeature.enable.staging=false
superFeature.enable.production=false
//#Service annotated class containing call to configuration
#Value("${superFeature.enable.{environment}:false}")
private boolean isSuperFeatureEnabled;
At the moment, when I run my app in my sandbox environment, isSuperFeatureEnabled is always false. Is my syntax correct for the above code snippet? Is there something I'm missing?
Shouldn't you have put
#Value("${superFeature.enable.{environmentName}:false}")
there?
This is just a guess, I'm afraid. It looked like an inconsistency there. But then, I don't know in which context and order these two statements above are executed, so I don't know where which variables are known.
I would suggest getting some more information first. Like, what happens if you replace the {environment} with the expected string for your environment, can you get the environment value in your code at that point. I don't know if it is even possible to have this kind of double indirection at all.
It should be the following(environment also enclosed within placeholder syntax starting with $) :
#Value("${superFeature.enable.${environment}:false}")

Categories