private static int importFromBookmarks( BookmarksDB db, final DigestURI baseURL, final InputStreamReader input, final String tag, final boolean importPublic) { int importCount = 0; Map<MultiProtocolURI, Properties> links = new HashMap<MultiProtocolURI, Properties>(); String title; MultiProtocolURI url; Bookmark bm; final Set<String> tags = ListManager.string2set(tag); // this allow multiple default tags try { // load the links final ContentScraper scraper = new ContentScraper(baseURL); // OutputStream os = new htmlFilterOutputStream(null, scraper, null, false); final Writer writer = new TransformerWriter(null, null, scraper, null, false); FileUtils.copy(input, writer); writer.close(); links = scraper.getAnchors(); } catch (final IOException e) { Log.logWarning( "BOOKMARKS", "error during load of links: " + e.getClass() + " " + e.getMessage()); } for (final Entry<MultiProtocolURI, Properties> link : links.entrySet()) { url = link.getKey(); title = link.getValue().getProperty("name", ""); Log.logInfo("BOOKMARKS", "links.get(url)"); if ("".equals(title)) { // cannot be displayed title = url.toString(); } bm = db.new Bookmark(url.toString()); bm.setProperty(Bookmark.BOOKMARK_TITLE, title); bm.setTags(tags); bm.setPublic(importPublic); db.saveBookmark(bm); importCount++; } return importCount; }
public Document parse( final MultiProtocolURI location, final String mimeType, final String charset, final IInStream source) throws Parser.Failure, InterruptedException { final Document doc = new Document( location, mimeType, charset, this, null, null, null, null, null, null, null, 0.0f, 0.0f, (Object) null, null, null, null, false); Handler archive; super.log.logFine("opening 7zip archive..."); try { archive = new Handler(source); } catch (final IOException e) { throw new Parser.Failure("error opening 7zip archive: " + e.getMessage(), location); } final SZParserExtractCallback aec = new SZParserExtractCallback(super.log, archive, doc, location.getFile()); super.log.logFine("processing archive contents..."); try { archive.Extract(null, -1, 0, aec); return doc; } catch (final IOException e) { if (e.getCause() instanceof InterruptedException) throw (InterruptedException) e.getCause(); if (e.getCause() instanceof Parser.Failure) throw (Parser.Failure) e.getCause(); throw new Parser.Failure( "error processing 7zip archive at internal file " + aec.getCurrentFilePath() + ": " + e.getMessage(), location); } finally { try { archive.close(); } catch (final IOException e) { } } }
@Override public void SetOperationResult(final int arg0) throws IOException { if (arg0 != IInArchive.NExtract_NOperationResult_kOK) { this.NumErrors++; switch (arg0) { case IInArchive.NExtract_NOperationResult_kUnSupportedMethod: throw new IOException("Unsupported Method"); case IInArchive.NExtract_NOperationResult_kCRCError: throw new IOException("CRC Failed"); case IInArchive.NExtract_NOperationResult_kDataError: throw new IOException("Data Error"); default: // throw new IOException("Unknown Error"); } } else try { if (this.cfos != null) { // parse the file Document[] theDocs; // workaround for relative links in file, normally '#' shall be used behind the // location, see // below for reversion of the effects final MultiProtocolURI url = MultiProtocolURI.newURL(doc.dc_source(), this.prefix + "/" + super.filePath); final String mime = TextParser.mimeOf(super.filePath.substring(super.filePath.lastIndexOf('.') + 1)); theDocs = TextParser.parseSource(url, mime, null, this.cfos.toByteArray()); this.doc.addSubDocuments(theDocs); } } catch (final Exception e) { final IOException ex = new IOException( "error parsing extracted content of " + super.filePath + ": " + e.getMessage()); ex.initCause(e); throw ex; } }