Я пробовал разные файлы "input.xml" и "tagMap.xml".Настраиваемся со структурой и тегами ... Но я продолжаю получать "MalformedURLException"
Любые предложения, кроме решения этой проблемы с iText, приветствуются.Пока входные файлы всегда представляют собой XML с содержимым (input.xml) и другим XML с тегом tagMap (tagMap.xml).
Эта проблема возникает из-за необходимости обновления наших систем.Сервер Weblogic с 8 по 12c, Java с 1.4 до 1.8 ... Нет смысла изменять какие-либо функции в приложении, просто кажется, что код / библиотеки несовместимы.
(Примечание: я сократил все Javaкод + содержимое / структура «input.xml» и «tagMap.xml» для демонстрационных целей.)
Есть идеи?
package sandbox;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import com.lowagie.text.xml.XmlParser;
public class Main {
public static void main(String[] args) {
String testPath = "D:"+File.separator+"JavaTest";
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 80, 50, 30, 65);
// step 2: we create a writer that listens to the document
try {
PdfWriter.getInstance(document, new FileOutputStream
(testPath+File.separator+"outPut.pdf"));
// step 3: we parse the document
XmlParser.parse(document, testPath+ File.separator+ "input.xml"
, testPath+ File.separator+ "tagMap.xml");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
Трассировка стека:
Exception in thread "main" ExceptionConverter: java.net.MalformedURLException
at java.net.URL.<init>(URL.java:627)
at java.net.URL.<init>(URL.java:490)
at java.net.URL.<init>(URL.java:439)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:620)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:148)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:805)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at com.lowagie.text.xml.TagMap.init(Unknown Source)
at com.lowagie.text.xml.TagMap.<init>(Unknown Source)
at com.lowagie.text.xml.XmlParser.go(Unknown Source)
at com.lowagie.text.xml.XmlParser.parse(Unknown Source)
at sandbox.Main.main(Main.java:32)
Caused by: java.lang.NullPointerException
at java.net.URL.<init>(URL.java:532)
... 15 more
input.xml content:
<?xml version="1.0"?>
<GREETING>
<TEXT>Hello World PDF Test</TEXT>
</GREETING>
tagMap.xml content:
<tagmap>
<tag name="iText" alias="GREETING" />
<tag name="paragraph" alias="TEXT">
<attribute name="leading" value="14" />
<attribute name="size" value="10" />
<attribute name="style" value="italic" />
<attribute name="align" value="left" />
</tag>
</tagmap>
Использование: com.lowagie.text.xml.XmlParser
public static void parse(DocListener document,
java.lang.String file,
java.lang.String tagmap)
Parses a given file that validates with the iText DTD and writes the content to a document.
Parameters:
document - The document that will listen to the parser
file - The path to a file with the content
tagmap - A user defined tagmap