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


Java TOCReference类代码示例

本文整理汇总了Java中nl.siegmann.epublib.domain.TOCReference的典型用法代码示例。如果您正苦于以下问题:Java TOCReference类的具体用法?Java TOCReference怎么用?Java TOCReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TOCReference类属于nl.siegmann.epublib.domain包,在下文中一共展示了TOCReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadBook

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private void loadBook() {

        try {
            // 打开书籍
            EpubReader reader = new EpubReader();
            InputStream is = new FileInputStream(mFilePath);
            mBook = reader.readEpub(is);

            mTocReferences = (ArrayList<TOCReference>) mBook.getTableOfContents().getTocReferences();
            mSpineReferences = mBook.getSpine().getSpineReferences();

            setSpineReferenceTitle();

            // 解压epub至缓存目录
            FileUtils.unzipFile(mFilePath, Constant.PATH_EPUB + "/" + mFileName);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
开发者ID:ynztlxdeai,项目名称:TextReader,代码行数:20,代码来源:ReadEPubActivity.java

示例2: onBindViewHolder

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
@Override
public void onBindViewHolder(VH holder, int position) {
    TOCReference tocReference = tableOfContents.get(position);
    String title = tocReference.getTitle();
    if (title == null) {
        title = "Chapter " + (position + 1);
    }
    holder.binding.chapterTitle.setText(title);

    if (position == currentTocPosition) {
        holder.binding.chapterTitle.setBackgroundColor(Color.LTGRAY);
    } else {
        holder.binding.chapterTitle.setBackgroundColor(Color.TRANSPARENT);
    }

    holder.binding.getRoot().setOnClickListener(v -> {
        // search correct chapter (spine position) for toc entry
        int spinePosition = epub.getSpinePositionForTocReference(tocReference);
        if (spinePosition >= 0) {
            jumpToChapter.onNext(spinePosition);
        }
    });

}
 
开发者ID:smartmobilefactory,项目名称:EpubReaderAndroid,代码行数:25,代码来源:TableOfContentsAdapter.java

示例3: flatten

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private void flatten(List<TOCReference> refs, List<TocEntry> entries,
		int level) {

	if (spine == null || refs == null || refs.isEmpty()) {
		return;
	}

	for (TOCReference ref : refs) {

		String title = "";

		for (int i = 0; i < level; i++) {
			title += "  ";
		}

		title += ref.getTitle();

		if (ref.getResource() != null) {
			entries.add(new TocEntry(title, spine.resolveTocHref(ref
					.getCompleteHref())));
		}

		flatten(ref.getChildren(), entries, level + 1);
	}
}
 
开发者ID:benjamarle,项目名称:typhon,代码行数:26,代码来源:BookView.java

示例4: parseChm

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
public static Book parseChm(FileObject chmRootDir, String inputHtmlEncoding)
		throws IOException, ParserConfigurationException,
		XPathExpressionException {
	Book result = new Book();
	result.getMetadata().addTitle(findTitle(chmRootDir));
	FileObject hhcFileObject = findHhcFileObject(chmRootDir);
	if(hhcFileObject == null) {
		throw new IllegalArgumentException("No index file found in directory " + chmRootDir + ". (Looked for file ending with extension '.hhc'");
	}
	if(inputHtmlEncoding == null) {
		inputHtmlEncoding = DEFAULT_CHM_HTML_INPUT_ENCODING;
	}
	Resources resources = findResources(chmRootDir, inputHtmlEncoding);
	List<TOCReference> tocReferences = HHCParser.parseHhc(hhcFileObject.getContent().getInputStream(), resources);
	result.setTableOfContents(new TableOfContents(tocReferences));
	result.setResources(resources);
	result.generateSpineFromTableOfContents();
	return result;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:20,代码来源:ChmParser.java

示例5: processUlNode

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private static List<TOCReference> processUlNode(Node ulNode, Resources resources) {
	List<TOCReference> result = new ArrayList<TOCReference>();
	NodeList children = ulNode.getChildNodes();
	for(int i = 0; i < children.getLength(); i++) {
		Node node = children.item(i);
		if(node.getNodeName().equals("li")) {
			List<TOCReference> section = processLiNode(node, resources);
			result.addAll(section);
		} else if(node.getNodeName().equals("ul")) {
			List<TOCReference> childTOCReferences = processUlNode(node, resources);
			if(result.isEmpty()) {
				result = childTOCReferences;
			} else {
				result.get(result.size() - 1).getChildren().addAll(childTOCReferences);
			}
		}
	}
	return result;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:20,代码来源:HHCParser.java

示例6: processLiNode

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private static List<TOCReference> processLiNode(Node liNode, Resources resources) {
	List<TOCReference> result = new ArrayList<TOCReference>();
	NodeList children = liNode.getChildNodes();
	for(int i = 0; i < children.getLength(); i++) {
		Node node = children.item(i);
		if(node.getNodeName().equals("object")) {
			TOCReference section = processObjectNode(node, resources);
			if(section != null) {
				result.add(section);
			}
		} else if(node.getNodeName().equals("ul")) {
			List<TOCReference> childTOCReferences = processUlNode(node, resources);
			if(result.isEmpty()) {
				result = childTOCReferences;
			} else {
				result.get(result.size() - 1).getChildren().addAll(childTOCReferences);
			}
		}
	}
	return result;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:22,代码来源:HHCParser.java

示例7: readTOCReferences

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private static List<TOCReference> readTOCReferences(NodeList navpoints, Book book) {
	if(navpoints == null) {
		return new ArrayList<TOCReference>();
	}
	List<TOCReference> result = new ArrayList<TOCReference>(navpoints.getLength());
	for(int i = 0; i < navpoints.getLength(); i++) {
		Node node = navpoints.item(i);
		if (node.getNodeType() != Document.ELEMENT_NODE) {
			continue;
		}
		if (! (node.getLocalName().equals(NCXTags.navPoint))) {
			continue;
		}
		TOCReference tocReference = readTOCReference((Element) node, book);
		result.add(tocReference);
	}
	return result;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:19,代码来源:NCXDocument.java

示例8: readTOCReference

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的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

示例9: writeNavPoints

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private static int writeNavPoints(List<TOCReference> tocReferences, int playOrder,
		XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException  {
	for(TOCReference tocReference: tocReferences) {
		if (tocReference.getResource() == null) {
			playOrder = writeNavPoints(tocReference.getChildren(), playOrder, serializer);
			continue;
		}
		writeNavPointStart(tocReference, playOrder, serializer);
		playOrder++;
		if(! tocReference.getChildren().isEmpty()) {
			playOrder = writeNavPoints(tocReference.getChildren(), playOrder, serializer);
		}
		writeNavPointEnd(tocReference, serializer);
	}
	return playOrder;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:17,代码来源:NCXDocument.java

示例10: getSpinePositionForTocReference

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
/**
 * @return -1 if toc position not found
 */
public int getSpinePositionForTocReference(TOCReference tocReference) {
    List<SpineReference> spineReferences = getBook().getSpine().getSpineReferences();
    for (int i = 0; i < spineReferences.size(); i++) {
        SpineReference spineReference = spineReferences.get(i);
        if (tocReference.getResourceId().equals(spineReference.getResourceId())) {
            return i;
        }
    }
    return -1;
}
 
开发者ID:smartmobilefactory,项目名称:EpubReaderAndroid,代码行数:14,代码来源:Epub.java

示例11: getTocPositionForSpinePosition

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
/**
 * @return -1 if spine position not found
 */
public int getTocPositionForSpinePosition(int spinePosition) {
    List<TOCReference> tocReferences = getBook().getTableOfContents().getTocReferences();
    for (int i = 0; i < tocReferences.size(); i++) {
        TOCReference tocReference = tocReferences.get(i);
        int spinePositionForTocReference = getSpinePositionForTocReference(tocReference);
        if (spinePositionForTocReference == spinePosition) {
            return i;
        }
        if (spinePositionForTocReference > spinePosition) {
            return i - 1;
        }
    }
    return -1;
}
 
开发者ID:smartmobilefactory,项目名称:EpubReaderAndroid,代码行数:18,代码来源:Epub.java

示例12: fixMissingResources

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private void fixMissingResources(Collection<TOCReference> tocReferences, Book book) {
	for (TOCReference tocReference:  tocReferences) {
		if (tocReference.getResource() == null) {
			
		}
	}
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:8,代码来源:FixMissingResourceBookProcessor.java

示例13: getTitle

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private String getTitle(TOCReference tocReference, Book book, XPath xpath) throws IOException, XPathExpressionException {
	Resource resource = tocReference.getResource();
	if(resource == null) {
		return null;
	}
	InputSource inputSource = new InputSource(resource.getInputStream());
	String title = xpath.evaluate("/html/head/title", inputSource);
	return title;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:10,代码来源:SectionTitleBookProcessor.java

示例14: parseHhc

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
public static List<TOCReference> parseHhc(InputStream hhcFile, Resources resources) throws IOException, ParserConfigurationException,	XPathExpressionException {
	HtmlCleaner htmlCleaner = new HtmlCleaner();
	CleanerProperties props = htmlCleaner.getProperties();
	TagNode node = htmlCleaner.clean(hhcFile);
	Document hhcDocument = new DomSerializer(props).createDOM(node);
	XPath xpath = XPathFactory.newInstance().newXPath();
	Node ulNode = (Node) xpath.evaluate("body/ul", hhcDocument
			.getDocumentElement(), XPathConstants.NODE);
	List<TOCReference> sections = processUlNode(ulNode, resources);
	return sections;
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:12,代码来源:HHCParser.java

示例15: writeNavPointStart

import nl.siegmann.epublib.domain.TOCReference; //导入依赖的package包/类
private static void writeNavPointStart(TOCReference tocReference, int playOrder, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException  {
	serializer.startTag(NAMESPACE_NCX, NCXTags.navPoint);
	serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, NCXAttributes.id, "navPoint-" + playOrder);
	serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, NCXAttributes.playOrder, String.valueOf(playOrder));
	serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, NCXAttributes.clazz, NCXAttributeValues.chapter);
	serializer.startTag(NAMESPACE_NCX, NCXTags.navLabel);
	serializer.startTag(NAMESPACE_NCX, NCXTags.text);
	serializer.text(tocReference.getTitle());
	serializer.endTag(NAMESPACE_NCX, NCXTags.text);
	serializer.endTag(NAMESPACE_NCX, NCXTags.navLabel);
	serializer.startTag(NAMESPACE_NCX, NCXTags.content);
	serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, NCXAttributes.src, tocReference.getCompleteHref());
	serializer.endTag(NAMESPACE_NCX, NCXTags.content);
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:15,代码来源:NCXDocument.java


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