google docs api folder - java

I'm trying to develop one java function to retrieve the id of one specific folder over Google Docs, but the documentation over this language is poor and have problems to develop it. Until now I've can make this, but don't work, it never show my the document id of my folder
public void findfolder(String folderName) throws MalformedURLException,IOException,ServiceException{
URL feedUrla=new URL("https://docs.google.com/feeds/default/private/full/-/folder");
DocumentQuery query = new DocumentQuery(feedUrl);
query.setTitleQuery(folderName);
query.setTitleExact(true);
DocumentListFeed feed=null;
try {
feed = client.getFeed(query, DocumentListFeed.class);
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
for (DocumentListEntry entry : feed.getEntries()) {
System.out.println(entry.getDocId());
}
}`

Related

DLL Method Not Working After Creating Exe Of Project

I have calling display method from dll file This works when I run my java project . But it stop working after creating of project exe file. My Code is as follow ..
static {
try {
Bridge.setVerbose(true);
try {
Bridge.init();
} catch (IOException e) {
e.printStackTrace();
}
File dll_File = new File("helloworld.j4n.dll");
Bridge.LoadAndRegisterAssemblyFrom(dll_File);
helloworld.Hello.display(str)
} catch (Exception exception) {
exception.printStackTrace();
}
}
Have you signed the dll? Please sign the dll and then check.

Jsoup: Android App crashes

I have this following code:
String webPage = "http://www.something.com";
String html = null;
try{
html = Jsoup.connect(webPage).get().html();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(this, html, Toast.LENGTH_SHORT).show();
If its the Exception Exception the code does the other stuff (before this code) and does not do the code in try{}, if the Exception is IOException, the app crashes
The app crashes due to NetworkOnMainThreadException
You are not allowed to perform network operations from the main thread.
Instead, try running Jsoup from an AsyncTask
Also, you should read what kind of Exception Jsoup can throw and handle each of them as you plan to instead of catching the base jave Exception class. You can also catch multiple exceptions in one catch block if you plan to handle them the same way.
Example:
String webPage = "http://www.something.com";
String html = null;
try {
html = Jsoup.connect(webPage).get().html();
} catch (SocketTimeoutException|IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace()
}
Toast.makeText(this, html, Toast.LENGTH_SHORT).show();

get the sharedlink of an existing file in Dropbox using the dropBox-sdk-java

I want to retrieve the shared file url of an existing file on Dropbox. I am using the dropbox-java-sdk, and I have managed to create a shared link for a file I just uploaded. The only way I managed to get the shared link of an existing file is by listing all links and get the one I want depending on the path, like so
public void getShareLink(String path) throws DbxApiException, DbxException{
DbxRequestConfig config = new DbxRequestConfig("test/DbApi-sdk");
DbxClientV2 client = new DbxClientV2(config, getToken(AuthorizationFile));
try {
ListSharedLinksResult sharedLinkMetadata = client.sharing().listSharedLinks();
for (SharedLinkMetadata slm: sharedLinkMetadata.getLinks()){
if(slm.getPathLower().equalsIgnoreCase(path)){
System.out.println(slm.getUrl());
return;
}
}
} catch (CreateSharedLinkWithSettingsErrorException ex) {
System.out.println(ex);
} catch (DbxException ex) {
System.out.println(ex);
}
}
Isn’t there a way to directly get the url for the file I want? I just think it is a waste to iterate all items just to get one of them.
Get a ListSharedLinksBuilder from listSharedLinksBuilder and set ListSharedLinksBuilder.withDirectOnly to request only links for the exact path specified:
public String getShareLink(String path) {
DbxRequestConfig config = new DbxRequestConfig("test/DbApi-sdk");
DbxClientV2 client = new DbxClientV2(config, getToken(AuthorizationFile));
try {
ListSharedLinksResult sh = client.sharing().listSharedLinksBuilder()
.withPath(path)
.withDirectOnly(true)
.start();
for (SharedLinkMetadata slm : sh.getLinks()) {
return slm.getUrl();
}
} catch (CreateSharedLinkWithSettingsErrorException ex) {
System.out.println(ex);
return null;
} catch (DbxException ex) {
System.out.println(ex);
return null;
}
return null;
}

Smack Api Group not working

I am trying to create Group using Smack Api
I use the following code
It crashes on muc#roomconfig_roomowners tag
If i remove that line, it works fine, Group creates
But no group is assigned to the current user, no one is owner
public void createGroup() {
MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor(mConnection).getMultiUserChat("room719#conference." + MYSITE);
try {
chatRoom.create("room719");
Form form = chatRoom.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_publicroom", true);
form.setAnswer("muc#roomconfig_roomname", "room719");
// List owners = new ArrayList();
// owners.add("currUser#"+MYSITE);
form.setAnswer("muc#roomconfig_roomowners", Arrays.asList("currUser#"+MYSITE));
form.setAnswer("muc#roomconfig_persistentroom", true);
chatRoom.sendConfigurationForm(form);
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
This code is working for me, can you try this?
if( !chatRoom.isJoined() ){
chatRoom.createOrJoin("your nickname");
List<String> owners = new ArrayList<String>();
owners.add("currUser#"+MYSITE);
Form form = chatRoom.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_roomname", "your roomname");
form.setAnswer("muc#roomconfig_roomowners", owners);
form.setAnswer("muc#roomconfig_persistentroom", true);
form.setAnswer("muc#roomconfig_publicroom", true);
chatRoom.sendConfigurationForm(form);
}

open pdf file located in a ressource folder

I'm trying to open a pdf located in a ressource folder with my application.
It does work on the emulator but nothing happens when I try on the exported application.
I'm guessing I'm not using the rigth path but do not see where I'm wrong. The getRessource method works very well with my images.
Here is a code snippet :
public void openPdf(String pdf){
if (Desktop.isDesktopSupported()) {
try {
URL monUrl = this.getClass().getResource(pdf);
File myFile = new File(monUrl.toURI());
Desktop.getDesktop().open(myFile);
} catch (IOException ex) {
// no application registered for PDFs
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I'm referring to the pdf variable this way : "name_of_the_file.pdf"
Edit: I've pasted the whole method
Ok, solved it. The file being located in a Jar, the only way to get it was through a inputsteam/outstream and creating a temp file.
Here is my final code, which works great :
public void openPdf(String pdf){
if (Desktop.isDesktopSupported())
{
InputStream jarPdf = getClass().getClassLoader().getResourceAsStream(pdf);
try {
File pdfTemp = new File("52502HPA3_ELECTRA_PLUS_Fra.pdf");
// Extraction du PDF qui se situe dans l'archive
FileOutputStream fos = new FileOutputStream(pdfTemp);
while (jarPdf.available() > 0) {
fos.write(jarPdf.read());
} // while (pdfInJar.available() > 0)
fos.close();
// Ouverture du PDF
Desktop.getDesktop().open(pdfTemp);
} // try
catch (IOException e) {
System.out.println("erreur : " + e);
} // catch (IOException e)
}
}
You mentioned that it is running on Emulator but not on the application. There is high probability that the platform on which the application is running does not support Desktop.
Desktop.isDesktopSupported()
might be returning false. Hence no stack trace or anything.
On Mac, you can do:
Runtime runtime = Runtime.getRuntime();
try {
String[] args = {"open", "/path/to/pdfFile"};
Process process = runtime.exec(args);
} catch (Exception e) {
Logger.getLogger(NoJavaController.class.getName()).log(Level.SEVERE, "", e);
}

Categories

Resources