/** * Searches the selected directories in the filesystem for Mp3 files. * * @param e ActionEvent */ public synchronized void actionPerformed(ActionEvent e) { try { Mp3Controller controller = getMp3Controller(); // launch filechooser and import selected directory FileSystemModel fsModel = controller.getFileSystemModel(); fsModel.clear(); File file = FileChooser.chooseDirectory(super.getSearchPanel(), "Import"); if (file != null) { getStatusPanel().startProcessing("Loading... " + file); fsModel.includeDirectory(file.toURI().toURL()); Mp3Model mp3Model = controller.getMp3Model(); mp3Model.setMp3ModelListener(getMp3ModelListener()); mp3Model.loadMp3s(fsModel); } // underlying model/data has changed getSearchPanel().constraintsHaveChanged(); getStatusPanel().stopProcessing("Successfully loaded: " + file); } catch (Exception exception) { getStatusPanel().stopProcessingError("Error(s) occurred while loading Mp3s"); ExceptionHandler.handleException(exception); } }
/** * Returns all Id3 property-values for the Mp3 as an Iterator of Triples. * * @return ClosableIterator * @throws QueryException */ public ClosableIterator getStatements() throws QueryException { ClosableIterator schemaProperties = null; try { schemaProperties = getSchemaProperties(); String query = getStatementsQuery(mp3.getResource(), schemaProperties); return model.query(query); } catch (Exception exception) { throw new QueryException("Failed to getStatements.", exception); } finally { if (schemaProperties != null) { schemaProperties.close(); } } }
/** * Returns a queryString in the following format: * * <p> * * <pre> * select $s $p $o * from <model.getResource()> * where $s $p $o * and $s <id3:uri> <mp3> * and ($p <mulgara:is> <schemaProperty-1> * or $p <mulgara:is> <schemaProperty-2> * ... * or $p <mulgara:is> <schemaProperty-n>) ; * </pre> * * where <schemaProperty> is a property of the ID3Tags schema. * * @return String * @param mp3 URIReference * @param properties Iterator of Triples where the SubjectNode's represent the schemaProperties. */ private String getStatementsQuery(URIReference mp3, Iterator properties) { // if there are no properties, there should be no statements. if ((properties == null) || !(properties.hasNext())) { return ";"; } Node currentProperty = ((Triple) properties.next()).getPredicate(); StringBuffer query = new StringBuffer("select $s $p $o" + NEWLINE); query.append("from <" + model.getResource().getURI() + ">" + NEWLINE); query.append("where $s $p $o" + NEWLINE); query.append("and $s" + ID3_URI + asString(mp3) + " " + NEWLINE); query.append( "and ( $p" + MULGARA_IS + asString((URIReference) currentProperty) + " " + NEWLINE); while (properties.hasNext()) { currentProperty = ((Triple) properties.next()).getSubject(); query.append( " or $p" + MULGARA_IS + asString((URIReference) currentProperty) + " " + NEWLINE); } // results must be ordered query.append(") order by $s $p $o ; "); return query.toString(); }