I'm using the <liferay-ui:message key="username" /> to get some data from my property file in my portlet.
Is there a Java code equivalent for this tag ?
Thank you.
Actually the question title does not go with question content. To read from portlet.properties you have to do as what Jonny said. But on seeing the content of the question, I assume that what you want is the java code equivalent of the tag output that you have mentioned.
liferay-ui:message DOES NOT read the value from portlet.properties file so PortletProps will not work if that is what you are expecting as it is meant to read value only from portlet.properties and not Language.properties.
You should use methods of LanguageUtil class to get the value.
Yes, it's PortletProps.get(String key).
Hope this helps!
~~ EDIT ~~
The above as Sandeep has pointed out isn't the equivalent of what liferay-ui:message does, but it is the method to retrieve values from a portlet.properties file.
As Sandeep has said you should use LanguageUtil to replicate the functionality in Java code.
If you need merely read property from property file you can:
Properties p = new Properties();
p.load(new FileInputStream("file_with.properties"));
String message = p.getProperty("username");
Related
As I'm trying to automate the API testing process, have to pass the XML file to Read method for example,
Given request read ( varXmlFile )
FYI: XML file is present in the same folder where the feature file exists.
Doing this, its throwing an exception like this
com.intuit.karate.exception.KarateException: called: D:\workspace\APIAutomationDemo\target\test-classes\com\org\features\rci_api_testing.feature, scenario: Get Membership Details, line: 15
javascript evaluation failed: read (varXmlFile )
So Karate doesn't allow this way or can we have any other alternative ?
Suggestion please.
Thanks
Please ensure the variable is set:
* def varXmlFile = 'some-xml-file.xml'
Given request read(varXmlFile)
Or just use normally:
Given request read('some-xml-file.xml')
The problem got solved as in the variable varXmlFile holds the file name along with single quote like this 'SampleXmlRequest.xml'.
So I removed the single quote while returning from the method.
I have opened my ontology so far and now I want to read all the objects and display their properties:
I have the next code:
// Opening the ontology.
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
model.read("file:C:/Users/Antonio/Desktop/myOntology.owl","OWL");
// Going through the ontology
for (Iterator<OntClass> i = model.listClasses();i.hasNext();){
OntClass cls = i.next();
System.out.print(cls.getLocalName()+": ");
// here I want to show the properties
}
which just shows the name of the classes, but not their properties.
I have been reading the documentation but I don't find anything useful.
Hopefully someone can help me.
Thanks in advance.
I'm not sure why you would want all the properties but you can do that easily. First of all make sure to import Jena's OntProperty import org.apache.jena.ontology.OntProperty;
Then you can simply inside your for loop : cls.listDeclaredProperties().toList()
If you want to access the content of a specific property though you could do it this way :
Check your .owl file for the URI which generally looks something like this "http://example.com/ontology#"
So your Java code is going to look like this : OntProperty nameOfProperty = model.getOntProperty("http://example.com/ontology#nameOfyourProperty");
Then inside your loop you could do for example something like this : cls.getProperty(nameOfProperty).getString()
And by the way before reading your file you might want to put it in a try catch statement. Hope that helped.
The code is printing classes because listClasses() returns classes of the ontology. For printing the object properties of the individuals, you can use OWL API
My scenario is to read a file from a file endpoint which contains only key value paris like a property file and take a few data from it based on the key .
Any idea how to do them other that using a custom bean or java component.
I would like to know if this is possible any way in Mule or Camel.
Thanks in advance.
If you want to use a Camel route, to pickup files, then something like this
from("file:inbox")
.convertBodyTo(Properties.class)
.log("The foo value is {${body[foo]}")
.log("The bar value is {${body[bar]}")
What we then need is a type converter from java.io.File -> java.util.Properties. Which we could add to camel-core out of the box.
I logged a ticket to add that type converter out of the box in Camel: https://issues.apache.org/jira/browse/CAMEL-7312
I think to this problem explained, the very easy solution is to use java.util.Properties class. Load the file using Properties class which maintains key value pair only.
I have a requirement in which the parameter is coming as file name that upon debugging I have analyzed, as shown below:
private processfile ( string filepath)
{
}
Now this file path can be like:
C:\abc\file1.txt
or
C:\abc\def\file1.txt
or
C:\ghj\ytr\wer\file1.txt
so I have achieved this with as shown below..
String p = new File(filePath).getName();
Now the issue is that upon printing the parameter p upon console it prints
file1.txt
whereever I was tring that only the file name to be stored and not the extension, such as
P should only contain file1 only and no extenstion. please advise.
What vishal_aim said will work and is correct, but in my opinion it is better to use a library because it will be more expressive and will you won't have to fix all the bugs they've already fixed. Therefore, you should use this:
FilenameUtils.getBaseName(yourFile)
Here's what the documentation says:
a/b/c.txt --> c
a.txt --> a
a/b/c --> c
a/b/c/ --> ""
That last case is something that probably didn't occur to any of us here as a possibility, but the library writers already thought of it for us.
there is no inbuilt API to to get file name without extension. But why cant you trancate it programmatically like:
p = p.substring(0, p.lastIndexOf("."));
I'm trying to read the property values from a bar file created by message broker.
I want to do this via java. The api is here: http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fbe43410_.htm
However, I can only figure out how to get the names of the properties NOT THEIR VALUES by using the deployment descriptor. I can see how to override the value that a property has, but once again, not how to retrieve the value. Another words I can see only how to write to the property not read from it. I want to do both! Call me greedy ;)
If I use the command line based utility: http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Faf03900_.htm
I can get the property values no problem.
But I want to get them via java if at all possible.
Thanks in advance for any help on this!
The problem was I was misunderstanding how the deployment descriptor worked. I thought that when the java API referred to overridden properties it meant ones that were over ridden in my java code. But it actually meant all the properties that had a value in the bar file.
That being said getting the values is not strait forward. You have to get all the identifiers and then pass them to getOverride();
BarFile b = BarFile.loadBarFile("C:\\BarParamTest\\myBar.bar");
DeploymentDescriptor d = b.getDeploymentDescriptor();
Enumeration<String> properties = d.getPropertyIdentifiers();
while(properties.hasMoreElements())
{
String p = properties.nextElement();
System.out.println(p + " = " + d.getOverride(p));
}
or use the following to only list properties that have values
Enumeration<String> properties = d.getOverriddenPropertyIdentifiers();
For some reason settings are not written to file, if they are not overriden or not changed.(the reason is the lack of necessity to keep the property's default value:) ) so the way to get the properties is to know their default values. But I would recommend you to use com.ibm.mq.jar library if you're able to connect to broker to read properties using method
java.util.Properties MessageFlowProxy.Node.getProperties()
from already deployed .bar.