\r
import java.io.BufferedReader;\r
import java.io.File;\r
+import java.io.FileWriter;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.io.InputStreamReader;\r
import java.util.List;\r
\r
import jp.cafebabe.commons.xmlcli.CommandLinePlus;\r
+import jp.cafebabe.commons.xmlcli.HelpFormatterPlus;\r
import jp.cafebabe.commons.xmlcli.OptionsBuilder;\r
import jp.cafebabe.commons.xmlcli.builder.OptionsBuilderFactory;\r
import jp.naist.se.stigmata.format.BirthmarkComparisonResultFormat;\r
import jp.naist.se.stigmata.spi.BirthmarkSpi;\r
import jp.naist.se.stigmata.spi.ResultFormatSpi;\r
import jp.naist.se.stigmata.ui.swing.StigmataFrame;\r
+import jp.naist.se.stigmata.utils.BirthmarkContextExporter;\r
\r
import org.apache.commons.cli.CommandLineParser;\r
import org.apache.commons.cli.HelpFormatter;\r
\r
/**\r
* Front end class.\r
- *\r
- * @author Haruaki TAMADA\r
- * @version $Revision$ $Date$\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
*/\r
public class Main{\r
private FormatManager manager = FormatManager.getInstance();\r
String mode = commandLine.getOptionValue("mode");\r
String format = commandLine.getOptionValue("format");\r
\r
- if(format == null) format = "xml";\r
- if(mode == null) mode = "gui";\r
+ if(format == null)\r
+ format = "xml";\r
+ if(mode == null)\r
+ mode = "gui";\r
\r
boolean exitFlag = executeOption(commandLine, options);\r
\r
if(!exitFlag){\r
if(!("gui".equals(mode) || "list".equals(mode))\r
&& (arguments == null || arguments.length == 0)){\r
+\r
printHelp(options);\r
return;\r
}\r
/**\r
* extract birthmarks.\r
*/\r
- private void extractBirthmarks(Stigmata stigmata, String[] birthmarks, String[] args, String format){\r
- try {\r
+ private void extractBirthmarks(Stigmata stigmata, String[] birthmarks,\r
+ String[] args, String format){\r
+ try{\r
BirthmarkSet[] holders = stigmata.extract(birthmarks, args, context);\r
\r
ResultFormatSpi spi = manager.getService(format);\r
BirthmarkExtractionResultFormat formatter = spi.getExtractionResultFormat();\r
formatter.printResult(new PrintWriter(System.out), holders);\r
- } catch(Exception ex) {\r
+ }catch(Exception ex){\r
ex.printStackTrace();\r
}\r
}\r
\r
/**\r
- *\r
+ * \r
*/\r
- private void compareBirthmarks(Stigmata stigmata, String[] birthmarks, String[] filters, String[] args, String format){\r
+ private void compareBirthmarks(Stigmata stigmata, String[] birthmarks,\r
+ String[] filters, String[] args, String format){\r
try{\r
- BirthmarkSet[] holders = stigmata.extract(birthmarks, args, context);\r
+ BirthmarkSet[] holders = stigmata\r
+ .extract(birthmarks, args, context);\r
ComparisonResultSet resultset = stigmata.compare(holders, context);\r
if(filters != null){\r
resultset = stigmata.filter(resultset, filters);\r
ResultFormatSpi spi = manager.getService(format);\r
BirthmarkComparisonResultFormat formatter = spi.getComparisonResultFormat();\r
formatter.printResult(new PrintWriter(System.out), resultset);\r
- } catch(Exception e){\r
+ }catch(Exception e){\r
e.printStackTrace();\r
}\r
}\r
BirthmarkServiceListFormat formatter = spi.getBirthmarkServiceListFormat();\r
\r
formatter.printResult(new PrintWriter(System.out), spis);\r
- }\r
- catch(IOException e){\r
+ }catch(IOException e){\r
e.printStackTrace();\r
}\r
}\r
\r
if(classpath != null){\r
for(String cp: classpath){\r
- try {\r
+ try{\r
File f = new File(cp);\r
if(f.exists()){\r
context.addClasspath(f.toURI().toURL());\r
}\r
- } catch (MalformedURLException ex) {\r
+ }catch(MalformedURLException ex){\r
}\r
}\r
}\r
printLicense();\r
exitFlag = true;\r
}\r
+ if(commandLine.hasOption("export-config")){\r
+ exportConfiguration(commandLine.getOptionValue("export-config"));\r
+ exitFlag = true;\r
+ }\r
return exitFlag;\r
}\r
\r
private Options buildOptions(){\r
- try {\r
+ try{\r
OptionsBuilderFactory factory = OptionsBuilderFactory.getInstance();\r
URL location = getClass().getResource("/resources/options.xml");\r
OptionsBuilder builder = factory.createBuilder(location);\r
Options options = builder.buildOptions();\r
\r
return options;\r
- } catch (DOMException ex) {\r
+ }catch(DOMException ex){\r
ex.printStackTrace();\r
- } catch (SAXException ex) {\r
+ }catch(SAXException ex){\r
ex.printStackTrace();\r
- } catch (IOException ex) {\r
+ }catch(IOException ex){\r
ex.printStackTrace();\r
}\r
return null;\r
}\r
\r
+ private void exportConfiguration(String file){\r
+ try{\r
+ PrintWriter out;\r
+ if(file == null){\r
+ out = new PrintWriter(System.out);\r
+ }\r
+ else{\r
+ if(!file.endsWith(".xml")){\r
+ file = file + ".xml";\r
+ }\r
+ out = new PrintWriter(new FileWriter(file));\r
+ }\r
+\r
+ new BirthmarkContextExporter(context).export(out);\r
+ out.close();\r
+ }catch(IOException e){\r
+ }\r
+ }\r
+\r
private void printHelp(Options options){\r
Package p = getClass().getPackage();\r
- HelpFormatter formatter = new HelpFormatter();\r
- formatter.printHelp("java -jar stigmata-" + p.getImplementationVersion() + ".jar <OPTIONS> <TARGETS>",\r
- "TARGETS is allowed as jar files, war files, class files, and classpath directory.", options, "");\r
+ HelpFormatter formatter = new HelpFormatterPlus();\r
+ System.out.println(options.getClass().getName());\r
+ formatter.printHelp(\r
+ String.format(\r
+ "java -jar stigmata-%s.jar <OPTIONS> <TARGETS>%n" + \r
+ "TARGETS is allowed as jar files, war files, class files, and classpath directory.",\r
+ p.getImplementationVersion()\r
+ ),\r
+ options\r
+ );\r
System.out.println();\r
System.out.println("Available birthmarks:");\r
for(BirthmarkSpi service: context.getServices()){\r
if(!service.isExpert()){\r
- System.out.printf(" %-5s (%s): %s%n", service.getType(), service.getDisplayType(), service.getDescription());\r
+ System.out.printf(" %-5s (%s): %s%n", service.getType(),\r
+ service.getDisplayType(), service.getDescription());\r
}\r
}\r
System.out.println();\r
System.out.println("Available filers:");\r
- for(ComparisonPairFilterSet filterset: context.getFilterManager().getFilterSets()){\r
- System.out.printf(" %s (%s)%n", filterset.getName(), filterset.isMatchAll()? "match all following condition": "match any following condition");\r
+ for(ComparisonPairFilterSet filterset: context.getFilterManager()\r
+ .getFilterSets()){\r
+ System.out.printf(" %s (%s)%n", filterset.getName(), filterset.isMatchAll()? "match all": "match any");\r
for(ComparisonPairFilter filter: filterset){\r
System.out.printf(" %s%n", filter);\r
}\r
}\r
\r
private void printLicense(){\r
- try {\r
+ try{\r
InputStream in = getClass().getResourceAsStream("/META-INF/license.txt");\r
BufferedReader reader = new BufferedReader(new InputStreamReader(in));\r
String line;\r
System.out.println(line);\r
}\r
reader.close();\r
- } catch (IOException ex) {\r
+ }catch(IOException ex){\r
ex.printStackTrace();\r
}\r
}\r
if(element instanceof BirthmarkSpi){\r
BirthmarkSpi service = (BirthmarkSpi)model.getElementAt(i);\r
// not expert birthmarks are defined as class.\r
- if(service.isExpert()){\r
+ if(service.isExpert() && service instanceof BirthmarkService){\r
out.println(" <birthmark-service>");\r
out.printf(" <type>%s</type>%n", service.getType());\r
out.printf(" <display-name>%s</display-name>%n", service.getDisplayType());\r
* $Id$\r
*/\r
\r
+import java.text.MessageFormat;\r
import java.util.MissingResourceException;\r
import java.util.ResourceBundle;\r
\r
return instance.get(key);\r
}\r
\r
+ public static String getString(String key, Object... strings){\r
+ String v = instance.get(key);\r
+\r
+ return MessageFormat.format(v, strings);\r
+ }\r
+\r
public static String[] getStringArray(String key){\r
return instance.getArray(key);\r
}\r
import java.io.PrintWriter;\r
import java.io.StringWriter;\r
import java.net.URL;\r
-import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.List;\r
\r
public void setCurrentDirectory(File directory){\r
if(!directory.isDirectory()){\r
- String message = MessageFormat.format(\r
- Messages.getString("notdirectory.dialog.message"),\r
- new Object[] { directory.getName(), }\r
+ JOptionPane.showMessageDialog(\r
+ this, \r
+ Messages.getString("notdirectory.dialog.message", directory.getName()),\r
+ Messages.getString("notdirectory.dialog.title"),\r
+ JOptionPane.ERROR_MESSAGE\r
);\r
- JOptionPane.showMessageDialog(this, message, Messages.getString("notdirectory.dialog.title"), JOptionPane.ERROR_MESSAGE);\r
return;\r
}\r
this.currentDirectory = directory;\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.util.Locale;\r
\r
import jp.naist.se.stigmata.utils.LocalizedDescriptionManager;\r
\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public abstract class AbstractComparisonPairFilterComponentService implements ComparisonPairFilterComponentService{\r
public String getDisplayFilterName(){\r
return getDisplayFilterName(Locale.getDefault());\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.awt.Dimension;\r
import java.awt.GridLayout;\r
-import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import jp.naist.se.stigmata.filter.BirthmarkElementCountComparisonPairFilter;\r
import jp.naist.se.stigmata.filter.BirthmarkElementCountComparisonPairFilterService;\r
import jp.naist.se.stigmata.filter.Target;\r
-import jp.naist.se.stigmata.spi.ComparisonPairFilterSpi;\r
import jp.naist.se.stigmata.spi.BirthmarkSpi;\r
+import jp.naist.se.stigmata.spi.ComparisonPairFilterSpi;\r
import jp.naist.se.stigmata.ui.swing.BirthmarkServiceListCellRenderer;\r
import jp.naist.se.stigmata.ui.swing.BirthmarkServiceListener;\r
import jp.naist.se.stigmata.ui.swing.Messages;\r
\r
-\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public class BirthmarkElementCountComparisonPairFilterComponentService extends AbstractComparisonPairFilterComponentService implements BirthmarkServiceListener{\r
private Pane pane;\r
\r
try{\r
int v = Integer.parseInt(threshold.getText());\r
if(v < 0){\r
- errors.add(MessageFormat.format(Messages.getString("error.negative.value"), v));\r
+ errors.add(Messages.getString("error.negative.value", v));\r
}\r
} catch(NumberFormatException e){\r
- errors.add(MessageFormat.format(Messages.getString("error.invalid.format.integer"), threshold.getText()));\r
+ errors.add(Messages.getString("error.invalid.format.integer", threshold.getText()));\r
}\r
\r
return errors.toArray(new String[errors.size()]);\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.util.Locale;\r
\r
import jp.naist.se.stigmata.spi.ComparisonPairFilterSpi;\r
\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public interface ComparisonPairFilterComponentService{\r
public String getDisplayFilterName(Locale locale);\r
\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import jp.naist.se.stigmata.ComparisonPairFilter;\r
\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public interface ComparisonPairFilterListener{\r
public void filterAdded(ComparisonPairFilter filter);\r
\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.util.HashMap;\r
import java.util.Map;\r
\r
import jp.naist.se.stigmata.filter.Target;\r
import jp.naist.se.stigmata.ui.swing.Messages;\r
\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public abstract class ComparisonPairFilterPane extends JPanel{\r
private Map<String, Criterion> criterionMap = new HashMap<String, Criterion>();\r
private Map<String, Target> targetMap = new HashMap<String, Target>();\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.awt.BorderLayout;\r
import java.awt.CardLayout;\r
import java.awt.Dimension;\r
import jp.naist.se.stigmata.ui.swing.StigmataFrame;\r
import jp.naist.se.stigmata.ui.swing.Utility;\r
\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public class FilterEditingPane extends JPanel{\r
private static final long serialVersionUID = -2607954525579006086L;\r
\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.awt.BorderLayout;\r
import java.awt.GridLayout;\r
import java.awt.event.ActionEvent;\r
import jp.naist.se.stigmata.ui.swing.Messages;\r
import jp.naist.se.stigmata.ui.swing.Utility;\r
\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public class FilterSetDefinitionPane extends JPanel implements ComparisonPairFilterListener{\r
private static final long serialVersionUID = 7519306603672717119L;\r
\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.awt.GridLayout;\r
-import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import jp.naist.se.stigmata.spi.ComparisonPairFilterSpi;\r
import jp.naist.se.stigmata.ui.swing.Messages;\r
\r
-\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public class SimilarityComparisonPairFilterComponentService extends AbstractComparisonPairFilterComponentService{\r
\r
public ComparisonPairFilterPane createComponent(ComparisonPairFilterSpi service){\r
try{\r
double v = Double.parseDouble(threshold.getText());\r
if(v < 0d){\r
- errors.add(MessageFormat.format(Messages.getString("error.negative.value"), v));\r
+ errors.add(Messages.getString("error.negative.value", v));\r
}\r
else if(v > 1.0d){\r
- errors.add(MessageFormat.format(Messages.getString("error.over.range"), "0-1"));\r
+ errors.add(Messages.getString("error.over.range", "0-1"));\r
}\r
} catch(NumberFormatException e){\r
- errors.add(MessageFormat.format(Messages.getString("error.invalid.format.double"), threshold.getText()));\r
+ errors.add(Messages.getString("error.invalid.format.double", threshold.getText()));\r
}\r
\r
return errors.toArray(new String[errors.size()]);\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.awt.GridLayout;\r
import java.util.ArrayList;\r
import java.util.List;\r
import jp.naist.se.stigmata.spi.ComparisonPairFilterSpi;\r
import jp.naist.se.stigmata.ui.swing.Messages;\r
\r
-\r
+/**\r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public class TargetNameComparisonPairFilterComponentService extends AbstractComparisonPairFilterComponentService{\r
\r
public ComparisonPairFilterPane createComponent(ComparisonPairFilterSpi service){\r
package jp.naist.se.stigmata.ui.swing.filter;\r
\r
+/*\r
+ * $Id$\r
+ */\r
+\r
import java.awt.GridLayout;\r
-import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import jp.naist.se.stigmata.spi.ComparisonPairFilterSpi;\r
import jp.naist.se.stigmata.ui.swing.Messages;\r
\r
-\r
+/**\r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
public class TotalElementCountComparisonPairFilterComponentService extends AbstractComparisonPairFilterComponentService{\r
\r
public ComparisonPairFilterPane createComponent(ComparisonPairFilterSpi service){\r
try{\r
int v = Integer.parseInt(threshold.getText());\r
if(v < 0){\r
- errors.add(MessageFormat.format(Messages.getString("error.negative.value"), v));\r
+ errors.add(Messages.getString("error.negative.value", v));\r
}\r
} catch(NumberFormatException e){\r
- errors.add(MessageFormat.format(Messages.getString("error.invalid.format.integer"), threshold.getText()));\r
+ errors.add(Messages.getString("error.invalid.format.integer", threshold.getText()));\r
}\r
return errors.toArray(new String[errors.size()]);\r
}\r
target.ONE_OF_TARGET=target 1 or target 2\r
\r
error.dialog.title=Error\r
-error.message.classpath=Failed proccessed operation because following classes do not found.<br>Please examine your classpath settings at ``Control'' tab.\r
-error.message.contactus=Failed proccessed operation because following exception. Please report to developer with following error messages.\r
+error.message.classpath=Failed proccessed operation because following classes did not found.<br>Please examine your classpath settings at ``Control'' tab.\r
+error.message.contactus=Failed proccessed operation because following exception.<br>Please report to developer with following error messages.\r
error.empty.threshold=Threshold is empty\r
error.empty.value=Value is empty\r
error.invalid.format={0}: Invalid format\r
error.filter.cannotcreate=Filter cannot create because following reasons:\r
error.negative.value={0}: Unacceptable negative value\r
error.over.range=Over acceptable range. valid range is {0}.\r
+error.io=IOException: {0}\r
\r
target1.button.label=${target.TARGET1} birthmark\r
target2.button.label=${target.TARGET2} birthmark\r
target.ONE_OF_TARGET=\82Ç\82¿\82ç\82©\r
\r
error.dialog.title=\83G\83\89\81[\r
-error.message.classpath=Failed proccessed operation because following classes do not found.<br>Please examine your classpath settings at ``Control'' tab.\r
-error.message.contactus=Failed proccessed operation because following exception. Please report to developer with following error messages.\r
-error.empty.threshold=Threshold is empty\r
-error.empty.value=Value is empty\r
-error.invalid.format={0}: Invalid format\r
-error.invalid.format.double={0}: Invalid double format\r
-error.invalid.format.integer={0}: Invalid integer format\r
-error.filter.cannotcreate=Filter cannot create because following reasons:\r
-error.negative.value={0}: Unacceptable negative value\r
-error.over.range=Over acceptable range. valid range is {0}.\r
-\r
-target1.button.label=${target.TARGET1} birthmark\r
-target2.button.label=${target.TARGET2} birthmark\r
-both.button.label=${target.BOTH} birthmarks\r
-\r
-target1.name.button.label=${target.TARGET1} class name\r
-target2.name.button.label=${target.TARGET2} class name\r
-both.name.button.label=${target.BOTH} class name\r
+error.message.classpath=\88È\89º\82Ì\83N\83\89\83X\82ª\8c©\82Â\82©\82ç\82È\82©\82Á\82½\82½\82ß\81C\8ew\92è\82³\82ê\82½\8f\88\97\9d\82ð\8a®\97¹\82·\82é\82±\82Æ\82ª\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81D<br>\81u\83R\83\93\83g\83\8d\81[\83\8b\81v\83^\83u\82Ì\83N\83\89\83X\83p\83X\90Ý\92è\82ð\8c©\92¼\82µ\82Ä\8dÄ\8eÀ\8ds\82µ\82Ä\82\82¾\82³\82¢\81D\r
+error.message.contactus=\88È\89º\82Ì\97á\8aO\82ª\94\90¶\82µ\82½\82½\82ß\81C\8ew\92è\82³\82ê\82½\8f\88\97\9d\82ð\8a®\97¹\82·\82é\82±\82Æ\82ª\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81D<br>\83G\83\89\81[\83\81\83b\83Z\81[\83W\82ð\93Y\95t\82µ\82Ä\8aJ\94\8eÒ\82Ü\82Å\83\8c\83|\81[\83g\82ð\82¨\8aè\82¢\82µ\82Ü\82·\81D\r
+error.empty.threshold=è\87\92l\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81D\r
+error.empty.value=\92l\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81D\r
+error.invalid.format={0}: \83t\83H\81[\83}\83b\83g\88È\8fã\82Å\82·\81D\r
+error.invalid.format.double={0}: \93ü\97Í\82³\82ê\82½\92l\82ð\8eÀ\90\94\82É\95Ï\8a·\82·\82é\82±\82Æ\82ª\82Å\82«\82Ü\82¹\82ñ\81D\r
+error.invalid.format.integer={0}: \93ü\97Í\82³\82ê\82½\92l\82ð\90®\90\94\92l\95Ï\8a·\82·\82é\82±\82Æ\82ª\82Å\82«\82Ü\82¹\82ñ\81D\r
+error.filter.cannotcreate=\83t\83B\83\8b\83^\82Í\88È\89º\82Ì\97\9d\97R\82É\82æ\82è\8dì\90¬\82³\82ê\82Ü\82¹\82ñ\82Å\82µ\82½:\r
+error.negative.value={0}: \95\89\82Ì\92l\82ð\93ü\97Í\82·\82é\82±\82Æ\82Í\82Å\82«\82Ü\82¹\82ñ\81D\r
+error.over.range=\94Í\88Í\82ð\89z\82¦\82Ä\82¢\82Ü\82·\81D{0}\82Ì\94Í\88Í\82É\8eû\82Ü\82é\82æ\82¤\82É\82µ\82Ä\82\82¾\82³\82¢\81D\r
+error.io=I/O\83G\83\89\81[: {0}\r
+\r
+target1.button.label=${target.TARGET1}\83o\81[\83X\83}\81[\83N\r
+target2.button.label=${target.TARGET2}\83o\81[\83X\83}\81[\83N\r
+both.button.label=${target.BOTH}\83o\81[\83X\83}\81[\83N\r
+\r
+target1.name.button.label=${target.TARGET1}\83N\83\89\83X\96¼\r
+target2.name.button.label=${target.TARGET2}\83N\83\89\83X\96¼\r
+both.name.button.label=${target.BOTH}\83N\83\89\83X\96¼\r