Replacement for COSName.DOCMDP in PDFBox 2.0.4 - java

I'm testing the example codes from this page:
https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/
But inside the file CreateSignatureBase.java, exactly in the functions getMDPPermission and setMDPPermission, it calls a property that doesn't exist anymore: COSName.DOCMDP. I perused the Pdfbox page and its migration guide and it doesn't mention this property and how to replace it. I also looked into the PDfbox source code (exactly the file COSName.java) and It doesn't have that property, despite this file:
https://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?view=markup does have it.
I checked both pdfbox-2.0.4.jar and pdfbox-app-2.0.4.jar adding them to the Netbeans project where I'm testing the java files from the pdfbox examples. None of them have the property COSName.DOCMDP in the COSName class.
Both jars and the pdfbox sourcecode are downloaded from here:
https://pdfbox.apache.org/download.cgi#20x
How can I replace the property COSName.DOCMDP in the CreateSignatureBase class? Am I getting the right jars?

It will appear in 2.1.0 version:
https://issues.apache.org/jira/browse/PDFBOX-3017
https://issues.apache.org/jira/browse/PDFBOX-3699
https://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?annotate=1786065
If you need it for testing purposes, you may download it's SNAPSHOT version from https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox/
Or, you may see this example in current stable version - just download 2.0.4 jar and browse examples.

Related

tink library com.google.protobuf.GeneratedMessageV3$ cannot be resolved

I recently tried to add the google tink library to eclipse and it always has a "com.google.protobuf.GeneratedMessageV3$ cannot be resolved" error, I normally never have any problems with adding libraries to my project, and from what I can tell it has something to do with the all key template files since the error only occours when I try to generate a new KeysetHandle with any key template, and the error only starts when i enter in the key template file# https://github.com/Gameidite/testProject
The Protobuf library can generate Java classes for you. You need to find where these .class files have been output to (eg there should be a GeneratedMessageV3$.class somewhere) and make sure that they are included on your classpath. There's presumably somewhere in Eclipse where you can configure where it looks for class files - you'll need to add the generated files there.
If the generated class files don't exist yet you need to figure out what to do to generate them. It might be easier to use Maven or Gradle as suggested in the Tink documentation rather than directly adding things to Eclipse.
I think it's probably because Eclipse cannot find the protobuf Java runtime. Have you tried adding Tink to your project with Maven or Gradle?

WS02 generates POM but no source code

Having recently upgraded from WS02 3.1.0 to 5.2.1 I also upgraded the associated axis2 and rampart versions to 1.5 and 1.6.2 respectively.
The WSo2 server runs up and creates my list of services and they are all present on the WSO2 console page.
My problem is that, due to the upgrade (axis2), I now have to regenerate the stubs that support our test harness in order to test those services as some classes/interfaces have changed and methods (e.g. org.apache.axis2.databinding.utils.writer.MTOMAwareXMLStreamWriter) are no longer present.
According to the notes left by the originator of the current stubs I need to open the list of services and then copy the WDSL2.0 link. Then open the WDSL2Java page on "Tools", paste the link into the uri field, select the version as 2.0 and generate. This is broadly what the WSO2 help page suggests too.
However, when I follow this procedure, this generates a .zip file which contains only a single .POM file (which has a link to the WSDL file in it).
The "generate" page is showing a set of MAVEN information above it which doesn't appear on the help page explanation.
My project is not MAVEN based so my question is how to get the source files generated in the same manner as they were, seemingly, created with WSO2 version 3. The WSDL2.0 file opens when I enter the URL into a browser and contains the details of the associated classes/methods as expected so that seems to be OK.
Is there some configuration I can tweak to turn off the MAVEN POM generation?
Having spent over a day on this I would really appreciate any help.
Greg
Finally found a solution to this after much experimentation:
Start your services with WSO2
Login to the WSO2 console web page and list the services
From the WSDL2 column copy the link to the WSDL file
From the cmd line navigate to axis2/bin
Enter WSDL2Java -uri [paste the url of the WSDL file here] -sd adl -wv 2.0 -o [destination folder for the generated code here (optional)]

How to load apache poi libs in R?

