Add interface

- Add JavaFX GUI
- Add XML/JSON parsing option
- Fix DOM track parsing JUnit not testing correct data
This commit is contained in:
Tanguy Herbron 2018-10-14 17:19:09 +02:00
parent c6c7005be8
commit 763c503229
18 changed files with 449 additions and 233 deletions

View File

@ -1,14 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="test">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/log4j-1.2.14.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/gagawa-1.0.1.jar"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -0,0 +1 @@
/target/

View File

@ -10,8 +10,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -9,4 +9,5 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -19,22 +19,50 @@
<li class="collection-item blue-grey darken-1"><span>Rusty Fonky</span><audio controls style="display: block"> <source src="http://cdn-preview-e.deezer.com/stream/c-ee21b7bada5a57f30d22f2fc62b06ddf-5.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Share a Line</span><audio controls style="display: block"> <source src="http://cdn-preview-2.deezer.com/stream/c-23bb98abf95e1615764b974d1c091bb8-5.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Mysterious Ways</span><audio controls style="display: block"> <source src="http://cdn-preview-f.deezer.com/stream/c-f9924ab2fff9b4c5e9a133cadbbf191e-4.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Killing Hallelujah</span><audio controls style="display: block"> <source src="http://cdn-preview-d.deezer.com/stream/c-df337b3bceea2691b9acf814e5e321c8-5.mp3" type="audio/mpeg"></li>
</div></div></div><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/56633592/image"> <span class="card-title" style="display: inline-block;">Smells Like Teen Spirit</span>
</div> </li>
</div></div></div></div><div class="row"><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/1121440/image"> <span class="card-title" style="display: inline-block;">The Geeks And The Jerkin' Socks</span>
</div> </li>
</div></div></div><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/8910295/image"> <span class="card-title" style="display: inline-block;">The Black Pixel Ape (Drinking Cigarettes to Take a Break) [Deezer Edition]</span>
</div> </li>
</div></div></div></div><div class="row"><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/7084004/image"> <span class="card-title" style="display: inline-block;">Monkeys in Bercy</span>
</div> </li>
</div></div></div><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/7529289/image"> <span class="card-title" style="display: inline-block;">The White Pixel Ape (Smoking Isolate to Keep in Shape)</span>
</div> </li>
<li class="collection-item blue-grey darken-1"><span>The White Pixel Ape (Smoking Isolate to Keep in Shape)</span><audio controls style="display: block"> <source src="http://cdn-preview-d.deezer.com/stream/c-df337b3bceea2691b9acf814e5e321c8-5.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Lucky G1rl</span><audio controls style="display: block"> <source src="http://cdn-preview-9.deezer.com/stream/c-9fb119c61130fef8705650cb57e88630-3.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Wanna Get Free</span><audio controls style="display: block"> <source src="http://cdn-preview-2.deezer.com/stream/c-2bcbc9f39c306a91ab0f72c8af78368d-1.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>M0nkey On The Wall</span><audio controls style="display: block"> <source src="http://cdn-preview-5.deezer.com/stream/c-526683c69cf2c05823e22e91f13dad98-2.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Scarify</span><audio controls style="display: block"> <source src="http://cdn-preview-4.deezer.com/stream/c-4d022fc56665700b144f2563b64ecec5-1.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Black Listed</span><audio controls style="display: block"> <source src="http://cdn-preview-0.deezer.com/stream/c-05f52e7f38cebd0f83305c6a81e16cda-2.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>An Eloquent</span><audio controls style="display: block"> <source src="http://cdn-preview-4.deezer.com/stream/c-4fe0dbd5932582d631dc9993e1b6c613-2.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>W0tz Goin'ON</span><audio controls style="display: block"> <source src="http://cdn-preview-5.deezer.com/stream/c-5439934bbd426f7bd73bea24af37051d-1.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Story O' my LF</span><audio controls style="display: block"> <source src="http://cdn-preview-b.deezer.com/stream/c-b7a89c8e9a56d2089c4226e4ee87daf9-1.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Gimme Guitarrrrra</span><audio controls style="display: block"> <source src="http://cdn-preview-0.deezer.com/stream/c-00dee5f18e8ff1131fa279bac320d679-1.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Last Alone</span><audio controls style="display: block"> <source src="http://cdn-preview-d.deezer.com/stream/c-d022e232f5d3a7304726839f76ec082b-2.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Altered Native Soul</span><audio controls style="display: block"> <source src="http://cdn-preview-1.deezer.com/stream/c-1270a0d5dae3bbd69d8cdf97e09f3782-1.mp3" type="audio/mpeg"></li>
<li class="collection-item blue-grey darken-1"><span>Heal Me Kill Me</span><audio controls style="display: block"> <source src="http://cdn-preview-5.deezer.com/stream/c-5bb5defae1b799ff50de820e4dd5422d-2.mp3" type="audio/mpeg"></li>
</div></div></div></div><div class="row"><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/637662/image"> <span class="card-title" style="display: inline-block;">Loco Con Da Frenchy Talkin' (Recycled version 2009)</span>
</div> </li>
</div></div></div><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/625593/image"> <span class="card-title" style="display: inline-block;">Bad Porn Movie Trax</span>
</div> </li>
</div></div></div></div><div class="row"><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/43199651/image"> <span class="card-title" style="display: inline-block;">ApeTizer - EP</span>
</div> </li>
</div></div></div><div class="col s12 m6"> <div class="card blue-grey darken-1">
<div class="card-content white-text">
<ul class="collection with-header blue-grey darken-1">
<li class="collection-header blue-grey darken-1"> <div> <img class="responsive-img circle" style="max-height: 50px; max-width: 50px" src="http://api.deezer.com/2.0/album/7327738/image"> <span class="card-title" style="display: inline-block;">Wanna Get Free - Single</span>
</div> </li>
</div></div></div></div></div></body></body></html>

