XPages - Create Word Documents with Apache POI - java

I'm trying to use Apache POI within XPages to create a Word document. I have a button which executes some SSJS to call a method from a Java class. However, as soon as the Java code tries to instantiate a new object, an error occurs. Here is my code:
SSJS:
importPackage(TESTPackage);
var jce:WordReferenceTest = new WordReferenceTest();
jce.newWordDoc();
Java:
package TESTPackage;
import org.apache.poi.xwpf.usermodel.*;
public class WordReferenceTest {
public void newWordDoc() {
try {
XWPFDocument doc = new XWPFDocument();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have IBM Notes 9.0 and have imported all the Apache POI JAR files as JARS directly into my database.
The error message I get is
Error 500
HTTP Web Server: Command Not Handled Exception

On OpenNTF there is OpenNTF Essentials. It contains everything that you need to handle word documents. Try to use that. You might run foul of security or logging.
Reuse what is there already.

Related

java.lang.UnsatisfiedLinkError exception while creating EpcDocument object from FesApi with in teiid jboss translator development

I am getting this exception while try to read epc file in EpcDocument with in Teiid Translator deployed in Jboss server
java.lang.UnsatisfiedLinkError:com.f2i.energisticsStandardsApi.fesapiJNI.new_common_EpcDocument(Ljava/lang/String;)J at com.f2i.energisticsStandardsApi.fesapiJNI.new_common_EpcDocument(Native Method)
at com.f2i.energisticsStandardsApi.common.EpcDocument.(EpcDocument.java:42)
Static {
try {
//Also tried this way
// System.load("D:\\fesapiEnv\\build\\fesapi\\install\\lib\\FesapiCpp.1.2.0.0.dll");
System.loadLibrary("FesapiCpp.1.2.0.0");
} catch (UnsatisfiedLinkError e) {
System.out.println("UnsatisfiedLinkError : " + e.toString());
}
}
public static void serializeEPC(String filePathwithName) {
// This class allows an access to a memory package representing an EPC document.
EpcDocument pck = new EpcDocument(filePathwithName);
// This abstract class acts as a buffer between the RESQML (business) classes
// and the persisted data.
DataObjectRepository repo = new DataObjectRepository();
}
I have also added environment path variable for DLL files(FesapiCpp.1.2.0.0.dll) loading of in bat file of Jboss as below
set PATH=%jBOSS_HOME%\modules\system\layers\base\com\f2i\energisticsStandardsApi\main\lib;%PATH%
The fesApi jar that i am using i get compiled form the below link
https://github.com/F2I-Consulting/fesapi
The Strange thing happening is that when i run standalone programme it runs successfully but with in Jboss environment it gives above exception.
Actually energisticsStandardsApi.jar was loaded as independent module in wildfly server while i was consuming it in separate module (Teiid Translator for RESQML).The above mentioned static block of code was in Translator module where i was loading DLL files while FesapiCpp.1.2.0.0.dll was being consumed by energisticsStandardsApi module, so this producing java.lang.UnsatisfiedLinkError exception while creating EpcDocument object.

Tinify API with Android

Is it possible to use tinify compression API in Android? I've implemented all the required stuff, but the app is crashing all the time. Here's the code:
File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), imageName()+".jpg");
try {
Log.d("TINY", photo.getAbsolutePath());
Source source = Tinify.fromFile(photo.getAbsolutePath());
} catch (IOException e) {
Log.e("TINY", e.getMessage());
e.printStackTrace();
}
A am getting the following error:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: java.nio.file.Paths
If it's not possible, are there any other good APIs for image compression for Android?
It's not possible as-is. Note that java.nio.file.Paths was added in Java 7, but Android still only fully supports Java 6, with some Java 7 language features if you are using a specific buildToolsVersion and minSdkVersion. Also see the Things that don't Work section at the Java7-on-Android project page.
Like the answer to Android import java.nio.file.Files; cannot be resolved states, it's not possible to use classes from the java.nio.file package.
But that doesn't necessarily mean you can't use the Tinify API. If you're able to provide all other referenced classes, you can use it with a few modifications, since it's open source and there are only two occurrences of Files and Paths you need to rewrite:
Result.java
public void toFile(final String path) throws IOException {
Files.write(Paths.get(path), toBuffer());
}
Source.java
public static Source fromFile(final String path) throws IOException {
return fromBuffer(Files.readAllBytes(Paths.get(path)));
}

Can Eclipse for Java and Eclipse for WEBMethods be on the same hard drive?

I am new to WEBMethods. I have been working on a Java service for a project. I really need to be able to write some code in regular Java for some quick testing of reading in a simple text expression with some regular expressions. Nothing at all that fancy with the Java part. But eclipse currently is set up for WEBMethods and I need to be in a regular Java mode for Eclipse (If there is such a thing). At home I have the standard eclipse version and have no trouble writting code. But at work I have WEBMethods installed in the Eclipse (Software AG Designer). I think that if I can write the code in regular Java then I can just copy and paste it into the WEBMethods Java services and set up the INPUT and OUTPUT variables and it should work. But currently I cannot find a way to just write Java code like I do from my home computer.
Question: How can I write just a regular Java program (classes, packages, ...etc...) with a machine with WEBMethods installed? Do I have to install another session of Eclipse on my hard drive? (I tried this a while back and there was an issue with having more than one session of Eclipse on the machine).
Java Web Services Code:
package DssAccessBackup.services.flow;
import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public final class new_javaService_SVC
{
/**
* The primary method for the Java service
*
* #param pipeline
* The IData pipeline
* #throws ServiceException
*/
public static final void new_javaService(IData pipeline)
throws ServiceException {
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String inputFileName = IDataUtil.getString( pipelineCursor, "inputFileName" );
pipelineCursor.destroy();
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "fileName", "fileName" );
// outDoc
IData outDoc = IDataFactory.create();
IDataUtil.put( pipelineCursor_1, "outDoc", outDoc );
pipelineCursor_1.destroy();
String fileName = new String();
fileName = null;
try {
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\itpr13266\\Desktop\\TestFile.txt"));
String line = null;
//Will read through the file until EOF
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
System.out.println("Try-Catch Message - " + e.getMessage());
e.printStackTrace();
}
}
// --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---
// --- <<IS-END-SHARED-SOURCE-AREA>> ---
}
You don't need to install another Eclipse for Java development. WebMethods Designer (v9) comes with Java tooling. Just open the Java perspective and use it.
Besides that you should use the Service Development perspective, when developing WebMethods Java Services, because WM Designer handles Java services in a special way, which could make importing standard Java files difficult.
There is no problem running multiple instances of Eclipse at the same time as long as they point to different workspaces.
Normally you get a dialog to choose the workspace when Eclipse starts up. If not, check this answer on how to enable that dialog: https://stackoverflow.com/a/8616216/1599890
So if you download, unzip and set up Eclipse for Java development and point it to another workspace than Software AG Designer uses you should be good to go.

