本文整理汇总了Java中nl.siegmann.epublib.domain.Resources.add方法的典型用法代码示例。如果您正苦于以下问题:Java Resources.add方法的具体用法?Java Resources.add怎么用?Java Resources.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nl.siegmann.epublib.domain.Resources
的用法示例。
在下文中一共展示了Resources.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readLazyResources
import nl.siegmann.epublib.domain.Resources; //导入方法依赖的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);
}
}
示例2: findResources
import nl.siegmann.epublib.domain.Resources; //导入方法依赖的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;
}
示例3: fixHrefs
import nl.siegmann.epublib.domain.Resources; //导入方法依赖的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;
}
示例4: loadResources
import nl.siegmann.epublib.domain.Resources; //导入方法依赖的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;
}
示例5: readManifest
import nl.siegmann.epublib.domain.Resources; //导入方法依赖的package包/类
/**
* Reads the manifest containing the resource ids, hrefs and mediatypes.
*
* @param packageDocument
* @param packageHref
* @param epubReader
* @param book
* @param resourcesByHref
* @return a Map with resources, with their id's as key.
*/
private static Resources readManifest(Document packageDocument, String packageHref,
EpubReader epubReader, Resources resources, Map<String, String> idMapping) {
Element manifestElement = DOMUtil.getFirstElementByTagNameNS(packageDocument.getDocumentElement(), NAMESPACE_OPF, OPFTags.manifest);
Resources result = new Resources();
if(manifestElement == null) {
log.error("Package document does not contain element " + OPFTags.manifest);
return result;
}
NodeList itemElements = manifestElement.getElementsByTagNameNS(NAMESPACE_OPF, OPFTags.item);
for(int i = 0; i < itemElements.getLength(); i++) {
Element itemElement = (Element) itemElements.item(i);
String id = DOMUtil.getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.id);
String href = DOMUtil.getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.href);
try {
href = URLDecoder.decode(href, Constants.CHARACTER_ENCODING);
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage());
}
String mediaTypeName = DOMUtil.getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.media_type);
Resource resource = resources.remove(href);
if(resource == null) {
log.error("resource with href '" + href + "' not found");
continue;
}
resource.setId(id);
MediaType mediaType = MediatypeService.getMediaTypeByName(mediaTypeName);
if(mediaType != null) {
resource.setMediaType(mediaType);
}
result.add(resource);
idMapping.put(id, resource.getId());
}
return result;
}