
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@272 f0f2a975-2e09-46c8-9428-3b39399b9f3c
93 lines
2.7 KiB
Java
93 lines
2.7 KiB
Java
/************************************************************************
|
|
*
|
|
* BatchHandlerImpl.java
|
|
*
|
|
* Copyright: 2002-2008 by Henrik Just
|
|
*
|
|
* This file is part of Writer2LaTeX.
|
|
*
|
|
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Writer2LaTeX is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* Version 1.0 (2008-10-03)
|
|
*
|
|
*/
|
|
|
|
package writer2latex;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
|
|
import writer2latex.api.BatchHandler;
|
|
|
|
/** This class implements a <code>BatchHandler</code> for command line usage
|
|
*/
|
|
public class BatchHandlerImpl implements BatchHandler {
|
|
private int nIndent = 0;
|
|
|
|
private void writeMessage(String sMsg) {
|
|
for (int i=0; i<nIndent; i++) {
|
|
System.out.print(" ");
|
|
}
|
|
System.out.println(sMsg);
|
|
}
|
|
|
|
public void startConversion() {
|
|
System.out.println("Press Enter to cancel the conversion");
|
|
}
|
|
|
|
public void endConversion() {
|
|
// No message
|
|
}
|
|
|
|
public void startDirectory(String sName) {
|
|
writeMessage("Converting directory "+sName);
|
|
nIndent++;
|
|
}
|
|
|
|
public void endDirectory(String sName, boolean bSuccess) {
|
|
nIndent--;
|
|
if (!bSuccess) {
|
|
writeMessage("--> Conversion of the directory "+sName+" failed!");
|
|
}
|
|
}
|
|
|
|
public void startFile(String sName) {
|
|
writeMessage("Converting file "+sName);
|
|
nIndent++;
|
|
}
|
|
|
|
public void endFile(String sName, boolean bSuccess) {
|
|
nIndent--;
|
|
if (!bSuccess) {
|
|
writeMessage("--> Conversion of the file "+sName+" failed!");
|
|
}
|
|
}
|
|
|
|
public boolean cancel() {
|
|
try {
|
|
if (System.in.available()>0) {
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
|
in.readLine();
|
|
System.out.print("Do you want to cancel the conversion (y/n)? ");
|
|
String s = in.readLine();
|
|
if (s!= null && s.toLowerCase().startsWith("y")) { return true; }
|
|
}
|
|
}
|
|
catch (IOException e) {
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|