Add Java SE Classes to Java ME read PDF

I'm writing a Java ME application that uses iText to read PDF. When I write my code in standard Java including the iText libraries in the class-path, the application runs. However if I move the code into a java mobile application including the iText libraries in the class-path there is an error during compiling that says
error: cannot access URL
PdfReader reader = new PdfReader(pdfPath);
class file for java.net.URL not found
My problem is that I need a work around to read the PDF file. I've tried adding rt.jar as a library into my code which is the package that contains java.io but it is too big to be compiled. Please help me find a work around. My code is here
package PDFreaderpackage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.TextArea;
import javax.microedition.midlet.MIDlet;
public class Midlet extends MIDlet {
Form displayForm;
TextArea pdfText;
private String bookcontent;
public static String INPUTFILE = "c:/test.pdf";
public static int pageNumber = 1;
public void startApp() {
Display.init(this);
this.bookcontent = readPDF(INPUTFILE, pageNumber);
pdfText = new TextArea(bookcontent);
displayForm = new Form("Works");
displayForm.addComponent(pdfText);
displayForm.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public String readPDF(String pdfPath, int pageNumber) {
try {
PdfReader reader = new PdfReader(pdfPath);
this.bookcontent = PdfTextExtractor.getTextFromPage(reader, pageNumber);
} catch (Exception e) {
System.out.println(e);
}
return bookcontent;
}
}
These classes aren't available on a mobile device and JavaME doesn't support Java 5 features. What you are trying to do is somewhat impractical. Codename One allows some more classes thanks to bytecode processing but even then this isn't close to a complete rt.jar.
If you have the time, you can try and create a Java ME compliant version of iText, but to properly open a PDF the library must use some form of Random Access File because of the xref table at the end of the file. This sort of file connection is not available in Java ME.
What the library can do is to fully load the PDF to memory, which is highly dependent on the file size and the handset memory available.
You better create a Web Service to receive your PDF and return, for example, PNG images from it.

Office 2007 is unable to open files when called through JACOB from a service

I'm using JACOB to do COM calls to PowerPoint and other Office applications from Java. On a particular Windows 7 box I'm getting the following message quite often, but not always:
Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.
From excel I get:
ERROR - Invoke of: Open
Source: Microsoft Office Excel
Description: Microsoft Office Excel cannot access the file 'c:\marchena\marchena10\work\marchena\batch_58288\input\content_1.xlsx'. There are several possible reasons:
? The file name or path does not exist.
? The file is being used by another program.
? The workbook you are trying to save has the same name as a currently open workbook.
The Word error is just:
VariantChangeType failed
The following is what I'm running, the error comes from the last line.
ComThread.InitSTA();
slideApp = new ActiveXComponent("PowerPoint.Application");
Dispatch presentations = slideApp.getProperty("Presentations").toDispatch();
Dispatch presentation = Dispatch.call(presentations, "Open", inputFile.getAbsolutePath(),
MsoTriState.msoTrue.getInteger(), // ReadOnly
MsoTriState.msoFalse.getInteger(), // Untitled The Untitled parameter is used to create a copy of the presentation.
MsoTriState.msoFalse.getInteger() // WithWindow
).toDispatch();
I've tried putting a breakpoint just before doing the Open call and the file is there, and I can actually open it with PowerPoint in the GUI but when I step the exception is thrown.
The annoying thing about this issue is that it seems to happen continuously to begin with, but after poking at it for a while (rerunning the same code), it eventually completes successfully, and after that never reoccurs.
Further research I've found this only happens with to .ppt, .doc and .xls files, not .pptx, .docx and .xlsx. And as far as I can tell it's not file system related (I've swapped out the mechanism that copies the files and tried putting the files on a different file system).
I've just noticed that this only happens when the Java application is running as a service, not when I run catalina.bat start from command line.
I had the same problem (jacob in service not working), and this helpful posting (changing the dcomcnfg) did the trick:
http://bytes.com/topic/c-sharp/answers/819740-c-service-excel-application-workbooks-open-fails-when-called-service#post3466746
Does this work for you?
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class PPT {
private static final String inputFile = "c:\\learning.ppt";
public static void main(String[] args) {
ActiveXComponent slideApp = new ActiveXComponent("PowerPoint.Application");
slideApp.setProperty("Visible", new Variant(true));
ActiveXComponent presentations = slideApp.getPropertyAsComponent("Presentations");
ActiveXComponent presentation = presentations.invokeGetComponent("Open",new Variant(inputFile), new Variant(true));
ComThread.Release();
}
}
Update: If this is working the client and it's just automation that is causing the issues, you can view http://support.microsoft.com/kb/257757 to look at possible issues. There error codes are obviously different, but it may help you troubleshoot all the same.

Categories