LibreOffice Mail Merge with Java - java

I'm trying to use the libre office mail merge functionality automatically from an java application.
I have tried to install the libreoffice sdk but without success because they require software that is not available anymore (e.g. zip-tools). Anyway I was able to get the jar files (jurtl-3.2.1.jar, ridl-3.2.1.jar, unoil-3.2.1.jar and juh-3.2.1.jar) from the maven repository.
With this jar files I was able to reproduce a lot of examples which are provided here http://api.libreoffice.org/examples/examples.html#Java_examples
Also in the LibreOffice API documentation a service named 'MailMerge' is listed (see here http://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1text_1_1MailMerge.html)
But in none of the jar's this service class is available, the only instance available for me is MailMergeType.
I'm able to open an *.odt templatefile within my javacode and the next step would be to create an instance of the mail merge service and pass a *.csv datasourcefile to the mail merge service.
At the API documentation some functions are listed which could help me but as I said before I'm not able to get access to this service class because its simply not exist in the provided jar files.
Do anybody know how I can get access to the mail merge service for libreoffice?
If you need more information about my environment just ask.
Sincerly

Looking at this code from 2004, apparently you can simply use Java's Object class. Here are a few snippets from that code:
Object mmservice = null;
try {
// Create an instance of the MailMerge service
mmservice = mxMCF.createInstanceWithContext(
"com.sun.star.text.MailMerge", mxComponentContext);
}
// Get the XPropertySet interface of the mmservice object
XPropertySet oObjProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, mmservice);
try {
// Set up the properties for the MailMerge command
oObjProps.setPropertyValue("DataSourceName", mDataSourceName);
}
// Get XJob interface from MailMerge service and call execute on it
XJob job = (XJob) UnoRuntime.queryInterface(XJob.class, mmservice);
try {
job.execute(new NamedValue[0]);
}
See also How to do a simple mail merge in OpenOffice.
Regarding a source for the old zip tools, try zip.exe from http://www.willus.com/archive/zip64/.

Related

How to run a gms model from API Java in Gams and set a folder with data in files

I'm trying to execute a GMS model in GAMS through the API Java. When I execute that model directly from Gams Studio, it works perfectly. But when I run the model through the API I obtain a lot of errors.
I have searched and I think I need to add input data to the job or workspace(I don't know what of them need to know the input data). I have a folder where I have a lot of files with data and those files are processed from GAMS Studio when I run the GMS model.
I believe I need to add these files in Java Api too, but I don't know how to add a folder or if I need to add one by one and how to do it.
My code is simple:
GAMSWorkspace workspace = new GAMSWorkspace();
workspace.setDebugLevel(DebugLevel.KEEP_FILES);
GAMSJob jobGams = workspace.addJobFromFile("fileModelGms");
jobGams.run();
I have solved the problem with Lutz's user helper. I needed to Include a dir with input that model uses.
This is my code commented line per line to understand how API Gams works. I used a specific workspace too because API creates a folder in temps file when you run a new Job. I did use for a database GDX too to run my model.
//specific workspace information is created example: C:/Desktop/Workspace
GAMSWorkspaceInfo workspaceInfo = new GAMSWorkspaceInfo();
workspaceInfo.setWorkingDirectory("specificPathWorkspace");
//A new workspace is created with workspaceInfo.
GAMSWorkspace workspace = new GAMSWorkspace(workspaceInfo);
workspace.setDebugLevel(DebugLevel.KEEP_FILES);
//Options where you're going to set input file data.
GAMSOptions options = workspace.addOptions();
//Set path with input Data example: C:/Desktop/InputDate
options.IDir.add("PathWithInputData");
//Using a database where is data to be processed example: db.gdx
GAMSDatabase gdxdb = workspace.addDatabaseFromGDX("db.gdx");
// Creating a JOB to execute the model.
GAMSJob jobGams = workspace.addJobFromFile(entradasModeloGamsDTO.getPathModeloGams());
//Running model
jobGams.run(options,gdxdb);

How to run a GPR file in Java API and run a model GAMS

I have a model with GMS extension. When I run that model with Gams studio, it run perfectly and I obtain the expected results.
I have tried to run the GMS model with Gams IDE but I obtain a lot of errors, so, I have tried something different. I Have opened a file with GPR extension and after of that I have imported the GMS model and everything works perfectly when I run the project.
I think I need to do same thing usinge Gams Java API, but I don't know how to import to my workspace a GPR file.
In this moment I just have the next code:
GAMSWorkspace workspace = new GAMSWorkspace();
workspace.setDebugLevel(DebugLevel.KEEP_FILES);
GAMSJob jobGams = workspace.addJobFromFile("fileModelGms");
jobGams.run();
When I run that code, I obtain an error:
GAMS process returns unsuccessfully with return code : 2 [there was a
compilation error]. Check \_gams_java_gjo1.lst] for more details.
The gpr file has a format that is only understood by the GAMSIDE. You can not pass it to any API. If you get errors calling your model from the API but not from the GAMSIDE, you probably have set certain options using the IDE which you should set now trough the API as well. Though, without seeing the exact error, it is hard to give further hints.
I have solved the problem with Lutz's helper. I needed to Include a dir with input that model uses.
This is my code commented line per line to understand how API Gams works. I used a specific workspace too because API creates a folder in temps file when you run a new Job. I did use for a database GDX too to run my model.
//specific workspace information is created example: C:/Desktop/Workspace
GAMSWorkspaceInfo workspaceInfo = new GAMSWorkspaceInfo();
workspaceInfo.setWorkingDirectory("specificPathWorkspace");
//A new workspace is created with workspaceInfo.
GAMSWorkspace workspace = new GAMSWorkspace(workspaceInfo);
workspace.setDebugLevel(DebugLevel.KEEP_FILES);
//Options where you're going to set input file data.
GAMSOptions options = workspace.addOptions();
//Set path with input Data example: C:/Desktop/InputDate
options.IDir.add("PathWithInputData");
//Using a database where is data to be processed example: db.gdx
GAMSDatabase gdxdb = workspace.addDatabaseFromGDX("db.gdx");
// Creating a JOB to execute the model.
GAMSJob jobGams = workspace.addJobFromFile(entradasModeloGamsDTO.getPathModeloGams());
//Running model
jobGams.run(options,gdxdb);

