本文整理汇总了Java中nl.siegmann.epublib.domain.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于nl.siegmann.epublib.domain包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSpineReferenceTitle
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private void setSpineReferenceTitle() {
int srSize = mSpineReferences.size();
int trSize = mTocReferences.size();
for (int j = 0; j < srSize; j++) {
String href = mSpineReferences.get(j).getResource().getHref();
for (int i = 0; i < trSize; i++) {
if (mTocReferences.get(i).getResource().getHref().equalsIgnoreCase(href)) {
mSpineReferences.get(j).getResource().setTitle(mTocReferences.get(i).getTitle());
break;
} else {
mSpineReferences.get(j).getResource().setTitle("");
}
}
}
for (int i = 0; i < trSize; i++) {
Resource resource = mTocReferences.get(i).getResource();
if (resource != null) {
mChapterList.add(new BookMixAToc.mixToc.Chapters(resource.getTitle(), resource.getHref()));
}
}
}
示例2: readLazyResources
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private static void readLazyResources(File root, Resources resources, File folder) throws IOException {
String hrefRoot = root.getAbsolutePath() + "/";
for (File file : folder.listFiles()) {
if (file.isDirectory()) {
readLazyResources(root, resources, file);
continue;
}
if (file.getName().equals(".ready")) {
continue;
}
String path = file.getAbsolutePath();
String href = path.replace(hrefRoot, "");
Resource resource = new LazyResource(path, 0, href);
resources.add(resource);
}
}
示例3: readEpubMetadata
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private void readEpubMetadata(final String filename, final File f, final EBook ebk) {
ebk.addFileType("epub");
ebk.setBook_title(f.getName().substring(0, f.getName().length() - 5));
ebk.setFull_file_dir_name(ebk.getFile_dir() + File.separator + ebk.getBook_title());
long flen = f.length();
if (flen < 24500000) {
try {
InputStream epubInputStream = new FileInputStream(filename);
Book book = erdr.readEpub(epubInputStream);
ebk.addAuthors(book.getMetadata().getAuthors());
ebk.setBook_title(book.getTitle());
Resource cvrImg = book.getCoverImage();
if (cvrImg != null) {
ebk.setCoverImageFromBitmap(BitmapFactory.decodeStream(cvrImg.getInputStream()));
}
epubInputStream.close();
} catch (IOException e) {
BookLibApplication.e(LOG_TAG + "Failed to read epub details from [" + filename + "] " + e.getMessage());
} catch (NullPointerException npe) {
BookLibApplication.e(LOG_TAG + "NullPointerException reading epub details from [" + filename + "] " + npe.getMessage());
}
} else {
BookLibApplication.d(LOG_TAG + "Skipping Large epub [filename: " + filename + ", size: " + f.length() + "]");
}
}
示例4: doInBackground
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private void doInBackground() {
if ( spine == null ) {
return;
}
Option<Resource> resource = spine.getNextResource();
resource.forEach( res -> {
Option<Spannable> cachedText = textLoader.getCachedTextForResource( res );
if ( isEmpty(cachedText) ) {
try {
textLoader.getText( res, PreLoadTask.this::isCancelled );
} catch ( Exception | OutOfMemoryError e ) {
//Ignore
}
}
});
}
示例5: TyphonSpine
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
/**
* Creates a new Spine from this book.
*
* @param book
*/
public TyphonSpine(Book book) {
this.entries = new ArrayList<>();
this.position = 0;
addResource(createCoverResource(book));
String href = null;
if ( entries.size() > 0 && ! entries.get(0).href.equals( COVER_HREF ) ) {
href = book.getCoverPage().getHref();
}
for ( int i=0; i < book.getSpine().size(); i++ ) {
Resource res = book.getSpine().getResource(i);
if ( href == null || ! (href.equals(res.getHref()))) {
addResource(res);
}
}
if ( book.getNcxResource() != null ) {
this.tocHref = book.getNcxResource().getHref();
}
}
示例6: processHtml
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
public byte[] processHtml(Resource resource, Book book, String outputEncoding) throws IOException {
// clean html
TagNode node = htmlCleaner.clean(resource.getReader());
// post-process cleaned html
HashMap<String, String> map = new HashMap<>(1);
map.put("xmlns", Constants.NAMESPACE_XHTML);
node.setAttributes(map);
node.setDocType(createXHTMLDoctypeToken());
// write result to output
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(out, outputEncoding);
writer = new NoCloseWriter(writer);
EpublibXmlSerializer xmlSerializer = new EpublibXmlSerializer(htmlCleaner.getProperties(), outputEncoding);
xmlSerializer.write(node, writer, outputEncoding);
writer.flush();
return out.toByteArray();
}
示例7: checkSpineReferences
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private static List<SpineReference> checkSpineReferences(Spine spine) {
List<SpineReference> result = new ArrayList<SpineReference>(spine.size());
Resource previousResource = null;
for(SpineReference spineReference: spine.getSpineReferences()) {
if(spineReference.getResource() == null
|| StringUtils.isBlank(spineReference.getResource().getHref())) {
continue;
}
if(previousResource == null
|| spineReference.getResource() == null
|| ( ! (spineReference.getResource().getHref().equals(previousResource.getHref())))) {
result.add(spineReference);
}
previousResource = spineReference.getResource();
}
return result;
}
示例8: findResources
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private static Resources findResources(FileObject rootDir, String inputEncoding) throws IOException {
Resources result = new Resources();
FileObject[] allFiles = rootDir.findFiles(new AllFileSelector());
for(int i = 0; i < allFiles.length; i++) {
FileObject file = allFiles[i];
if (file.getType() == FileType.FOLDER) {
continue;
}
MediaType mediaType = MediatypeService.determineMediaType(file.getName().getBaseName());
if(mediaType == null) {
continue;
}
String href = file.getName().toString().substring(rootDir.getName().toString().length() + 1);
byte[] resourceData = IOUtils.toByteArray(file.getContent().getInputStream());
if(mediaType == MediatypeService.XHTML && ! nl.siegmann.epublib.Constants.CHARACTER_ENCODING.equalsIgnoreCase(inputEncoding)) {
resourceData = ResourceUtil.recode(inputEncoding, nl.siegmann.epublib.Constants.CHARACTER_ENCODING, resourceData);
}
Resource fileResource = new Resource(null, resourceData, href, mediaType);
result.add(fileResource);
}
return result;
}
示例9: read
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
public static void read(Resource packageResource, EpubReader epubReader, Book book, Resources resources) throws UnsupportedEncodingException, SAXException, IOException, ParserConfigurationException {
Document packageDocument = ResourceUtil.getAsDocument(packageResource);
String packageHref = packageResource.getHref();
resources = fixHrefs(packageHref, resources);
readGuide(packageDocument, epubReader, book, resources);
// Books sometimes use non-identifier ids. We map these here to legal ones
Map<String, String> idMapping = new HashMap<String, String>();
resources = readManifest(packageDocument, packageHref, epubReader, resources, idMapping);
book.setResources(resources);
readCover(packageDocument, book);
book.setMetadata(PackageDocumentMetadataReader.readMetadata(packageDocument));
book.setSpine(readSpine(packageDocument, epubReader, book.getResources(), idMapping));
// if we did not find a cover page then we make the first page of the book the cover page
if (book.getCoverPage() == null && book.getSpine().size() > 0) {
book.setCoverPage(book.getSpine().getResource(0));
}
}
示例10: fixHrefs
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
/**
* Strips off the package prefixes up to the href of the packageHref.
*
* Example:
* If the packageHref is "OEBPS/content.opf" then a resource href like "OEBPS/foo/bar.html" will be turned into "foo/bar.html"
*
* @param packageHref
* @param resourcesByHref
* @return The stipped package href
*/
private static Resources fixHrefs(String packageHref,
Resources resourcesByHref) {
int lastSlashPos = packageHref.lastIndexOf('/');
if(lastSlashPos < 0) {
return resourcesByHref;
}
Resources result = new Resources();
for(Resource resource: resourcesByHref.getAll()) {
if(StringUtil.isNotBlank(resource.getHref())
|| resource.getHref().length() > lastSlashPos) {
resource.setHref(resource.getHref().substring(lastSlashPos + 1));
}
result.add(resource);
}
return result;
}
示例11: generateSpineFromResources
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
/**
* Creates a spine out of all resources in the resources.
* The generated spine consists of all XHTML pages in order of their href.
*
* @param resources
* @return a spine created out of all resources in the resources.
*/
private static Spine generateSpineFromResources(Resources resources) {
Spine result = new Spine();
List<String> resourceHrefs = new ArrayList<String>();
resourceHrefs.addAll(resources.getAllHrefs());
Collections.sort(resourceHrefs, String.CASE_INSENSITIVE_ORDER);
for (String resourceHref: resourceHrefs) {
Resource resource = resources.getByHref(resourceHref);
if (resource.getMediaType() == MediatypeService.NCX) {
result.setTocResource(resource);
} else if (resource.getMediaType() == MediatypeService.XHTML) {
result.addSpineReference(new SpineReference(resource));
}
}
return result;
}
示例12: readCover
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
/**
* Finds the cover resource in the packageDocument and adds it to the book if found.
* Keeps the cover resource in the resources map
* @param packageDocument
* @param book
* @param resources
*/
private static void readCover(Document packageDocument, Book book) {
Collection<String> coverHrefs = findCoverHrefs(packageDocument);
for (String coverHref: coverHrefs) {
Resource resource = book.getResources().getByHref(coverHref);
if (resource == null) {
log.error("Cover resource " + coverHref + " not found");
continue;
}
if (resource.getMediaType() == MediatypeService.XHTML) {
book.setCoverPage(resource);
} else if (MediatypeService.isBitmapImage(resource.getMediaType())) {
book.setCoverImage(resource);
}
}
}
示例13: loadResources
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
/**
* Loads all entries from the ZipInputStream as Resources.
*
* Loads the contents of all ZipEntries into memory.
* Is fast, but may lead to memory problems when reading large books on devices with small amounts of memory.
*
* @param zipInputStream
* @param defaultHtmlEncoding
* @return
* @throws IOException
*/
public static Resources loadResources(ZipInputStream zipInputStream, String defaultHtmlEncoding) throws IOException {
Resources result = new Resources();
ZipEntry zipEntry;
do {
// get next valid zipEntry
zipEntry = getNextZipEntry(zipInputStream);
if((zipEntry == null) || (zipEntry == ERROR_ZIP_ENTRY) || zipEntry.isDirectory()) {
continue;
}
// store resource
Resource resource = ResourceUtil.createResource(zipEntry, zipInputStream);
if(resource.getMediaType() == MediatypeService.XHTML) {
resource.setInputEncoding(defaultHtmlEncoding);
}
result.add(resource);
} while(zipEntry != null);
return result;
}
示例14: writeManifest
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private static void writeManifest(Book book, EpubWriter epubWriter, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
serializer.startTag(NAMESPACE_OPF, OPFTags.manifest);
serializer.startTag(NAMESPACE_OPF, OPFTags.item);
serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.id, epubWriter.getNcxId());
serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.href, epubWriter.getNcxHref());
serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.media_type, epubWriter.getNcxMediaType());
serializer.endTag(NAMESPACE_OPF, OPFTags.item);
// writeCoverResources(book, serializer);
for(Resource resource: getAllResourcesSortById(book)) {
writeItem(book, resource, serializer);
}
serializer.endTag(NAMESPACE_OPF, OPFTags.manifest);
}
示例15: writeItem
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
/**
* Writes a resources as an item element
* @param resource
* @param serializer
* @throws IOException
* @throws IllegalStateException
* @throws IllegalArgumentException
*/
private static void writeItem(Book book, Resource resource, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
if(resource == null ||
(resource.getMediaType() == MediatypeService.NCX
&& book.getSpine().getTocResource() != null)) {
return;
}
if(StringUtil.isBlank(resource.getId())) {
log.error("resource id must not be empty (href: " + resource.getHref() + ", mediatype:" + resource.getMediaType() + ")");
return;
}
if(StringUtil.isBlank(resource.getHref())) {
log.error("resource href must not be empty (id: " + resource.getId() + ", mediatype:" + resource.getMediaType() + ")");
return;
}
if(resource.getMediaType() == null) {
log.error("resource mediatype must not be empty (id: " + resource.getId() + ", href:" + resource.getHref() + ")");
return;
}
serializer.startTag(NAMESPACE_OPF, OPFTags.item);
serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.id, resource.getId());
serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.href, resource.getHref());
serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.media_type, resource.getMediaType().getName());
serializer.endTag(NAMESPACE_OPF, OPFTags.item);
}