本文整理汇总了Java中nl.siegmann.epublib.domain.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于nl.siegmann.epublib.domain包,在下文中一共展示了Resource类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()));
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:ReadEPubActivity.java
示例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);
}
}
开发者ID:smartmobilefactory,项目名称:EpubReaderAndroid,代码行数:18,代码来源:UncompressedEpubReader.java
示例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() + "]");
}
}
开发者ID:mrspaceman,项目名称:ebookmgr,代码行数:27,代码来源:LibraryScanner.java
示例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
}
}
});
}
开发者ID:benjamarle,项目名称:typhon,代码行数:20,代码来源:PreLoadTask.java
示例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();
}
}
开发者ID:benjamarle,项目名称:typhon,代码行数:30,代码来源:TyphonSpine.java
示例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();
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:22,代码来源:HtmlCleanerBookProcessor.java
示例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;
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:18,代码来源:SectionHrefSanityCheckBookProcessor.java
示例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;
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:23,代码来源:ChmParser.java
示例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));
}
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:21,代码来源:PackageDocumentReader.java
示例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;
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:27,代码来源:PackageDocumentReader.java
示例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;
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:23,代码来源:PackageDocumentReader.java
示例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);
}
}
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:24,代码来源:PackageDocumentReader.java
示例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;
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:32,代码来源:ResourcesLoader.java
示例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);
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:18,代码来源:PackageDocumentWriter.java
示例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);
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:33,代码来源:PackageDocumentWriter.java
示例16: getPackageResourceHref
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private String getPackageResourceHref(Resources resources) {
String defaultResult = "OEBPS/content.opf";
String result = defaultResult;
Resource containerResource = resources.remove("META-INF/container.xml");
if(containerResource == null) {
return result;
}
try {
Document document = ResourceUtil.getAsDocument(containerResource);
Element rootFileElement = (Element) ((Element) document.getDocumentElement().getElementsByTagName("rootfiles").item(0)).getElementsByTagName("rootfile").item(0);
result = rootFileElement.getAttribute("full-path");
} catch (Exception e) {
log.error(e.getMessage(), e);
}
if(StringUtil.isBlank(result)) {
result = defaultResult;
}
return result;
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:21,代码来源:EpubReader.java
示例17: read
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
public static Resource read(Book book, EpubReader epubReader) {
Resource ncxResource = null;
if(book.getSpine().getTocResource() == null) {
log.error("Book does not contain a table of contents file");
return ncxResource;
}
try {
ncxResource = book.getSpine().getTocResource();
if(ncxResource == null) {
return ncxResource;
}
Document ncxDocument = ResourceUtil.getAsDocument(ncxResource);
Element navMapElement = DOMUtil.getFirstElementByTagNameNS(ncxDocument.getDocumentElement(), NAMESPACE_NCX, NCXTags.navMap);
TableOfContents tableOfContents = new TableOfContents(readTOCReferences(navMapElement.getChildNodes(), book));
book.setTableOfContents(tableOfContents);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return ncxResource;
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:21,代码来源:NCXDocument.java
示例18: readTOCReference
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
private static TOCReference readTOCReference(Element navpointElement, Book book) {
String label = readNavLabel(navpointElement);
String tocResourceRoot = StringUtil.substringBeforeLast(book.getSpine().getTocResource().getHref(), '/');
if (tocResourceRoot.length() == book.getSpine().getTocResource().getHref().length()) {
tocResourceRoot = "";
} else {
tocResourceRoot = tocResourceRoot + "/";
}
String reference = StringUtil.collapsePathDots(tocResourceRoot + readNavReference(navpointElement));
String href = StringUtil.substringBefore(reference, Constants.FRAGMENT_SEPARATOR_CHAR);
String fragmentId = StringUtil.substringAfter(reference, Constants.FRAGMENT_SEPARATOR_CHAR);
Resource resource = book.getResources().getByHref(href);
if (resource == null) {
log.error("Resource with href " + href + " in NCX document not found");
}
TOCReference result = new TOCReference(label, resource, fragmentId);
readTOCReferences(navpointElement.getChildNodes(), book);
result.setChildren(readTOCReferences(navpointElement.getChildNodes(), book));
return result;
}
开发者ID:DASAR,项目名称:epublib-android,代码行数:21,代码来源:NCXDocument.java
示例19: calculateChapterPositionsEpub2
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
public ChapterPosition calculateChapterPositionsEpub2(List<List<Epubline>> newChapters,
List<Resource> resources, Resource tocResource) {
epublineTraitsExtractor = new Epub2TraitsExtractor(resources, tocResource);
int currentSize = 0;
ChapterPosition chapterPosition = new ChapterPosition();
for (List<Epubline> chapter : newChapters) {
chapterPosition
.addChapter(chapter.indexOf(epublineTraitsExtractor.getHeading(chapter)) + currentSize,
chapter.indexOf(epublineTraitsExtractor.getTextStart(chapter)) + currentSize,
chapter.indexOf(epublineTraitsExtractor.getTextEnd(chapter)) + currentSize);
currentSize = currentSize + chapter.size();
}
return chapterPosition;
}
开发者ID:vita-us,项目名称:ViTA,代码行数:18,代码来源:ChapterPositionMaker.java
示例20: getElementsIds
import nl.siegmann.epublib.domain.Resource; //导入依赖的package包/类
/**
* Returns jsoup Elements with the ids of the chapters
*
* @return
* @throws IOException
*/
private List<Element> getElementsIds() throws IOException {
List<Element> elementsIds = new ArrayList<Element>();
Map<String, String> map = new HashMap<String, String>();
for (Resource resource : resources) {
document = Jsoup.parse(contentBuilder.getStringFromInputStream(resource.getInputStream()));
for (String id : tocIds) {
if (document.getElementById(id) != null && !map.containsKey(id)) {
elementsIds.add(document.getElementById(id));
map.put(id, document.getElementById(id).text());
}
}
}
return elementsIds;
}
开发者ID:vita-us,项目名称:ViTA,代码行数:22,代码来源:Epub2IdsAndTitlesExtractor.java
注:本文中的nl.siegmann.epublib.domain.Resource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论