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


Java Book类代码示例

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


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

示例1: epubParse

import nl.siegmann.epublib.domain.Book; //导入依赖的package包/类
public String epubParse(InputStream fileIn) throws IOException
{
	EpubReader epubReader = new EpubReader();
	Book book = epubReader.readEpub(fileIn);

	for (int i = 0; i < book.getSpine().size(); i++) 
	{
		InputStream is = book.getSpine().getSpineReferences().get(i).getResource().getInputStream();
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		StringBuilder sb = new StringBuilder();
		String line = null;
		while ((line = reader.readLine()) != null) 
		{
			sb.append(line + "\n");
		}

		htmltext = sb.toString();
		htmltext = htmltext.replaceAll("\\<.*?\\>", "");
	}
	return htmltext;
	
}
 
开发者ID:arks-api,项目名称:arks-api,代码行数:23,代码来源:EpubParser.java

示例2: getDocumentContent

import nl.siegmann.epublib.domain.Book; //导入依赖的package包/类
/**
 * Implementation of Public method that is used to return the entire content of a .epub file as a single value String.
 * Turns one-by-one all internal html files into String values.
 * @return String: the entire content of a .epub file
 */
@Override
public String getDocumentContent() throws IOException {
    System.out.println(getUri());

    EpubReader epubReader = new EpubReader();
    Book book = epubReader.readEpub(new FileInputStream(getUri()));

    String entireContent = "";
    String textContent = "";
    int fileNumber = book.getContents().size();


    for(int i=0; i<fileNumber; i++) {
        InputStream inputStream = book.getContents().get(i).getInputStream(); // file .html
        try {
            Scanner scanner = new Scanner(inputStream).useDelimiter("\\A");
            entireContent = scanner.hasNext() ? scanner.next() : "";
        } finally {
            inputStream.close();
        }

        org.jsoup.nodes.Document doc = Jsoup.parse(entireContent);
        textContent += doc.body().text();
        textContent += "\n\n";
    }

    return textContent;

}
 
开发者ID:Visions-Team,项目名称:eBread,代码行数:35,代码来源:EPubDocument.java

示例3: readEpubMetadata

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

import nl.siegmann.epublib.domain.Book; //导入依赖的package包/类
/**
 * Get the first non-empty author from the given {@link Book}.
 * @param book Book.
 * @return Author string as "FirstName LastName" (or just first or last name, if only one is filled in). If {@code
 * book} is {@code null}, or has no authors, or author names are empty strings, returns {@code null}.
 */
public static String getFirstAuthor(Book book) {
    if (book == null || book.getMetadata().getAuthors().isEmpty()) return null;

    // Loop through authors to get first non-empty one.
    for (Author author : book.getMetadata().getAuthors()) {
        String fName = author.getFirstname();
        String lName = author.getLastname();
        // Skip this author now if it doesn't have a non-null, non-empty name.
        if ((fName == null || fName.isEmpty()) && (lName == null || lName.isEmpty())) continue;

        // Return the name, which might only use one of the strings.
        if (fName == null || fName.isEmpty()) return lName;
        if (lName == null || lName.isEmpty()) return fName;
        return fName + " " + lName;
    }
    return null;
}
 
开发者ID:bkromhout,项目名称:Minerva,代码行数:24,代码来源:DataUtils.java

示例5: TyphonSpine

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

import nl.siegmann.epublib.domain.Book; //导入依赖的package包/类
private String generateCoverPage(Book book) {
	
	String centerpiece;
	
	//Else we construct a basic front page with title and author.
	if ( book.getCoverImage() == null ) {												
		centerpiece = "<center><h1>" + (book.getTitle() != null ? book.getTitle(): "Book without a title") + "</h1>";
		
		if ( ! book.getMetadata().getAuthors().isEmpty() ) {						
			for ( Author author: book.getMetadata().getAuthors() ) {							
				centerpiece += "<h3>" + author.getFirstname() + " " + author.getLastname() + "</h3>";
			}
		} else {
			centerpiece += "<h3>Unknown author</h3>";
		}

           centerpiece += "</center>";

	} else {
		//If the book has a cover image, we display that
		centerpiece = "<img src='" + book.getCoverImage().getHref() + "'>";
	}		
	
	return "<html><body>" + centerpiece + "</body></html>";
}
 
开发者ID:benjamarle,项目名称:typhon,代码行数:26,代码来源:TyphonSpine.java

示例7: processHtml

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

示例8: parseChm

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

示例9: read

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

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

示例11: write

import nl.siegmann.epublib.domain.Book; //导入依赖的package包/类
public static void write(EpubWriter epubWriter, XmlSerializer serializer, Book book) throws IOException {
	try {
		serializer.startDocument(Constants.CHARACTER_ENCODING, false);
		serializer.setPrefix(PREFIX_OPF, NAMESPACE_OPF);
		serializer.setPrefix(PREFIX_DUBLIN_CORE, NAMESPACE_DUBLIN_CORE);
		serializer.startTag(NAMESPACE_OPF, OPFTags.packageTag);
		serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.version, "2.0");
		serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.uniqueIdentifier, BOOK_ID_ID);

		PackageDocumentMetadataWriter.writeMetaData(book, serializer);
		
		writeManifest(book, epubWriter, serializer);
		writeSpine(book, epubWriter, serializer);
		writeGuide(book, epubWriter, serializer);
		
		serializer.endTag(NAMESPACE_OPF, OPFTags.packageTag);
		serializer.endDocument();
		serializer.flush();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:24,代码来源:PackageDocumentWriter.java

示例12: writeSpine

import nl.siegmann.epublib.domain.Book; //导入依赖的package包/类
/**
 * Writes the package's spine.
 * 
 * @param book
 * @param epubWriter
 * @param serializer
 * @throws IOException 
 * @throws IllegalStateException 
 * @throws IllegalArgumentException 
 */
private static void writeSpine(Book book, EpubWriter epubWriter, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
	serializer.startTag(NAMESPACE_OPF, OPFTags.spine);
	serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.toc, book.getSpine().getTocResource().getId());

	if(book.getCoverPage() != null // there is a cover page
		&&	book.getSpine().findFirstResourceById(book.getCoverPage().getId()) < 0) { // cover page is not already in the spine
		// write the cover html file
		serializer.startTag(NAMESPACE_OPF, OPFTags.itemref);
		serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.idref, book.getCoverPage().getId());
		serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.linear, "no");
		serializer.endTag(NAMESPACE_OPF, OPFTags.itemref);
	}
	writeSpineItems(book.getSpine(), serializer);
	serializer.endTag(NAMESPACE_OPF, OPFTags.spine);
}
 
开发者ID:DASAR,项目名称:epublib-android,代码行数:26,代码来源:PackageDocumentWriter.java

示例13: writeManifest

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

示例14: writeItem

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

示例15: read

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


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