View File

@ -1,2 +1,3 @@
/.DS_Store
/MainWindow.class
/fr/
/MainWindow.fxml

View File

@ -1,110 +0,0 @@
package fr.ensim.xml.deezer;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MainWindow {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainWindow window = new MainWindow();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public MainWindow() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 75);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
JPanel pnMainPanel;
final JTextField tfSearchTextBox;
JLabel lbSearchLabel;
JButton btSearchButton;
pnMainPanel = new JPanel();
GridBagLayout gbMainPanel = new GridBagLayout();
GridBagConstraints gbcMainPanel = new GridBagConstraints();
pnMainPanel.setLayout( gbMainPanel );
tfSearchTextBox = new JTextField( );
gbcMainPanel.gridx = 3;
gbcMainPanel.gridy = 1;
gbcMainPanel.gridwidth = 7;
gbcMainPanel.gridheight = 2;
gbcMainPanel.fill = GridBagConstraints.BOTH;
gbcMainPanel.weightx = 1;
gbcMainPanel.weighty = 0;
gbcMainPanel.anchor = GridBagConstraints.NORTH;
gbMainPanel.setConstraints( tfSearchTextBox, gbcMainPanel );
pnMainPanel.add( tfSearchTextBox );
lbSearchLabel = new JLabel( "Search :" );
gbcMainPanel.gridx = 0;
gbcMainPanel.gridy = 1;
gbcMainPanel.gridwidth = 3;
gbcMainPanel.gridheight = 2;
gbcMainPanel.fill = GridBagConstraints.BOTH;
gbcMainPanel.weightx = 1;
gbcMainPanel.weighty = 1;
gbcMainPanel.anchor = GridBagConstraints.NORTH;
gbMainPanel.setConstraints( lbSearchLabel, gbcMainPanel );
pnMainPanel.add( lbSearchLabel );
btSearchButton = new JButton( "Search" );
gbcMainPanel.gridx = 11;
gbcMainPanel.gridy = 1;
gbcMainPanel.gridwidth = 5;
gbcMainPanel.gridheight = 2;
gbcMainPanel.fill = GridBagConstraints.BOTH;
gbcMainPanel.weightx = 1;
gbcMainPanel.weighty = 0;
gbcMainPanel.anchor = GridBagConstraints.NORTH;
gbMainPanel.setConstraints( btSearchButton, gbcMainPanel );
pnMainPanel.add( btSearchButton );
frame.add(pnMainPanel);
btSearchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String str = tfSearchTextBox.getText();
str = str.replaceAll("\\s", "%20");
new Main(str);
}
});
}
}

