use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project tika by apache.
the class SXSLFPowerPointExtractorDecorator method handleBasicRelatedParts.
/**
* This should handle the comments, master, notes, etc
*
* @param contentType
* @param xhtmlClassLabel
* @param parentPart
* @param contentHandler
*/
private void handleBasicRelatedParts(String contentType, String xhtmlClassLabel, PackagePart parentPart, ContentHandler contentHandler) throws SAXException {
PackageRelationshipCollection relatedPartPRC = null;
try {
relatedPartPRC = parentPart.getRelationshipsByType(contentType);
} catch (InvalidFormatException e) {
metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e));
}
if (relatedPartPRC != null && relatedPartPRC.size() > 0) {
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", "class", "class", "CDATA", xhtmlClassLabel);
contentHandler.startElement("", "div", "div", attributes);
for (int i = 0; i < relatedPartPRC.size(); i++) {
PackageRelationship relatedPartPackageRelationship = relatedPartPRC.getRelationship(i);
try {
PackagePart relatedPartPart = parentPart.getRelatedPart(relatedPartPackageRelationship);
try (InputStream stream = relatedPartPart.getInputStream()) {
context.getSAXParser().parse(stream, new OfflineContentHandler(new EmbeddedContentHandler(contentHandler)));
} catch (IOException | TikaException e) {
metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e));
}
} catch (InvalidFormatException e) {
metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e));
}
}
contentHandler.endElement("", "div", "div");
}
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project tika by apache.
the class SXWPFWordExtractorDecorator method addRelatedParts.
private void addRelatedParts(PackagePart documentPart, List<PackagePart> relatedParts) {
for (String relation : MAIN_PART_RELATIONS) {
PackageRelationshipCollection prc = null;
try {
prc = documentPart.getRelationshipsByType(relation);
if (prc != null) {
for (int i = 0; i < prc.size(); i++) {
PackagePart packagePart = documentPart.getRelatedPart(prc.getRelationship(i));
relatedParts.add(packagePart);
}
}
} catch (InvalidFormatException e) {
}
}
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project tika by apache.
the class XSLFPowerPointExtractorDecorator method addSlideParts.
private void addSlideParts(PackagePart slidePart, List<PackagePart> parts) {
for (String relation : new String[] { XSLFRelation.VML_DRAWING.getRelation(), XSLFRelation.SLIDE_LAYOUT.getRelation(), XSLFRelation.NOTES_MASTER.getRelation(), XSLFRelation.NOTES.getRelation() }) {
try {
for (PackageRelationship packageRelationship : slidePart.getRelationshipsByType(relation)) {
if (packageRelationship.getTargetMode() == TargetMode.INTERNAL) {
PackagePartName relName = PackagingURIHelper.createPartName(packageRelationship.getTargetURI());
parts.add(packageRelationship.getPackage().getPart(relName));
}
}
} catch (InvalidFormatException e) {
}
}
//and slide of course
parts.add(slidePart);
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project local-data-aragopedia by aragonopendata.
the class GenerateData method readMappingFile.
private HashMap<String, SkosBean> readMappingFile(String skosPath) {
log.debug("Init readSkosFile");
HashMap<String, SkosBean> mapSkos = new HashMap<String, SkosBean>();
File skosMappingg = new File(configDirectoryString + File.separator + skosPath);
InputStream inp = null;
Workbook wb = null;
try {
inp = new FileInputStream(skosMappingg);
wb = WorkbookFactory.create(inp);
} catch (FileNotFoundException e) {
log.error(e.getMessage());
} catch (InvalidFormatException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
if (wb != null) {
Sheet sheet = wb.getSheetAt(0);
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
Row row = sheet.getRow(i);
Cell cellId = row.getCell(0);
Cell cellUri = row.getCell(1);
SkosBean skosBean = new SkosBean();
SkosBean skosBeanExtra = new SkosBean();
String idCell = "";
if (cellId.getCellType() == 0) {
Double d = new Double(cellId.getNumericCellValue());
idCell = d.intValue() + "";
} else {
idCell = cellId.getStringCellValue();
}
skosBean.setLabel(idCell);
idCell = Utils.urlify(idCell);
skosBean.setId(idCell);
String uriCell = "";
if (cellUri.getCellType() == 0) {
Double d = new Double(cellUri.getNumericCellValue());
uriCell = d.intValue() + "";
} else {
uriCell = cellUri.getStringCellValue();
String id = uriCell.substring(uriCell.lastIndexOf("/") + 1, uriCell.length());
if (!idCell.equals(id)) {
skosBeanExtra.setId(id);
skosBeanExtra.setLabel(id);
skosBeanExtra.setURI(uriCell);
mapSkos.put(id, skosBeanExtra);
}
}
skosBean.setURI(uriCell);
mapSkos.put(idCell, skosBean);
}
}
log.debug("End readSkosFile");
return mapSkos;
}
use of org.apache.poi.openxml4j.exceptions.InvalidFormatException in project local-data-aragopedia by aragonopendata.
the class GenerateRDF method readMappingFile.
private HashMap<String, SkosBean> readMappingFile(String skosPath) {
log.debug("Init readSkosFile");
HashMap<String, SkosBean> mapSkos = new HashMap<String, SkosBean>();
File skosMappingg = new File(configDirectoryString + File.separator + skosPath);
InputStream inp = null;
Workbook wb = null;
try {
inp = new FileInputStream(skosMappingg);
wb = WorkbookFactory.create(inp);
} catch (FileNotFoundException e) {
log.error(e.getMessage());
} catch (InvalidFormatException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
if (wb != null) {
Sheet sheet = wb.getSheetAt(0);
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
Row row = sheet.getRow(i);
Cell cellId = row.getCell(0);
Cell cellUri = row.getCell(1);
if (cellId == null || cellUri == null) {
continue;
}
SkosBean skosBean = new SkosBean();
SkosBean skosBeanExtra = new SkosBean();
String idCell = "";
if (cellId.getCellType() == 0) {
Double d = new Double(cellId.getNumericCellValue());
idCell = d.intValue() + "";
} else {
idCell = cellId.getStringCellValue();
}
skosBean.setLabel(idCell);
idCell = Utils.urlify(idCell);
skosBean.setId(idCell);
String uriCell = "";
if (cellUri.getCellType() == 0) {
Double d = new Double(cellUri.getNumericCellValue());
uriCell = d.intValue() + "";
} else {
uriCell = cellUri.getStringCellValue();
String id = uriCell.substring(uriCell.lastIndexOf("/") + 1, uriCell.length());
if (!idCell.equals(id)) {
skosBeanExtra.setId(id);
skosBeanExtra.setLabel(id);
skosBeanExtra.setURI(uriCell);
mapSkos.put(id, skosBeanExtra);
}
}
skosBean.setURI(uriCell);
mapSkos.put(idCell, skosBean);
}
}
log.debug("End readSkosFile");
return mapSkos;
}
Aggregations