Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Apr 26, 2024
1 parent cbb4c3f commit 2da16df
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class TempFileClosingTest {
private int initialFileAmount;

public void test() throws VeraPDFException {
File testFile = new File(TEST_FILE);
switchTempDir();
initialFileAmount = getAmountOfFiles(currentTempDir);
try {
File testFile = new File(TEST_FILE);
GreenfieldCliWrapper.main(new String[] {testFile.getAbsolutePath(), FORMAT_OPTION, TEXT_VARIANT});
} catch (VeraPDFException e) {
System.setProperty(TEMP_DIR_PROPERTY, initialTempDir.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public String getLatestVersion(final ReleaseDetails details) {

private static SemanticVersionNumber getLatestVersionFromUrl(final String endpoint) {
try {
URL url = new URL(endpoint);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
builder.setErrorHandler(null);
URL url = new URL(endpoint);
Document doc = builder.parse(new InputSource(url.openStream()));
XPath path = XPathFactory.newInstance().newXPath();
NodeList versions = ((NodeList) path.evaluate("//str[@name='v']", doc, XPathConstants.NODESET));
Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/java/org/verapdf/cli/VeraPdfCliProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ ProcessorConfig getProcessorConfig() {
}

ExitCodes processPaths(final List<String> pdfPaths, boolean nonPdfExt) throws VeraPDFException {
ExitCodes retStatus = ExitCodes.VALID;
if (isServerMode) {
try {
this.tempFile = Files.createTempFile("tempReport", ".xml").toFile();
Expand All @@ -91,6 +90,7 @@ ExitCodes processPaths(final List<String> pdfPaths, boolean nonPdfExt) throws Ve
this.os = System.out;
}
// If the path list is empty then process the STDIN stream
ExitCodes retStatus = ExitCodes.VALID;
if (pdfPaths.isEmpty() && !isServerMode) {
retStatus = processStdIn();
} else {
Expand Down
47 changes: 27 additions & 20 deletions gui/src/main/java/org/verapdf/gui/MiniLogoPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,37 @@ class MiniLogoPanel extends JPanel {
label.setToolTipText(GUIConstants.LABEL_TOOL_TIP);
try (InputStream is = getClass().getClassLoader().getResourceAsStream(logoPath)) {
final BufferedImage image = ImageIO.read(is);
Icon icon = new Icon() {

private static final double SCALE = 0.3;

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
g.drawImage(image, 0, 0, getIconWidth(), getIconHeight(), 0, 0, image.getWidth(), image.getHeight(),
null);
}

@Override
public int getIconWidth() {
return (int) (image.getWidth() * SCALE);
}

@Override
public int getIconHeight() {
return (int) (image.getHeight() * SCALE);
}
};
Icon icon = new VeraPDFIcon(image);
label.setIcon(icon);
}

add(label);

}

private static class VeraPDFIcon implements Icon {

private static final double SCALE = 0.3;
private final BufferedImage image;

public VeraPDFIcon(BufferedImage image) {
this.image = image;
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
g.drawImage(image, 0, 0, getIconWidth(), getIconHeight(), 0, 0, image.getWidth(), image.getHeight(),
null);
}

@Override
public int getIconWidth() {
return (int) (image.getWidth() * SCALE);
}

@Override
public int getIconHeight() {
return (int) (image.getHeight() * SCALE);
}
}
}
3 changes: 1 addition & 2 deletions gui/src/main/java/org/verapdf/gui/SettingsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ class SettingsPanel extends JPanel {

panel.add(new JLabel(GUIConstants.SELECTED_PATH_FOR_FIXER_LABEL_TEXT));

File currentDir = new File(new File(GUIConstants.DOT).getCanonicalPath());

JButton choose2 = new JButton(GUIConstants.FIX_METADATA_FOLDER_CHOOSE_BUTTON);
this.folderChooser = new JFileChooser();
File currentDir = new File(new File(GUIConstants.DOT).getCanonicalPath());
this.folderChooser.setCurrentDirectory(currentDir);
this.folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
choose2.addActionListener(new ActionListener() {
Expand Down
4 changes: 2 additions & 2 deletions gui/src/main/java/org/verapdf/gui/ValidateWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ protected void done() {

private void writeHtmlReport() {
final String extension = "html";
final String ext = '.' + extension;
try {
final String ext = '.' + extension;
this.htmlReport = File.createTempFile("veraPDF-tempHTMLReport", ext); //$NON-NLS-1$
this.htmlReport.deleteOnExit();
try (InputStream xmlStream = new FileInputStream(this.xmlReport);
Expand All @@ -173,10 +173,10 @@ private void writeHtmlReport() {
this.configManager.getApplicationConfig().getWikiPath(), true);

} catch (IOException | TransformerException excep) {
final String message = String.format(GUIConstants.IOEXCEP_SAVING_REPORT, extension);
JOptionPane.showMessageDialog(this.parent,
String.format(GUIConstants.IOEXCEP_SAVING_REPORT, extension), GUIConstants.ERROR,
JOptionPane.ERROR_MESSAGE);
final String message = String.format(GUIConstants.IOEXCEP_SAVING_REPORT, extension);
logger.log(Level.SEVERE, message, excep);
this.htmlReport = null;
}
Expand Down

0 comments on commit 2da16df

Please sign in to comment.