How to properly copy-paste a slide with Apache POI - apache-poi

I'm trying to duplicate a slide in Apache POI.
Depending on the slide content I have three cases
The duplication succeeds (also for some slides with XSLFPictureShape objects)
I get NullPointerException while POI is trying to copy a XSLFPictureShape (stacktrace follows)
Exception in thread "main" java.lang.NullPointerException
at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:651)
at org.apache.poi.xslf.usermodel.XSLFPictureShape.copy(XSLFPictureShape.java:202)
at org.apache.poi.xslf.usermodel.XSLFSheet.wipeAndReinitialize(XSLFSheet.java:452)
at org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:431)
at org.apache.poi.xslf.usermodel.XSLFSlide.importContent(XSLFSlide.java:294)
...
I get ClassCastException while POI is trying to copy a XSLFPictureShape (stacktrace follows)
Exception in thread "main" java.lang.ClassCastException: org.apache.poi.ooxml.POIXMLDocumentPart cannot be cast to org.apache.poi.xslf.usermodel.XSLFPictureData
at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:651)
at org.apache.poi.xslf.usermodel.XSLFPictureShape.copy(XSLFPictureShape.java:223)
at org.apache.poi.xslf.usermodel.XSLFSheet.wipeAndReinitialize(XSLFSheet.java:452)
at org.apache.poi.xslf.usermodel.XSLFSheet.importContent(XSLFSheet.java:431)
at org.apache.poi.xslf.usermodel.XSLFSlide.importContent(XSLFSlide.java:294)
...
What am I doing wrong?
UPDATE
I have found that the NullPointerException issue of point #2 was due to a corrupted pptx file (maybe because it has been edited once with a mac?)
The only real issue I have now is the one at point #3
UPDATE
It seems that ClassCastException of point #3 was due to some pictures with "artistic effects" applied on them, that are currently unsupported by Apache POI. Copying the pictures in PowerPoint and pasting "as image" removes the effect and the issue.

I have found the asnwer my own as stated in the updates of the original questions:
I have found that the NullPointerException issue of point #2 was due to a corrupted pptx file (maybe because it has been edited once with a mac?)
It seems that ClassCastException of point #3 was due to some pictures with "artistic effects" applied on them, that are currently unsupported by Apache POI. Copying the pictures in PowerPoint and pasting "as image" removes the effect and the issue.

Related

Null Pointer Exception in render response phase, JSF/Primefaces

In server log multiple errors can be found like below
java.lang.NullPointerException at
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:95)
What can be the possible reason for this? Though I tried to recreate in I am unable to recreate after several attempt. Any possible reason or any idea related to this issue?
I need to understand why can we get null pointer exception while rendering response in JSF/Primeface?
primefaces v.3.4.1
javax.faces v.2.1.18
if I check the source code of JSF issue is at this line of source code
ViewDeclarationLanguage vdl =
vh.getViewDeclarationLanguage(facesContext,
facesContext.getViewRoot().getViewId());
javax.faces.STATE_SAVING_METHOD is set to server.
Check you xhtml file for any not closed tags or other xml/html issues. For example divs. Id your IDE doesn't do that, then change IDE or use online XML validators.

Untraceable errors in XHTML templates caused by a missing space between attributes among (X)HTML tags

Have a simple question. Let's consider the following tag.
<h:inputText id="text" value="#{bean.value}"/>
If it is mistakenly written as follows.
<h:inputText id="text"value="#{bean.value}"/>
Please notice that there is no space between the id and the value attributes in this case. This is expected to be a parse error that should occur during parsing of the XHTML file possibly throwing an appropriate exception.
If it were to happen, absolutely nothing exceptional would be reported. No errors/exceptions would be thrown on the server-side. The target web page on the browser would then merely be left blank (white) in its entirely which would also indicate no errors as obvious on the client-side, since parsing of the file happens on the server-side.
Additional Information :
This already happened to me several times on XHTML files having several lines of code even though extreme care is exercised/taken. Mostly happens during copy/pasting which is many a times essential.
If it were to happen, the only way to trace the error was scan the XHTML document manually starting from the first line, all the way down to the last line (or the trace line, if one is caught) possibly scrolling in the middle through a long, ugly horizontal scroll bar on the IDE's GUI too.
Fortunately, I duplicated the same application twice - once using Java EE and again using Spring hereby XHTML code was same in both of the projects. I had been solving this problem as of now, since I began those applications in parallel by copy/pasting the whole XHTML code from one project to another, when it happened and I was unable to trace the line by average attempts. This is not always an alternative.
Can it get to throw an exception, when an XHTML document is mal-formed in this way? Are there someways to make it debuggable/traceable so that one can get rid of manual/tedious/time-consuming/eye-stretching tracing of an XHTML document?

crystal viewer disrupts the log4j configuration

