use of eu.transkribus.core.model.beans.pagecontent.PcGtsType in project TranskribusCore by Transkribus.
the class PageXmlUtils method createEmptyPcGtsType.
public static PcGtsType createEmptyPcGtsType(final URL imgUrl, Dimension dim) throws IOException {
final String prot = imgUrl.getProtocol();
PcGtsType pcGts;
if (prot.startsWith("http")) {
// fimagestore file
FimgStoreImgMd md = FimgStoreReadConnection.getImgMd(imgUrl);
pcGts = createEmptyPcGtsTypeForRemoteImg(imgUrl, md);
} else {
// try to deal with it as local file
final File imgFile = FileUtils.toFile(imgUrl);
pcGts = createEmptyPcGtsType(imgFile, dim);
}
return pcGts;
}
use of eu.transkribus.core.model.beans.pagecontent.PcGtsType in project TranskribusCore by Transkribus.
the class PageXmlUtils method unmarshal.
public static PcGtsType unmarshal(String pageStr) throws JAXBException {
Unmarshaller u = createUnmarshaller();
StringReader sr = new StringReader(pageStr);
@SuppressWarnings("unchecked") PcGtsType pageData = ((JAXBElement<PcGtsType>) u.unmarshal(sr)).getValue();
return pageData;
}
use of eu.transkribus.core.model.beans.pagecontent.PcGtsType in project TranskribusCore by Transkribus.
the class PageXmlUtils method unmarshal.
public static PcGtsType unmarshal(File file) throws JAXBException {
Unmarshaller u = createUnmarshaller();
// Use FileInputStream because JaxB handles File objects via URL internally and thus does not
// allow all POSIX compliant file names, e.g. containing "#"
FileInputStream fis;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
throw new JAXBException("File not found: " + file.getAbsolutePath(), e);
}
@SuppressWarnings("unchecked") PcGtsType pageData = ((JAXBElement<PcGtsType>) u.unmarshal(fis)).getValue();
onPostConstruct(pageData);
return pageData;
}
use of eu.transkribus.core.model.beans.pagecontent.PcGtsType in project TranskribusCore by Transkribus.
the class PageXmlUtils method marshalToFile.
// public static File marshalToFile(PcGtsType page, File fileOut) throws JAXBException, IOException {
// return marshalToFile(page, fileOut, true);
// }
public static File marshalToFile(PcGtsType page, File fileOut) throws JAXBException, IOException {
ValidationEventCollector vec = new ValidationEventCollector();
Marshaller marshaller = createMarshaller(vec);
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<PcGtsType> je = objectFactory.createPcGts(page);
File backup = null;
if (fileOut.exists()) {
logger.debug("file exists: " + fileOut.getAbsolutePath() + " - backing up!");
backup = CoreUtils.backupFile(fileOut);
}
try {
marshaller.marshal(je, fileOut);
} catch (Exception e) {
if (backup != null) {
logger.debug("restoring backup: " + backup.getAbsolutePath());
FileUtils.copyFile(backup, fileOut);
}
if (e instanceof JAXBException)
throw e;
else
throw new JAXBException(e.getMessage(), e);
} finally {
if (backup != null)
backup.delete();
}
String msg = buildMsg(vec, page);
if (!msg.startsWith(NO_EVENTS_MSG))
logger.info(msg);
return fileOut;
}
use of eu.transkribus.core.model.beans.pagecontent.PcGtsType in project TranskribusCore by Transkribus.
the class PageXmlUtils method unmarshal.
public static PcGtsType unmarshal(byte[] bytes) throws JAXBException {
Unmarshaller u = createUnmarshaller();
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
@SuppressWarnings("unchecked") PcGtsType pageData = ((JAXBElement<PcGtsType>) u.unmarshal(bis)).getValue();
onPostConstruct(pageData);
return pageData;
}
Aggregations