use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class FeedFormController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == cancelButton && event.wasTriggerdBy(FormEvent.ONCLICK)) {
fireEvent(ureq, Event.CANCELLED_EVENT);
} else if (source == file && event.wasTriggerdBy(FormEvent.ONCHANGE)) {
// display the uploaded file
if (file.isUploadSuccess()) {
String newFilename = file.getUploadFileName();
boolean isValidFileType = newFilename.toLowerCase().matches(".*[.](png|jpg|jpeg|gif)");
if (!isValidFileType) {
file.setErrorKey("feed.form.file.type.error.images", null);
} else {
file.clearError();
}
deleteImage.setVisible(true);
}
} else if (source == deleteImage) {
VFSLeaf img = FeedManager.getInstance().createFeedMediaFile(feed, feed.getImageName(), null);
if (file.getUploadFile() != null && file.getUploadFile() != file.getInitialFile()) {
file.reset();
if (img == null) {
deleteImage.setVisible(false);
imageDeleted = true;
} else {
deleteImage.setVisible(true);
imageDeleted = false;
}
} else if (img != null) {
imageDeleted = true;
deleteImage.setVisible(false);
file.setInitialFile(null);
}
flc.setDirty(true);
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class ScormRepositoryIndexer method doIndex.
protected void doIndex(SearchResourceContext resourceContext, OlatFullIndexer indexWriter, File cpRoot) throws IOException, InterruptedException {
VFSContainer container = new LocalFolderImpl(cpRoot);
VFSLeaf fManifest = (VFSLeaf) container.resolve("imsmanifest.xml");
if (fManifest != null) {
Element rootElement = IMSLoader.loadIMSDocument(fManifest).getRootElement();
Document manfiestDoc = createManifestDocument(fManifest, rootElement, resourceContext);
indexWriter.addDocument(manfiestDoc);
ScormFileAccess accessRule = new ScormFileAccess();
doIndexVFSContainer(resourceContext, container, indexWriter, "", accessRule);
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class SPCourseNodeIndexer method indexSubPages.
private void indexSubPages(SearchResourceContext courseNodeResourceContext, VFSContainer rootContainer, OlatFullIndexer indexWriter, VFSLeaf leaf, Set<String> alreadyIndexFileNames, int subPageLevel, String rootFilePath) throws IOException, InterruptedException {
int mySubPageLevel = subPageLevel;
// check deepness of recursion
if (mySubPageLevel++ <= 5) {
List<String> links = getLinkListFrom(leaf);
for (String link : links) {
if (log.isDebug())
log.debug("link=" + link);
if ((rootFilePath != null) && !rootFilePath.equals("")) {
if (rootFilePath.endsWith("/")) {
link = rootFilePath + link;
} else {
link = rootFilePath + "/" + link;
}
}
if (!alreadyIndexFileNames.contains(link)) {
VFSItem item = rootContainer.resolve(link);
if ((item != null) && (item instanceof VFSLeaf)) {
VFSLeaf subPageLeaf = (VFSLeaf) item;
if (log.isDebug())
log.debug("subPageLeaf=" + subPageLeaf);
String filePath = getPathFor(subPageLeaf);
String newRootFilePath = filePath;
doIndexVFSLeafByMySelf(courseNodeResourceContext, subPageLeaf, indexWriter, filePath);
alreadyIndexFileNames.add(link);
indexSubPages(courseNodeResourceContext, rootContainer, indexWriter, subPageLeaf, alreadyIndexFileNames, mySubPageLevel, newRootFilePath);
} else {
if (log.isDebug())
log.debug("Could not found sub-page for link=" + link);
}
} else {
if (log.isDebug())
log.debug("sub-page already indexed, link=" + link);
}
}
} else {
if (log.isDebug())
log.debug("Reach to many sub-page levels. Go not further with indexing sub-pages last leaf=" + leaf.getName());
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class SPCourseNodeIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext courseResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
if (log.isDebug())
log.debug("Index SinglePage...");
SearchResourceContext courseNodeResourceContext = createSearchResourceContext(courseResourceContext, courseNode, TYPE);
Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
indexWriter.addDocument(nodeDocument);
// The root of the configured single page. Depends on the configuration
// whether to follow relative links or not. When relative links are
// followed, the root is the course folder root, if not, it is folder
// where the configured file is in
VFSContainer rootContainer;
// The filename of the configured file relative to the rootContainer
String chosenFile;
// Read the course node configuration
VFSContainer courseFolderContainer = course.getCourseEnvironment().getCourseFolderContainer();
boolean allowRelativeLinks = courseNode.getModuleConfiguration().getBooleanSafe(SPEditController.CONFIG_KEY_ALLOW_RELATIVE_LINKS);
String fileName = (String) courseNode.getModuleConfiguration().get(SPEditController.CONFIG_KEY_FILE);
// *** IF YOU CHANGE THIS LOGIC, do also change it in SinglePageController! ***
if (allowRelativeLinks) {
// Case 1: relative links are allowed. The root is the root of the
// course, the file name is relative to the root
rootContainer = courseFolderContainer;
chosenFile = fileName;
} else {
// Case 2: relative links are NOT allowed. We have to calculate the
// new root and remove the relative path to the course folder form
// the file.
String startURI = ((fileName.charAt(0) == '/') ? fileName.substring(1) : fileName);
int sla = startURI.lastIndexOf('/');
if (sla != -1) {
// Some subfolder path is detected, create basecontainer from it
String root = startURI.substring(0, sla);
startURI = startURI.substring(sla + 1);
// Create new root folder from the relative folder path
VFSContainer newroot = (VFSContainer) courseFolderContainer.resolve(root);
newroot.setParentContainer(null);
rootContainer = newroot;
} else {
// No subpath detected, just use course base container
rootContainer = courseFolderContainer;
}
chosenFile = startURI;
}
VFSLeaf leaf = (VFSLeaf) rootContainer.resolve(chosenFile);
if (leaf != null) {
String filePath = getPathFor(leaf);
// Use inherited method from LeafIndexer for the actual indexing of the content
SearchResourceContext fileContext = new SearchResourceContext(courseNodeResourceContext);
doIndexVFSLeafByMySelf(fileContext, leaf, indexWriter, filePath);
if (!indexOnlyChosenFile) {
if (log.isDebug())
log.debug("Index sub pages in SP.");
Set<String> alreadyIndexFileNames = new HashSet<String>();
alreadyIndexFileNames.add(chosenFile);
// Check if page has links to subpages and index those as well
indexSubPages(courseNodeResourceContext, rootContainer, indexWriter, leaf, alreadyIndexFileNames, 0, filePath);
} else if (log.isDebug()) {
log.debug("Index only chosen file in SP.");
}
} else if (log.isDebug()) {
log.debug("Can not found choosen file in SP => Nothing indexed.");
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class DialogCourseNodeIndexer method doIndexFile.
/**
* Index a file of dialog-module.
* @param filename
* @param forumKey
* @param leafResourceContext
* @param indexWriter
* @throws IOException
* @throws InterruptedException
*/
private void doIndexFile(DialogElement element, SearchResourceContext leafResourceContext, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
DialogElementsManager dialogElmsMgr = CoreSpringFactory.getImpl(DialogElementsManager.class);
VFSContainer dialogContainer = dialogElmsMgr.getDialogContainer(element);
VFSLeaf leaf = (VFSLeaf) dialogContainer.getItems(new VFSLeafFilter()).get(0);
if (isLogDebugEnabled())
logDebug("Analyse VFSLeaf=" + leaf.getName());
try {
if (CoreSpringFactory.getImpl(FileDocumentFactory.class).isFileSupported(leaf)) {
leafResourceContext.setFilePath(element.getFilename());
leafResourceContext.setDocumentType(TYPE_FILE);
Document document = CoreSpringFactory.getImpl(FileDocumentFactory.class).createDocument(leafResourceContext, leaf);
indexWriter.addDocument(document);
} else {
if (isLogDebugEnabled())
logDebug("Documenttype not supported. file=" + leaf.getName());
}
} catch (DocumentAccessException e) {
if (isLogDebugEnabled())
logDebug("Can not access document." + e.getMessage());
} catch (IOException ioEx) {
logWarn("IOException: Can not index leaf=" + leaf.getName(), ioEx);
} catch (InterruptedException iex) {
throw new InterruptedException(iex.getMessage());
} catch (Exception ex) {
logWarn("Exception: Can not index leaf=" + leaf.getName(), ex);
}
}
Aggregations