/** * Opens a signature file for parsing. * * @param filePath * the file location (relative or absolute) of the signature file * to parse. * @throws SignatureFileException * if the path specified was not a valid signature file. */ private Path openFile(final URI filePath) throws SignatureFileException { final Path f = Paths.get(filePath); if (!Files.exists(f)) { throw new SignatureFileException(String.format( "Signature file does not exist [%s]", filePath), ErrorCode.FILE_NOT_FOUND); } if (!Files.isRegularFile(f)) { throw new SignatureFileException(String.format( INVALID_SIGNATURE_FILE, filePath), ErrorCode.INVALID_SIGNATURE_FILE); } return f; }
/** * Executes this action. * @param parent the parent window */ public void execute(Window parent) { final Path f = Paths.get(fileName); try { final SignatureFileInfo info = signatureManager.install(type, f, useAsDefault); final String message = String.format("Signature file %s has been installed", info.getFile().getFileName().toString()); JOptionPane.showMessageDialog(parent, message, "Signature file installed", JOptionPane.INFORMATION_MESSAGE); } catch (final SignatureFileException e) { JOptionPane.showMessageDialog(parent, e.getMessage(), "Error installing signature file", JOptionPane.ERROR_MESSAGE); } }
/** * Opens a signature file for parsing. * * @param filePath * the file location (relative or absolute) of the signature file * to parse. * @throws SignatureFileException * if the path specified was not a valid signature file. */ private File openFile(URI filePath) throws SignatureFileException { File f = new File(filePath); if (!f.exists()) { throw new SignatureFileException(String.format( "Signature file does not exist [%s]", filePath), ErrorCode.FILE_NOT_FOUND); } if (!f.isFile()) { throw new SignatureFileException(String.format( INVALID_SIGNATURE_FILE, filePath), ErrorCode.INVALID_SIGNATURE_FILE); } return f; }
/** * Executes this action. * @param parent the parent window */ public void execute(Window parent) { File f = new File(fileName); try { SignatureFileInfo info = signatureManager.install(type, f, useAsDefault); String message = String.format("Signature file %s has been installed", info.getFile().getName()); JOptionPane.showMessageDialog(parent, message, "Signature file installed", JOptionPane.INFORMATION_MESSAGE); } catch (SignatureFileException e) { JOptionPane.showMessageDialog(parent, e.getMessage(), "Error installing signature file", JOptionPane.ERROR_MESSAGE); } }
/** * {@inheritDoc} */ @Override public void formats(final FormatCallback callback) throws SignatureFileException { final FileFormatHandler handler = new FileFormatHandler(callback); final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); try { final SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(file.toFile(), handler); } catch (SAXException e) { throw new SignatureFileException(String.format( INVALID_SIGNATURE_FILE, file.toUri()), e, ErrorCode.INVALID_SIGNATURE_FILE); } catch (final ParserConfigurationException | IOException e) { log.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } }
signatures = signatureManager.getDefaultSignatures(); } catch (SignatureFileException e) { throw new ProfileManagerException(e.getMessage());
private static SignatureFileInfo forSimpleVersionedFile(File file, SignatureType type) throws SignatureFileException { // parse the version from the filename String filename = FilenameUtils.getBaseName(file.getName()); try { int version = Integer.valueOf(StringUtils.substringAfterLast(filename, "-")); final SignatureFileInfo signatureFileInfo = new SignatureFileInfo(version, false, type); signatureFileInfo.setFile(file); return signatureFileInfo; } catch (NumberFormatException e) { String message = String.format("Invalid signature filename [%s]", file.getName()); throw new SignatureFileException(message, e, ErrorCode.INVALID_SIGNATURE_FILE); } }
signatures = signatureManager.getDefaultSignatures(); } catch (SignatureFileException e) { throw new ProfileManagerException(e.getMessage());
/** * {@inheritDoc} */ @Override public void formats(FormatCallback callback) throws SignatureFileException { FileFormatHandler handler = new FileFormatHandler(callback); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); try { SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(file, handler); } catch (SAXException e) { throw new SignatureFileException(String.format( INVALID_SIGNATURE_FILE, file.toURI()), e, ErrorCode.INVALID_SIGNATURE_FILE); } catch (ParserConfigurationException e) { log.error(e); throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { log.error(e); throw new RuntimeException(e.getMessage(), e); } }
SignatureFileInfo parse(final Path sigFile) throws SignatureFileException { final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); final SignatureFileVersionHandler handler = new SignatureFileVersionHandler(); try { final SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(sigFile.toFile(), handler); throw new SignatureFileException(String.format( INVALID_SIGNATURE_FILE, sigFile), ErrorCode.INVALID_SIGNATURE_FILE); } catch (final ValidSignatureFileException e) { return e.getInfo(); } catch (final SAXException e) { throw new SignatureFileException(String.format( INVALID_SIGNATURE_FILE, sigFile), e, ErrorCode.INVALID_SIGNATURE_FILE); } catch (final ParserConfigurationException | IOException e) { throw new RuntimeException(e.getMessage(), e); } } }
SignatureFileInfo parse(File sigFile) throws SignatureFileException { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); final SignatureFileVersionHandler handler = new SignatureFileVersionHandler(); try { SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(sigFile, handler); throw new SignatureFileException(String.format( INVALID_SIGNATURE_FILE, sigFile), ErrorCode.INVALID_SIGNATURE_FILE); } catch (ValidSignatureFileException e) { return e.getInfo(); } catch (SAXException e) { throw new SignatureFileException(String.format( INVALID_SIGNATURE_FILE, sigFile), e, ErrorCode.INVALID_SIGNATURE_FILE); } catch (ParserConfigurationException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } } }
private static SignatureFileInfo forSimpleVersionedFile(final Path file, final SignatureType type) throws SignatureFileException { // parse the version from the filename final String filename = FilenameUtils.getBaseName(FileUtil.fileName(file)); try { final int version = Integer.valueOf(StringUtils.substringAfterLast(filename, "-")); final SignatureFileInfo signatureFileInfo = new SignatureFileInfo(version, false, type); signatureFileInfo.setFile(file); return signatureFileInfo; } catch (final NumberFormatException e) { final String message = String.format("Invalid signature filename [%s]", FileUtil.fileName(file)); throw new SignatureFileException(message, e, ErrorCode.INVALID_SIGNATURE_FILE); } }
String errorMessage = String.format(errorMessagePattern, config.getProperties() .getString(defaultVersionProperties.get(type).getName())); throw new SignatureFileException(errorMessage, ErrorCode.FILE_NOT_FOUND);
String errorMessage = String.format(errorMessagePattern, config.getProperties() .getString(defaultVersionProperties.get(type).getName())); throw new SignatureFileException(errorMessage, ErrorCode.FILE_NOT_FOUND);
/** * {@inheritDoc} */ @Override public SignatureFileInfo install(SignatureType type, File signatureFile, boolean setDefault) throws SignatureFileException { SignatureInfoParser parser = new SignatureInfoParser(); SignatureFileInfo sigFileInfo = forBinarySigFile(signatureFile, parser); try { FileUtils.copyFileToDirectory(signatureFile, config.getSignatureFileDir(), true); File newSignatureFile = new File(config.getSignatureFileDir(), signatureFile.getName()); sigFileInfo.setFile(newSignatureFile); if (setDefault) { config.getProperties().setProperty(defaultVersionProperties.get(type).getName(), FilenameUtils.getBaseName(newSignatureFile.getName())); } return sigFileInfo; } catch (IOException e) { log.error(e); throw new SignatureFileException(e.getMessage(), e, ErrorCode.FILE_NOT_FOUND); } }
/** * {@inheritDoc} */ @Override public SignatureFileInfo install(final SignatureType type, final Path signatureFile, final boolean setDefault) throws SignatureFileException { final SignatureInfoParser parser = new SignatureInfoParser(); final SignatureFileInfo sigFileInfo = forBinarySigFile(signatureFile, parser); try { final Path newSignatureFile = Files.copy(signatureFile, config.getSignatureFileDir()); sigFileInfo.setFile(newSignatureFile); if (setDefault) { config.getProperties().setProperty(defaultVersionProperties.get(type).getName(), FilenameUtils.getBaseName(FileUtil.fileName(newSignatureFile))); } return sigFileInfo; } catch (final IOException e) { log.error(e.getMessage(), e); throw new SignatureFileException(e.getMessage(), e, ErrorCode.FILE_NOT_FOUND); } }
throw new SignatureFileException(ERROR_READING_SIGNATURE_FILE, e, ErrorCode.FILE_NOT_FOUND); } catch (SignatureParseException e) { throw new SignatureFileException(ERROR_READING_SIGNATURE_FILE, e, ErrorCode.INVALID_SIGNATURE_FILE);
throw new SignatureFileException(ERROR_READING_SIGNATURE_FILE, e, ErrorCode.FILE_NOT_FOUND); } catch (SignatureParseException e) { throw new SignatureFileException(ERROR_READING_SIGNATURE_FILE, e, ErrorCode.INVALID_SIGNATURE_FILE);