当前位置: 首页>>代码示例>>Java>>正文


Java Resources.add方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:smartmobilefactory,项目名称:EpubReaderAndroid,代码行数:18,代码来源:UncompressedEpubReader.java

示例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;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:23,代码来源:ChmParser.java

示例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;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:27,代码来源:PackageDocumentReader.java

示例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;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:32,代码来源:ResourcesLoader.java

示例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;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:45,代码来源:PackageDocumentReader.java


注:本文中的nl.siegmann.epublib.domain.Resources.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。