1616import java .util .regex .Matcher ;
1717import java .util .regex .Pattern ;
1818
19+ import javax .inject .Inject ;
1920import javax .xml .parsers .DocumentBuilder ;
2021import javax .xml .parsers .DocumentBuilderFactory ;
2122import javax .xml .parsers .ParserConfigurationException ;
3435public class MediaDataExtractor {
3536 private final MediaWikiApi mediaWikiApi ;
3637 private boolean fetched ;
37-
38- private String filename ;
3938 private ArrayList <String > categories ;
4039 private Map <String , String > descriptions ;
4140 private String license ;
4241 private @ Nullable LatLng coordinates ;
43- private LicenseList licenseList ;
4442
45- /**
46- * @param mwApi instance of MediaWikiApi
47- * @param filename of the target media object, should include 'File:' prefix
48- */
49- public MediaDataExtractor (String filename , LicenseList licenseList , MediaWikiApi mwApi ) {
50- this .filename = filename ;
43+ @ Inject
44+ public MediaDataExtractor (MediaWikiApi mwApi ) {
5145 this .categories = new ArrayList <>();
5246 this .descriptions = new HashMap <>();
5347 this .fetched = false ;
54- this .licenseList = licenseList ;
5548 this .mediaWikiApi = mwApi ;
5649 }
5750
58- /**
51+ /*
5952 * Actually fetch the data over the network.
6053 * todo: use local caching?
6154 *
6255 * Warning: synchronous i/o, call on a background thread
6356 */
64- public void fetch () throws IOException {
57+ public void fetch (String filename , LicenseList licenseList ) throws IOException {
6558 if (fetched ) {
6659 throw new IllegalStateException ("Tried to call MediaDataExtractor.fetch() again." );
6760 }
@@ -72,7 +65,7 @@ public void fetch() throws IOException {
7265 extractCategories (result .getWikiSource ());
7366
7467 // Description template info is extracted from preprocessor XML
75- processWikiParseTree (result .getParseTreeXmlSource ());
68+ processWikiParseTree (result .getParseTreeXmlSource (), licenseList );
7669 fetched = true ;
7770 }
7871
@@ -91,7 +84,7 @@ private void extractCategories(String source) {
9184 }
9285 }
9386
94- private void processWikiParseTree (String source ) throws IOException {
87+ private void processWikiParseTree (String source , LicenseList licenseList ) throws IOException {
9588 Document doc ;
9689 try {
9790 DocumentBuilder docBuilder = DocumentBuilderFactory .newInstance ().newDocumentBuilder ();
0 commit comments