I am trying to read word files into R in order to text parse them. After researching for a little while I found that Apache POI is the way to go for me, because it appears to be the most flexible w.r.t. handling different Word formats.
I tried to follow what the R packages xlsx' orcommonJavaJarsandxlsxjars` do. Unfortunately I was not able to create a few lines of R that work analogously.
E.g.:
inputStream <- .jnew("java/io/FileInputStream", path.expand(file))
wbFactory <- .jnew("org/apache/poi/ss/usermodel/WorkbookFactory")
What I do get from this, is that first an input stream is created (which i was able to do for a word fie as well). Then this Workbook Factory is created from the apache poi library using another .jnew. Looking for the a similar functionality for word I found this part of the POI package and tried:
wdoc <- .jnew("org/apache/poi/hwpf/HWPFDocument")
All i got is a java.lang.ClassNotFoundException. POI packages other than Excel relevant packages should be available as there's a poi-3.9-20121203.jar in the source code of xlsxjars which contains the .jars xlsx depends on.
Also tried to use the package commonJavaJars and ran the function
loadJars("poi")
without an error, but did not succeed with subsequent calls. Can someone get me started here?
EDIT:
I obviously miss a package here. Can I instantly load additional jars into my R session or do I have to compile a package to add new jars?
Apache POI provides a handy page of the POI components, their jars and their dependencies. If you look on that, you'll see that to use HWPF you need both the main poi jar and the poi-scratchpad jar
So, assuming you're sticking with poi-3.9 (and not using the latest version, which is 3.10 beta 2 as of writing), you'll need to list poi-3.9-20121203.jar and poi-scratchpad-3.9-20121203.jar on your classpath. Once both are there, you should be fine to use HWPF
Since you're using R, if you decide to use the CommonJavaJars library you should refer to the R loadJars documentation for details about how to load all of the jars you need in one go.
Alternately, if you want to skip CommonJavaJars and do it all by hand, then the following snippet shows how to to extract the text from a Word Document from R. Note - it's not pretty, because the R Java interface is decidedly low level...
library(rJava)
.jinit()
.jaddClassPath("poi-3.10-beta3-20131022.jar")
.jaddClassPath("poi-scratchpad-3.10-beta3-20131022.jar")
inputStream <- .jnew("java/io/FileInputStream", path.expand("test.doc"))
wdoc <- .jnew("org/apache/poi/hwpf/HWPFDocument",
.jcast(inputStream,"java/io/InputStream"))
wext <- .jnew("org/apache/poi/hwpf/extractor/WordExtractor", wdoc)
text <- .jcall(wext, "Ljava/lang/String;", "getText")
print(text)
If you want to use other components of Apache POI, be sure to look at the components page to review any dependencies for them (some have more than others)

Image won't display in PDF using FOP 1.1 and Java

I've searched Google through and through and can't seem to find the solution to my issue...
I'm using Apache FOP 1.1 and Java to generate a PDF file from Java classes. This Java project runs from a JAR file. I am using an image that is external to the JAR itself. The XSL file that is used to generate the PDF contains this:
<fo:external-graphic src="file:///C:/images/image.jpg" width="7.5in" />
Based on much searching/reading, I've tried many different variations of the src attribute:
src="file:///C:/images/image.jpg"
src="C:/images/image.jpg"
src="url('file:///C:/images/image.jpg')"
src="url('C:/images/image.jpg')"
all without success...
Now, here's the confusing part. I am doing my development from Eclipse IDE and when using the variations of src attribute:
src="C:/images/image.jpg"
src="url('C:/images/image.jpg')"
The PDF is created properly with the images embedded.
I can not figure out what is keeping the image from being displayed when running from the JAR file...
Thanks in advance! (hopefully)
Devin
The syntax
<fo:external-graphic src="url('C:/images/image.jpg')" content-height="100%" content-width="100%"/>
works perfectly fine for me, both from Eclipse or from a JAR. Have figured out what the problem was?
I know this is an old thread but I had a similar problem and eventually figured out a partial fix. It was a combo of 2 things:
Difference between JVMs in dev and deployed environments (for me raw sun ... err oracle vs. ibm websphere bundled java)
IBM JVM doesn't like indexed PNG files. As soon as I converted it to RGB it worked.
Here is the error message I got when I manually ran the fop.bat file with websphere jvm:
SEVERE: Image not available. URI: /tmp/image.png. Reason: org.apache.xmlgraphics.image.loader.ImageException: I/O error while extracting image metadata: Error reading PNG metadata (See position 30:182)
btw, i was using fop 1.0 + java 1.6 + WAS 7.0 (java 1.6)
Hope this helps someone else!

Need help with using Saxon-B(version 9.1.0.8) with Java 1.4.2

I need to transform one XML document into another using XSLT (for now from command line). I have to use Java 1.4.2. Based on that someone recommended using Saxon and provided the XSLT. It seems simple it should work, but I am lost.
I come more form a .NET environment, and have worked with XML and XSLT but not with Saxon and I am not that strong in Java.
Let me start by explaining what my problem is and what I have tried so far:
The Error:
C:\Projects\new_saxon_download>java net.sf.saxon.Transform -s:source.xml -xsl:style.xsl -o:output.xml
Exception in thread "main" java.lang.NoClassDefFoundError: org/xml/sax/ext/DefaultHandler2
at net.sf.saxon.Configuration.(Configuration.java:2047)
at net.sf.saxon.Transform.setFactoryConfiguration(Transform.java:81)
at net.sf.saxon.Transform.doTransform(Transform.java:133)
at net.sf.saxon.Transform.main(Transform.java:66)
Steps that led me here:
I downloaded Saxon-B by following a link from this page
I also found some information on a dependency about SAX2 from this
page and thus obtained that as well.
Set the CLASSPATH in my session:
set CLASSPATH=.;C:\Projects\new_saxon_download\saxon9.jar;C:\Projects\new_saxon_download\sax2r2.jar
Tried the transformation:
java net.sf.saxon.Transform -s:source.xml -xsl:style.xsl -o:output.xml
Then I get the error shown above. I have tried multiple google search, but nothing has helped.
Any advice or solution would be very helpful.
GOT IT - the description on how to fix the dependendcy issue is crap (sorry).
This file sax2r2.jar isn't the one you have to add to the classpath. It contains another jar (sax.jar) and that's the library you actually need. Just extract the sax2r2.jar and put sax.jar on the classpath, then it should work.
Give this a try: apache xml-commons includes xml-api.jar. I can't tell if this is usable with java 1.4.12 but it's worth a try.
Binary releases can be found here. Download one of the xml-commons-external archives, extract xml-api.jar and add that to your classpath.

Categories