Skip to content

Commit

Permalink
0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
KursX committed Aug 3, 2017
1 parent f62ce46 commit 27abd35
Show file tree
Hide file tree
Showing 36 changed files with 101 additions and 21 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
*.class
*.iml
.idea/
out/*
*.fb2


# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
hs_err_pid*
File renamed without changes.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# fb2parser
## Easy parser fb2 files into java objects
# Fb2 parser
## Simple parser of book format fb2 in java objects

download jar/fb2parser.jar
Download [Fb2Parser.jar](https://github.com/KursX/fb2parser/raw/master/jar/fb2parser.jar)

Using:

```java
try {
FictionBook fb2 = new FictionBook(new File("book.fb2"));
FictionBook fb2 = new FictionBook(new File("book.fb2"));
} catch (ParserConfigurationException | IOException | SAXException e) {
e.printStackTrace();
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions com/kursx/parser/fb2/EmptyLine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kursx.parser.fb2;

public class EmptyLine extends P {

public EmptyLine() {
p = "";
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ public class FictionBook {
protected List<Body> bodies = new ArrayList<>();
protected Map<String, Binary> binaries = new HashMap<>();

public FictionBook() {
}
public FictionBook() {}

public FictionBook(File file) throws ParserConfigurationException, IOException, SAXException {
public FictionBook(File file) throws ParserConfigurationException, IOException, SAXException, OutOfMemoryError {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream inputStream = new FileInputStream(file);
BufferedReader br = new BufferedReader(new FileReader(file));
String line = br.readLine();
String encoding = line.substring(line.indexOf("encoding=\"") + 10, line.length() - 3);
String encoding = "utf-8";
try {
String line = br.readLine();
encoding = line.substring(line.indexOf("encoding=\"") + 10, line.indexOf("\"?>"));
} catch (Exception e) {
e.printStackTrace();
}
Document doc = db.parse(new InputSource(new InputStreamReader(inputStream, encoding)));
initXmlns(doc);
description = new Description(doc);
Expand Down
7 changes: 7 additions & 0 deletions com/kursx/parser/fb2/Gson.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kursx.parser.fb2;

/**
* Created by kurs on 30.7.17.
*/
public class Gson {
}
File renamed without changes.
File renamed without changes.
29 changes: 23 additions & 6 deletions src/com/kursx/parser/fb2/P.java → com/kursx/parser/fb2/P.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.kursx.parser.fb2;

import com.kursx.parser.fb2.fonts.Emphasis;
import com.kursx.parser.fb2.fonts.StrikeThrough;
import com.kursx.parser.fb2.fonts.Strong;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

Expand All @@ -9,11 +12,13 @@
public class P {

protected String p;
protected List<Image> images = new ArrayList<>();
// TODO <empty-line/>
// Жирный - <strong>, а курсивный - <emphasis>

protected List<Image> images;
protected List<Emphasis> emphasis;
protected List<Strong> strong;
protected List<StrikeThrough> strikeThrough;
// TODO
// Для нижних индексов <sub>, а для верхних индексов <sup>
// Перечеркнутый - <strikethrough>
// Программный код - <code>
// <subtitle>* * *</subtitle>

Expand All @@ -28,19 +33,31 @@ public P() {
}

public P(Image image) {
if (images == null) images = new ArrayList<>();
images.add(image);
}

public P(Node p) {
this.p = p.getTextContent();
NodeList nodeList = p.getChildNodes();
for (int index = 0; index < nodeList.getLength(); index++) {
Node node = nodeList.item(index);
switch (nodeList.item(index).getNodeName()) {
case "image":
if (images == null) images = new ArrayList<>();
images.add(new Image(node));
break;
case "#text":
this.p = p.getTextContent();
case "strikethrough":
if (strikeThrough == null) strikeThrough = new ArrayList<>();
strikeThrough.add(new StrikeThrough(node.getTextContent(), p.getTextContent()));
break;
case "strong":
if (strong == null) strong = new ArrayList<>();
strong.add(new Strong(node.getTextContent(), p.getTextContent()));
break;
case "emphasis":
if (emphasis == null) emphasis = new ArrayList<>();
emphasis.add(new Emphasis(node.getTextContent(), p.getTextContent()));
break;
}
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public Section() {
case "p":
paragraphs.add(new P(node));
break;
case "empty-line":
paragraphs.add(new EmptyLine());
break;
}
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions com/kursx/parser/fb2/fonts/Emphasis.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kursx.parser.fb2.fonts;

public class Emphasis extends Font {

public Emphasis(String emphasis, String p) {
super(emphasis, p);
}
}
19 changes: 19 additions & 0 deletions com/kursx/parser/fb2/fonts/Font.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.kursx.parser.fb2.fonts;

public class Font {

protected final int startIndex, finishIndex;

protected Font(String emphasis, String p) {
startIndex = p.indexOf(emphasis);
finishIndex = startIndex + emphasis.length();
}

public int getStartIndex() {
return startIndex;
}

public int getFinishIndex() {
return finishIndex;
}
}
8 changes: 8 additions & 0 deletions com/kursx/parser/fb2/fonts/StrikeThrough.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kursx.parser.fb2.fonts;

public class StrikeThrough extends Font {

public StrikeThrough(String strong, String p) {
super(strong, p);
}
}
8 changes: 8 additions & 0 deletions com/kursx/parser/fb2/fonts/Strong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.kursx.parser.fb2.fonts;

public class Strong extends Font {

public Strong(String strong, String p) {
super(strong, p);
}
}
Binary file modified jar/fb2parser.jar
Binary file not shown.
2 changes: 0 additions & 2 deletions src/META-INF/MANIFEST.MF

This file was deleted.

Empty file removed src/file.fb2
Empty file.
2 changes: 0 additions & 2 deletions src/out/production/fb2parser/META-INF/MANIFEST.MF

This file was deleted.

Empty file.

0 comments on commit 27abd35

Please sign in to comment.