https://bz.apache.org/bugzilla/show_bug.cgi?id=57639

            Bug ID: 57639
           Summary: casting IFile to XWPFDocument throws
                    InvocationTargetException
           Product: POI
           Version: 3.9-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XWPF
          Assignee: [email protected]
          Reporter: [email protected]

I created a plug-in project. In runtime eclipse, I did set up a command and
added to menu in order to convert selected IFile(docx) file to XWPFDocument
which I can parse it later in other java class. However, when I try to cast
IFile to XWPFDocument, I get an MethodRequestor.java/InvocationTargetException.

Exception detail: org.apache.poi.xwpf.usermodel.XWPFDocument cannot be found by
eu.modelwriter.architecture.textconnectors.docx.command.ui_1.0.0.qualifier

On the other hand in my java project, which is referenced in this plugin
project, this line is working properly. Same jars included in both projects.

My command handler is like below:

public Object execute(ExecutionEvent event) throws ExecutionException {
    // TODO Auto-generated method stub

    XWPFDocument document = null;
    Shell shell = HandlerUtil.getActiveShell(event);
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    IStructuredSelection selection = (IStructuredSelection) sel;

    Object firstElement = selection.getFirstElement();

    if(firstElement instanceof IFile){

        try {

            IFile ifile = (IFile)
Platform.getAdapterManager().getAdapter(firstElement, IFile.class);

            if (ifile == null) {
                if (firstElement instanceof IAdaptable) {
                    ifile = (IFile) ((IAdaptable)
firstElement).getAdapter(IFile.class);
                }
            }

            if (ifile != null) {

                File f = ifile.getFullPath().toFile();
                document = new XWPFDocument(new FileInputStream(f)); //throws
exception
            }


        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to