super();
}
protected void init(SearchResourceContext leafResourceContext, VFSLeaf leaf) throws IOException,DocumentException,DocumentAccessException {
// Load metadata for this file
MetaInfo meta = null;
if (leaf instanceof OlatRelPathImpl) {
meta = MetaInfoFactory.createMetaInfoFor((OlatRelPathImpl)leaf);
}
// Set all know attributes
this.setResourceUrl(leafResourceContext.getResourceUrl());
this.setLastChange(new Date(leaf.getLastModified()));
// Check if there are documents attributes set in resource context
if (leafResourceContext.getDocumentType() != null && !leafResourceContext.getDocumentType().equals("")) {
// document-type in context is set => get from there
this.setDocumentType(leafResourceContext.getDocumentType());
} else {
this.setDocumentType(TYPE);
}
String metaTitle = (meta == null ? null : meta.getTitle());
if(!StringHelper.containsNonWhitespace(metaTitle)) {
metaTitle = null;
}
if (leafResourceContext.getTitle() != null && !leafResourceContext.getTitle().equals("")) {
// Title in context is set => get from there and add filename
this.setTitle(leafResourceContext.getTitle() + " , " + (metaTitle == null ? "" : (metaTitle + " ( ")) + leaf.getName() + (metaTitle == null ? "" : " )"));
} else {
this.setTitle((metaTitle == null ? "" : (metaTitle + " ( ")) + leaf.getName() + (metaTitle == null ? "" : " )"));
}
String metaDesc = (meta == null ? null : meta.getComment());
if (leafResourceContext.getDescription() != null && !leafResourceContext.getDescription().equals("")) {
// Title in context is set => get from there
this.setDescription(leafResourceContext.getDescription() + (metaDesc == null ? "" : " " + metaDesc));
} else {
// no description this.setDescription();
if (metaDesc != null) this.setDescription(metaDesc);
}
this.setParentContextType(leafResourceContext.getParentContextType());
this.setParentContextName(leafResourceContext.getParentContextName());
// Add the content itself
this.setContent(readContent(leaf));
// Add other metadata from meta info
if (meta != null) {
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_DESCRIPTION, meta.getComment());
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_LANGUAGE, meta.getLanguage());
// Date is 2009 200902 or 20090228
String[] pubDateArray = meta.getPublicationDate();
if (pubDateArray != null) {
String pubDate = null;
if (pubDateArray.length == 1) pubDate = meta.getPublicationDate()[0];
if (pubDateArray.length == 2) pubDate = meta.getPublicationDate()[0]+meta.getPublicationDate()[1];
if (pubDateArray.length == 3) pubDate = meta.getPublicationDate()[0]+meta.getPublicationDate()[1]+meta.getPublicationDate()[2];
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_DATE, pubDate);
}
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_PUBLISHER, meta.getPublisher());
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_SOURCE, meta.getSource());
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_SOURCE, meta.getUrl());
// use creator and author as olat author
setAuthor((meta.getCreator() == null ? meta.getAuthor() : meta.getAuthor() + " " + meta.getCreator()));
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_CREATOR, meta.getCreator());
}
// Add file type
String mimeType = WebappHelper.getMimeType(leaf.getName());
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_FORMAT, mimeType);