AnyTextHelper { public static String getAnyText( ISORecord r, AnyText anyText ) { String anyTextString = null; if ( anyText == null || anyText.getCore() != null ) { StringBuilder sb = new StringBuilder(); for ( String s : r.getAbstract() ) { sb.append( s ).append( STOPWORD ); } for ( String f : r.getFormat() ) { sb.append( f ).append( STOPWORD ); } if ( r.getIdentifier() != null ) { sb.append( r.getIdentifier() ).append( STOPWORD ); } if ( r.getLanguage() != null ) { sb.append( r.getLanguage() ).append( STOPWORD ); } if ( r.getModified() != null ) { sb.append( r.getModified() ).append( STOPWORD ); } for ( String f : r.getRelation() ) { sb.append( f ).append( STOPWORD ); } for ( String f : r.getTitle() ) { sb.append( f ).append( STOPWORD ); } if ( r.getType() != null ) { sb.append( r.getType() ).append( STOPWORD ); } for ( String f : r.getSubject() ) { sb.append( f ).append( STOPWORD ); } sb.append( r.isHasSecurityConstraints() ).append( STOPWORD ); for ( String f : r.getRights() ) { sb.append( f ).append( STOPWORD ); } if ( r.getContributor() != null ) { sb.append( r.getContributor() ).append( STOPWORD ); } if ( r.getPublisher() != null ) { sb.append( r.getPublisher() ).append( STOPWORD ); } if ( r.getSource() != null ) { sb.append( r.getSource() ).append( STOPWORD ); } if ( r.getCreator() != null ) { sb.append( r.getCreator() ).append( STOPWORD ); } if ( r.getParentIdentifier() != null ) { sb.append( r.getParentIdentifier() ).append( STOPWORD ); } anyTextString = sb.toString(); } else if ( anyText.getAll() != null ) { StringBuilder sb = new StringBuilder(); try { XMLStreamReader xmlStream = r.getAsXMLStream(); while ( xmlStream.hasNext() ) { xmlStream.next(); if ( xmlStream.getEventType() == XMLStreamConstants.CHARACTERS && !xmlStream.isWhiteSpace() ) { sb.append( xmlStream.getText() ).append( STOPWORD ); } } } catch ( XMLStreamException e ) { e.printStackTrace(); } anyTextString = sb.toString(); } else if ( anyText.getCustom() != null ) { List<String> xpathList = anyText.getCustom().getXPath(); if ( xpathList != null && !xpathList.isEmpty() ) { XPath[] path = new XPath[xpathList.size()]; int counter = 0; for ( String x : xpathList ) { path[counter++] = new XPath( x, ns ); } anyTextString = generateAnyText( r, path ).toString(); } } else { anyTextString = ""; } return anyTextString; }  static String getAnyText( ISORecord r, AnyText anyText );  }
@Test public void testAnyTextElement_ALL() throws JAXBException { LOG.info( "START Test: test anyText element 'ALL' for one metadataRecord " ); ISORecord rec = (ISORecord) MetadataRecordFactory.create( ( new XMLAdapter( TstConstants.tst_10 ) ).getRootElement() ); String anyText = AnyTextHelper.getAnyText( rec, getConfig( TstConstants.configURL_ANYTEXT_ALL ).getAnyText() ); String expected = "d0e5c36eec7f473b91b8b249da87d522 eng UTF 8 dataset European Commission, Joint Research Centre cid-contact@jrc.ec.europa.eu pointOfContact 2007-01-23 ISO 19115:2003/19139 1.0 2 6000 6000 true false 10.2295939511158 52.6984540463519 10.4685111911662 53.2174450795883 9.34255616300099 52.8445914851784 9.57111840348035 53.3646726482873 center 4326 EPSG SPOT 5 RAW 2007-01-23T10:25:14 2007-01-23T10:25:14 d0e5c36eec7f473b91b8b249da87d522 Raw (source) image from CwRS campaigns. European Commission, Joint Research Centre, IPSC, MARS Unit cid-contact@jrc.ec.europa.eu pointOfContact SPOT 5 PATH 50 ROW 242 Orthoimagery GEMET - INSPIRE themes, version 1.0 2008-06-01 publication http: Assert.assertEquals( "anyText ALL: ", expected, anyText ); }
@Test public void testAnyTextElement_CORE() throws JAXBException { TimeZone.setDefault( TimeZone.getTimeZone( "GMT" ) ); LOG.info( "START Test: test anyText element 'CORE' for one metadataRecord " ); ISORecord rec = (ISORecord) MetadataRecordFactory.create( ( new XMLAdapter( TstConstants.tst_10 ) ).getRootElement() ); String anyText = AnyTextHelper.getAnyText( rec, getConfig( TstConstants.configURL_ANYTEXT_CORE ).getAnyText() ); String expected = "Raw (source) image from CwRS campaigns. RAW ECW d0e5c36eec7f473b91b8b249da87d522 eng 2007-01-23 SPOT 5 RAW 2007-01-23T10:25:14 dataset SPOT 5 PATH 50 ROW 242 Orthoimagery imageryBaseMapsEarthCover true otherRestrictions license Raw (Source) image as delivered by image provider. "; Assert.assertEquals( "anyText CORE: ", expected, anyText ); }
@Test public void testAnyTextElement_CUSTOM() throws JAXBException { LOG.info( "START Test: test anyText element 'CUSTOM' for one metadataRecord " ); ISORecord rec = (ISORecord) MetadataRecordFactory.create( ( new XMLAdapter( TstConstants.tst_10 ) ).getRootElement() ); String anyText = AnyTextHelper.getAnyText( rec, getConfig( TstConstants.configURL_ANYTEXT_CUSTOM ).getAnyText() ); String expected = "d0e5c36eec7f473b91b8b249da87d522 SPOT 5 PATH 50 ROW 242 Orthoimagery "; Assert.assertEquals( "anyText CUSTOM: ", expected, anyText ); }