ApplicationParser extends Dom4JParser { @Override public Patent parse(Document document) { DocumentId publicationId = new PublicationIdNode(document).read(); if (publicationId != null) { MDC.put("DOCID", publicationId.toText()); } else { LOGGER.warn("Publication ID not read!"); } String title = Dom4jUtil.getTextOrNull(document, XML_ROOT + "/us-bibliographic-data-application/invention-title"); String dateProduced = Dom4jUtil.getTextOrNull(document, XML_ROOT + "/@date-produced"); String datePublished = Dom4jUtil.getTextOrNull(document, XML_ROOT + "/@date-publ"); DocumentDate dateProducedDate = null; if (dateProduced != null) { try { dateProducedDate = new DocumentDate(dateProduced); } catch (InvalidDataException e) { LOGGER.warn("{} : {}", e.getMessage(), "dateProduced"); } } DocumentDate datePublishedDate = null; if (datePublished != null) { try { datePublishedDate = new DocumentDate(datePublished); } catch (InvalidDataException e) { LOGGER.warn("{} : {}", e.getMessage(), "datePublished"); } } String patentTypeStr = Dom4jUtil.getTextOrNull(document, XML_ROOT + "/us-bibliographic-data-application/application-reference/@appl-type"); PatentType patentType = PatentType.UNDEFINED; try { patentType = PatentType.fromString(patentTypeStr); } catch (InvalidDataException e1) { LOGGER.warn("{} : {}", e1.getMessage(), "patentTypeStr"); } DocumentId applicationId = new ApplicationIdNode(document).read(); List<DocumentId> priorityIds = new PriorityClaims(document).read(); List<DocumentId> pctRegionalIds = new PctRegionalIdNode(document).read(); DocumentId relatedId = new RelatedIdNode(document).read(); List<DocumentId> relationIds = new Relations(document).read(); List<Inventor> inventors = new InventorNode(document).read(); List<Applicant> applicants = new ApplicantNode(document).read(); List<Agent> agents = new AgentNode(document).read(); List<Assignee> assignees = new AssigneeNode(document).read(); List<Citation> citations = new CitationNode(document).read(); Set<PatentClassification> classifications = new ClassificationNode(document).read(); FormattedText textProcessor = new FormattedText(); Abstract abstractText = new AbstractTextNode(document, textProcessor).read(); Description description = new DescriptionNode(document, textProcessor).read(); List<Claim> claims = new ClaimNode(document, textProcessor).read(); new ClaimTreeBuilder(claims).build(); Patent patent = new PatentApplication(publicationId, patentType); patent.setSource(getSource()); patent.setDateProduced(dateProducedDate); patent.setDatePublished(datePublishedDate); patent.setDocumentId(publicationId); if (publicationId != null) { DocumentId docIdWithoutKind = new DocumentId(publicationId.getCountryCode(), publicationId.getDocNumber()); docIdWithoutKind.setType(DocumentIdType.PUBLISHED); docIdWithoutKind.setDate(publicationId.getDate()); patent.addOtherId(publicationId); } patent.setApplicationId(applicationId); patent.addPriorityId(priorityIds); patent.addOtherId(pctRegionalIds); patent.addRelationIds(relationIds); patent.addOtherId(patent.getApplicationId()); patent.addOtherId(patent.getPriorityIds()); patent.addRelationIds(patent.getOtherIds()); patent.setTitle(title); patent.setAbstract(abstractText); patent.setDescription(description); patent.setInventor(inventors); patent.setApplicant(applicants); patent.setAgent(agents); patent.setAssignee(assignees); patent.setCitation(citations); patent.setClaim(claims); patent.setClassification(classifications); LOGGER.trace(patent.toString()); return patent; }  @Override Patent parse(Document document); static final String XML_ROOT; }
@Test public void readSamples() throws PatentReaderException, IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { ApplicationParser xmlApp = new ApplicationParser(); Path dirPath = Paths.get("resources/samples/xmlApp2004"); Preconditions.checkArgument(dirPath.toFile().isDirectory(), "XML App sample dir does not exist."); for (File file : dirPath.toFile().listFiles()) { Patent patent = xmlApp.parse(file); ValidatePatent.methodsReturnNonNull(patent); } }