
com.jaeksoft.searchlib.crawler.file.process.fileInstances.SwiftFileInstance Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearchserver Show documentation
Show all versions of opensearchserver Show documentation
OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface,
the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and
easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and
Linux/Unix/BSD.
The newest version!
/**
* License Agreement for OpenSearchServer
*
* Copyright (C) 2013-2016 Emmanuel Keller / Jaeksoft
*
* http://www.open-search-server.com
*
* This file is part of OpenSearchServer.
*
* OpenSearchServer is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenSearchServer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenSearchServer.
* If not, see .
**/
package com.jaeksoft.searchlib.crawler.file.process.fileInstances;
import com.jaeksoft.searchlib.SearchLibException;
import com.jaeksoft.searchlib.crawler.file.database.FilePathItem;
import com.jaeksoft.searchlib.crawler.file.database.FileTypeEnum;
import com.jaeksoft.searchlib.crawler.file.process.FileInstanceAbstract;
import com.jaeksoft.searchlib.crawler.file.process.fileInstances.swift.SwiftProtocol;
import com.jaeksoft.searchlib.crawler.file.process.fileInstances.swift.SwiftProtocol.ObjectMeta;
import com.jaeksoft.searchlib.crawler.file.process.fileInstances.swift.SwiftToken;
import com.jaeksoft.searchlib.crawler.web.spider.HttpDownloader;
import com.jaeksoft.searchlib.util.LinkUtils;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
public class SwiftFileInstance extends FileInstanceAbstract {
private SwiftToken token;
private ObjectMeta object;
public SwiftFileInstance() {
super();
token = null;
}
protected SwiftFileInstance(FilePathItem filePathItem, SwiftFileInstance parent, SwiftToken token,
ObjectMeta object) throws URISyntaxException, UnsupportedEncodingException {
this.token = token;
this.object = object;
init(filePathItem, parent, object.pathName);
}
private void authentication(HttpDownloader downloader)
throws ClientProtocolException, URISyntaxException, IOException, JSONException {
if (token != null)
return;
token = new SwiftToken(downloader, filePathItem.getSwiftAuthURL(), filePathItem.getUsername(),
filePathItem.getPassword(), filePathItem.getSwiftAuthType(), filePathItem.getSwiftTenant());
}
@Override
public URI init() throws URISyntaxException, UnsupportedEncodingException {
String path = getPath();
if (token != null)
return token.getURI(filePathItem.getSwiftContainer(), path, false);
return new URI(LinkUtils.concatPath(getFilePathItem().getSwiftAuthURL(), path));
}
@Override
public FileTypeEnum getFileType() {
if (object == null)
return FileTypeEnum.directory;
return object.isDirectory ? FileTypeEnum.directory : FileTypeEnum.file;
}
private FileInstanceAbstract[] listFiles(boolean withDirectory)
throws URISyntaxException, ClientProtocolException, JSONException, IOException {
HttpDownloader downloader = new HttpDownloader(null, false, null, 600);
try {
authentication(downloader);
List objectList = SwiftProtocol
.listObjects(downloader, token, filePathItem.getSwiftContainer(), getPath(), withDirectory,
filePathItem.isIgnoreHiddenFiles(), filePathItem.getExclusionMatchers());
if (objectList == null)
return null;
FileInstanceAbstract[] files = new FileInstanceAbstract[objectList.size()];
int i = 0;
FilePathItem fpi = this.getFilePathItem();
for (ObjectMeta object : objectList)
files[i++] = new SwiftFileInstance(fpi, this, token, object);
return files;
} finally {
downloader.release();
}
}
@Override
public FileInstanceAbstract[] listFilesAndDirectories()
throws URISyntaxException, ClientProtocolException, JSONException, IOException {
return listFiles(true);
}
@Override
public FileInstanceAbstract[] listFilesOnly()
throws URISyntaxException, ClientProtocolException, JSONException, IOException {
return listFiles(false);
}
@Override
public Long getLastModified() {
if (object == null)
return null;
return object.lastModified;
}
@Override
public Long getFileSize() {
if (object == null)
return null;
return object.contentLength;
}
@Override
public String getFileName() {
if (object == null)
return null;
return object.name;
}
@Override
public void delete() throws IOException {
throw new IOException("Delete not implemented");
}
@Override
public InputStream getInputStream() throws IOException {
try {
HttpDownloader downloader = new HttpDownloader(null, false, null, 600);
authentication(downloader);
return SwiftProtocol.getObject(downloader, getFilePathItem().getSwiftContainer(), token, object);
} catch (URISyntaxException e) {
throw new IOException(e);
} catch (JSONException e) {
throw new IOException(e);
} catch (SearchLibException e) {
throw new IOException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy