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

Java source normalization (fixes #516) #631

Open
wants to merge 3 commits into
base: integration
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
482 changes: 224 additions & 258 deletions jhove-apps/src/main/java/Jhove.java

Large diffs are not rendered by default.

211 changes: 97 additions & 114 deletions jhove-apps/src/main/java/JhoveView.java
Original file line number Diff line number Diff line change
@@ -1,139 +1,122 @@
/**********************************************************************
* Jhove - JSTOR/Harvard Object Validation Environment
* Copyright 2004-2008 by JSTOR and the President and Fellows of Harvard College
/**
* ******************************************************************** Jhove - JSTOR/Harvard Object
* Validation Environment Copyright 2004-2008 by JSTOR and the President and Fellows of Harvard
* College
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
**********************************************************************/

* <p>This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* <p>This program 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 Lesser General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA ********************************************************************
*/
import edu.harvard.hul.ois.jhove.App;
import edu.harvard.hul.ois.jhove.ExitCode;
import edu.harvard.hul.ois.jhove.CoreMessageConstants;
import edu.harvard.hul.ois.jhove.ExitCode;
import edu.harvard.hul.ois.jhove.JhoveBase;
import edu.harvard.hul.ois.jhove.JhoveException;
import edu.harvard.hul.ois.jhove.viewer.JhoveWindow;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.Toolkit;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
* JhoveView - JSTOR/Harvard Object Validation Environment.
*/
public class JhoveView
{
private static final Logger LOGGER = Logger.getLogger(JhoveView.class.getCanonicalName());

/** Application name. */
private static final String NAME = "JhoveView"; //$NON-NLS-1$
/** Application icon. */
private static final String ICON_PATH = "org/openpreservation/jhove/icon.png"; //$NON-NLS-1$
/** JhoveView - JSTOR/Harvard Object Validation Environment. */
public class JhoveView {
private static final Logger LOGGER = Logger.getLogger(JhoveView.class.getCanonicalName());

/** Stub constructor. */
private JhoveView()
{
}
/** Application name. */
private static final String NAME = "JhoveView"; // $NON-NLS-1$
/** Application icon. */
private static final String ICON_PATH = "org/openpreservation/jhove/icon.png"; // $NON-NLS-1$

/**
* Application main entry point.
*
* @param args Command-line arguments
*/
public static void main(String[] args)
{
// Make sure we have a satisfactory version of Java.
String version = System.getProperty("java.vm.version"); //$NON-NLS-1$
if (version.compareTo("1.8.0") < 0) { //$NON-NLS-1$
LOGGER.log(Level.SEVERE, CoreMessageConstants.EXC_JAVA_VER_INCMPT);
errorAlert(CoreMessageConstants.EXC_JAVA_VER_INCMPT);
System.exit(ExitCode.INCOMPATIBLE_VM.getReturnCode());
}
/** Stub constructor. */
private JhoveView() {}

// If we're running on a Macintosh, put the menubar at the top
// of the screen where it belongs.
System.setProperty("apple.laf.useScreenMenuBar", "true"); //$NON-NLS-1$ //$NON-NLS-2$
/**
* Application main entry point.
*
* @param args Command-line arguments
*/
public static void main(String[] args) {
// Make sure we have a satisfactory version of Java.
String version = System.getProperty("java.vm.version"); // $NON-NLS-1$
if (version.compareTo("1.8.0") < 0) { // $NON-NLS-1$
LOGGER.log(Level.SEVERE, CoreMessageConstants.EXC_JAVA_VER_INCMPT);
errorAlert(CoreMessageConstants.EXC_JAVA_VER_INCMPT);
System.exit(ExitCode.INCOMPATIBLE_VM.getReturnCode());
}

App app = App.newAppWithName(NAME);
try {
// If we're running on a Macintosh, put the menubar at the top
// of the screen where it belongs.
System.setProperty("apple.laf.useScreenMenuBar", "true"); // $NON-NLS-1$ //$NON-NLS-2$

// Retrieve configuration.
String configFile = JhoveBase.getConfigFileFromProperties();
String saxClass = JhoveBase.getSaxClassFromProperties();
App app = App.newAppWithName(NAME);
try {

// Pre-parse the command line for -c and -x config options.
boolean quoted = false;
for (int i = 0; i < args.length; i++) {
if (quoted) {
int len = args[i].length();
if (args[i].charAt(len - 1) == '"') {
quoted = false;
}
}
else {
if ("-c".equals(args[i])) {
if (i < args.length - 1) {
configFile = args[++i];
}
}
else if ("-x".equals(args[i])) {
if (i < args.length - 1) {
saxClass = args[++i];
}
}
else if (args[i].charAt(0) == '"') {
quoted = true;
}
}
}
// Retrieve configuration.
String configFile = JhoveBase.getConfigFileFromProperties();
String saxClass = JhoveBase.getSaxClassFromProperties();

// Initialize the JHOVE engine.
JhoveBase je = new JhoveBase();
try {
je.init(configFile, saxClass);
// Pre-parse the command line for -c and -x config options.
boolean quoted = false;
for (int i = 0; i < args.length; i++) {
if (quoted) {
int len = args[i].length();
if (args[i].charAt(len - 1) == '"') {
quoted = false;
}
} else {
if ("-c".equals(args[i])) {
if (i < args.length - 1) {
configFile = args[++i];
}
catch (JhoveException e) {
errorAlert(e.getMessage());
// Keep going, so user can correct in editor
} else if ("-x".equals(args[i])) {
if (i < args.length - 1) {
saxClass = args[++i];
}
} else if (args[i].charAt(0) == '"') {
quoted = true;
}
}
}

// Create the main window to select a file.
JhoveWindow jwin = new JhoveWindow(app, je);
URL url = ClassLoader.getSystemResource(ICON_PATH); //$NON-NLS-1$
Toolkit kit = Toolkit.getDefaultToolkit();
jwin.setIconImage(kit.createImage(url));
jwin.setVisible (true);
// Initialize the JHOVE engine.
JhoveBase je = new JhoveBase();
try {
je.init(configFile, saxClass);
} catch (JhoveException e) {
errorAlert(e.getMessage());
// Keep going, so user can correct in editor
}

}
catch (Exception e) {
e.printStackTrace(System.err);
LOGGER.log(Level.SEVERE, e.getMessage());
System.exit(ExitCode.ERROR.getReturnCode());
}
}
// Create the main window to select a file.
JhoveWindow jwin = new JhoveWindow(app, je);
URL url = ClassLoader.getSystemResource(ICON_PATH); // $NON-NLS-1$
Toolkit kit = Toolkit.getDefaultToolkit();
jwin.setIconImage(kit.createImage(url));
jwin.setVisible(true);

/** Displays an error alert. */
private static void errorAlert(String msg)
{
JFrame hiddenFrame = new JFrame();
// Truncate long messages so the alert isn't wider than the screen
String message = (msg.length() > 80) ? msg.substring(0, 79) + "..." : msg;
LOGGER.log(Level.WARNING, msg);
JOptionPane.showMessageDialog(hiddenFrame, message, "Jhove Error",
JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
e.printStackTrace(System.err);
LOGGER.log(Level.SEVERE, e.getMessage());
System.exit(ExitCode.ERROR.getReturnCode());
}
}

/** Displays an error alert. */
private static void errorAlert(String msg) {
JFrame hiddenFrame = new JFrame();
// Truncate long messages so the alert isn't wider than the screen
String message = (msg.length() > 80) ? msg.substring(0, 79) + "..." : msg;
LOGGER.log(Level.WARNING, msg);
JOptionPane.showMessageDialog(hiddenFrame, message, "Jhove Error", JOptionPane.ERROR_MESSAGE);
}
}
50 changes: 20 additions & 30 deletions jhove-apps/src/main/java/UserHome.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
/**********************************************************************
* UserHome - JSTOR/Harvard Object Validation Environment
* Copyright 2006 by the President and Fellows of Harvard College
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
**********************************************************************/



/**
* Determine the default value of the Java user.home property.
* ******************************************************************** UserHome - JSTOR/Harvard
* Object Validation Environment Copyright 2006 by the President and Fellows of Harvard College
*
* <p>This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* <p>This program 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 Lesser General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA ********************************************************************
*/
public class UserHome
{
public static void main (String [] args)
{
System.out.println ("Default user.home is \"" +
System.getProperty ("user.home") + "\"");
}

/** Determine the default value of the Java user.home property. */
public class UserHome {
public static void main(String[] args) {
System.out.println("Default user.home is \"" + System.getProperty("user.home") + "\"");
}
}
Loading