View File

@ -12,10 +12,12 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import fr.ensim.json.JSONSearchAlbum;
import fr.ensim.json.JSONSearchAlbumTracks;
import fr.ensim.xml.deezer.data.Album;
import fr.ensim.xml.deezer.data.Track;
import fr.ensim.xml.deezer.dom.DOMSearchAlbums;
import fr.ensim.xml.deezer.dom.SearchAlbumTracks;
import fr.ensim.xml.deezer.dom.DOMSearchAlbumTracks;
import fr.ensim.xml.deezer.sax.SAXSearchAlbums;
import fr.ensim.xml.deezer.stax.HtmlAlbum;
@ -24,44 +26,36 @@ import fr.ensim.xml.deezer.stax.HtmlAlbum;
* @author Denis Apparicio
*
*/
public class Main {
public class Runner {
/**
* @param args
*/
public Main(String args) {
public Runner() {
// configuration du proxy et des logs
DOMConfigurator.configure("log4J.xml");
ProxyConfiguration.configure();
}
Logger log = Logger.getLogger(Main.class);
public File start(String searchString)
{
Logger log = Logger.getLogger(Runner.class);
FileOutputStream out = null;
try {
List<Album> listAlbum;
List<Album> listAlbum = new JSONSearchAlbum().find(searchString, false);
//listAlbum = new SAXSearchAlbums().find(args);
listAlbum = new DOMSearchAlbums().find(args);
// recuperation des titres de l album
for(int i = 0; i < listAlbum.size(); i++)
for(int i = 0; i < 1; i++)
{
listAlbum.get(i).setTracks(SearchAlbumTracks.find(listAlbum.get(i).getId()));
listAlbum.get(i).setTracks(JSONSearchAlbumTracks.find(listAlbum.get(i).getId()));
}
// Ecriture de la page html
File fileHtml = new File(listAlbum.get(0).getArtist().getName() + ".html");
out = new FileOutputStream(fileHtml);
HtmlAlbum.write(listAlbum, out);
out.close();
// Ouverture de la page
if (fileHtml.isFile()) {
if (Desktop.isDesktopSupported()
&& Desktop.getDesktop().isSupported(Action.BROWSE)) {
Desktop.getDesktop().browse(fileHtml.toURI());
}
if(fileHtml.isFile())
{
return fileHtml;
}
}
catch (Exception e) {
@ -80,6 +74,61 @@ public class Main {
}
log.debug("<<main");
return null;
}
public File start(String searchString, boolean useDom)
{
Logger log = Logger.getLogger(Runner.class);
FileOutputStream out = null;
try {
List<Album> listAlbum;
//listAlbum = new SAXSearchAlbums().find(args);
listAlbum = new DOMSearchAlbums().find(searchString, true);
// recuperation des titres de l album
for(int i = 0; i < 1; i++)
{
listAlbum.get(i).setTracks(DOMSearchAlbumTracks.find(listAlbum.get(i).getId()));
}
// Ecriture de la page html
File fileHtml = new File(listAlbum.get(0).getArtist().getName() + ".html");
out = new FileOutputStream(fileHtml);
HtmlAlbum.write(listAlbum, out);
out.close();
// Ouverture de la page
if (fileHtml.isFile()) {
return fileHtml;
/*if (Desktop.isDesktopSupported()
&& Desktop.getDesktop().isSupported(Action.BROWSE)) {
Desktop.getDesktop().browse(fileHtml.toURI());
}*/
}
}
catch (Exception e) {
log.error("", e);
fail(e.getMessage());
}
finally {
try {
if (out != null) {
out.close();
}
}
catch (IOException e) {
log.error("", e);
}
}
log.debug("<<main");
return null;
}
}

View File

@ -25,8 +25,8 @@ import fr.ensim.xml.deezer.data.Track;
* @author Denis Apparicio
*
*/
public class SearchAlbumTracks {
private static Logger log = Logger.getLogger(SearchAlbumTracks.class);
public class DOMSearchAlbumTracks {
private static Logger log = Logger.getLogger(DOMSearchAlbumTracks.class);
/**
* Restitue la liste des chansons d'un album.
@ -100,6 +100,7 @@ public class SearchAlbumTracks {
doc.normalize();
parseChildElements(doc.getDocumentElement(), listTracks);
listTracks.add(buildingTrack);
log.debug(">>find");
return listTracks;

View File

@ -26,7 +26,7 @@ import fr.ensim.xml.deezer.data.Track;
*
*/
public class DOMSearchAlbums extends AbstractSearchAlbum {
private static final Logger LOG = Logger.getLogger(DOMSearchAlbumsTest.class);
private static final Logger LOG = Logger.getLogger(DOMSearchAlbums.class);
/*
* (non-Javadoc)

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.MenuButton?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.web.WebView?>
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.181" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane prefHeight="400.0" prefWidth="640.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="7.0" prefWidth="640.0" />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="89.0" minHeight="0.0" prefHeight="27.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="188.0" minHeight="10.0" prefHeight="58.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="187.0" minHeight="10.0" prefHeight="187.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="113.0" minHeight="10.0" prefHeight="113.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<WebView fx:id="webView" prefHeight="-1.0" prefWidth="-1.0" GridPane.columnSpan="2" GridPane.rowIndex="1" GridPane.rowSpan="3" />
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="589.0" minWidth="10.0" prefWidth="460.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="314.0" minWidth="10.0" prefWidth="113.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="314.0" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="searchButton" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Rechercher" GridPane.columnIndex="1" />
<TextField fx:id="searchBar" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" />
<MenuButton fx:id="parserSelector" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" prefHeight="35.0" prefWidth="90.0" text="Parser" GridPane.columnIndex="2">
<items>
<MenuItem mnemonicParsing="false" text="XML" fx:id="xmlOption" />
<MenuItem fx:id="jsonOption" mnemonicParsing="false" text="JSON" />
</items>
</MenuButton>
</children>
</GridPane>
<GridPane GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</GridPane>
</children>
</VBox>

View File

@ -0,0 +1,86 @@
package fr.ensim.xml.ui;
import java.io.File;
import java.io.IOException;
import fr.ensim.xml.deezer.Runner;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class MainWindow extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("MainWindow.fxml"));
Scene scene = new Scene(root, 640, 400);
primaryStage.setTitle("Deezer pour les nuls");
primaryStage.setScene(scene);
primaryStage.show();
initiateEvents(scene);
}
private void initiateEvents(Scene scene)
{
final TextField searchTextField = (TextField) scene.lookup("#searchBar");
Button searchButton = (Button) scene.lookup("#searchButton");
final MenuButton menuButton = (MenuButton) scene.lookup("#parserSelector");
final MenuItem xmlOption = menuButton.getItems().get(0);
final MenuItem jsonOption = menuButton.getItems().get(1);
final WebView webView = (WebView) scene.lookup("#webView");
searchButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(menuButton.getText().equals(jsonOption.getText()))
{
Runner runner = new Runner();
File htmlFile = runner.start(searchTextField.getText().replaceAll("\\s", "%20"));
WebEngine engine = webView.getEngine();
engine.load(htmlFile.toURI().toString());
}
else
{
Runner runner = new Runner();
File htmlFile = runner.start(searchTextField.getText().replaceAll("\\s", "%20"), false);
WebEngine engine = webView.getEngine();
engine.load(htmlFile.toURI().toString());
}
}
});
xmlOption.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
menuButton.setText(xmlOption.getText());
}
});
jsonOption.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
menuButton.setText(jsonOption.getText());
}
});
}
public static void main(String[] args) {
launch(args);
}
}

View File

@ -0,0 +1,48 @@
package fr.ensim.json;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.xml.sax.SAXException;
import fr.ensim.xml.deezer.data.Album;
import fr.ensim.xml.deezer.dom.DOMSearchAlbums;
public class JSONSearchAlbumTest {
private static final Logger LOG = Logger.getLogger(JSONSearchAlbumTest.class);
@Test
public void testParse() throws Exception {
LOG.debug(">>testParse");
// Recuperation du flux a parser
//InputStream in = getClass().getResourceAsStream("../list-albums.json");
InputStream in = getClass().getClassLoader().getResourceAsStream("fr/ensim/json/list-albums.json");
List<Album> listAlbums = new JSONSearchAlbum().readAlbums(in);
assertEquals(10, listAlbums.size());
assertEquals("47685332", listAlbums.get(0).getId());
assertEquals("The Evol", listAlbums.get(0).getTitle());
assertEquals("http://api.deezer.com/2.0/album/47685332/image", listAlbums.get(0).getCover());
assertEquals("83325", listAlbums.get(0).getArtist().getId());
assertEquals("Shaka Ponk", listAlbums.get(0).getArtist().getName());
// Second album
assertEquals("56633592", listAlbums.get(1).getId());
assertEquals("Smells Like Teen Spirit", listAlbums.get(1).getTitle());
assertEquals("http://api.deezer.com/2.0/album/56633592/image", listAlbums.get(1).getCover());
assertEquals("83325", listAlbums.get(1).getArtist().getId());
assertEquals("Shaka Ponk", listAlbums.get(1).getArtist().getName());
LOG.debug("<<testParse");
}
}

View File

@ -0,0 +1,45 @@
package fr.ensim.json;
import static org.junit.Assert.*;
import java.io.InputStream;
import java.util.List;
import org.apache.log4j.Logger;
import org.junit.Test;
import fr.ensim.xml.deezer.data.Album;
public class JSONSearchAlbumTracksTest {
private static final Logger LOG = Logger.getLogger(JSONSearchAlbumTest.class);
@Test
public void test() throws Exception {
LOG.debug(">>testParse");
// Recuperation du flux a parser
//InputStream in = getClass().getResourceAsStream("../list-albums.json");
InputStream in = getClass().getClassLoader().getResourceAsStream("fr/ensim/json/list-albums.json");
List<Tra> listAlbums = new JSONSearchAlbum().readAlbums(in);
assertEquals(10, handler.getListAlbum().size());
//First album
assertEquals("47685332", handler.getListAlbum().get(0).getId());
assertEquals("The Evol", handler.getListAlbum().get(0).getTitle());
assertEquals("http://api.deezer.com/2.0/album/47685332/image", handler.getListAlbum().get(0).getCover());
assertEquals("83325", handler.getListAlbum().get(0).getArtist().getId());
assertEquals("Shaka Ponk", handler.getListAlbum().get(0).getArtist().getName());
//Second album
assertEquals("1121440", handler.getListAlbum().get(1).getId());
assertEquals("The Geeks And The Jerkin' Socks", handler.getListAlbum().get(1).getTitle());
assertEquals("http://api.deezer.com/2.0/album/1121440/image", handler.getListAlbum().get(1).getCover());
assertEquals("83325", handler.getListAlbum().get(1).getArtist().getId());
assertEquals("Shaka Ponk", handler.getListAlbum().get(1).getArtist().getName());
LOG.debug("<<testParse");
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,53 @@
package fr.ensim.xml.deezer.dom;
import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import fr.ensim.xml.deezer.data.Track;
import fr.ensim.xml.deezer.sax.SAXSearchAlbumsHandler;
import fr.ensim.xml.deezer.sax.SAXSearchAlbumsTest;
public class DOMSearchAlbumTracksTest {
static {
DOMConfigurator.configure("log4J.xml");
}
private static final Logger LOG = Logger.getLogger(DOMSearchAlbumTracksTest.class);
@Test
public void test() throws ParserConfigurationException, SAXException, IOException {
LOG.debug(">>testParse");
// Recuperation du flux a parser
InputStream in = getClass().getResourceAsStream("../album-stupeflip.xml");
List<Track> trackList = new DOMSearchAlbumTracks().find(in);
assertEquals(19, trackList.size());
//First album
assertEquals("Intro", trackList.get(0).getTitle());
assertEquals("http://cdn-preview-f.deezer.com/stream/c-f4d3cef094894988635ab62f1e8d6c4e-3.mp3", trackList.get(0).getPreview());
//Second album
assertEquals("The Antidote", trackList.get(1).getTitle());
assertEquals("http://cdn-preview-a.deezer.com/stream/c-ac96a1f36c1ffe00fa17919160081e77-3.mp3", trackList.get(1).getPreview());
LOG.debug("<<testParse");
}
}

View File

@ -1,67 +0,0 @@
package fr.ensim.xml.deezer.dom;
import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import fr.ensim.xml.deezer.sax.SAXSearchAlbumsHandler;
import fr.ensim.xml.deezer.sax.SAXSearchAlbumsTest;
public class SearchAlbumTracksTest {
static {
DOMConfigurator.configure("log4J.xml");
}
private static final Logger LOG = Logger.getLogger(SearchAlbumTracksTest.class);
@Test
public void test() throws ParserConfigurationException, SAXException, IOException {
LOG.debug(">>testParse");
// Recuperation du flux a parser
InputStream in = getClass().getResourceAsStream("../list-albums.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
// constitution du flux xml
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
InputSource source = new InputSource(reader);
// parsing
SAXSearchAlbumsHandler handler = new SAXSearchAlbumsHandler();
parser.parse(source, handler);
assertEquals(10, handler.getListAlbum().size());
//First album
assertEquals("47685332", handler.getListAlbum().get(0).getId());
assertEquals("The Evol", handler.getListAlbum().get(0).getTitle());
assertEquals("http://api.deezer.com/2.0/album/47685332/image", handler.getListAlbum().get(0).getCover());
assertEquals("83325", handler.getListAlbum().get(0).getArtist().getId());
assertEquals("Shaka Ponk", handler.getListAlbum().get(0).getArtist().getName());
//Second album
assertEquals("1121440", handler.getListAlbum().get(1).getId());
assertEquals("The Geeks And The Jerkin' Socks", handler.getListAlbum().get(1).getTitle());
assertEquals("http://api.deezer.com/2.0/album/1121440/image", handler.getListAlbum().get(1).getCover());
assertEquals("83325", handler.getListAlbum().get(1).getArtist().getId());
assertEquals("Shaka Ponk", handler.getListAlbum().get(1).getArtist().getName());
LOG.debug("<<testParse");
}
}

View File

@ -1,8 +1,4 @@
16:23:10,446 DEBUG fr.ensim.xml.deezer.stax.StAXSearchAlbumsTest - >>testCount
16:23:10,449 DEBUG fr.ensim.xml.deezer.stax.StAXSearchAlbums - >>count
16:23:10,460 DEBUG fr.ensim.xml.deezer.stax.StAXSearchAlbums - <<count 10
16:23:10,461 DEBUG fr.ensim.xml.deezer.stax.StAXSearchAlbumsTest - <<testCount
16:23:10,462 DEBUG fr.ensim.xml.deezer.stax.StAXSearchAlbumsTest - >>testParse
16:23:10,462 DEBUG fr.ensim.xml.deezer.stax.StAXSearchAlbums - >>readAlbums
16:23:10,467 DEBUG fr.ensim.xml.deezer.stax.StAXSearchAlbums - <<readAlbums
16:23:10,468 DEBUG fr.ensim.xml.deezer.stax.StAXSearchAlbumsTest - <<testParse
17:15:23,447 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbumTracksTest - >>testParse
17:15:23,450 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbumTracks - >>find
17:15:23,461 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbumTracks - >>find
17:15:23,462 DEBUG fr.ensim.xml.deezer.dom.DOMSearchAlbumTracksTest - <<testParse