boolean readMetaInfo() { myEncoding = null; myLanguage = null; myTitle = null; myAuthors = null; myTags = null; mySeriesInfo = null; myIsSaved = false; final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File); if (plugin == null || !plugin.readMetaInfo(this)) { return false; } if (myTitle == null || myTitle.length() == 0) { final String fileName = File.getShortName(); final int index = fileName.lastIndexOf('.'); setTitle(index > 0 ? fileName.substring(0, index) : fileName); } final String demoPathPrefix = Paths.BooksDirectoryOption().getValue() + java.io.File.separator + "Demos" + java.io.File.separator; if (File.getPath().startsWith(demoPathPrefix)) { final String demoTag = LibraryUtil.resource().getResource("demo").getValue(); setTitle(getTitle() + " (" + demoTag + ")"); addTag(demoTag); } return true; }
// FIXME: temporary implementation; implement as a native code (?) @Override public String readAnnotation(ZLFile file) { final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file, FormatPlugin.Type.JAVA); if (plugin != null) { return plugin.readAnnotation(file); } return null; }
public Book getBookByFile(ZLFile bookFile) { if (bookFile == null) { return null; } final FormatPlugin plugin = PluginCollection.Instance().getPlugin(bookFile); if (plugin == null) { return null; } try { bookFile = plugin.realBookFile(bookFile); } catch (BookReadingException e) { return null; } Book book = myBooksByFile.get(bookFile); if (book != null) { return book; } final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile(); if (physicalFile != null && !physicalFile.exists()) { return null; } final FileInfoSet fileInfos = new FileInfoSet(myDatabase, bookFile); book = myDatabase.loadBookByFile(fileInfos.getId(bookFile), bookFile); if (book != null) { book.loadLists(myDatabase); } if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) { saveBook(book, false); // saved addBook(book, false); return book; } fileInfos.save(); try { if (book == null) { book = new Book(bookFile); } else { book.readMetaInfo(); } } catch (BookReadingException e) { return null; } saveBook(book, false); return book; }
@Override public AbstractGroupScan getPhysicalScan(JSONOptions selection) throws IOException { FormatSelection formatSelection = selection.getWith(context.getConfig(), FormatSelection.class); FormatPlugin plugin; if (formatSelection.getFormat() instanceof NamedFormatPluginConfig) { plugin = formatsByName.get(((NamedFormatPluginConfig) formatSelection.getFormat()).name); } else { plugin = formatPluginsByConfig.get(formatSelection.getFormat()); } if (plugin == null) throw new IOException( String.format( "Failure getting requested format plugin named '%s'. It was not one of the format plugins registered.", formatSelection.getFormat())); return plugin.getGroupScan(formatSelection.getSelection()); }
synchronized ZLImage getCover() { if (myCover == NULL_IMAGE) { return null; } else if (myCover != null) { final ZLImage image = myCover.get(); if (image != null) { return image; } } ZLImage image = null; final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File); if (plugin != null) { image = plugin.readCover(File); } myCover = image != null ? new WeakReference<ZLImage>(image) : NULL_IMAGE; return image; }
public FileSystemPlugin(FileSystemConfig config, DrillbitContext context, String name) throws ExecutionSetupException { try { this.config = config; this.context = context; Configuration fsConf = new Configuration(); fsConf.set(FileSystem.FS_DEFAULT_NAME_KEY, config.connection); fsConf.set("fs.classpath.impl", ClassPathFileSystem.class.getName()); fsConf.set("fs.drill-local.impl", LocalSyncableFileSystem.class.getName()); this.fs = FileSystemCreator.getFileSystem(context.getConfig(), fsConf); this.formatsByName = FormatCreator.getFormatPlugins(context, fs, config); List<FormatMatcher> matchers = Lists.newArrayList(); formatPluginsByConfig = Maps.newHashMap(); for (FormatPlugin p : formatsByName.values()) { matchers.add(p.getMatcher()); formatPluginsByConfig.put(p.getConfig(), p); } List<WorkspaceSchemaFactory> factories = null; if (config.workspaces == null || config.workspaces.isEmpty()) { factories = Collections.singletonList( new WorkspaceSchemaFactory(this, "default", name, fs, "/", matchers)); } else { factories = Lists.newArrayList(); for (Map.Entry<String, String> space : config.workspaces.entrySet()) { factories.add( new WorkspaceSchemaFactory( this, space.getKey(), name, fs, space.getValue(), matchers)); } } this.schemaFactory = new FileSystemSchemaFactory(name, factories); } catch (IOException e) { throw new ExecutionSetupException("Failure setting up file system plugin.", e); } }