How to get list of issues inside a specific project using rcarz/jira-client

I am having a problem with get list of issues inside a specific project.I have used Jira client API to connect to my Jira project.My project structure something like this.
Base jira url=https://myproject.info
inside base project i have setup number of projects.like TC/CODE
so far i can connect to base project successfully and can go inside the "TC" project.In there i can get lot of attributes related to the project.But i couldn't get issues listed inside that project.(I can not see any method to obtain this)
I am new to jira client API please let me know how can i get the all issues listed in "TC" project.
BasicCredentials credentials=new BasicCredentials(userName,passWord);
JiraClient jira=new JiraClient("https://myproject.info",credentials);
Project tCProject= jira.getProject("TC");
System.out.println(tCProject.getLead().toString());
//How can i get the all issues inside the TC project.
if anyone familiar with rcarz/jira-client please let me know how can i solve this.
You can get list of issues like below.
BasicCredentials credentials=new BasicCredentials(userName,passWord);
JiraClient jira=new JiraClient("https://myproject.info",credentials);
Issue.SearchResult sr = jira.searchIssues("Your project Name(in my case TC)", 100);
for (Issue i : sr.issues) {
System.out.println(i.getSummary());
System.out.println(i.getKey());
etc ...
}

rackspace cloudfiles throws ContainerNotFoundException after migration from jclouds 1.5 to 1.7

I am trying to update the jclouds libs we use from version 1.5 to 1.7.
We access the api the following way:
https://github.com/jclouds/jclouds-examples/tree/master/rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles
private RestContext<CommonSwiftClient, CommonSwiftAsyncClient> swift;
BlobStoreContext context = ContextBuilder.newBuilder(PROVIDER)
.credentials(username, apiKey)
.buildView(BlobStoreContext.class);
swift = context.unwrap();
RestContext is deprecated since 1.6.
http://demobox.github.io/jclouds-maven-site-1.6.0/1.6.0/jclouds-multi/apidocs/org/jclouds/rest/RestContext.html
I tried to get it working this way:
ContextBuilder contextBuilder = ContextBuilder.newBuilder(rackspaceProvider)
.credentials(rackspaceUsername, rackspaceApiKey);
rackspaceApi = contextBuilder.buildApi(CloudFilesClient.class);
At runtime, uploading a file i get the following error:
org.jclouds.blobstore.ContainerNotFoundException
The examples in the jclouds github project seem to use the deprecated approach (Links mentioned above).
Any ideas how to solve this? Any alternatives?
Does the container that you're uploading into exist? The putObject method doesn't automatically create the container that you name if it doesn't exist; you need to call createContainer explicitly to create it, first.
Here's an example that creates a container and uploads a file into it:
CloudFilesClient client = ContextBuilder.newBuilder("cloudfiles-us")
.credentials(USERNAME, APIKEY)
.buildApi(CloudFilesClient.class);
client.createContainer("sample");
SwiftObject object = client.newSwiftObject();
object.getInfo().setName("somefile.txt");
object.setPayload("file or bytearray or something else here");
client.putObject("sample", object);
// ...
client.close();
You're right that the examples in jclouds-examples still reference RestClient, but you should be able to translate to the new style by substituting your rackspaceApi object where they call swift.getApi().

How to deploy a blackberry app using OSGi

I want to make a blackberry app installable over-the-air (OTA) by deploying it as an OSGi bundle. Any ideas on how to setup the OSGi bundle?
I believe I'll need a way to enable a directory listing at particular URL as well associate the mime type for two file types (*.cod, *.jad)
Any takers?
See Wireless Application Deployment to BlackBerry Smartphones for the details.
In the end I was able to figure it out.
Used the following:
For the most part I followed the steps laid out by Peter Friese (found here)
The tweaking required is as follows:
Tweak1:
In the HttpServiceTracker's addingService() method one needs to invoke:
httpService.registerResources("/blackberry", "/appfiles", new CustomResourceHttpContext());
instead of the servlet registration to map a URL to the location of your files.
Tweak2:
You'll need to create a folder called appfiles at the root of your eclipse project in which you place your blackberry binaries.
Tweak3:
You'll need to implement your own custom HttpContext class inside the HTTPServiceTracker to associate the required mime types
e.g
public String getMimeType(String name) {
if (name.endsWith(".jad")) {
return "text/vnd.sun.j2me.app-descriptor";
} else if (name.endsWith(".cod")) {
return "application/vnd.rim.cod";
} else {
return null;
}
}
Caveat: In order to install the app over the air you'll need to specify the jad file name as there is no support for a directory listing using this approach.

Categories