Refactoring

This commit is contained in:
Georgy Litvinov 2020-01-29 17:02:15 +01:00
parent bd32335e71
commit 3365665d23
11 changed files with 72 additions and 77 deletions

View file

@ -66,7 +66,7 @@ public class CellStyleParser extends StyleWithPropertiesParser {
* @param style to use * @param style to use
* @return the tag name. * @return the tag name.
*/ */
public String getDefaultTagName(StyleWithProperties style) { public String getStyleTag() {
return "td"; return "td";
} }

View file

@ -77,7 +77,7 @@ public class FrameStyleParser extends StyleWithPropertiesParser {
getTextSc().cssTextCommon(style, props, true); getTextSc().cssTextCommon(style, props, true);
if (!props.isEmpty()) { if (!props.isEmpty()) {
buf.append(indent); buf.append(indent);
buf.append(getDefaultTagName(null)); buf.append(getStyleTag());
buf.append("."); buf.append(".");
buf.append(getClassNamePrefix()); buf.append(getClassNamePrefix());
buf.append(styleNames.addToExport(sDisplayName)); buf.append(styleNames.addToExport(sDisplayName));
@ -110,7 +110,7 @@ public class FrameStyleParser extends StyleWithPropertiesParser {
* @param style to use * @param style to use
* @return the tag name. * @return the tag name.
*/ */
public String getDefaultTagName(StyleWithProperties style) { public String getStyleTag() {
return ""; return "";
} }

View file

@ -110,7 +110,7 @@ public class ListStyleParser extends StyleParser {
buf.append(" {"); buf.append(" {");
buf.append(props.toString()); buf.append(props.toString());
buf.append("}"); buf.append("}");
buf.append(config.prettyPrint() ? "\n" : " "); buf.append(prettyPrint ? "\n" : " ");
if (config.listFormatting() == XhtmlConfig.HARD_LABELS) { if (config.listFormatting() == XhtmlConfig.HARD_LABELS) {
// Apply left margin and text indent to the paragraphs contained in // Apply left margin and text indent to the paragraphs contained in
// the list // the list
@ -124,7 +124,7 @@ public class ListStyleParser extends StyleParser {
buf.append(" p {"); buf.append(" p {");
buf.append(parProps.toString()); buf.append(parProps.toString());
buf.append("}"); buf.append("}");
buf.append(config.prettyPrint() ? "\n" : " "); buf.append(prettyPrint ? "\n" : " ");
} }
} }
} }

View file

@ -71,7 +71,7 @@ public class ParStyleParser extends StyleWithPropertiesParser {
* @param style to use * @param style to use
* @return the tag name. * @return the tag name.
*/ */
public String getDefaultTagName(StyleWithProperties style) { public String getStyleTag() {
return "p"; return "p";
} }

View file

@ -79,7 +79,7 @@ public class PresentationStyleParser extends FrameStyleParser {
* @param style to use * @param style to use
* @return the tag name. * @return the tag name.
*/ */
public String getDefaultTagName(StyleWithProperties style) { public String getStyleTag() {
return "div"; return "div";
} }
@ -87,14 +87,15 @@ public class PresentationStyleParser extends FrameStyleParser {
* @param sIndent a String of spaces to add before each line * @param sIndent a String of spaces to add before each line
*/ */
public String getStyleSelectors() { public String getStyleSelectors() {
if (bConvertStyles) { if (!bConvertStyles) {
return "";
}
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(super.getStyleSelectors()); buf.append(super.getStyleSelectors());
Enumeration<String> names = outlineStyleNames.keys(); Enumeration<String> names = outlineStyleNames.keys();
while (names.hasMoreElements()) { while (names.hasMoreElements()) {
String sDisplayName = names.nextElement(); String sDisplayName = names.nextElement();
StyleWithProperties style = (StyleWithProperties) StyleWithProperties style = (StyleWithProperties) getStyles().getStyleByDisplayName(sDisplayName);
getStyles().getStyleByDisplayName(sDisplayName);
if (!style.isAutomatic()) { if (!style.isAutomatic()) {
// Apply style to paragraphs within a list item with this class // Apply style to paragraphs within a list item with this class
CSVList props = new CSVList(";"); CSVList props = new CSVList(";");
@ -113,10 +114,7 @@ public class PresentationStyleParser extends FrameStyleParser {
} }
} }
return buf.toString(); return buf.toString();
}
else {
return "";
}
} }

View file

@ -66,7 +66,7 @@ public class RowStyleParser extends StyleWithPropertiesParser {
* @param style to use * @param style to use
* @return the tag name. * @return the tag name.
*/ */
public String getDefaultTagName(StyleWithProperties style) { public String getStyleTag() {
return "tr"; return "tr";
} }

View file

@ -70,7 +70,7 @@ public class SectionStyleParser extends StyleWithPropertiesParser {
* @return the tag name. If the style is null, a default result should be * @return the tag name. If the style is null, a default result should be
* returned. * returned.
*/ */
public String getDefaultTagName(StyleWithProperties style) { public String getStyleTag() {
return "div"; return "div";
} }

View file

@ -55,8 +55,8 @@ public abstract class StyleParser extends Parser {
// The type of xhtml document // The type of xhtml document
protected int nType; protected int nType;
private boolean prettyPrint = true; protected boolean prettyPrint = true;
String indent = null; protected String indent = null;
// Scaling and unit transformation to use // Scaling and unit transformation to use
private String sScale; private String sScale;
private String sColScale; private String sColScale;

View file

@ -61,7 +61,7 @@ public abstract class StyleWithPropertiesParser extends StyleParser {
*/ */
public void applyStyle(String sStyleName, StyleInfo info) { public void applyStyle(String sStyleName, StyleInfo info) {
StyleWithProperties style = (StyleWithProperties) getStyles().getStyle(sStyleName); StyleWithProperties style = (StyleWithProperties) getStyles().getStyle(sStyleName);
info.sTagName = getDefaultTagName(style); info.sTagName = getStyleTag();
if (style!=null) { if (style!=null) {
if (config.multilingual()) { applyLang(style,info); } if (config.multilingual()) { applyLang(style,info); }
applyDirection(style,info); applyDirection(style,info);
@ -95,35 +95,32 @@ public abstract class StyleWithPropertiesParser extends StyleParser {
* @param sIndent a String of spaces to add before each line * @param sIndent a String of spaces to add before each line
*/ */
public String getStyleSelectors() { public String getStyleSelectors() {
if (bConvertStyles) { if (!bConvertStyles) {
return "";
}
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
Enumeration<String> names = styleNames.keys(); Enumeration<String> names = styleNames.keys();
while (names.hasMoreElements()) { while (names.hasMoreElements()) {
String sDisplayName = names.nextElement(); String sDisplayName = names.nextElement();
StyleWithProperties style = (StyleWithProperties) StyleWithProperties style = (StyleWithProperties) getStyles().getStyleByDisplayName(sDisplayName);
getStyles().getStyleByDisplayName(sDisplayName);
if (!style.isAutomatic()) { if (!style.isAutomatic()) {
CSVList props = new CSVList(";"); CSVList props = new CSVList(";");
applyProperties(style, props, true); applyProperties(style, props, true);
buf.append(indent); buf.append(indent);
buf.append(getDefaultTagName(null)); buf.append(getStyleTag());
buf.append("."); buf.append(".");
buf.append(getClassNamePrefix()); buf.append(getClassNamePrefix());
buf.append(styleNames.addToExport(sDisplayName)); buf.append(styleNames.addToExport(sDisplayName));
buf.append(" {"); buf.append(" {");
buf.append(props.toString()); buf.append(props.toString());
buf.append("}"); buf.append("}");
buf.append(config.prettyPrint() ? "\n" : " "); buf.append(prettyPrint ? "\n" : " ");
// TODO: Create a method "getStyleDeclarationsInner" // TODO: Create a method "getStyleDeclarationsInner"
// to be used by eg. FrameStyleConverter // to be used by eg. FrameStyleConverter
} }
} }
return buf.toString(); return buf.toString();
} }
else {
return "";
}
}
/** Return a prefix to be used in generated css class names /** Return a prefix to be used in generated css class names
* @return the prefix * @return the prefix
@ -136,7 +133,7 @@ public abstract class StyleWithPropertiesParser extends StyleParser {
* @return the tag name. If the style is null, a default result should be * @return the tag name. If the style is null, a default result should be
* returned. * returned.
*/ */
public abstract String getDefaultTagName(StyleWithProperties style); public abstract String getStyleTag();
/** Convert formatting properties for a specific style. /** Convert formatting properties for a specific style.
* @param style the style to convert * @param style the style to convert

View file

@ -66,7 +66,7 @@ public class TableStyleParser extends StyleWithPropertiesParser {
* @param style to use * @param style to use
* @return the tag name * @return the tag name
*/ */
public String getDefaultTagName(StyleWithProperties style) { public String getStyleTag() {
return "table"; return "table";
} }

View file

@ -232,7 +232,7 @@ public class TextStyleParser extends StyleWithPropertiesParser {
* @param style to use * @param style to use
* @return the tag name. * @return the tag name.
*/ */
public String getDefaultTagName(StyleWithProperties style) { public String getStyleTag() {
return "span"; return "span";
} }