package tools; import java.io.File; import java.io.PrintWriter; import java.io.Serializable; import java.util.Collection; import java.util.HashMap; import javax.swing.text.html.HTMLDocument.Iterator; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.google.gwt.user.client.Random; public class Authority implements Serializable { public static final String DEFAULT_NAME = "DEFAULT_NAME" ; public static final int DEFAULT_ID = 0 ; public String authorityName ; public int authorityID ; public HashMap data ; public Configuration configuration ; public Configuration confManifestation ; public PrintWriter writer ; public String sortingField ; public Translator transManif; public Translator transConfig ; public PrintWriter oMovies; public PrintWriter oActors; public PrintWriter oManifest; public PrintWriter oActorMovie; public Authority() { this.authorityName = DEFAULT_NAME ; this.authorityID = DEFAULT_ID ; this.data = new HashMap() ; this.configuration = null ; } public Authority(PrintWriter writer) { this() ; this.writer = writer ; } public Authority(Configuration configuration) { this.data = new HashMap() ; this.configuration = configuration ; } public Authority(HashMap data, Configuration configuration) { this.data = data ; this.configuration = configuration ; } public Authority(PrintWriter out, PrintWriter oMovies, PrintWriter oActors, PrintWriter oManifest, PrintWriter oActorMovie) { this() ; this.writer = out ; this.oMovies = oMovies ; this.oActors = oActors ; this.oManifest = oManifest ; this.oActorMovie = oActorMovie ; } public boolean addElement(ElementData element) { return this.data.put("" + element.id, element) != null ; } private char dec2hex(int value) { if (value < 10) return (char) ('0' + value) ; else return (char) ('A' + (value - 10)) ; } public String genID(int length) { String id = "" ; for (int i = 0 ; i < length ; i ++) { id += dec2hex(Random.nextInt() % 16) ; } return id ; } public ElementData getElement(long id) { return this.data.get("" + id) ; } public Object [] getAllData() { return data.values().toArray() ; } public static String readField(Element element, String tagName) { try { NodeList nodeList = element.getElementsByTagName(tagName) ; Element tagElement = (Element) nodeList.item(0) ; NodeList textList = tagElement.getChildNodes() ; return ((Node) textList.item(0)).getNodeValue().trim() ; } catch (Exception e) { return null ; } } public void createFromFile2(String fileName) { try { configuration = new Configuration("Filmwerk") ; configuration.addField("uid", "ExtIDs/extid/", "integer", 0.0) ; configuration.addField("title", "ExtIDs/extid/", "string", 1.9, CompareUtilities.JARO_DISTANCE_REFERENCE | CompareUtilities.TITLE_DISTANCE_REFERENCE) ; configuration.addField("sortval", "IDTitel/@sortval", "string", 3.5, CompareUtilities.EDIT_DISTANCE_REFERENCE) ; configuration.addField("year", "ProdJahr/", "string", 3.8, CompareUtilities.YEAR_DISTANCE_REFERENCE) ; configuration.addField("region", "Ursprungsland/Region/RegionCode/", "string", 0.7, CompareUtilities.JARO_DISTANCE_REFERENCE) ; configuration.compile() ; confManifestation = new Configuration("FilmManifestation") ; confManifestation.addField("workRelation", "WerkRelation", "string", 0.6, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("gaugeFormat", "Traegerformat", "string", 0.2, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("aspectRatioFormat", "Bildformat", "string", 0.4, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("sound", "Ton", "string", 1.5, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("colour", "Farbe", "string", 2.5, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("duration", "Dauer", "string", 8.6, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("dimension", "Laenge", "string", 3.0, CompareUtilities.JARO_DISTANCE_REFERENCE) ; PrintWriter out = new PrintWriter("test.txt") ; try { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(new File(fileName)) ; doc.getDocumentElement().normalize() ; //PrintWriter out = new PrintWriter(new File("output.txt")) ; NodeList movies = doc.getElementsByTagName(configuration.rootPath) ; for (int iMovies = 0 ; iMovies < movies.getLength() ; iMovies ++) { Node curMovieNode = (Node) movies.item(iMovies) ; if (curMovieNode.getNodeType() == Node.ELEMENT_NODE) { Element movie = (Element) curMovieNode ; ElementData record = new ElementData(this) ; readData(movie, record, configuration.root) ; addElement(record) ; String movieID = genID(32) ; oMovies.println(movieID) ; /// record.addData("uid", movie.getAttribute("uid")) ; try { oMovies.println(movie.getAttribute("uid")) ; } catch (Exception e) { oMovies.println(); } //out.println("ID: " + movie.getAttribute("uid")) ; NodeList title = movie.getElementsByTagName("IDTitel") ; Element curTitle = (Element) title.item(0) ; try { oMovies.println(curTitle.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } ; try { oMovies.println(curTitle.getAttribute("sortval")) ; } catch (Exception e) { oMovies.println(); } ; ///record.addData("title", curTitle.getChildNodes().item(0).getNodeValue()) ; ///record.addData("sortval", curTitle.getAttribute("sortval")) ; //out.println("IDTitel = " + curTitle.getChildNodes().item(0).getNodeValue()) ; //out.println("sortval = " + curTitle.getAttribute("sortval")) ; try { NodeList productionYear = movie.getElementsByTagName("ProdJahr") ; Element curYear = (Element) productionYear.item(0) ; oMovies.println(curYear.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } ; ///record.addData("year", curYear.getChildNodes().item(0).getNodeValue()) ; //out.println("Production year: " + curYear.getChildNodes().item(0).getNodeValue()) ; try { NodeList regionCode = movie.getElementsByTagName("RegionCode") ; Element curRegion = (Element) regionCode.item(0) ; oMovies.println(curRegion.getChildNodes().item(0).getNodeValue()) ; ///record.addData("region", curRegion.getChildNodes().item(0).getNodeValue()) ; //out.println("Region: " + curRegion.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } //out.println("Region rang: " + curRegion.getAttribute("rang")) ; try { NodeList movieType = movie.getElementsByTagName("Gattung") ; Element curType = (Element) movieType.item(0) ; oMovies.println(curType.getChildNodes().item(0).getNodeValue()) ; ///record.addData("type", curType.getChildNodes().item(0).getNodeValue()) ; //out.println("Movie type: " + curType.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } try { NodeList movieAbout = movie.getElementsByTagName("Anmerkung") ; Element curAbout = (Element) movieAbout.item(0) ; oMovies.println(curAbout.getChildNodes().item(0).getNodeValue()) ; ///record.addData("type", curType.getChildNodes().item(0).getNodeValue()) ; //out.println("Movie type: " + curType.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } try { NodeList manifestations = movie.getElementsByTagName("FilmManifestation") ; for (int iManifestation = 0 ; iManifestation < manifestations.getLength() ; iManifestation ++) { Element curManifestation = (Element) manifestations.item(iManifestation) ; AVManifestation avManifestation = new AVManifestation(this, curManifestation, movieID) ; record.addData(avManifestation) ; } } catch (Exception e) { } try { NodeList credits = movie.getElementsByTagName("CreditRel") ; for (int icredits = 0 ; icredits < credits.getLength() ; icredits ++) { Element curCredit = (Element) credits.item(icredits) ; //out.println(icredits) ; if (curCredit.hasAttribute("rel")) { //out.println("rel = " + curCredit.getAttribute("rel") + ", id = " + curCredit.getAttribute("uid")) ; } Element curCorporate = (Element) curCredit.getElementsByTagName("Koerperschaft").item(0) ; if (curCorporate != null) { //out.println("idname = " + curCorporate.getAttribute("idname") + ", id = " + curCorporate.getAttribute("uid")) ; } } } catch (Exception e) { //out.println("EXCEPTIOOOOOOOOOOONNNNNNNNNNN") ; } addElement(record) ; } } } catch (Exception e) { System.out.println("Exception: " + e) ; } */ } catch (Exception e) { System.out.println("Exception: " + e) ; } } private void readData(Element element, ElementData record, ConfigTree tree) { String name = tree.name ; if (name != null) { record.addData(name, getValue(element, tree.path)) ; } Collection children = tree.children.values() ; for (java.util.Iterator it = children.iterator() ; it.hasNext() ; ) { ConfigTree child = it.next() ; NodeList productionYear = element.getElementsByTagName(child.path) ; for (int i = 0 ; i < productionYear.getLength() ; i ++) { Element nextElement = (Element) productionYear.item(i) ; readData(nextElement, record, child) ; } } } private String getValue(Element element, String path) { try { if (path.charAt(0) == '@') { return element.getAttribute(path.substring(1)) ; } else { NodeList nodeList = element.getElementsByTagName(path) ; Element curElement = (Element) nodeList.item(0) ; return curElement.getChildNodes().item(0).getNodeValue() ; } } catch (Exception e) { return "" ; } } public void createFromFile(String fileName) { try { transConfig = new Translator() ; transConfig.addWord("id", "ExtIDs/extid/text()") ; transConfig.addWord("title", "IDTitel/text()") ; transConfig.addWord("sortval", "IDTitel/@sortval") ; transConfig.addWord("year", "ProdJahr/text()") ; transConfig.addWord("region", "Ursprungsland/Region/RegionCode/text()") ; configuration = new Configuration() ; configuration.addField("uid", "integer", 0.0) ; configuration.addField("title", "string", 1.9, CompareUtilities.JARO_DISTANCE_REFERENCE | CompareUtilities.TITLE_DISTANCE_REFERENCE) ; configuration.addField("sortval", "string", 3.5, CompareUtilities.EDIT_DISTANCE_REFERENCE) ; configuration.addField("year", "string", 3.8, CompareUtilities.YEAR_DISTANCE_REFERENCE) ; configuration.addField("region", "string", 0.7, CompareUtilities.JARO_DISTANCE_REFERENCE) ; transManif = new Translator() ; transManif.addWord("workRelation", "WerkRelation") ; transManif.addWord("gaugeFormat", "Traegerformat") ; transManif.addWord("aspectRatioFormat", "Bildformat") ; transManif.addWord("sound", "Ton") ; transManif.addWord("colour", "Farbe") ; transManif.addWord("carrierType", "CarrierType??") ; transManif.addWord("duration", "Dauer") ; transManif.addWord("dimension", "Laenge") ; confManifestation = new Configuration() ; confManifestation.addField("workRelation", "string", 0.6, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("gaugeFormat", "string", 0.2, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("aspectRatioFormat", "string", 0.4, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("sound", "string", 1.5, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("colour", "string", 2.5, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("carrierType", "string", 0.7, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("duration", "string", 8.6, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("dimension", "string", 3.0, CompareUtilities.JARO_DISTANCE_REFERENCE) ; PrintWriter out = new PrintWriter("test.txt") ; DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(false); DocumentBuilder builder = domFactory.newDocumentBuilder(); long costInit = 0, costCompile = 0, costEvaluate = 0, curTime ; try { curTime = System.currentTimeMillis() ; Document doc = builder.parse(new File(fileName)) ; doc.getDocumentElement().normalize() ; costInit += System.currentTimeMillis() - curTime ; curTime = System.currentTimeMillis() ; XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("/dif_export/Filmwerk"); NodeList movies = (NodeList) expr.evaluate(doc, XPathConstants.NODESET) ; Collection colNames = transConfig.dictionary.keySet() ; XPathExpression [] exprFields = new XPathExpression [colNames.size()] ; int iField = 0 ; for (java.util.Iterator itNames = colNames.iterator() ; itNames.hasNext(); ) { String fieldName = itNames.next() ; exprFields [iField ++] = xpath.compile(transConfig.translate(fieldName)) ; } costCompile += System.currentTimeMillis() - curTime ; curTime = System.currentTimeMillis() ; int countEvaluate = 0 ; for (int iMovies = 0 ; iMovies < movies.getLength() ; iMovies ++) { Node curMovieNode = (Node) movies.item(iMovies) ; ElementData record = new ElementData(this) ; iField = 0 ; for (java.util.Iterator itNames = colNames.iterator() ; itNames.hasNext(); ) { String fieldName = itNames.next() ; countEvaluate ++ ; String value = (String) exprFields [iField ++].evaluate(curMovieNode, XPathConstants.STRING) ; record.addData(fieldName, value) ; } //System.out.println("Adding: " + record) ; addElement(record) ; } costEvaluate += System.currentTimeMillis() - curTime ; curTime = System.currentTimeMillis() ; System.out.println("COST: " + costInit + ", " + costCompile + ", " + costEvaluate + ", " + countEvaluate) ; } catch (Exception e) { System.out.println("Exception: " + e) ; } /* DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(false); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(fileName); //System.out.println(doc.getBaseURI() + "#" + doc.getDocumentURI() + "#" + // doc.getNamespaceURI()) ; Node root = doc.getFirstChild() ; //System.out.println(root.getBaseURI() + "#" + root.getLocalName() + "#" + // root.getNamespaceURI() + "#" + root.getNodeValue()) ; XPath xpath = XPathFactory.newInstance().newXPath(); //NamespaceContext ns = new NamespaceContextImpl() ; //xpath.setNamespaceContext(ns) ; //NodeList nodes = (NodeList) // XPath Query for showing all nodes value BufferedReader in = new BufferedReader(new InputStreamReader(System.in)) ; String line = "/dif_export/Filmwerk" ; // = in.readLine(); System.out.print("Document query: ") ; line = in.readLine() ; while (line.length() > 0) { try { XPathExpression expr = xpath.compile(line); Object result = expr.evaluate(doc, XPathConstants.NODESET) ; //NODESET); NodeList nodes = (NodeList) result; System.out.println("Nodes size: " + nodes.getLength()) ; for (int i = 0; i < nodes.getLength(); i++) { System.out.println("NODE DESCRIPTION") ; System.out.println("[" + nodes.item(i).getNodeValue() + "]") ; System.out.println("#####################") ; System.out.println("node: " + nodes.item(i)); System.out.println(nodes.item(i).getNodeValue()); System.out.println("baseURI: " + nodes.item(i).getBaseURI()); System.out.println("localName: " + nodes.item(i).getLocalName()); System.out.println("namespace: " + nodes.item(i).getNamespaceURI()); System.out.println("nodeName: " + nodes.item(i).getNodeName()); System.out.println("textContent: " + nodes.item(i).getTextContent()); System.out.println("attributes: " + nodes.item(i).getAttributes().getLength()); System.out.println("#####################") ; String tst ; System.out.print("Node query: ") ; tst = in.readLine() ; while (tst.length() > 0) { System.out.println("tst: " + tst + ", length = " + tst.length()) ; xpath.reset() ; expr = xpath.compile(tst) ; NodeList list = (NodeList) expr.evaluate(nodes.item(i), XPathConstants.NODESET) ; System.out.println("List size = " + list.getLength()) ; for (int k = 0 ; k < list.getLength() ; k ++) { System.out.println("[" + list.item(k).getNodeValue() + "]") ; System.out.println("#####################") ; System.out.println("node: " + list.item(k)); System.out.println(list.item(k).getNodeValue()); System.out.println("baseURI: " + list.item(k).getBaseURI()); System.out.println("localName: " + list.item(k).getLocalName()); System.out.println("namespace: " + list.item(k).getNamespaceURI()); System.out.println("nodeName: " + list.item(k).getNodeName()); System.out.println("textContent: " + list.item(k).getTextContent()); System.out.println("attributes: " + list.item(k).getAttributes().getLength()); System.out.println("#####################") ; } System.out.print("Node query: ") ; tst = in.readLine() ; } } } catch (Exception e) { System.out.println("Error in query().") ; } System.out.print("Document query: ") ; line = in.readLine() ; //break ; //line = in.readLine() ; } */ /* configuration = new Configuration() ; configuration.addField("uid", "integer", 0.0) ; configuration.addField("title", "string", 1.9, CompareUtilities.JARO_DISTANCE_REFERENCE | CompareUtilities.TITLE_DISTANCE_REFERENCE) ; configuration.addField("sortval", "string", 3.5, CompareUtilities.EDIT_DISTANCE_REFERENCE) ; configuration.addField("year", "string", 3.8, CompareUtilities.YEAR_DISTANCE_REFERENCE) ; configuration.addField("region", "string", 0.7, CompareUtilities.JARO_DISTANCE_REFERENCE) ; transManif = new Translator() ; transManif.addWord("workRelation", "WerkRelation") ; transManif.addWord("gaugeFormat", "Traegerformat") ; transManif.addWord("aspectRatioFormat", "Bildformat") ; transManif.addWord("sound", "Ton") ; transManif.addWord("colour", "Farbe") ; transManif.addWord("carrierType", "CarrierType??") ; transManif.addWord("duration", "Dauer") ; transManif.addWord("dimension", "Laenge") ; confManifestation = new Configuration() ; confManifestation.addField("workRelation", "string", 0.6, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("gaugeFormat", "string", 0.2, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("aspectRatioFormat", "string", 0.4, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("sound", "string", 1.5, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("colour", "string", 2.5, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("carrierType", "string", 0.7, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("duration", "string", 8.6, CompareUtilities.JARO_DISTANCE_REFERENCE) ; confManifestation.addField("dimension", "string", 3.0, CompareUtilities.JARO_DISTANCE_REFERENCE) ; PrintWriter out = new PrintWriter("test.txt") ; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder() ; try { Document doc = docBuilder.parse(new File(fileName)) ; doc.getDocumentElement().normalize() ; //PrintWriter out = new PrintWriter(new File("output.txt")) ; NodeList movies = doc.getElementsByTagName("Filmwerk") ; for (int iMovies = 0 ; iMovies < movies.getLength() ; iMovies ++) { Node curMovieNode = (Node) movies.item(iMovies) ; if (curMovieNode.getNodeType() == Node.ELEMENT_NODE) { Element movie = (Element) curMovieNode ; ElementData record = new ElementData(this) ; String movieID = genID(32) ; oMovies.println(movieID) ; /// record.addData("uid", movie.getAttribute("uid")) ; try { oMovies.println(movie.getAttribute("uid")) ; } catch (Exception e) { oMovies.println(); } //out.println("ID: " + movie.getAttribute("uid")) ; NodeList title = movie.getElementsByTagName("IDTitel") ; Element curTitle = (Element) title.item(0) ; try { oMovies.println(curTitle.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } ; try { oMovies.println(curTitle.getAttribute("sortval")) ; } catch (Exception e) { oMovies.println(); } ; ///record.addData("title", curTitle.getChildNodes().item(0).getNodeValue()) ; ///record.addData("sortval", curTitle.getAttribute("sortval")) ; //out.println("IDTitel = " + curTitle.getChildNodes().item(0).getNodeValue()) ; //out.println("sortval = " + curTitle.getAttribute("sortval")) ; try { NodeList productionYear = movie.getElementsByTagName("ProdJahr") ; Element curYear = (Element) productionYear.item(0) ; oMovies.println(curYear.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } ; ///record.addData("year", curYear.getChildNodes().item(0).getNodeValue()) ; //out.println("Production year: " + curYear.getChildNodes().item(0).getNodeValue()) ; try { NodeList regionCode = movie.getElementsByTagName("RegionCode") ; Element curRegion = (Element) regionCode.item(0) ; oMovies.println(curRegion.getChildNodes().item(0).getNodeValue()) ; ///record.addData("region", curRegion.getChildNodes().item(0).getNodeValue()) ; //out.println("Region: " + curRegion.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } //out.println("Region rang: " + curRegion.getAttribute("rang")) ; try { NodeList movieType = movie.getElementsByTagName("Gattung") ; Element curType = (Element) movieType.item(0) ; oMovies.println(curType.getChildNodes().item(0).getNodeValue()) ; ///record.addData("type", curType.getChildNodes().item(0).getNodeValue()) ; //out.println("Movie type: " + curType.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } try { NodeList movieAbout = movie.getElementsByTagName("Anmerkung") ; Element curAbout = (Element) movieAbout.item(0) ; oMovies.println(curAbout.getChildNodes().item(0).getNodeValue()) ; ///record.addData("type", curType.getChildNodes().item(0).getNodeValue()) ; //out.println("Movie type: " + curType.getChildNodes().item(0).getNodeValue()) ; } catch (Exception e) { oMovies.println(); } try { NodeList manifestations = movie.getElementsByTagName("FilmManifestation") ; for (int iManifestation = 0 ; iManifestation < manifestations.getLength() ; iManifestation ++) { Element curManifestation = (Element) manifestations.item(iManifestation) ; AVManifestation avManifestation = new AVManifestation(this, curManifestation, movieID) ; record.addData(avManifestation) ; } } catch (Exception e) { } try { NodeList credits = movie.getElementsByTagName("CreditRel") ; for (int icredits = 0 ; icredits < credits.getLength() ; icredits ++) { Element curCredit = (Element) credits.item(icredits) ; //out.println(icredits) ; if (curCredit.hasAttribute("rel")) { //out.println("rel = " + curCredit.getAttribute("rel") + ", id = " + curCredit.getAttribute("uid")) ; } Element curCorporate = (Element) curCredit.getElementsByTagName("Koerperschaft").item(0) ; if (curCorporate != null) { //out.println("idname = " + curCorporate.getAttribute("idname") + ", id = " + curCorporate.getAttribute("uid")) ; } } } catch (Exception e) { //out.println("EXCEPTIOOOOOOOOOOONNNNNNNNNNN") ; } addElement(record) ; } } } catch (Exception e) { System.out.println("Exception: " + e) ; } */ } catch (Exception e) { System.out.println("Exception: " + e) ; } } } /* public static String readField(Element element, String tagName) { try { NodeList nodeList = element.getElementsByTagName(tagName) ; Element tagElement = (Element) nodeList.item(0) ; NodeList textList = tagElement.getChildNodes() ; return ((Node) textList.item(0)).getNodeValue().trim() ; } catch (Exception e) { return null ; } } public void createFromFile(String fileName) { /* try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder() ; try { Document doc = docBuilder.parse(new File(fileName)) ; doc.getDocumentElement().normalize() ; PrintWriter out = new PrintWriter(new File("output.txt")) ; NodeList movies = doc.getElementsByTagName("Filmwerk") ; System.out.println("Number of movies: " + movies.getLength()) ; for (int iMovies = 0 ; iMovies < movies.getLength() ; iMovies ++) { Node curMovieNode = (Node) movies.item(iMovies) ; if (curMovieNode.getNodeType() == Node.ELEMENT_NODE) { Element movie = (Element) curMovieNode ; out.println("Movie name: " + readField(movie, "FilmTitel")) ; } } /* int [] [] d = new int [movieList.size() + 1] [movieList.size() + 1] ; for (int i = 0 ; i < movieList.size() ; i ++) { MovieFrance ma = (MovieFrance) movieList.get(i) ; System.out.println(i + "/" + movieList.size()) ; for (int j = 0 ; j < movieList.size() ; j ++) { MovieFrance mb = (MovieFrance) movieList.get(j) ; d [i] [j] = StringCompare.editDistance(ma.anneProdPresumee, mb.anneProdPresumee) + StringCompare.editDistance(ma.anneProduction, mb.anneProduction) + StringCompare.editDistance(ma.titreEnFrancais, mb.titreEnFrancais) ; out.println(i + " " + j + " " + d [i] [j]) ; } } int count = movieList.size() ; double average = 0.0, total = 0.0 ; for (int i = 0 ; i < count ; i ++) for (int j = 0 ; j < count ; j ++) total += d [i] [j] ; average = total / (count * count) ; out.println(average) ; double stAverage = 0.0, stTotal = 0.0 ; for (int i = 0 ; i < count ; i ++) for (int j = 0 ; j < count ; j ++) stTotal += (d [i] [j] - average) * (d [i] [j] - average) ; stAverage = Math.sqrt(stTotal / (count * count)) ; out.println(stAverage) ; out.flush() ; } catch (Exception e) { System.out.println("Exception: " + e) ; } } catch (Exception e) { } } } /* SAXBuilder builder = new SAXBuilder() ; Document document = builder.build(new File("fileName")) ; Element root = document.getRootElement() ; List movies = root.getChildren("Filmwerk") ; for (Iterator itMovies = movies.iterator() ; itMovies.hasNext() ; ) { Element movie = (Element) itMovies.next() ; } */ /* SAXBuilder builder = new SAXBuilder() ; try { Document document = builder.build(new FileInputStream(fileName)); Element root = document.getRootElement() ; List export = root.getChildren("dif_export") ; System.out.println("Export size: " + export.size()) ; List movies = ((Element) export.get(0)).getChildren("Filmwerk") ; PrintWriter out = new PrintWriter(new File("output.txt")) ; System.out.println("Number of movies: " + movies.size()) ; for (Iterator itMovies = movies.iterator() ; itMovies.hasNext() ; ) { Element movie = (Element) itMovies.next() ; out.println("id: " + movie.getAttributeValue("uid")) ; } } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println("FileNotFoundException: " + e) ; e.printStackTrace(); } catch (JDOMException e) { // TODO Auto-generated catch block System.out.println("JDOMException: " + e) ; e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("IOException: " + e) ; e.printStackTrace(); } */