public static ArrayList<ArticleData> readJArticlesFromFile(String path) throws ParserConfigurationException, SAXException, IOException, ParseException { ArrayList<ArticleData> result = new ArrayList<ArticleData>(); File file = new File(path); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); doc.getDocumentElement().normalize(); NodeList nodeLst = doc.getElementsByTagName("art"); for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { ArticleData article = new ArticleData(); Element fstElmnt = (Element) fstNode; article.acc = Integer.parseInt(fstElmnt.getAttribute("ac")); article.refId = Integer.parseInt(fstElmnt.getAttribute("id")); article.pub = Boolean.getBoolean(fstElmnt.getAttribute("published")); article.translationType = PMDataTypes.DITT_JARTICLE; article.title = StringUtils.getXMLFromElement(fstElmnt, "title"); article.www = StringUtils.getXMLFromElement(fstElmnt, "www"); result.add(article); } } return result; }
public static ArrayList<ResourceData> readResourcesFromFile(String path) throws ParserConfigurationException, SAXException, IOException, ParseException { ArrayList<ResourceData> result = new ArrayList<ResourceData>(); File file = new File(path); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); doc.getDocumentElement().normalize(); NodeList nodeLst = doc.getElementsByTagName("items"); for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { ResourceData resource = new ResourceData(); Element fstElmnt = (Element) fstNode; resource.description = StringUtils.getXMLFromElement(fstElmnt, "description"); resource.title = StringUtils.getXMLFromElement(fstElmnt, "title"); resource.alias = StringUtils.getXMLFromElement(fstElmnt, "alias"); resource.custom0 = StringUtils.getXMLFromElement(fstElmnt, "c0"); resource.custom1 = StringUtils.getXMLFromElement(fstElmnt, "c1"); resource.pub = StringUtils.getBooleanFromXMLElement(fstElmnt, "published"); // resource.p= StringUtils.getIntegerFromXMLElement(fstElmnt, "type"); resource.type = StringUtils.getIntegerFromXMLElement(fstElmnt, "type"); resource.id = StringUtils.getIntegerFromXMLElement(fstElmnt, "id"); resource.cat_id = StringUtils.getIntegerFromXMLElement(fstElmnt, "id"); resource.www = StringUtils.getXMLFromElement(fstElmnt, "www"); result.add(resource); } } return result; }