Skip to main content

change url in xhp.json

6 replies [Last post]
metalrabby
Offline
Joined: 2008-03-18

hi! I'm new to jmaki.
I don't know how to manipulate dynamically a feed url which is mapped to a xhp.json file.
for example, if I call a feed from index.jsp:

and "rss" is mapped in xhp.json as:

{"id": "rss",
"url":"http://ws.audioscrobbler.com/1.0/user/USERNAME/friendevents.rss",
"xslStyleSheet": "rss.xsl"
}

how can I replace the "USERNAME" string with the real username?

is there a way to call a feed directly from the widget attribute (after having modified it) eg service="http://somefeed", and say to jmaki that the feed must be processed with rss.xsl file, without passing for xhp.json file?

thank you.

Message was edited by: metalrabby

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
metalrabby
Offline
Joined: 2008-03-18

Ok there's a working solution, consisting of accessing the xhp.json file via jsp and overwriting it.
I create a new json file which contains a generic {"key" : "value"} mapping, and called it protoxhp.json. For instance:

protoxhp.json:

{ "id": "rss",
"url":"http://ws.audioscrobbler.com/1.0/user/USERNAME/friendevents.rss",
"xslStyleSheet": "rss.xsl"
}

Then there is a blank xhp.json file, it will be subsequently filled, after having replaced the substring USERNAME occurrence in protoxhp with its original value.

index.jsp:

<%@ page import="java.io.*"%>
<%
String username = "my_username", line = "";
String pathToJson = application.getRealPath("/resources/xhp.json" );
String pathToProto = application.getRealPath("/resources/protoxhp.json" );

BufferedReader input = new BufferedReader(new FileReader( pathToProto ));

PrintWriter pw = new PrintWriter(new FileWriter(new File(pathToJson)));

while ((line = input.readLine()) != null) {
line = line.replaceAll("USERNAME", username);
pw.println(line); }

input.close();
pw.close();
%>

bakarirum
Offline
Joined: 2005-07-07

assuming the javascript variable is in scope, you should be able to just do something like this....

service="/xhp?id=rss" />

and "rss" is mapped in xhp.json as:

{"id": "rss",
"url":"http://ws.audioscrobbler.com/1.0/user/" + username + "/friendevents.rss",
"xslStyleSheet": "rss.xsl"
}

metalrabby
Offline
Joined: 2008-03-18

thank you, but it still doesn't work :(
I'm not sure if json allows two or more strings to be appended.. i'll continue to work on it...

Message was edited by: metalrabby

bakarirum
Offline
Joined: 2005-07-07

Below is a test html page and as you can see, you can create JSON objects with javascript (JS) variables. The problem must be how the JSON is loaded within jMaki. You could follow the code through and see why it will not translate the JS variable. My guess is that the jmaki is doing on "eval" on the values within the json file. I do not have any answers for you, but maybe I am leading you down the right path.







]]>

bakarirum
Offline
Joined: 2005-07-07

What if you changed the service to be a jsp or serlvet call (or whatever server technology you are using) and have this return a JSON string that would be in the JSON document? Would that work?

Example:

service="test.jsp?username=test" />

**************************

test.jsp:

<%@page contentType="text/JSON"%>
<%
out.print("{\"id\":\"rss\",");
out.print("\"url\":\"http://ws.audioscrobbler.com/1.0/user/" + request.getParameter("username") + "/friendevents.rss\",");
out.print("\"xslStyleSheet\":\"rss.xsl\"}");
%>

]]>

metalrabby
Offline
Joined: 2008-03-18

bakarirum thank you for your helpful suggestions, I still haven't solved my problem, but as soon as I'll find a solution [I hope] I'll post it here.
thank you