@Test public void testExtractFromDocumentWithAllFieldsMissing() throws Exception { String xmlContents = buildXMLContents(null, null, null, null, null, null, null); Patent.Builder patentBuilder = parser.parse(xmlContents, getPatentBuilderInitializedWithRequiredFields()); Patent patent = patentBuilder.build(); assertNotNull(patent); assertNull(patent.getApplnTitle()); assertNull(patent.getApplnAbstract()); assertNull(patent.getApplnNrEpodoc()); assertNull(patent.getApplnFilingDate()); assertNull(patent.getEarliestPublnDate()); assertNull(patent.getIpcClassSymbol()); }
@Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } }
OpsPatentMetadataXPathBasedParser implements PatentMetadataParser { @Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } } }
OpsPatentMetadataXPathBasedParser implements PatentMetadataParser { @Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } } OpsPatentMetadataXPathBasedParser(); }
OpsPatentMetadataXPathBasedParser implements PatentMetadataParser { @Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } } OpsPatentMetadataXPathBasedParser(); @Override Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder); }
OpsPatentMetadataXPathBasedParser implements PatentMetadataParser { @Override public Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder) throws PatentMetadataParserException { try { XPath xPath = XPathFactory.newInstance().newXPath(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document xmlDocument = builder.parse(new InputSource(new StringReader(source.toString()))); patentBuilder.setApplnTitle(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_INVENTION_TITLE).evaluate(xmlDocument, XPathConstants.NODESET))); patentBuilder.setApplnAbstract(extractTrimmedValueForPreferredEnglishLanguage( (NodeList) xPath.compile(XPATH_EXPR_ABSTRACT).evaluate(xmlDocument, XPathConstants.NODESET))); CharSequence epoDoc = extractFirstNonEmptyTrimmedTextContent( (NodeList) xPath.compile(xPathExpApplnDocIdEpodoc).evaluate(xmlDocument, XPathConstants.NODESET)); if (StringUtils.isNotBlank(epoDoc)) { patentBuilder.setApplnNrEpodoc(epoDoc); } patentBuilder.setApplnFilingDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_APLN_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); patentBuilder.setEarliestPublnDate(convertDate(extractEarliestDate( (NodeList) xPath.compile(XPATH_EXPR_PUBL_DATE).evaluate(xmlDocument, XPathConstants.NODESET)))); List<CharSequence> ipcClasses = extractNonEmptyTrimmedTextContent( (NodeList) xPath.compile(XPATH_EXPR_CLASS_IPC).evaluate(xmlDocument, XPathConstants.NODESET)); if (CollectionUtils.isNotEmpty(ipcClasses)) { patentBuilder.setIpcClassSymbol(ipcClasses); } NodeList epodocNameNodes = (NodeList) xPath.compile(xPathExpApplicantEpodocName).evaluate(xmlDocument, XPathConstants.NODESET); List<CharSequence> applicantEpodocNames = extractNonEmptyTrimmedTextContent(epodocNameNodes); if (CollectionUtils.isNotEmpty(applicantEpodocNames)) { patentBuilder.setApplicantNames(cleanNames(applicantEpodocNames)); patentBuilder.setApplicantCountryCodes(extractCountryCodes(applicantEpodocNames)); } return patentBuilder; } catch (Exception e) { throw new PatentMetadataParserException("error while parsing XML contents: " + source, e); } } OpsPatentMetadataXPathBasedParser(); @Override Patent.Builder parse(CharSequence source, Patent.Builder patentBuilder);  }