001: package de.java2html.plugin.jspwiki;
002:
003: import java.util.Map;
004:
005: import com.ecyrd.jspwiki.plugin.PluginException;
006:
007: import de.java2html.options.ConversionOptionsUtilities;
008: import de.java2html.options.HorizontalAlignment;
009: import de.java2html.options.JavaSourceConversionOptions;
010: import de.java2html.options.JavaSourceStyleTable;
011: import de.java2html.plugin.AbstractJava2HtmlPlugin;
012: import de.java2html.plugin.ParameterUtilities;
013:
014: /**
015: * @author Markus Gebhard
016: */
017: public class PluginConversionOptionsParser {
018:
019: public JavaSourceConversionOptions parseConversionOptions(Map params)
020: throws PluginException {
021: JavaSourceConversionOptions conversionOptions = AbstractJava2HtmlPlugin
022: .getDefaultSettings().getConversionOptions();
023: adjustStyleTable(params, conversionOptions);
024: adjustBorder(params, conversionOptions);
025: adjustLineNumbers(params, conversionOptions);
026: adjustTabSize(params, conversionOptions);
027: adjustAlignment(params, conversionOptions);
028: return conversionOptions;
029: }
030:
031: private void adjustStyleTable(Map params,
032: JavaSourceConversionOptions conversionOptions)
033: throws PluginException {
034: String style = ParameterUtilities.getParameter(params,
035: PluginParameter.STYLE);
036: if (style != null) {
037: JavaSourceStyleTable styleTable = JavaSourceStyleTable
038: .getPredefinedTable(style);
039: if (styleTable == null) {
040: throw new PluginException("Unsupported style '"
041: + style
042: + "' - available styles are: "
043: + ConversionOptionsUtilities
044: .getPredefinedStyleTableNameString());
045: }
046: conversionOptions.setStyleTable(styleTable);
047: }
048: }
049:
050: private void adjustBorder(Map params,
051: JavaSourceConversionOptions conversionOptions)
052: throws PluginException {
053: String border = ParameterUtilities.getParameter(params,
054: PluginParameter.BORDER);
055: if (border != null) {
056: conversionOptions.setShowTableBorder(ParameterUtilities
057: .getBoolean(border));
058: }
059: }
060:
061: private void adjustLineNumbers(Map params,
062: JavaSourceConversionOptions conversionOptions)
063: throws PluginException {
064: String lineNumbers = ParameterUtilities.getParameter(params,
065: PluginParameter.LINE_NUMBERS);
066: if (lineNumbers != null) {
067: conversionOptions.setShowLineNumbers(ParameterUtilities
068: .getBoolean(lineNumbers));
069: }
070: }
071:
072: private void adjustTabSize(Map params,
073: JavaSourceConversionOptions conversionOptions)
074: throws PluginException {
075: String tabSize = ParameterUtilities.getParameter(params,
076: PluginParameter.TAB_SIZE);
077: if (tabSize != null) {
078: conversionOptions.setTabSize(ParameterUtilities
079: .getInt(tabSize));
080: }
081: }
082:
083: private void adjustAlignment(Map params,
084: JavaSourceConversionOptions conversionOptions)
085: throws PluginException {
086: String alignment = ParameterUtilities.getParameter(params,
087: PluginParameter.ALIGNMENT);
088: if (alignment != null) {
089: HorizontalAlignment horizontalAlignment = HorizontalAlignment
090: .getByName(alignment);
091: if (horizontalAlignment == null) {
092: throw new PluginException(
093: "Unsupported alignment '"
094: + alignment
095: + "' - valid values are: "
096: + ConversionOptionsUtilities
097: .getAvailableHorizontalAlignmentNameString());
098: }
099: conversionOptions
100: .setHorizontalAlignment(horizontalAlignment);
101: }
102: }
103: }
|