I have an url, that contains Russian symbols and for encoding/decoding I use URIUtil.encodeQuery/decode. For example this piece of code
String url =
"https://dom.sakh.com/flat/sell?s[layout][]=102 серия&s[layout][]=138 серия&s[layout][]=306 серия&s[layout][]=97 серия&s[layout][]=97-С серия&s[layout][]=брежневка&s[layout][]=гостинка&s[layout][]=индивидуальная&s[layout][]=новая пл.&s[layout][]=сталинка&s[layout][]=хрущевка&s[price][min]=0&s[price][max]=10000000000";
System.out.println(URIUtil.encodeQuery(url));
It will display the following string
https://dom.sakh.com/flat/sell?s%5Blayout%5D%5B%5D=102%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=138%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=306%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=97%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=97-%D0%A1%20%D1%81%D0%B5%D1%80%D0%B8%D1%8F&s%5Blayout%5D%5B%5D=%D0%B1%D1%80%D0%B5%D0%B6%D0%BD%D0%B5%D0%B2%D0%BA%D0%B0&s%5Blayout%5D%5B%5D=%D0%B3%D0%BE%D1%81%D1%82%D0%B8%D0%BD%D0%BA%D0%B0&s%5Blayout%5D%5B%5D=%D0%B8%D0%BD%D0%B4%D0%B8%D0%B2%D0%B8%D0%B4%D1%83%D0%B0%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F&s%5Blayout%5D%5B%5D=%D0%BD%D0%BE%D0%B2%D0%B0%D1%8F%20%D0%BF%D0%BB.&s%5Blayout%5D%5B%5D=%D1%81%D1%82%D0%B0%D0%BB%D0%B8%D0%BD%D0%BA%D0%B0&s%5Blayout%5D%5B%5D=%D1%85%D1%80%D1%83%D1%89%D0%B5%D0%B2%D0%BA%D0%B0&s%5Bprice%5D%5Bmin%5D=0&s%5Bprice%5D%5Bmax%5D=5000000000
And if I apply a method URIUtil.decode to this url i will get back:
https://dom.sakh.com/flat/sell?s[layout][]=102 серия&s[layout][]=138 серия&s[layout][]=306 серия&s[layout][]=97 серия&s[layout][]=97-С серия&s[layout][]=брежневка&s[layout][]=гостинка&s[layout][]=индивидуальнаяs[layout][]=новая пл.&s[layout][]=сталинка&s[layout][]=хрущевка&s[price][min]=0&s[price][max]=10000000000
But these methods are a bit old (httpclient's (3.1) URIUtil.encodeQuery() is gone in org.apache.httpcomponents (4.4.1) and i am trying to replace thsese methods). So my question is how to change my code saving the behavior? What to use? Provide an example, please, if it is possible.
Related
I have a Java class that mainly contains strings. It does not have a layout as it is neither a Fragment nor an Activity. It is more used as an auxilliary class. I would like to assign the String values in the class by using the Resource strings as I would like to automatically translate the Strings. Howvever, I can't access the string resources from Java. I use the following code:
static String more = getString(R.string.more);
And in the XML file I have the ressource:
<string name="more">More</string>
I get the error message
Cannot resolve method 'getString'
I also tried static String more = getContext().getString(R.string.more);
but I got the error message:
Cannot resolve method 'getContext'
Would anyone mind helping me on that? I'd appreciate every comment.
Update: I tried to use the answer from "MikaelM"
Resources.getSystem().getString(R.string.more)
However, I get an "exception in initializer error" and when I use the initial String again, I do not get this error. So I still can't get the String from the ressource. DO you have an idea what I can do? I'd appreciate every further comment.
So the error is caused by "Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f120038"
The strange thing is that the resource in fact exists (I checked this several times).
getString(R.string...
is not the same as
Resources.getSystem().getString(android.R.string...
Only the second variant you can use in the static context. Alas, you can get this way only system resources.
If you need to get your own resources, no one-line solution exists. Use https://stackoverflow.com/a/4391811/715269 solution of #Cristian. And notice: it is a very good solution, even more, it is the solution meant to be used by the creators of Android.
You should be able to get your string with:
Resources.getSystem().getString(R.string.more)
See more here, getString Outside of a Context or Activity
Recently,When I plan to rewrite mine company program. I use the RxJava+OkHttp+Retrofit. But I have a problem.
Our application has only one access interface which can provide the base address for all modules. The format is as follows.
My intention is to dynamically replace baseurl with interceptors, the code reads as follows:
That's my code but I found a question,the converted URL becomes so:
www.xxapi.com:80/authorize/login/{#version code} (This is wrong).
This is wrong. This version field should be behind the base address.The correct url like this:
www.xxapi.com:80/{#version code}/authorize/login (This is right).
I've tried many ways, and I can't change the location of the version field.
I really don't know how to go on,I'm sorry.
Replace the call to addPathSegment(version) with a call to setPathSegment(0, version).
https://square.github.io/okhttp/3.x/okhttp/okhttp3/HttpUrl.Builder.html#setPathSegment-int-java.lang.String-
Can anyone give me at least one idea to how can I connect java with protoge?
how can I access OWL using jena API in java?!
The Jena website has plenty of tutorials available. If you have difficulties getting started, please post the code that does not work and we'll help you along.
First tutorial here
// some definitions
static String personURI = "http://somewhere/JohnSmith";
static String fullName = "John Smith";
// create an empty Model
Model model = ModelFactory.createDefaultModel();
// create the resource
Resource johnSmith = model.createResource(personURI);
// add the property
johnSmith.addProperty(VCARD.FN, fullName);
In order to make this work, you'll need the right imports. Assuming that the Java technicalities are not a problem, this example shows how to create a statement and add it to a model, i.e., an rdf file.
From the same page you can get to more complex material, including OWL tutorials.
You have not mentioned which task you're trying to carry out. Can you describe it?
I want to write Java API code using playframework! (I'm using the Eclipse IDE.)
What would a sample API look like for insertion and selection?
How do I assign URLs in a routes file?
This answer applies to version 3 of the Play framework.
Here is a sample route file configuration to show a page. In this example, you can visit http://yoursite.com/1 , which will call controllers.Application.show("1").
# Extract the page parameter from the path.
# i.e. http://myserver.com/index
GET /:page controllers.Application.show(page)
SELECTION
Here is the corresponding show method definition in the controllers.Application controller:
public Result show(String page) {
String content = Page.getContentOf(page);
response().setContentType("text/html");
return ok(content);
}
INSERTION
For insertion, check out the "Form submission and validation" and "Working with JSON" sections of the documentation. There are examples there; sorry for not adding them here, but these are more complicated for this short format.
Source, and more information: https://www.playframework.com/documentation/3.0.x/JavaRouting
I am trying to display the result of a Mondrian query using JPivot. Many examples are showing how to use the tag library for JSP but I need to use the Java API, I looked at the documentation but I cannot understand how to use it to display the results in the table. Here is my code
Query query = connection.parseQuery(mdxQuery);
Result result = connection.execute(query);
result.print(new PrintWriter(System.out,true));
I would like to know if I can use the result object to build the jpivot table.
Thanks in advance!
First of all, using JPivot
is a pretty bad idea.
It was discontinued back in 2008.
There is a good project which is intended to replace the JPivot called Pivot4j. Despite it is currently under development (0.8 -> 0.9 version), Pivot4j can actually do the business.
However, if we're talking about your case:
result.print(new PrintWriter(System.out,true));
This string prints the HTML code with OLAP cube into your System.out.
You can write the HTML code in some output stream (like FileOuputStream), and then display it.
OutputStream out = new FileOutputStream("result.html");
result.print(new PrintWriter(out, true));
//then display this file in a browser
However, if you want to have the same interface as in JPivot, I don't think there is an easy way to do it without .jsp. In these case I strongly recommend you to try Pivot4j.
Good luck!