I am trying to embed a tweet in Vaadin v7:
Label oneTweet = new Label();
String s = "<blockquote class=\"twitter-tweet\"><p>Four more years. twitter.com/BarackObama/st…</p>— Barack Obama (#BarackObama) November 7, 2012</blockquote>";
s = s + "<script async src=\"http://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>";
oneTweet.setValue(s);
oneTweet.setContentMode(ContentMode.HTML);
layout.addComponent(oneTweet);
The problem is, Vaadin does not pick up the script file widget.js. I tried forcing it by putting
#JavaScript( {"http://platform.twitter.com/widgets.js"} )
at the beginning of my source code. It picks up the file but does not style the embedded tweet at all. I was wondering if someone has done this before.
Does it work with the ContentMode Label.CONTENT_XHTML or Label.CONTENT_RAW? Another guess that comes to mind is to include the script in your gwt.xml file and take it out from the Label. Good luck.
In case someone else is having the same question, I solved it by calling this at the end of loading a tweet:
String script = "!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"http://platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");";
Page.getCurrent().getJavaScript().execute(script);
The javascript snippet comes from the guideline by Twitter (Troubleshooting).
Related
I'm trying to make a program that checks avaliable positions and books the first avaliable one. I started writing it and i ran into a problem pretty early.
The problem is that when I try to connect with the site (which is https) the program doesn't do anything. It doesn't throw an error, it doesn't crash. And the weirdest thing is that it works with some https websites and with some it doesn't.
I've spent countless hours trying to resolve this problem. I tried using htmlunitdriver and it still doesn't work. Please help.
private final WebClient webc = new WebClient(BrowserVersion.CHROME);
webc.getCookieManager().setCookiesEnabled(true);
HtmlPage loginpage = webc.getPage(loginurl);
System.out.println(loginpage.getTitleText());
I'm getting really frustrated with this. Thank you in advance.
As far as i can see this has nothing to do with HttpS. It is a good idea to do some traffic analysis using Charles or Fiddler.
What you can see....
The page returned from the server as response to your first call to https://online.enel.pl/ loads some external javascript. And then the story begins:
This JS looks like
(function() {
var z = "";
var b = "766172205f3078666.....";
eval((function() {
for (var i = 0; i < b.length; i += 2) {
z += String.fromCharCode(parseInt(b.substring(i, i + 2), 16));
}
return z;
})());
})();
As you can see someone likes to hide the real javascript that gets processed.
Next step is to check the javascript after this simple decoding
It is really huge and looks like this
var _0xfbfd = ['\x77\x71\x30\x6b\x77 ....
(function (_0x2ea96d, _0x460da4) {
var _0x1da805 = function (_0x55e996) {
while (--_0x55e996) {
_0x2ea96d['\x70\x75\x73\x68'](_0x2ea96d['\x73\x68\x69\x66\x74']());
}
};
.....
Ok now we have obfuscated javascript. If you like you can start with http://ddecode.com/hexdecoder/ to get some more readable text but this was the step where i have stopped my analysis. Looks like this script does some really bad things or someone still believes in security by obscurity.
If you run this with HtmlUnit, this codes gets interpreted - yes the decoding works and the code runs. Sadly this code runs endless (maybe because of an error or some incompatibility with real browsers).
If you like to get this working, you have to figure out, where the error is and open an bug report for HtmlUnit. For this you can simply start with a small local HtmlFile and include the code from the first external javascript. Then add some log statements to get the decoded version. Then replace this with the decoded version and try to understand what is going on. You can start adding alert statements and check if the code in HtmlUnit follows the same path as browsers do. Sorry but my time is to limited to do all this work but i really like to help/fix if you can point to a specific function in HtmlUnit that works different from real browsers.
Without the URL that you are querying it is dificult to say what could be wrong. However, having worked with HTML unit some time back I found that it was failing with many sites that I needed to get data from. The site owners will do many things to avoid you using programs to access them and you might have to resort to using some lower level library like Apache HTTP components where you have more control over what is going on under the hood.
Also check if the website is constructed using JavaScript which is getting more and more popular but making it increasingly dificult to use programs to interrogate the content.
I am trying to write an application from extracting entities from a text and want to use GATE jar files. For which I have installed the GATE tool and have imported jar files, but it is giving errors. I can't understand from where to download more jar files and how to run the first simple program with this.
Please make sure that you added gate.jar from YOUR_GATE_HOME/bin folder.
From your screenshot I can assume that you used an example provided by GitHub. This example looks good, except one part (from my point of view of course). I would suggest to replace output piece with the next more readable code:
String text = "Steve works for Apple Inc in California.";
Document gateDocument = Factory.newDocument(text);
corpus.add(gateDocument);
// tell the ANNIE application about the corpus and run it
annie.setCorpus(corpus);
annie.execute();
List<Annotation> personAnnotations = gateDocument.getAnnotations().get(ANNIEConstants.PERSON_ANNOTATION_TYPE).inDocumentOrder();
for (Annotation personAnnotation : personAnnotations) {
System.out.println("Entity Text: " + gate.Utils.stringFor(gateDocument, personAnnotation) + " Features: " + personAnnotation.getFeatures());
}
Similar things could be done for Location, Organisation and other Entity types defined in GATE. Also do not forget to release resources with Factory.deleteResource().
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!
Hi i formulated a linear programing problem using java
and i want to send it to be solved by lpsolve without the need to create each constraint seperatlly.
i want to send the entire block (which if i insert it to the ide works well) and get a result
so basically instead of using something like
problem.strAddConstraint("", LpSolve.EQ, 9);
problem.strAddConstraint("", LpSolve.LE, 5);
i want to just send as one string
min: 0*x11 + 0*x12 + 0*x13
x11 + x12 + x13= 9;
x12 + x12<5;
can it be done if so how?
LpSolve supports LP files as well as MPS files. Everything is thoroughly detailed in the API documentation (see http://lpsolve.sourceforge.net/5.5/).
You can do your job like this in java :
lp = LpSolve.readLP("model.lp", NORMAL, "test model");
LpSolve.solve(lp)
What is sad with file based approaches is that you will not be able to use warm start features. I would not suggest you to use such approach if you want to optimize successive similar problems.
Cheers
I have this code down and this working fine from command line ...
But when I put this in applet I get following error
com.sun.star.lang.IllegalArgumentException
at com.sun.star.comp.bridgefactory.BridgeFactory.createBridge(BridgeFactory.java:158)
at
com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:130)
Anybody have solution for this problem ? Where I can find BridgeFactory source ?
Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 3/program/soffice.exe -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"); // oooUrlW - the url of soffice.exe
Thread.sleep(5000);
XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
Object urlResolver = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",xLocalContext);
XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class,urlResolver);
Object initialObject = xUnoUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,initialObject);
XComponentContext remoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, xPropertySet.getPropertyValue("DefaultContext"));
XMultiComponentFactory remoteServiceManager = remoteContext.getServiceManager();
Object desktop = remoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", remoteContext);
xDesktop =(XDesktop) UnoRuntime.queryInterface( XDesktop.class, desktop);
XComponent xCalcComponent =
newDocComponent(xDesktop, "scalc");
XSpreadsheetDocument xCalcDocument =
(XSpreadsheetDocument)UnoRuntime.queryInterface(
XSpreadsheetDocument.class, xCalcComponent);
XSpreadsheets a=xCalcDocument.getSheets();
Object o = a.getByName("Sheet1");
XSpreadsheet sheet = (XSpreadsheet)UnoRuntime.queryInterface(
XSpreadsheet.class, o);
XCell jjjj = sheet.getCellByPosition(0, 0);
jjjj.setFormula("Some Text ");
Is your applet signed ? else I don't think you can call
Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 3/program/soffice.exe-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
from an applet.
I agree with Pierre... you would need a trusted/signed applet to do that. You might also want to reconsider why you are trying to do this with an applet rather than a standalone application (using webstart or something if you need to web-deliverable).
One more thing to consider is that the end-user would have to have OpenOffice installed locally (unless they have changed the way their API works) for any Java-OO.o access to work correctly. This requirement may have changed though, it has been a while since I have played around with their API.
Good luck and I hope this helps a little.
It is signed, and I found kind of solution - on client I grant
permission java.security.AllPermission; and now everything work...
I still did'nt try grant SignedBy "MyCompany" permission java.securyty.AllPermission
which I must do...
Error message is misleading me
com.sun.star.lang.IllegalArgumentException ... stupid message
I must use applet ... it is Oracle Forms application and I need to start Calc on client and fill some data.
Thanks on help.
There is a very simple way to place OOo in an applet - use the OfficeBean
While you'll still have your java security problem, your code will be a lot tighter. We're using this to do the same thing. My post on how to get OO 3.2 working in Java 6 applets is here is you want to take a look. It works for 3.1 and 3.2.