List of usage examples for org.jdom2 Element getValue
@Override
public String getValue()
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
MCREditorSubmission(Element saved, List submitted, String root, MCRRequestParameters parms) { Element input = saved.getChild("input"); List children = input.getChildren(); String varpath = parms.getParameter("subselect.varpath"); boolean merge = "true".equals(parms.getParameter("subselect.merge")); LinkedHashMap<String, String> table = new LinkedHashMap<String, String>(); for (Object aChildren : children) { Element var = (Element) aChildren; String path = var.getAttributeValue("name"); String value = var.getAttributeValue("value"); if (merge || !(path.equals(varpath) || path.startsWith(varpath + "/"))) { table.put(path, value);/*from w ww .ja v a 2 s . c om*/ } } for (Object aSubmitted : submitted) { MCREditorVariable var = (MCREditorVariable) aSubmitted; String path = var.getPath(); String value = var.getValue(); path = varpath + path.substring(root.length()); table.put(path, value); } for (String path : table.keySet()) { String value = table.get(path); addVariable(path, value); } Collections.sort(variables); setRepeatsFromVariables(); }
From source file:org.onosproject.provider.netconf.device.impl.NetconfDevice.java
License:Apache License
private void processCapabilities(Element rootElement) { List<Element> children = rootElement.getChildren(); if (children.isEmpty()) { return;/*from www. j a v a 2s. com*/ } for (Element child : children) { if (child.getName().equals(XML_CAPABILITY_KEY)) { capabilities.add(child.getValue()); } if (!child.getChildren().isEmpty()) { processCapabilities(child); } } }
From source file:org.openflexo.foundation.ontology.owl.OWLOntology.java
License:Open Source License
public static String findOntologyName(File aFile) { if (aFile == null || !aFile.exists() || aFile.length() == 0) { if (aFile != null && aFile.length() == 0) { aFile.delete();/*from w ww . j av a 2 s .c o m*/ } return null; } Document document; try { logger.fine("Try to find name for " + aFile); document = readXMLFile(aFile); Element root = getElement(document, "RDF"); if (root != null) { Element ontology = getElement(root, "Ontology"); if (ontology != null) { Element title = getElement(root, "title"); if (title != null) { return title.getValue(); } List<Attribute> l = ontology.getAttributes(); for (int i = 0; i < l.size(); i++) { Attribute a = l.get(i); if (a.getName().equals("title")) { return a.getValue(); } } } } } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.openflexo.technologyadapter.owl.model.OWLOntology.java
License:Open Source License
public static String findOntologyName(File aFile) { if (aFile == null || !aFile.exists() || aFile.length() == 0) { if (aFile != null && aFile.length() == 0) { aFile.delete();/*from www. ja va 2 s . co m*/ } return null; } Document document; try { logger.fine("Try to find name for " + aFile); document = readXMLFile(aFile); Element root = getElement(document, "RDF"); if (root != null) { Element ontology = getElement(root, "Ontology"); if (ontology != null) { Element title = getElement(root, "title"); if (title != null) { return title.getValue(); } List<Attribute> l = ontology.getAttributes(); for (int i = 0; i < l.size(); i++) { Attribute a = l.get(i); if (a.getName().equals("title")) { return a.getValue(); } } } } } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return aFile.getName(); }
From source file:org.rometools.feed.module.itunes.io.ITunesParser.java
License:Open Source License
public com.sun.syndication.feed.module.Module parse(org.jdom2.Element element) { AbstractITunesObject module = null;/*from w w w . j av a 2 s .c om*/ if (element.getName().equals("channel")) { FeedInformationImpl feedInfo = new FeedInformationImpl(); module = feedInfo; //Now I am going to get the channel specific tags Element owner = element.getChild("owner", ns); if (owner != null) { Element name = owner.getChild("name", ns); if (name != null) { feedInfo.setOwnerName(name.getValue().trim()); } Element email = owner.getChild("email", ns); if (email != null) { feedInfo.setOwnerEmailAddress(email.getValue().trim()); } } Element image = element.getChild("image", ns); if ((image != null) && (image.getAttributeValue("href") != null)) { try { URL imageURL = new URL(image.getAttributeValue("href").trim()); feedInfo.setImage(imageURL); } catch (MalformedURLException e) { log.finer( "Malformed URL Exception reading itunes:image tag: " + image.getAttributeValue("href")); } } List categories = element.getChildren("category", ns); for (Iterator it = categories.iterator(); it.hasNext();) { Element category = (Element) it.next(); if ((category != null) && (category.getAttribute("text") != null)) { Category cat = new Category(); cat.setName(category.getAttribute("text").getValue().trim()); Element subcategory = category.getChild("category", ns); if (subcategory != null && subcategory.getAttribute("text") != null) { Subcategory subcat = new Subcategory(); subcat.setName(subcategory.getAttribute("text").getValue().trim()); cat.setSubcategory(subcat); } feedInfo.getCategories().add(cat); } } } else if (element.getName().equals("item")) { EntryInformationImpl entryInfo = new EntryInformationImpl(); module = entryInfo; //Now I am going to get the item specific tags Element duration = element.getChild("duration", ns); if (duration != null && duration.getValue() != null) { Duration dur = new Duration(duration.getValue().trim()); entryInfo.setDuration(dur); } } if (module != null) { //All these are common to both Channel and Item Element author = element.getChild("author", ns); if (author != null && author.getText() != null) { module.setAuthor(author.getText()); } Element block = element.getChild("block", ns); if (block != null) { module.setBlock(true); } Element explicit = element.getChild("explicit", ns); if ((explicit != null) && explicit.getValue() != null && explicit.getValue().trim().equalsIgnoreCase("yes")) { module.setExplicit(true); } Element keywords = element.getChild("keywords", ns); if (keywords != null) { StringTokenizer tok = new StringTokenizer(getXmlInnerText(keywords).trim(), ","); String[] keywordsArray = new String[tok.countTokens()]; for (int i = 0; tok.hasMoreTokens(); i++) { keywordsArray[i] = tok.nextToken(); } module.setKeywords(keywordsArray); } Element subtitle = element.getChild("subtitle", ns); if (subtitle != null) { module.setSubtitle(subtitle.getTextTrim()); } Element summary = element.getChild("summary", ns); if (summary != null) { module.setSummary(summary.getTextTrim()); } } return module; }
From source file:org.springframework.data.solr.showcase.Application.java
License:Apache License
public static String readElement(Element e, String textin) { //System.out.println("Found a " + e.getName()); if (e.getName().equalsIgnoreCase("p")) { //System.out.println(">>>> p " + e.getValue().substring(0, 15) + "....."); textin = textin.concat(e.getValue()); }//from ww w .j a va 2 s . c o m if (e.getName().equalsIgnoreCase("sec")) { List<Element> secchildren = e.getChildren(); for (int i = 0; i < secchildren.size(); i++) { //System.out.println("Going Deeper"); Element bc = secchildren.get(i); String text2 = readElement(bc, ""); textin = textin.concat(text2); //System.out.println("ReadElement in sec " + readElement(bc, s)); } } return textin; }
From source file:org.t3.metamediamanager.MediaCenterDataMediaBrowser.java
License:Apache License
@Override public MediaInfo openSeries(String filename) throws ProviderException { System.out.println("Entre dans open serie"); System.out.println("open serie filename :" + filename); MediaInfo mediainfo = new MediaInfo(); org.jdom2.Document document = null; HashMap<String, String> hashinfo = _saverconfig.getFieldsAssociation(); File directory = new File(filename); File xmlfile = new File(directory.getAbsolutePath() + File.separator + "Series.xml"); //System.out.println(xmlfile.getAbsolutePath()); if (!xmlfile.exists()) { return null; }//ww w.ja va2s . c om SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(xmlfile); } catch (Exception e) { throw (new ProviderException("Erreur lors de l'ouverture du fichier")); } Element root = document.getRootElement().getChild("Series"); // root is the 2nd element of the xml file : series List<Element> childlist = root.getChildren(); Iterator<Element> i = childlist.iterator(); ArrayList<ActorInfo> actors = new ArrayList<ActorInfo>(); while (i.hasNext()) { Element child = (Element) i.next(); String key = child.getName(); String value = child.getValue(); if (key.equals("Actors")) { List<Element> childlist2 = child.getChildren(); Iterator<Element> i2 = childlist2.iterator(); int i3 = 0; String name = null, role = null; while (i2.hasNext()) { Element childchild = (Element) i2.next(); if (childchild.getChild("Name") != null) { name = childchild.getChild("Name").getValue(); role = childchild.getChild("Role").getValue(); i3++; } if (i3 >= 1) { actors.add(new ActorInfo(name, role, null)); name = ""; role = ""; i3 = 0; } } } else { for (Entry<String, String> entry : hashinfo.entrySet()) { String key2 = entry.getKey(); String value2 = entry.getValue(); System.out.println(key + "->" + value2); if (key.equals(value2)) { System.out.println(key2 + "->" + value); mediainfo.put(key2, value); } } } } System.out.println(mediainfo.toString()); ActorInfo[] actorsi = new ActorInfo[actors.size()]; actors.toArray(actorsi); mediainfo.setActors(actorsi); //images String posterName = "folder.jpg"; ArrayList<String> imagesNames = new ArrayList<String>(); String fanartName = "backdrop1.jpg"; String bannerName = "banner.jpg"; File f1 = new File(directory, fanartName); int i2 = 1; while (f1.exists()) { fanartName = "backdrop" + i2 + ".jpg"; f1 = new File(directory, fanartName); if (f1.exists()) { imagesNames.add((f1.getAbsolutePath())); } i2++; } String[] castimagesNames = imagesNames.toArray(new String[imagesNames.size()]); mediainfo.putImages("img_fanart", castimagesNames); String[] imagesNames2 = new String[1]; File f2 = new File(directory, posterName); if (f2.exists()) { imagesNames2[0] = f2.getAbsolutePath(); mediainfo.putImages("img_poster", imagesNames2); } String[] imagesNames3 = new String[1]; File f3 = new File(directory, bannerName); if (f3.exists()) { imagesNames3[0] = f3.getAbsolutePath(); mediainfo.putImages("img_banner", imagesNames3); } //images String images[]; images = mediainfo.getImages("img_banner"); if (images[0] != "") { copy_images(images[0], new File(directory, "banner.jpg").getAbsolutePath()); } images = mediainfo.getImages("img_poster"); if (images[0] != "") { copy_images(images[0], new File(directory, "folder.jpg").getAbsolutePath()); } images = mediainfo.getImages("img_fanart"); if (images[0] != "") { for (int i1 = 0; i1 < images.length; i1++) { int j = i1 + 1; copy_images(images[i1], new File(directory, "backdrop" + j + ".jpg").getAbsolutePath()); } } String genre = mediainfo.get("type"); genre = genre.replace('|', ','); if (genre != null && genre != "" && genre.length() > 2) { if (genre.charAt(0) == ',') genre = genre.substring(1); if (genre.charAt(genre.length() - 1) == ',') genre = genre.substring(0, genre.length() - 1); mediainfo.put("type", genre); } return mediainfo; }
From source file:org.t3.metamediamanager.MediaCenterDataMediaBrowser.java
License:Apache License
@Override public MediaInfo openEpisode(String filename) { System.out.println("Entre dans open ep"); System.out.println("open ep :" + filename); org.jdom2.Document document = null; File directory = new File(filename).getParentFile(); File metadatafile = new File(directory.getAbsolutePath(), "metadata"); if (!metadatafile.exists()) { return null; }/*from w w w . j a v a 2s .c om*/ File infofile = new File(metadatafile, filename.substring(filename.lastIndexOf(File.separator), filename.lastIndexOf(".")) + ".xml"); if (!infofile.exists()) { return null; } SAXBuilder sxb = new SAXBuilder(); try { document = sxb.build(infofile); } catch (Exception e) { return null; } MediaInfo mediainfo = new MediaInfo(); Element root = document.getRootElement().getChild("Episode"); List<Element> elements = root.getChildren(); Iterator<Element> i = elements.iterator(); HashMap<String, String> hashinfo = _saverconfig.getFieldsAssociation(); while (i.hasNext()) { Element child = (Element) i.next(); String key = child.getName(); String value = child.getValue(); for (Entry<String, String> entry : hashinfo.entrySet()) { String key2 = entry.getKey(); String value2 = entry.getValue(); if (key.equals(value2)) { mediainfo.put(key2, value); } } } //images String posterName = "folder.jpg"; String bannerName = "banner.jpg"; //images String[] imagesNames2 = new String[1]; File f2 = new File(directory, posterName); if (f2.exists()) { imagesNames2[0] = f2.getAbsolutePath(); mediainfo.putImages("img_poster", imagesNames2); } String[] imagesNames3 = new String[1]; File f3 = new File(directory, bannerName); if (f3.exists()) { imagesNames3[0] = f3.getAbsolutePath(); mediainfo.putImages("img_banner", imagesNames3); } //System.out.println(mediainfo.toString()); return mediainfo; }
From source file:org.t3.metamediamanager.MediaCenterDataXBMC.java
License:Apache License
@Override public MediaInfo open(String filename) throws ProviderException { org.jdom2.Document document = null; Element root; // root of the media xml HashMap<String, String> fieldsAssociation = _saverconfig.getFieldsAssociation(); // HashMap between XBMC fields and DB fields HashMap<String, String> xmlAssociation = new HashMap<String, String>(); // HashMap between XBMC fields and the content String key, value, key2, value2; // key, value -> fieldsAssociation ||| key2, value2 -> xmlAssociation SAXBuilder sxb = new SAXBuilder(); MediaInfo mediainfo = new MediaInfo(); String newFileName = filename.substring(0, filename.lastIndexOf('.')); newFileName += ".nfo"; File f = new File(newFileName); if (!f.exists()) { return null; }//from ww w.j a va 2 s .c o m try { document = sxb.build(f); } catch (Exception e) { throw (new ProviderException("Erreur lors de l'ouverture du fichier")); } root = document.getRootElement(); List<Element> elements = root.getChildren(); // all elements with "movie" as father List<Element> childelements; Iterator<Element> i = elements.iterator(); Iterator<Element> ichild; Element current, currentchild; String credits = "", genre = ""; ArrayList<ActorInfo> actors = new ArrayList<ActorInfo>(); while (i.hasNext()) // create HashMap with media information (example "name" -> "moviename") { current = (Element) i.next(); childelements = null; ichild = null; int i2; if (current.getName().equals("actor")) //special traitment for actor { childelements = current.getChildren(); ichild = childelements.iterator(); String name = "", role = "", imgurl = ""; i2 = 0; File dirActors = new File(new File(filename).getParentFile(), ".actors"); while (ichild.hasNext()) { currentchild = (Element) ichild.next(); if (currentchild.getName().equals("name")) { name = currentchild.getValue(); String newActorName = name.replace(' ', '_'); File actor = new File(dirActors, newActorName + ".jpg"); if (actor.exists()) { imgurl = actor.getAbsolutePath(); } i2++; } else if (currentchild.getName().equals("role")) { role = currentchild.getValue(); i2++; } else if (currentchild.getName().equals("thumb")) { } if (i2 >= 2) { actors.add(new ActorInfo(name, role, imgurl)); name = ""; role = ""; imgurl = ""; } } } else if (current.getName().equals("genre")) { genre += current.getValue() + ","; } else if (current.getName().equals("credits")) { credits += current.getValue() + ","; } else if (current.getName().equals("fanart")) // same { //do nothing } else if (current.getName().equals("fileinfo")) //same because of multiple childrens { childelements = current.getChild("streamdetails").getChild("video").getChildren(); ichild = childelements.iterator(); while (ichild.hasNext()) { currentchild = (Element) ichild.next(); if (currentchild.getName().equals("codec")) //exception for codec beaucause same attribut for audio and video codec { mediainfo.put("videoCodec", currentchild.getText()); } else { xmlAssociation.put(currentchild.getName(), currentchild.getText()); } } childelements = current.getChild("streamdetails").getChild("audio").getChildren(); ichild = childelements.iterator(); while (ichild.hasNext()) { currentchild = (Element) ichild.next(); if (currentchild.getName().equals("codec")) //exception for codec beaucause same attribut for audio and video codec { mediainfo.put("audioCodec", currentchild.getText()); } else { xmlAssociation.put(currentchild.getName(), currentchild.getText()); } } } else //simple traitment { xmlAssociation.put(current.getName(), current.getText()); } } if (genre.length() >= 1) // add genre { mediainfo.put("genre", genre.substring(0, genre.length() - 1)); } if (credits.length() >= 1) // add credits { mediainfo.put("credits", credits.substring(0, credits.length() - 1)); } ActorInfo[] actorsinfo = new ActorInfo[actors.size()]; //adding actors into mediainfo actors.toArray(actorsinfo); mediainfo.setActors(actorsinfo); for (Entry<String, String> entry : fieldsAssociation.entrySet()) //add into mediainfo<hashmap> { key = entry.getKey(); value = entry.getValue(); for (Entry<String, String> entry2 : xmlAssociation.entrySet()) { key2 = entry2.getKey(); value2 = entry2.getValue(); if (value.equals(key2) && !value2.equals("")) { mediainfo.put(key, value2); } } } // Recuperation des images File movieFile = new File(filename); String movieName = movieFile.getName().substring(0, movieFile.getName().lastIndexOf('.')); String fanartName = movieName + "-fanart.jpg"; String posterName = movieName + "-poster.jpg"; String thumbName = movieName + "-thumb.jpg"; String[] imagesNames = new String[1]; File f1 = new File(movieFile.getParent(), fanartName); if (f1.exists()) { imagesNames[0] = f1.getAbsolutePath(); mediainfo.putImages("img_fanart", imagesNames); } File f2 = new File(movieFile.getParent(), posterName); if (f2.exists()) { imagesNames[0] = f2.getAbsolutePath(); mediainfo.putImages("img_realposter", imagesNames); } File f3 = new File(movieFile.getParent(), thumbName); if (f3.exists()) { imagesNames[0] = f3.getAbsolutePath(); mediainfo.putImages("img_poster", imagesNames); } return mediainfo; }
From source file:org.t3.metamediamanager.MediaCenterDataXBMC.java
License:Apache License
/******************** *********OPEN********//from w w w . j a v a 2s .c o m ********SERIES******/ public MediaInfo openSeries(String filename) throws ProviderException { org.jdom2.Document document = null; Element root; // root of the media xml HashMap<String, String> fieldsAssociation = _saverconfig.getFieldsAssociation(); // HashMap between XBMC fields and DB fields HashMap<String, String> xmlAssociation = new HashMap<String, String>(); // HashMap between XBMC fields and the content String key, value, key2, value2; // key, value -> fieldsAssociation ||| key2, value2 -> xmlAssociation SAXBuilder sxb = new SAXBuilder(); MediaInfo mediainfo = new MediaInfo(); ArrayList<ActorInfo> actors = new ArrayList<ActorInfo>(); File f = new File(filename, "tvshow.nfo"); if (!f.exists()) { return null; } try { document = sxb.build(f); } catch (Exception e) { throw (new ProviderException("Erreur lors de l'ouverture du fichier")); } root = document.getRootElement(); List<Element> elements = root.getChildren(); List<Element> childelements; Iterator<Element> i = elements.iterator(); Iterator<Element> ichild; Element current, currentchild; String genre = "", credits = ""; while (i.hasNext()) // create HashMap with media information (example "name" -> "moviename") { current = (Element) i.next(); childelements = null; ichild = null; int i2; if (current.getName().equals("actor")) //special traitment for actor { childelements = current.getChildren(); ichild = childelements.iterator(); String name = "", role = "", imgurl = ""; i2 = 0; File dirActors = new File(new File(filename).getParentFile(), ".actors"); while (ichild.hasNext()) { currentchild = (Element) ichild.next(); if (currentchild.getName().equals("name")) { name = currentchild.getValue(); String newActorName = name.replace(' ', '_'); File actor = new File(dirActors, newActorName + ".jpg"); if (actor.exists()) { imgurl = actor.getAbsolutePath(); } i2++; } else if (currentchild.getName().equals("role")) { role = currentchild.getValue(); i2++; } else if (currentchild.getName().equals("thumb")) { } if (i2 >= 2) { actors.add(new ActorInfo(name, role, imgurl)); name = ""; role = ""; imgurl = ""; } } } else if (current.getName().equals("fanart")) { } else if (current.getName().equals("genre")) { genre += current.getValue() + ','; } else if (current.getName().equals("credits")) { credits += current.getValue() + ','; } else { xmlAssociation.put(current.getName(), current.getText()); } } if (genre.length() >= 2) { mediainfo.put("type", genre.substring(0, genre.length() - 1)); } if (credits.length() >= 2) { mediainfo.put("credits", credits.substring(0, credits.length() - 1)); } ActorInfo[] actorsinfo = new ActorInfo[actors.size()]; //adding actoes into mediainfo actors.toArray(actorsinfo); mediainfo.setActors(actorsinfo); for (Entry<String, String> entry : fieldsAssociation.entrySet()) //add into mediainfo<hashmap> { key = entry.getKey(); value = entry.getValue(); for (Entry<String, String> entry2 : xmlAssociation.entrySet()) { key2 = entry2.getKey(); value2 = entry2.getValue(); ; if (value.equals(key2) && !value2.equals("")) { mediainfo.put(key, value2); } } } // Recuperation des images; String[] imagesNames = new String[1]; File f1 = new File(filename, "poster.jpg"); if (f1.exists()) { imagesNames[0] = f1.getAbsolutePath(); mediainfo.putImages("img_poster", imagesNames); } File f2 = new File(filename, "season-all-poster.jpg"); if (f2.exists()) { imagesNames[0] = f2.getAbsolutePath(); mediainfo.putImages("img_poster", imagesNames); } File f3 = new File(filename, "banner.jpg"); if (f3.exists()) { imagesNames[0] = f3.getAbsolutePath(); mediainfo.putImages("banner_series", imagesNames); } return mediainfo; }