Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document builder #11

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The idea is to provide a "kit" of components which can either be used "as-is", f
What's currently included?
--------------------------
* Raw RTF Parser - parses RTF, sends events representing content to a listener. Performs minimal processing - you get the RTF commands and data exactly as they appear in the file.
* Standard RTF Parser - parses RTF, sends events representing content to a listener. Handles character encoding, Unicode and so on, so you don't have to. This is probably the parser you want to use.
* Standard RTF Parser - parses RTF, sends events representing content to a listener. Handles character encoding, Unicode and so on, so you don't have to.
* Document Builder RTF Parser - parses RTF and constructs a document object model via an implementation of the Document interface. You can either use the provided DefaultDocument implementation, or provide your own. This is probably the parser you want to use.
* Text Converter - demonstrates very simple text extraction from an RTF file
* RTF Dump - another demonstration, this time writing the RTF file contents as XML

Expand Down
2 changes: 2 additions & 0 deletions RTF Parser Kit/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
41 changes: 41 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/Annotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

import java.util.Date;

/**
* Interface for annotation elements. The annotation contents are accessible
* via the DocumentPart functionality. Note that this would mean support for
* nested annotations.
*/
public interface Annotation extends DocumentPart
{

public void setId(String id);

public String getId();

public void setAuthor(String author);

public String getAuthor();

public void setDate(Date date);

public Date getDate();

}
71 changes: 71 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/CharacterStyle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* Interface for storing paragraph style parameters.
*/
public interface CharacterStyle extends Style
{
public enum UnderlineStyle
{
NONE, SINGLE, DOUBLE, WORD, DOTTED, DASHED, DASH_DOTTED, DASH_DOT_DOTTED, LONG_DASHED, THICK, THICK_DOTTED, THICK_DASHED, THICK_DASH_DOTTED, THICK_DASH_DOT_DOTTED, THICK_LONG_DASHED, WAVE, HEAVY_WAVE, DOUBLE_WAVE
}

public CharacterStyle createDerivedStyle();

public CharacterStyle createFlattenedStyle();

@Override
public CharacterStyle getParent();

public void setFont(Font font);

public Font getFont();

public void setFontSize(float value);

public float getFontSize();

public void setBold(boolean bold);

public boolean getBold();

public void setItalic(boolean italic);

public boolean getItalic();

public void setCaps(boolean caps);

public boolean getCaps();

public void setStrikeOut(boolean strikeOut);

public boolean getStrikeOut();

public void setUnderlined(UnderlineStyle style);

public UnderlineStyle getUnderlined();

public void setBackgroundColor(Color color);

public Color getBackgroundColor();

public void setForegroundColor(Color color);

public Color getForegroundColor();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* Interface for style table in which character styles can be
* retrieved by their ID.
*/
public interface CharacterStyleTable extends Iterable<CharacterStyle>
{

public CharacterStyle createStyle();

public void addStyle(int id, CharacterStyle style);

public CharacterStyle styleFor(int id);

public int countStyles();

}
30 changes: 30 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/Chunk.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* A chunk of text with a certain style.
*/
public interface Chunk extends Element
{

public String getText();

public CharacterStyle getStyle();

public void append(String string);
}
31 changes: 31 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* Represents a color that can be placed in the ColorTable.
*/
public interface Color
{

public int getRed();

public int getGreen();

public int getBlue();

}
31 changes: 31 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/ColorTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* Interface for adding a color to the global color table and retrieving
* a Color instance at a specific index.
*/
public interface ColorTable
{

public void addColor(int red, int green, int blue);

public int countColors();

public Color colorAt(int index);
}
40 changes: 40 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/Document.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* Interface for getting to all relevant parts of the document model.
*/
public interface Document extends DocumentPart
{

public FontTable getFontTable();

public ColorTable getColorTable();

public StyleSheet getStyleSheet();

public DocumentSettings getDocumentSettings();

public int countSections();

public Section sectionAt(int index);

public void nextSection();

public Section getLastSection();
}
40 changes: 40 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/DocumentPart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* Interface for appending styled text and handling paragraphs. A flattened
* String representation of all contained text can be obtained via the Text
* functionality.
*/
public interface DocumentPart extends Text
{

public int countParagraphs();

public Paragraph paragraphAt(int index);

public void append(String text, CharacterStyle style);

public void nextParagraph(CharacterStyle lastStyle);

public void nextLine();

public Annotation appendAnnotation();

public ParagraphStyle createDefaultStyle();
}
25 changes: 25 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/DocumentSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* Interface for controlling global settings of the document.
*/
public interface DocumentSettings
{
public PageSettings getPageSettings();
}
25 changes: 25 additions & 0 deletions RTF Parser Kit/src/com/rtfparserkit/document/Element.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2015 Stephan Aßmus <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.rtfparserkit.document;

/**
* Base type for various possible children of a Paragraph.
*/
public interface Element
{

}
Loading