private static Node parseModel(Reader r) { StreamTokenizer st = new StreamTokenizer(r); try { Split root = new Split(); parseSplit(st, root); return root.getChildren().get(0); } catch (Exception e) { Main.error(e); } finally { Utils.close(r); } return null; }
/** * Builds the style sheet used in the internal help browser * * @return the style sheet */ protected StyleSheet buildStyleSheet() { StyleSheet ss = new StyleSheet(); BufferedReader reader = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream("/data/help-browser.css"))); StringBuffer css = new StringBuffer(); try { String line = null; while ((line = reader.readLine()) != null) { css.append(line); css.append("\n"); } } catch (Exception e) { Main.error( tr("Failed to read CSS file ''help-browser.css''. Exception is: {0}", e.toString())); e.printStackTrace(); return ss; } finally { Utils.close(reader); } ss.addRule(css.toString()); return ss; }
@Override protected void realRun() throws SAXException, IOException, OsmTransferException { if (files == null || files.isEmpty()) return; /** Find the importer with the chosen file filter */ FileImporter chosenImporter = null; for (FileImporter importer : ExtensionFileFilter.importers) { if (fileFilter == importer.filter) { chosenImporter = importer; } } /** * If the filter hasn't been changed in the dialog, chosenImporter is null now. When the * filter has been set explicitly to AllFormatsImporter, treat this the same. */ if (chosenImporter instanceof AllFormatsImporter) { chosenImporter = null; } getProgressMonitor().setTicksCount(files.size()); if (chosenImporter != null) { // The importer was explicitly chosen, so use it. List<File> filesNotMatchingWithImporter = new LinkedList<File>(); List<File> filesMatchingWithImporter = new LinkedList<File>(); for (final File f : files) { if (!chosenImporter.acceptFile(f)) { if (f.isDirectory()) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { JOptionPane.showMessageDialog( Main.parent, tr( "<html>Cannot open directory ''{0}''.<br>Please select a file.</html>", f.getAbsolutePath()), tr("Open file"), JOptionPane.ERROR_MESSAGE); } }); // TODO when changing to Java 6: Don't cancel the // task here but use different modality. (Currently 2 dialogs // would block each other.) return; } else { filesNotMatchingWithImporter.add(f); } } else { filesMatchingWithImporter.add(f); } } if (!filesNotMatchingWithImporter.isEmpty()) { alertFilesNotMatchingWithImporter(filesNotMatchingWithImporter, chosenImporter); } if (!filesMatchingWithImporter.isEmpty()) { importData(chosenImporter, filesMatchingWithImporter); } } else { // find appropriate importer MultiMap<FileImporter, File> importerMap = new MultiMap<FileImporter, File>(); List<File> filesWithUnknownImporter = new LinkedList<File>(); List<File> urlFiles = new LinkedList<File>(); FILES: for (File f : files) { for (FileImporter importer : ExtensionFileFilter.importers) { if (importer.acceptFile(f)) { importerMap.put(importer, f); continue FILES; } } if (urlFileFilter.accept(f)) { urlFiles.add(f); } else { filesWithUnknownImporter.add(f); } } if (!filesWithUnknownImporter.isEmpty()) { alertFilesWithUnknownImporter(filesWithUnknownImporter); } List<FileImporter> importers = new ArrayList<FileImporter>(importerMap.keySet()); Collections.sort(importers); Collections.reverse(importers); Set<String> fileHistory = new LinkedHashSet<String>(); Set<String> failedAll = new HashSet<String>(); for (FileImporter importer : importers) { List<File> files = new ArrayList<File>(importerMap.get(importer)); importData(importer, files); // suppose all files will fail to load List<File> failedFiles = new ArrayList<File>(files); if (recordHistory && !importer.isBatchImporter()) { // remove the files which didn't fail to load from the failed list failedFiles.removeAll(successfullyOpenedFiles); for (File f : successfullyOpenedFiles) { fileHistory.add(f.getCanonicalPath()); } for (File f : failedFiles) { failedAll.add(f.getCanonicalPath()); } } } for (File urlFile : urlFiles) { try { BufferedReader reader = new BufferedReader(new FileReader(urlFile)); String line; while ((line = reader.readLine()) != null) { Matcher m = Pattern.compile(".*(http://.*)").matcher(line); if (m.matches()) { String url = m.group(1); Main.main.menu.openLocation.openUrl(false, url); } } Utils.close(reader); } catch (Exception e) { Main.error(e); } } if (recordHistory) { Collection<String> oldFileHistory = Main.pref.getCollection("file-open.history"); fileHistory.addAll(oldFileHistory); // remove the files which failed to load from the list fileHistory.removeAll(failedAll); int maxsize = Math.max(0, Main.pref.getInteger("file-open.history.max-size", 15)); Main.pref.putCollectionBounded("file-open.history", maxsize, fileHistory); } } }