List of usage examples for java.util LinkedList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:org.pdfsam.plugin.unpack.listeners.RunButtonActionListener.java
public void actionPerformed(ActionEvent arg0) { if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) { DialogUtility.showWarningAddingDocument(panel); return;/*from w w w .j av a2 s.c om*/ } PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows(); if (ArrayUtils.isEmpty(items)) { DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC); return; } LinkedList<String> args = new LinkedList<String>(); // validation and permission check are demanded to the CmdParser object try { // overwrite confirmation if (panel.getOverwriteCheckbox().isSelected() && Configuration.getInstance().isAskOverwriteConfirmation()) { int dialogRet = DialogUtility.askForOverwriteConfirmation(panel); if (JOptionPane.NO_OPTION == dialogRet) { panel.getOverwriteCheckbox().setSelected(false); } else if (JOptionPane.CANCEL_OPTION == dialogRet) { return; } } args.addAll(getInputFilesArguments(items)); args.add("-" + UnpackParsedCommand.O_ARG); if (StringUtils.isEmpty(panel.getDestinationTextField().getText())) { String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]); int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getDestinationTextField().setText(suggestedDir); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } args.add(panel.getDestinationTextField().getText()); if (panel.getOverwriteCheckbox().isSelected()) { args.add("-" + UnpackParsedCommand.OVERWRITE_ARG); } args.add(UnpackParsedCommand.COMMAND_UNPACK); String[] myStringArray = (String[]) args.toArray(new String[args.size()]); WorkExecutor.getInstance().execute(new WorkThread(myStringArray)); } catch (Exception e) { log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), e); SoundPlayer.getInstance().playErrorSound(); } }
From source file:com.d2dx.j2objc.TranslateMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (this.includeDependencySources) { //@formatter:off executeMojo(/*from w w w.j a v a 2 s.co m*/ plugin(groupId("org.apache.maven.plugins"), artifactId("maven-dependency-plugin"), version("2.8")), goal("unpack-dependencies"), configuration(element("classifier", "sources"), element("failOnMissingClassifierArtifact", "false"), element(name("outputDirectory"), "${project.build.directory}/j2objc-sources")), executionEnvironment(this.mavenProject, this.mavenSession, this.pluginManager)); } /* * Extracts j2objc automagically */ //@formatter:off executeMojo( plugin(groupId("org.apache.maven.plugins"), artifactId("maven-dependency-plugin"), version("2.8")), goal("unpack"), configuration( element("artifactItems", element("artifactItem", element("groupId", "com.d2dx.j2objc"), element("artifactId", "j2objc-package"), element("version", this.j2objcVersion))), element(name("outputDirectory"), "${project.build.directory}/j2objc-bin")), executionEnvironment(this.mavenProject, this.mavenSession, this.pluginManager)); //@formatter:on /* * Time to do detection and run j2objc with proper parameters. */ this.outputDirectory.mkdirs(); // Gather the source paths // Right now, we limit to sources in two directories: project srcdir, and additional sources. // Later, we should add more. HashSet<String> srcPaths = new HashSet<String>(); String srcDir = this.mavenSession.getCurrentProject().getBuild().getSourceDirectory(); srcPaths.add(srcDir); String buildDir = this.mavenSession.getCurrentProject().getBuild().getDirectory(); String addtlSrcDir = buildDir + "/j2objc-sources"; srcPaths.add(addtlSrcDir); // Gather sources. HashSet<File> srcFiles = new HashSet<File>(); for (String path : srcPaths) { File sdFile = new File(path); Collection<File> scanFiles = FileUtils.listFiles(sdFile, new String[] { "java" }, true); srcFiles.addAll(scanFiles); } // Gather prefixes into a file FileOutputStream fos; OutputStreamWriter out; if (this.prefixes != null) { try { fos = new FileOutputStream(new File(this.outputDirectory, "prefixes.properties")); out = new OutputStreamWriter(fos); for (Prefix p : this.prefixes) { out.write(p.javaPrefix); out.write(": "); out.write(p.objcPrefix); out.write("\n"); } out.flush(); out.close(); fos.close(); } catch (FileNotFoundException e) { throw new MojoExecutionException("Could not create prefixes file"); } catch (IOException e1) { throw new MojoExecutionException("Could not create prefixes file"); } } // We now have: // Sources, source directories, and prefixes. // Call the maven-exec-plugin with the new environment! LinkedList<Element> args = new LinkedList<Element>(); if (this.includeClasspath) { args.add(new Element("argument", "-cp")); args.add(new Element("classpath", "")); } String srcDirsArgument = ""; for (String p : srcPaths) srcDirsArgument += ":" + p; // Crop the first colon if (srcDirsArgument.length() > 0) srcDirsArgument = srcDirsArgument.substring(1); args.add(new Element("argument", "-sourcepath")); args.add(new Element("argument", srcDirsArgument)); if (this.prefixes != null) { args.add(new Element("argument", "--prefixes")); args.add(new Element("argument", this.outputDirectory.getAbsolutePath() + "/prefixes.properties")); } args.add(new Element("argument", "-d")); args.add(new Element("argument", this.outputDirectory.getAbsolutePath())); for (File f : srcFiles) args.add(new Element("argument", f.getAbsolutePath())); try { Runtime.getRuntime() .exec("chmod u+x " + this.mavenProject.getBuild().getDirectory() + "/j2objc-bin/j2objc"); } catch (IOException e) { e.printStackTrace(); } //@formatter:off executeMojo(plugin(groupId("org.codehaus.mojo"), artifactId("exec-maven-plugin"), version("1.3")), goal("exec"), configuration(element("arguments", args.toArray(new Element[0])), element("executable", this.mavenProject.getBuild().getDirectory() + "/j2objc-bin/j2objc"), element("workingDirectory", this.mavenProject.getBuild().getDirectory() + "/j2objc-bin/")), executionEnvironment(this.mavenProject, this.mavenSession, this.pluginManager)); //@formatter:on }
From source file:org.talend.tql.bean.BeanPredicateVisitor.java
private Method[] getMethods(String field) { StringTokenizer tokenizer = new StringTokenizer(field, "."); List<String> methodNames = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { methodNames.add(tokenizer.nextToken()); }/*from ww w. j a v a 2 s . co m*/ Class currentClass = targetClass; LinkedList<Method> methods = new LinkedList<>(); for (String methodName : methodNames) { if ("_class".equals(methodName)) { try { methods.add(Class.class.getMethod("getClass")); methods.add(Class.class.getMethod("getName")); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Unable to get methods for class' name.", e); } } else { String[] getterCandidates = new String[] { "get" + WordUtils.capitalize(methodName), // methodName, // "is" + WordUtils.capitalize(methodName) }; final int beforeFind = methods.size(); for (String getterCandidate : getterCandidates) { try { methods.add(currentClass.getMethod(getterCandidate)); break; } catch (Exception e) { LOGGER.debug("Can't find getter '{}'.", field, e); } } if (beforeFind == methods.size()) { throw new UnsupportedOperationException("Can't find getter '" + field + "'."); } else { currentClass = methods.getLast().getReturnType(); } } } return methods.toArray(new Method[0]); }
From source file:org.pdfsam.plugin.decrypt.listeners.RunButtonActionListener.java
public void actionPerformed(ActionEvent e) { if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) { DialogUtility.showWarningAddingDocument(panel); return;/*from w w w . j a v a2 s. co m*/ } PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows(); if (ArrayUtils.isEmpty(items)) { DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC); return; } final LinkedList<String> args = new LinkedList<String>(); try { // overwrite confirmation if (panel.getOverwriteCheckbox().isSelected() && Configuration.getInstance().isAskOverwriteConfirmation()) { int dialogRet = DialogUtility.askForOverwriteConfirmation(panel); if (JOptionPane.NO_OPTION == dialogRet) { panel.getOverwriteCheckbox().setSelected(false); } else if (JOptionPane.CANCEL_OPTION == dialogRet) { return; } } args.addAll(getInputFilesArguments(items)); args.add("-" + DecryptParsedCommand.O_ARG); if (StringUtils.isEmpty(panel.getDestinationTextField().getText())) { String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]); int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getDestinationTextField().setText(suggestedDir); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } args.add(panel.getDestinationTextField().getText()); if (panel.getOverwriteCheckbox().isSelected()) { args.add("-" + DecryptParsedCommand.OVERWRITE_ARG); } if (panel.getOutputCompressedCheck().isSelected()) { args.add("-" + DecryptParsedCommand.COMPRESSED_ARG); } args.add("-" + EncryptParsedCommand.P_ARG); args.add(panel.getOutPrefixTextField().getText()); args.add("-" + DecryptParsedCommand.PDFVERSION_ARG); args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId()); args.add(AbstractParsedCommand.COMMAND_DECRYPT); String[] myStringArray = args.toArray(new String[args.size()]); WorkExecutor.getInstance().execute(new WorkThread(myStringArray)); } catch (Exception ex) { log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex); SoundPlayer.getInstance().playErrorSound(); } }
From source file:com.sun.portal.rssportlet.SettingsHandler.java
/** * Persist this handler's <code>RssPortletBean</code>, if necessary. */// w ww . j a va 2 s . c o m public void persistSettingsBean(SettingsBean delta) throws ReadOnlyException, IOException, ValidatorException { boolean store = false; LinkedList feeds = null; // selected feed if (delta.getFeeds() != null && delta.getFeedsSize() == 0) { // if there are no feeds, set the selected feed to null getPortletSession().setAttribute(SessionKeys.SELECTED_FEED, null); } else if (delta.getSelectedFeed() != null) { getPortletSession().setAttribute(SessionKeys.SELECTED_FEED, delta.getSelectedFeed()); } // feeds and start feed - remove default feeds- not stored in preferences if (delta.getFeeds() != null) { feeds = delta.getFeeds(); Iterator it = null; if (log.isDebugEnabled()) { it = feeds.listIterator(); while (it.hasNext()) { log.debug("Delta feeds before ***********" + (String) it.next()); } } //remove mandatory+role feeds- not stored in preferences //retrieved from jsp file if (delta.getFeedsSize() > 0) { if (null != role_feeds && role_feeds.length != 0) { feeds = fileterFeeds(delta, role_feeds); } if (null != mandate_feeds && mandate_feeds.length != 0) { feeds = fileterFeeds(delta, mandate_feeds); } } if (log.isDebugEnabled()) { it = feeds.listIterator(); while (it.hasNext()) { log.debug("Delta feeds after ***********" + (String) it.next()); } } getPortletPreferences().setValues(PrefKeys.USER_FEEDS, (String[]) feeds.toArray(new String[0])); getPortletPreferences().setValue(PrefKeys.START_FEED, delta.getStartFeed()); getPortletPreferences().setValue(PrefKeys.DEFAULT_FEEDS_LEVEL, String.valueOf(default_feeds.size())); store = true; } // feed titles - for all feeds if (delta.getFeeds() != null && delta.getFeedsSize() != 0) { delta.setTitleList(delta.getFeeds()); } // max age if (delta.isMaxAgeSet()) { getPortletPreferences().setValue(PrefKeys.MAX_AGE, Integer.toString(delta.getMaxAge())); store = true; } // disable max age if (delta.isDisableMaxAgeSet()) { getPortletPreferences().setValue(PrefKeys.DISABLE_MAX_AGE, Boolean.toString(delta.isDisableMaxAge())); store = true; } // max entries if (delta.isMaxEntriesSet()) { getPortletPreferences().setValue(PrefKeys.MAX_ENTRIES, Integer.toString(delta.getMaxEntries())); store = true; } // new window if (delta.isNewWindowSet()) { getPortletPreferences().setValue(PrefKeys.NEWWIN, Boolean.toString(delta.isNewWindow())); store = true; } if (store) { getPortletPreferences().store(); } }
From source file:com.trsst.Command.java
public int doPost(Client client, CommandLine commands, LinkedList<String> arguments, PrintStream out, InputStream in) {/*from w w w . j a v a2 s.co m*/ String id = null; if (arguments.size() == 0 && commands.getArgList().size() == 0) { printPostUsage(); return 127; // "command not found" } if (arguments.size() > 0) { id = arguments.removeFirst(); System.err.println("Obtaining keys for feed id: " + id); } else { System.err.println("Generating new feed id... "); } // read input text String subject = commands.getOptionValue("s"); String verb = commands.getOptionValue("v"); String base = commands.getOptionValue("b"); String body = commands.getOptionValue("c"); String name = commands.getOptionValue("n"); String email = commands.getOptionValue("m"); String uri = commands.getOptionValue("uri"); String title = commands.getOptionValue("t"); String subtitle = commands.getOptionValue("subtitle"); String icon = commands.getOptionValue("i"); if (icon == null && commands.hasOption("i")) { icon = "-"; } String logo = commands.getOptionValue("l"); if (logo == null && commands.hasOption("l")) { logo = "-"; } String attach = commands.getOptionValue("a"); if (attach == null && commands.hasOption("a")) { attach = "-"; } String[] recipients = commands.getOptionValues("e"); String[] mentions = commands.getOptionValues("r"); String[] tags = commands.getOptionValues("g"); String url = commands.getOptionValue("u"); String vanity = commands.getOptionValue("vanity"); // obtain password char[] password = null; String pass = commands.getOptionValue("p"); if (pass != null) { password = pass.toCharArray(); } else { try { Console console = System.console(); if (console != null) { password = console.readPassword("Password: "); } else { log.info("No console detected for password input."); } } catch (Throwable t) { log.error("Unexpected error while reading password", t); } } if (password == null) { log.error("Password is required to post."); return 127; // "command not found" } if (password.length < 6) { System.err.println("Password must be at least six characters in length."); return 127; // "command not found" } // obtain keys KeyPair signingKeys = null; KeyPair encryptionKeys = null; String keyPath = commands.getOptionValue("k"); // if id was not specified from the command line if (id == null) { // if password was not specified from command line if (pass == null) { try { // verify password char[] verify = null; Console console = System.console(); if (console != null) { verify = console.readPassword("Re-type Password: "); } else { log.info("No console detected for password verification."); } if (verify == null || verify.length != password.length) { System.err.println("Passwords do not match."); return 127; // "command not found" } for (int i = 0; i < verify.length; i++) { if (verify[i] != password[i]) { System.err.println("Passwords do not match."); return 127; // "command not found" } verify[i] = 0; } } catch (Throwable t) { log.error("Unexpected error while verifying password: " + t.getMessage(), t); } } // create new account if (base == null) { // default to trsst hub base = "https://home.trsst.com/feed"; } // generate vanity id if required if (vanity != null) { System.err.println("Searching for vanity feed id prefix: " + vanity); switch (vanity.length()) { case 0: case 1: break; case 2: System.err.println("This may take several minutes."); break; case 3: System.err.println("This may take several hours."); break; case 4: System.err.println("This may take several days."); break; case 5: System.err.println("This may take several months."); break; default: System.err.println("This may take several years."); break; } System.err.println("Started: " + new Date()); System.err.println("^C to exit"); } do { signingKeys = Common.generateSigningKeyPair(); id = Common.toFeedId(signingKeys.getPublic()); } while (vanity != null && !id.startsWith(vanity)); if (vanity != null) { System.err.println("Finished: " + new Date()); } encryptionKeys = Common.generateEncryptionKeyPair(); System.err.println("New feed id created: " + id); File keyFile; if (keyPath != null) { keyFile = new File(keyPath, id + Common.KEY_EXTENSION); } else { keyFile = new File(Common.getClientRoot(), id + Common.KEY_EXTENSION); } // persist to keystore writeSigningKeyPair(signingKeys, id, keyFile, password); writeEncryptionKeyPair(encryptionKeys, id, keyFile, password); } else { File keyFile; if (keyPath != null) { keyFile = new File(Common.getClientRoot(), keyPath); } else { keyFile = new File(Common.getClientRoot(), id + Common.KEY_EXTENSION); } if (keyFile.exists()) { System.err.println("Using existing account id: " + id); } else { System.err.println("Cannot locate keys for account id: " + id); return 78; // "configuration error" } signingKeys = readSigningKeyPair(id, keyFile, password); if (signingKeys != null) { encryptionKeys = readEncryptionKeyPair(id, keyFile, password); if (encryptionKeys == null) { encryptionKeys = signingKeys; } } } // clear password chars for (int i = 0; i < password.length; i++) { password[i] = 0; } if (signingKeys == null) { System.err.println("Could not obtain keys for signing."); return 73; // "can't create output error" } String[] recipientIds = null; if (recipients != null) { LinkedList<String> keys = new LinkedList<String>(); for (int i = 0; i < recipients.length; i++) { if ("-".equals(recipients[i])) { // "-" is shorthand for encrypt for mentioned ids if (mentions != null) { for (String mention : mentions) { if (Common.isFeedId(mention)) { keys.add(mention); } } } } else if (Common.isFeedId(recipients[i])) { keys.add(recipients[i]); } else { log.warn("Could not parse recipient id: " + recipients[i]); } } recipientIds = keys.toArray(new String[0]); } // handle binary attachment String mimetype = null; byte[] attachment = null; if (attach != null) { InputStream input = null; try { if ("-".equals(attach)) { input = new BufferedInputStream(in); } else { File file = new File(attach); input = new BufferedInputStream(new FileInputStream(file)); System.err.println("Attaching: " + file.getCanonicalPath()); } attachment = Common.readFully(input); mimetype = new Tika().detect(attachment); System.err.println("Detected type: " + mimetype); } catch (Throwable t) { log.error("Could not read attachment: " + attach, t); return 73; // "can't create output error" } finally { try { input.close(); } catch (IOException ioe) { // suppress any futher error on closing } } } Object result; try { EntryOptions options = new EntryOptions(); options.setStatus(subject); options.setVerb(verb); if (mentions != null) { options.setMentions(mentions); } if (tags != null) { options.setTags(tags); } options.setBody(body); if (attachment != null) { options.addContentData(attachment, mimetype); } else if (url != null) { options.setContentUrl(url); } FeedOptions feedOptions = new FeedOptions(); feedOptions.setAuthorEmail(email); feedOptions.setAuthorName(name); feedOptions.setAuthorUri(uri); feedOptions.setTitle(title); feedOptions.setSubtitle(subtitle); feedOptions.setBase(base); if (icon != null) { if ("-".equals(icon)) { feedOptions.setAsIcon(true); } else { feedOptions.setIconURL(icon); } } if (logo != null) { if ("-".equals(logo)) { feedOptions.setAsLogo(true); } else { feedOptions.setLogoURL(logo); } } if (recipientIds != null) { EntryOptions publicEntry = new EntryOptions().setStatus("Encrypted content").setVerb("encrypt"); // TODO: add duplicate mentions to outside of envelope options.encryptFor(recipientIds, publicEntry); } result = client.post(signingKeys, encryptionKeys, options, feedOptions); } catch (IllegalArgumentException e) { log.error("Invalid request: " + id + " : " + e.getMessage(), e); return 76; // "remote error" } catch (IOException e) { log.error("Error connecting to service for id: " + id, e); return 76; // "remote error" } catch (org.apache.abdera.security.SecurityException e) { log.error("Error generating signatures for id: " + id, e); return 73; // "can't create output error" } catch (Exception e) { log.error("General security error for id: " + id, e); return 74; // "general io error" } if (result != null) { if (format) { out.println(Common.formatXML(result.toString())); } else { out.println(result.toString()); } } return 0; // "OK" }
From source file:storage.FileStorageInterface.java
/** * Logic to get the data to fill the InformationChangeTable. * /*from ww w . ja va2 s . c o m*/ * @return data to fill the InformationChangeTable */ @Override public String[] getRawResults(ExtractionResultCollection coll) { LinkedList<String> res = new LinkedList<String>(); File out = new File(Constants.OUTPUT_DIRECTORY, coll.profileUUID); FileUtils.createDirectory(out.toPath()); if (coll instanceof Part) { if (pathToId.size() == 0) initPathToId(); Part part = (Part) coll; String path = part.getPath(); String id = pathToId.get(path); if (id == null) return new String[0]; File partOut = new File(out, id); FileUtils.createDirectory(partOut.toPath()); String[] envs = partOut.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.startsWith("file")) return true; return false; } }); Arrays.sort(envs); for (String e : envs) { try { res.add(org.apache.commons.io.FileUtils.readFileToString(new File(partOut, e))); } catch (IOException e1) { EXCEPTION_LOGGER.log(Level.SEVERE, "Exception at getRawResults", e1); } } } else if (coll instanceof Environment) { String[] envs = out.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.startsWith("environment")) return true; return false; } }); Arrays.sort(envs); for (String e : envs) { try { res.add(org.apache.commons.io.FileUtils.readFileToString(new File(out, e))); } catch (IOException e1) { EXCEPTION_LOGGER.log(Level.SEVERE, "Exception at getRawResults", e1); } } } else return null; return res.toArray(new String[0]); }
From source file:com.netscape.cmsutil.crypto.CryptoUtil.java
/** * Sorts certificate chain from root to leaf. * * This method sorts an array of certificates (e.g. from a PKCS #7 * data) that represents a certificate chain from root to leaf * according to the subject DNs and issuer DNs. * * The input array is a set of certificates that are part of a * chain but not in specific order./*from w w w . j a v a 2 s .co m*/ * * The result is a new array that contains the certificate chain * sorted from root to leaf. The input array is unchanged. * * @param certs input array of certificates * @return new array containing sorted certificates */ public static java.security.cert.X509Certificate[] sortCertificateChain( java.security.cert.X509Certificate[] certs) throws Exception { // lookup map: subject DN -> cert Map<String, java.security.cert.X509Certificate> certMap = new LinkedHashMap<>(); // hierarchy map: subject DN -> issuer DN Map<String, String> parentMap = new HashMap<>(); // reverse hierarchy map: issuer DN -> subject DN Map<String, String> childMap = new HashMap<>(); // build maps for (java.security.cert.X509Certificate cert : certs) { String subjectDN = cert.getSubjectDN().toString(); String issuerDN = cert.getIssuerDN().toString(); if (certMap.containsKey(subjectDN)) { throw new Exception("Duplicate certificate: " + subjectDN); } certMap.put(subjectDN, cert); // ignore self-signed certificate if (subjectDN.equals(issuerDN)) continue; if (childMap.containsKey(issuerDN)) { throw new Exception("Branched chain: " + issuerDN); } parentMap.put(subjectDN, issuerDN); childMap.put(issuerDN, subjectDN); } if (logger.isDebugEnabled()) { logger.debug("Certificates:"); for (String subjectDN : certMap.keySet()) { logger.debug(" - " + subjectDN); String parent = parentMap.get(subjectDN); if (parent != null) logger.debug(" parent: " + parent); String child = childMap.get(subjectDN); if (child != null) logger.debug(" child: " + child); } } // find leaf cert List<String> leafCerts = new ArrayList<>(); for (String subjectDN : certMap.keySet()) { // if cert has a child, skip if (childMap.containsKey(subjectDN)) continue; // found leaf cert leafCerts.add(subjectDN); } if (leafCerts.isEmpty()) { throw new Exception("Unable to find leaf certificate"); } if (leafCerts.size() > 1) { StringBuilder sb = new StringBuilder(); for (String subjectDN : leafCerts) { if (sb.length() > 0) sb.append(", "); sb.append("[" + subjectDN + "]"); } throw new Exception("Multiple leaf certificates: " + sb); } // build sorted chain LinkedList<java.security.cert.X509Certificate> chain = new LinkedList<>(); // start from leaf String current = leafCerts.get(0); while (current != null) { java.security.cert.X509Certificate cert = certMap.get(current); if (cert == null) { // incomplete chain break; } // add to the beginning of chain chain.addFirst(cert); // follow parent to root current = parentMap.get(current); } return chain.toArray(new java.security.cert.X509Certificate[chain.size()]); }
From source file:org.pdfsam.plugin.rotate.listeners.RunButtonActionListener.java
public void actionPerformed(ActionEvent e) { if (WorkExecutor.getInstance().getRunningThreads() > 0 || panel.getSelectionPanel().isAdding()) { DialogUtility.showWarningAddingDocument(panel); return;// www . j ava 2 s.c o m } PdfSelectionTableItem[] items = panel.getSelectionPanel().getTableRows(); if (ArrayUtils.isEmpty(items)) { DialogUtility.showWarningNoDocsSelected(panel, DialogUtility.AT_LEAST_ONE_DOC); return; } LinkedList<String> args = new LinkedList<String>(); try { // overwrite confirmation if (panel.getOverwriteCheckbox().isSelected() && Configuration.getInstance().isAskOverwriteConfirmation()) { int dialogRet = DialogUtility.askForOverwriteConfirmation(panel); if (JOptionPane.NO_OPTION == dialogRet) { panel.getOverwriteCheckbox().setSelected(false); } else if (JOptionPane.CANCEL_OPTION == dialogRet) { return; } } args.addAll(getInputFilesArguments(items)); args.add("-" + RotateParsedCommand.O_ARG); if (StringUtils.isEmpty(panel.getDestinationTextField().getText())) { String suggestedDir = getSuggestedDestinationDirectory(items[items.length - 1]); int chosenOpt = DialogUtility.showConfirmOuputLocationDialog(panel, suggestedDir); if (JOptionPane.YES_OPTION == chosenOpt) { panel.getDestinationTextField().setText(suggestedDir); } else if (JOptionPane.CANCEL_OPTION == chosenOpt) { return; } } args.add(panel.getDestinationTextField().getText()); if (panel.getOverwriteCheckbox().isSelected()) { args.add("-" + RotateParsedCommand.OVERWRITE_ARG); } if (panel.getOutputCompressedCheck().isSelected()) { args.add("-" + RotateParsedCommand.COMPRESSED_ARG); } args.add("-" + RotateParsedCommand.R_ARG); args.add(((StringItem) panel.getRotationPagesBox().getSelectedItem()).getId() + ":" + panel.getRotationBox().getSelectedItem()); args.add("-" + RotateParsedCommand.P_ARG); args.add(panel.getOutPrefixTextField().getText()); args.add("-" + RotateParsedCommand.PDFVERSION_ARG); args.add(((StringItem) panel.getVersionCombo().getSelectedItem()).getId()); args.add(AbstractParsedCommand.COMMAND_ROTATE); String[] myStringArray = args.toArray(new String[args.size()]); WorkExecutor.getInstance().execute(new WorkThread(myStringArray)); } catch (Exception ex) { log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error: "), ex); SoundPlayer.getInstance().playErrorSound(); } }
From source file:com.stimulus.archiva.search.StandardSearch.java
protected Searcher getVolumeSearchers() throws MessageSearchException { logger.debug("getVolumeSearchers()"); boolean searcherPresent = false; Hashtable<String, String> remoteServers = new Hashtable<String, String>(); List<Volume> volumes = Config.getConfig().getVolumes().getVolumes(); LinkedList<Searchable> searchers = new LinkedList<Searchable>(); Iterator<Volume> vl = volumes.iterator(); logger.debug("searching for suitable searchers"); while (vl.hasNext()) { Volume volume = (Volume) vl.next(); logger.debug("should search volume? {" + volume + "}"); try {/*from w ww . j ava 2s.co m*/ Searchable volsearcher; if (shouldSearch(volume)) { try { volsearcher = new IndexSearcher(volume.getIndexPath()); logger.debug("adding volume to search {indexpath='" + volume.getIndexPath() + "'}"); searchers.add(volsearcher); searcherPresent = true; } catch (Exception e) { logger.error("failed to volume to search{" + volume + "}: " + e.getMessage(), e); } } else { logger.debug("deliberately not searching inside volume {" + volume.getIndexPath() + "}"); } } catch (Exception io) { logger.error("failed to open index for search {" + volume + "}.", io); } } if (!searcherPresent) return null; for (String remotePath : remoteServers.values()) { try { Searchable volsearcher = (Searchable) Naming.lookup(remotePath); searchers.add(volsearcher); } catch (Exception e) { logger.error("failed to add volume searcher", e); } } Searchable[] searcherarraytype = new Searchable[searchers.size()]; Searchable[] allsearchers = (Searchable[]) (searchers.toArray(searcherarraytype)); Searcher searcher; try { searcher = new ParallelMultiSearcher(allsearchers); } catch (IOException io) { throw new MessageSearchException("failed to open/create one or more index searchers", logger); } return searcher; }