Embed web liferay content within existing liferay web content - java

I'm trying to print a web content from inside another web content in Liferay 5.2.3. Following the issue How to embed WebContent in Liferay i've tried:
set ($group_id = $getterUtil.getLong($request.theme-display.scope-group-id))
set ($webcontent-id = "ROBAPAGINES-COL-ESQUERRA")
set ($webcontent=$journalContentUtil.getContent($group_id, $webcontent-id, "", "$locale", ""))
$webcontent
It works when the embedded web content has no structure and template but $webcontent is empty when I assign an structure-template to the same web content.
I'd greatly appreciate any help

It seems you are calling below method for getting web-content.
public static String getContent(
long groupId, String articleId, String viewMode, String languageId,
String xmlRequest)
But, you can use below mentioned method which accept templatedId.
public static String getContent(
long groupId, String articleId, String templateId, String viewMode,
String languageId, String xmlRequest)

Related

Handle file upload in RFC 6902 Json Patch

I'm working on a application in which users can update their information. For the moment, RFC 6902 Json-patch is used to update textual information (firstname, lastname, phone...) via a basic HTML Form.
User can now add images to their profile. Is there any way to use Json-patch to perform multipart operations ?
Note : The images are stored in a file system. So in the client side, only the image path is given and it can be updated only after the form submission. My dto is as below :
public class ProfileDto {
private Integer id;
private String firstname;
private String lastname;
private String defaultMedia; // <-- image path
...
}
Solution to which I think :
Since defaultMedia is of type String, Json-patch can be used to update the image path. The idea is when the form is submitted, perform a Multipart POST request to upload the image and get its URL. Then set defaultMedia of my DTO to the new URL.
This solution can create unsued images in the case when a error happened server side on form submission. So I need to add something to clean the file system.
Is there any easier solution to meet my needs ?
I'm using :
Spring Boot : 1.5.1
Angular 2 : 2.4.5

Bolding text within a string created via StringBuilder in Java

I need to display a string of text with select words in bold. This is for a web application which uses jsf icefaces, but the problem is with the java. The string needs to be passed to the ui already formatted.
It should return a string such as: Hello Universe! Greetings Earthing!
Example code:
public String displayMessage(){
StringBuilder sb = new StringBuilder();
sb.append("Hello");
sb.append("Universe!");
sb.append("Greetings Earthing!");
return sb.toString();
}
Everything I've found so far uses either swing, which I can't use, or is for android, which I'm obviously not using. I've tried html tags, but it obviously doesn't work. I've also tried String.format() with html tags and Font.BOLD, but that doesn't seem to work either.
Help?

How to get deployed address programmatically?

I have following application URI structure:
ip:port/applicationName/someAction
How can I get following part of URI programmatically:
ip:port/applicationName/
I tryed
servletContext.getContext()
but it returns only applicationName.
P.S.
this works
String applicationBasePath = request.getRequestURL().substring(0,request.getRequestURL().indexOf("/",request.getRequestURL().indexOf("/")+2));
and this:
request.getRequestURL().substring(0, request.getRequestURL().indexOf(request.getRequestURI()))
But I don't like it.
I believe you need to get HttpServletRequest and there you can extract that information from getRequestURL().
The problem with servlet context only is that your application can be access e.g. via http://127.0.0.1/ or http://192.168.1.1/ and you don't know that without having actual request done. If you can define any "canonical" server name, you can do it e.g. like here: Getting server name during servlet initialization
ie. String serverName = getServletContext().getInitParameter("serverName"); with defined init parameter.
I couldn't write code better than:
public static String getApplicationBasePath(HttpServletRequest request) {
String absolutePath = request.getRequestURL().toString();
String contextPath = request.getRequestURI().toString();
return absolutePath.substring(0,absolutePath.indexOf(contextPath));
}

java print the redirected url

original url : http://pricecheckindia.com/go/store/ebay/52440?ref=velusliv
redirected url : http://www.ebay.in/itm/Asus-Zenfone-6-A600CG-A601CG-White-16-GB-/111471688863?pt=IN_Mobile_Phones&aff_source=DA
I need a program that will take the original url and print the redirected url.
How to get this done in java.
public static void main(String[] args) throws IOException, InterruptedException
{
String url = "http://pricecheckindia.com/go/store/ebay/52440?ref=velusliv";
Response response = Jsoup.connect(url).followRedirects(false).execute();
System.out.println(response.url());
}
It seems that you are being redirected via JavaScript code, which Jsoup doesn't support (it is simple HTML parser, not browser emulator). Your choice then is to either use tool which will support JavaScript like Selenium web driver, or parse your page to get url from click here link from
If it is taking too long to redirect, then please click here
text.
You can use Jsoup to get this link by adding to your current code
Document doc = response.parse();
String redirectUrl = doc.select("a:contains(click here)").attr("href");
System.out.println(redirectUrl);
which will return and print
http://rover.ebay.com/rover/1/4686-127726-2357-15/2?&site=Partnership_PRCCHK&aff_source=DA&mpre=http%3A%2F%2Fwww.ebay.in%2Fitm%2FAsus-Zenfone-6-A600CG-A601CG-White-16-GB-%2F111471688863%3Fpt%3DIN_Mobile_Phones%26aff_source%3DDA
so now all we need to do is parse query from this URL to get value of mpre key, which encoded version looks like
http%3A%2F%2Fwww.ebay.in%2Fitm%2FAsus-Zenfone-6-A600CG-A601CG-White-16-GB-%2F111471688863%3Fpt%3DIN_Mobile_Phones%26aff_source%3DDA
but after decoding it will actually represents
http://www.ebay.in/itm/Asus-Zenfone-6-A600CG-A601CG-White-16-GB-/111471688863?pt=IN_Mobile_Phones&aff_source=DA
To get value of this key and decode it you can use one of solutions from this question: Parse a URI String into Name-Value Collection. With help of method from accepted answer in previously mentioned question we can just invoke
URL address = new URL(redirectUrl);
Map<String,List<String>> urlQuerryMap= splitQuery(address);
String redirected = urlQuerryMap.get("mpre").get(0);
System.out.println(redirected);
to see result
http://www.ebay.in/itm/Asus-Zenfone-6-A600CG-A601CG-White-16-GB-/111471688863?pt=IN_Mobile_Phones&aff_source=DA

sending String using servlet while dowloading in GWT

i am using GWT
I trying to dowload a file using Servlet.
I have fileId on the client side.
i have my servlet ready to look for the file using fileId and send back to client.
But on the Client side.
I dont understand how to send this id and retrieve this on server side to use it.
String fileId = "aValidId"
Window.open(GWT.getHostPageBaseURL() + "DownloadFileServlet", "", "");
Can any one help me to do this.
If this question is repeated , please send me a link (i could not find it )
Thanks in advance
You can simply append the parameter to the servlet path like below
String fileId = "aValidId"
Window.open(GWT.getHostPageBaseURL() +
"DownloadFileServlet?fileId ="+fileId , "", "");
And in servlet get the parameter like below:
String myParam = req.getParameter("myparam");
And please go through the below link for encoding and for other techniques..
http://perishablepress.com/how-to-write-valid-url-query-string-parameters/

Categories