We have JBoss 4.0.3, log4j.xml in the jboss/server/default/conf folder. We set the system property ear.config.files.location to this folder. This log4j.xml gets loaded good when the application is running. We use crystal viewer components (java reporting component) to view few reports. The moment one of this report is loaded, our logging configuration is gone.
Almost nothing comes to the log file anymore. Is there a way to track down how this happens
The moment crystal report loads, SimpleLayout class gets loaded. i wonder why?
I am seeing DomConfigurator.configure can we use it to reload the file. Or can we use DomConfigurator.configureAndWatch to load it periodically.
Any ideas will be very helpful.
The solution posted here solved my issue
http://scn.sap.com/thread/1273402
In case the above link does not work, I have copy-pasted the necessary information below
After a long search, I have found the following :
In the JRCCommunicationAdapter class, a fonction is calling Logger.getRootLogger().setLevel(Level.ERROR).
So I'have made a copy of the rootLogger's level before I open the ReportClientDocument and re-set it after the open.
Level rootLevel = Logger.getRootLogger().getLevel();
...
oReportClientDocument.open (iRptName, OpenReportOptions._openAsReadOnly);
Logger.getRootLogger().setLevel(rootLevel);

LWUIT- out of memory exception in JavaME

I am developing an app in Java ME using Netbeans IDE, where I'm creating 3 Forms which contains Button, Command (OK and back) and Image in the 1st Form.
Using OK Command I can transfer the control to the 2nd form. This works
In 2nd Form I have 2 Command OK and Back. On click of OK it should go to the 3rd Form. On click of back it should return to the 1st Form.
When I am in the 2nd Form, I'm neither able to transfer to the 3rd nor to the 1st Form.
I am getting the following exception.............
java.lang.OutOfMemoryError
(stack trace incomplete)
An exception occurred during transition paint this might be valid in case of a resize in the middle of a transition
Please help me out.
Thanks in advance
Sanjay's answer is correct however if it doesn't solve the problem I would guess you have a recursion somewhere in your code leading to a stack overflow. Many J2ME VM's fail in triggering the stack overflow exception and instead throw an out of memory error.
Just use a debugger and walk over the code to see the recursion.
With the informations you provided, The possible issue is with the image in the first form, you need to keep track of the size of the image you are using. When an image is loaded, the data is decompressed to a pixel array. Pixels can need anything from 2 to 4 bytes each, depending on the device.Say an 800x600 image has 480,000 pixels, so will need at least 1Mb of heap (possible as much as 2Mb) to load it. This will explain why you are running out of memory. During a transition it may be LWUIT makes a local copy of the Image to "transform" (redraw) it(though I'm not sure) so its not a surprise if you need more memory while transition.
Here is a good read which might help you : Memory Leaks In LWUIT And Tracking Memory In Java ME
You can extend the memory of the emulator. You have to click on Properties of the project / Platform / Manage emulators / Tools & extensions / Open preferences / Storage
In this window you will see heap size, write here 1000 f.e. and try it again.
When you swiching to 2nd or 3rd pass object of that class & display object(which is from mdilet) with next form constructor, and when you calling back button just write one line of code like display.setCurrent(previous_form_object); & you know how to go next form when you clicking ok command. And one thing which is mentioned by Sanjay.
Thanks

Core Java Faces - 3rd edition (Cay Horstmann) : Chapter 4 selection tags pg 165 example not working

I'm not sure how i should put this question cos' there are couple of files (.java, .xhtml, etc) involved. Anyway this programs involves couple of checkboxes (selectmanycheckbox) and others. There is a onchange=submit() on this selectmanycheckboxes.
Here's what i noticed:
The generated html for each of those checkboxes there is a onchange=submit(). Kind of funny that by checking a checkboxes, it is submitting the form everytime.
The real issue is when i check one of the checkboxes, there is an error exactly as printed.
======================================================================
java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
Caused by:
java.lang.ClassCastException - [I cannot be cast to [Ljava.lang.Object;
I don't understand the [I here. Any idea?
What i did after that was to remove all the checkboxes and submit the form. Still getting the same error.
Any idea?
The source code is available on their site. Your particular code is provided in javaee/ch04/select folder.
The generated html for each of those checkboxes there is a onchange=submit(). Kind of funny that by checking a checkboxes, it is submitting the form everytime.
It's been set by the <h:selectManyCheckbox onchange="submit()" /> in the code example. The onchange attribute is indeed totally unnecessary. It's likely an oversight of the author.
The real issue is when i check one of the checkboxes, there is an error exactly as printed.
java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
I don't understand the [I here. Any idea?
The [I is the signature of an int[] type. The exception is telling that an instance of int[] type cannot be cast to an instance of Object[]. This makes in turn no sense, it should work fine. This particular problem is caused by something else.
What i did after that was to remove all the checkboxes and submit the form. Still getting the same error.
The <h:selectManyMenu> in the code example is also bound to an int[] property.
However removing them is not the right solution. It should work fine. Your problem is caused by something else deeper under the hoods. It's likely a bug in the EL implementation used. What servletcontainer make/version are you using? What servlet API version is your web.xml declared to? Did you try upgrading the servletcontainer?
I assume you are trying to run the example on Tomcat 6
Your WEB-INF/lib folder should have only these files: jsf-api.jar, jsf-impl.jar. You can download them from http://javaserverfaces.dev.java.net/
On your Tomcat/lib folder, you should replace the file el-api.jar by the file el-api2.2.jar. You can download it from http://download.java.net/maven/2/javax/el/el-api/2.2/

Resources