How to start an OpenOffice extension? [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to write an extension for OpenOffice.
This extension would be written in java (compiled, I don't want people to see the code).
It should do actions when I start openOffice writer, when I click on a button and when I print.
I've already added the button but I can't find how to link it with the code of what it should do.
I've read the wiki and the DevGuide but I don't find it very clear.
Could you please help me to start understanding how to create an extension (where should I put my code, how to link it with the GUI etc...)?

As an example, follow instructions at https://wiki.openoffice.org/wiki/OpenOffice_NetBeans_Integration#Configuration. Install the Apache OpenOffice API Plugin by going to Tools -> Plugins.
Click on the link that says OpenOffice.org Add-On Project Type to get more instructions. If you haven't yet, download AOO 4.1.2 and the AOO 4.1.2 SDK. (The plugin did not work for me using LibreOffice, but the resulting extension did work in LibreOffice).
After the code is generated according to the instructions, then add this code to the dispatch method of TestAddOn.java:
if ( aURL.Path.compareTo("HelloWorld") == 0 )
{
// add your own code here
com.sun.star.frame.XController xController = m_xFrame.getController();
if (xController != null) {
XModel xModel = (com.sun.star.frame.XModel) xController.getModel();
XTextDocument xTextDocument = (com.sun.star.text.XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xModel);
XText xText = xTextDocument.getText();
XTextRange xTextRange = xText.getEnd();
xTextRange.setString( "Hello World (in Java)" );
return;
}
}
Now compile and deploy the extension. When the "Hello World" toolbar button is clicked, it should put "Hello World (in Java)" in the document.
The code was adapted from https://forum.openoffice.org/en/forum/viewtopic.php?f=47&t=72459.
In order to handle events like when the document is opened, I also tried calling a method of the extension from Basic code like this:
Sub CallJavaMacro
MSPF = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
scriptPro = MSPF.createScriptProvider("")
xScript = scriptPro.getScript("vnd.sun.star.script:" & _
"com.example.testaddon.TestAddOn.PutHello?" & _
"language=Java&location=user:uno_packages/TestAddOn.oxt")
Thing = xScript.Invoke()
End Sub
However the Basic routine said it could not find the method. Maybe I did not declare the method properly or something.

Related

Open CMD with the User Account Control (UAC) dialog [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 26 days ago.
The community is reviewing whether to reopen this question as of 26 days ago.
Improve this question
I am working on a JavaFX project. At some point in the program I need to ask the user for elevated rights to perform a certain action.
How can I code this action?
My program is coded to work on Windows 10.
My program does not need any permission to work in the usual operation, only for this action is needed.
My program detects some devices that I have designed. The problem I have is that sometimes I need to change the VLAN ID of my network card. To do this I do it as follows:
public void VlanChanged (int vlanId) {
StopDeviceSearch();
try {
Runtime rt = Runtime.getRuntime();
String cmd = "cmd /c \"Echo S|powershell set-netadapter -InterfaceDescription 'Killer E2400 Gigabit Ethernet Controller' -VlanID " + vlanId + "\"";
rt.exec(cmd);
} catch (Exception e) {
System.out.println (e);
}
RestarDeviceSearch();
}
If I run myProject.jar as administrator the above code works correctly, but if I don't run it as administrator the above code doesn't work.
Could I run my program and when the user activates the "VlanChanged" function that my program asks the user for administrator permissions to run CMD as administrator and be able to perform the VLAN ID change action correctly?
I have tried with the command
"runas /profile /user: Administrator"
but it doesn't work.
I would like the Windows banner to be opened that asks you:
"Do you want to allow this application to make changes to the device?"
That the window has the title: "User Account Control".
I have been searching and I just want the "UAC dialog".

Using IF commands to Check if a button exists in Selenium Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a java selenium program that automatically presses on a button in a website. The code i am using looks like this :
driver.findElement(By.id("button")).click();
I want the program to use if statements if possible.
Thanks for your help.
Use can use findelements by along with if to achieve this. Below code might give you some idea.
if(driver.findElements(by.xpath("//*[#id=253]")).size>0)
{
//element exists with id = 253
// do the stuff
} else
{
//element do not exist with id = 253.
// do the stuff
}
Hope this helps. Thanks.
You may try this:
public void ClickButton () throws InterruptedException
{
WebElement button = driver.findElement(By.id("button"));
String Source = driver.getPageSource();
if (Source.contains(button))
{
button.click();
Thread.sleep(3000);
}
else
{
driver.quit;
}
}
Hope this can be helpful. Let me know if you are still facing problem.

FaceBook ShareLinkContent setImageUrl image is overriden by setContentUrl meta-data image [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to Post the below infromation to FaceBook from Myapp using FaceBook ShareLinkContent class
- link url (using SetContentUrl method)
- image (using setImageurl method)
- hashtags (using setHashTag method)
- and Description
as like
ShareHashtag shareHashTag = new ShareHashtag.Builder().setHashtag(hashtag_name).build();
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setImageUrl(Uri.parse(selectedImagePath))
.setShareHashtag(shareHashTag)
.setContentDescription(textd)
.setContentUrl(Uri.parse(linkUrlPath))
.build();
shareDialog.show(linkContent);
}
} else {
shareImage();
}
The question is, instead of posting the image from "selectedImagePath" url, it post the meta-data image coming from the "linkUrlPath" url.
How to overcome it, so that i can post the image which i send in the method setImageUrl() method.
note: I am using Facebook SDK 4.14.1
Kindly provide suggestions
I guess this is what you are looking for -
Template Matching
Template Matching is a method for searching and finding the location of a template image in a larger image. OpenCV comes with a function matchTemplate() for this purpose. It simply slides the template image over the input image (as in 2D convolution) and compares the template and patch of input image under the template image.

Ensuring if excel worksheet contains any user defined function [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
My application contains an upload option from which the user can upload files(any file).
I know that users have the ability to write code/scripts in excel worksheet.So how can i prevent that from happening as it can lead to security breach.
Or what check can i apply to know that the uploaded worksheet contains any function?
I assume from the Java tag that your appliction to which the sheet gets uploaded is a Java application.
Using Apache POI, you can use a POIFSReader (see this doc) to read the file on a lower level.
There is an example by RĂ©al Gagnon which shows how you can check the content by looking at the name.
I had to modify the listener (added another comparision)
class MacroListener implements POIFSReaderListener {
[...]
#Override
public void processPOIFSReaderEvent(POIFSReaderEvent event) {
System.out.println(" Event: Name " + event.getName() + ", path "
+ event.getPath());
if (event.getPath().toString().startsWith("\\Macros")
|| event.getPath().toString().startsWith("\\_VBA")
|| event.getPath().toString().contains("_VBA_")) {
this.macroDetected = true;
}
}
}
so that it worked for some test files. You might have to tune/extend the checks.

How to upload video on twitpic/twitter programatically? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am new in Android.
I was working for uploading Image/Video on Twitter. I used the twitpic for this purpose.
I first sent image to twitpic and then updated the status in twitter with url of the tweet.
Image is successfully loading as per my selection from gallery.
But I am stuck in uploading video on Twitter. As there is option of twitpic or twitvid for uploading video. But there is no such type of code or sdk given. So confused that how to do this, which classes has to be used.
I need a sample code for uploading video.
Was stuck on this for a while myself as well (not a lot of examples around) and found a non-working example here on SO which I've managed to hammer into shape...
First you'll need the twitvid Java API
1 download the jar file (I used twitvid-java 1.6.1)
2 put it in your "libs" folder
3 right-click on your project and go to "properties"
4 select "Java build path" and include the jar ("libraries" tab) and make sure it's built ("order and export" tab)
The code that follows assumes you've already made a token with the regular twitter4j methods:
private void postToTwitvid(String videoPath){
AccessToken token = mTwitter.getAccessToken();
Values values = new Values();
values.setSession(new Session());
TwitvidApi api = new TwitvidApi(values);
api.setSecureUrlEnabled(false);
Session session;
try {
session = api.authenticate(new TwitterAuthPack.Builder()
.setConsumerKey(twitter_consumer_key)
.setConsumerSecret(twitter_secret_key)
.setOAuthToken(token.getToken())
.setOAuthTokenSecret(token.getTokenSecret())
.build());
api.getValues().setSession(session);
final UploadHelper helper = new UploadHelper(api);
File file=new File(videoPath);
TwitvidPost twitvidPost = new TwitvidPost.Builder()
.setFile(file).setChunkSize(10485760)
.setMessage("Twitvid test")
.setPostToTwitter(true)
.create();
try {
if (helper.upload(twitvidPost))
{
Toast.makeText(TwitterShare.this, "Posted on Twitter and Twitvid", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(TwitterShare.this, "Post failed", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}
}
The token depends on how you've implemented the regular posting to twitter, just include yours.
Hope this helps!
PS: I had to force the UI thread to accept network connections to make this work
(My first answer! w00t!)

Categories