1818import org .energyos .espi .common .utils .DateConverter ;
1919import org .energyos .espi .common .utils .EntryTypeIterator ;
2020import org .energyos .espi .common .utils .ExportFilter ;
21+ import org .energyos .espi .common .utils .AtomMarshallerListener ;
2122import org .springframework .beans .factory .annotation .Autowired ;
2223import org .springframework .beans .factory .annotation .Qualifier ;
2324import org .springframework .oxm .jaxb .Jaxb2Marshaller ;
2627
2728import javax .servlet .ServletOutputStream ;
2829import javax .xml .bind .JAXBException ;
30+ import javax .xml .bind .Marshaller ;
2931import javax .xml .bind .Unmarshaller ;
3032import javax .xml .transform .stream .StreamResult ;
3133
@@ -471,15 +473,12 @@ public void exportUsagePointFull(Long usagePointId, Long retailCustomerId,
471473 //
472474
473475 private void buildHeader (OutputStream stream , String hrefFragment ) throws IOException {
476+
477+ String selfRef = "<link ref=\" self\" href=\" " + applicationInformationService .getDataCustodianResourceEndpoint () + hrefFragment + "\" />" ;
474478 DateTimeType updated = DateConverter .toDateTimeType (new Date ());
475479 String temp = updated .getValue ().toXMLFormat ();
476480 String uuid = UUID .randomUUID ().toString ();
477-
478- String selfRef = "<link rel=\" self\" href=\" /espi/1_1/resource" + hrefFragment + "\" />\n " ;
479-
480- //GregorianCalendar updated = new GregorianCalendar();
481- //updated.setTimeZone(TimeZone.getTimeZone("UTC"))
482- //String temp = DateConverter.epoch().toString();
481+
483482 stream .write ("<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n " .getBytes ());
484483 stream .write ("<feed xmlns=\" http://www.w3.org/2005/Atom\" xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" >" .getBytes ());
485484 stream .write ("<id>urn:uuid:" .getBytes ());
@@ -492,31 +491,37 @@ private void buildHeader (OutputStream stream, String hrefFragment) throws IOExc
492491 stream .write (selfRef .getBytes ());
493492 }
494493
495- private void exportEntries (EntryTypeIterator entries , OutputStream stream , ExportFilter exportFilter , Class resourceClass , String hrefFragment ) throws IOException {
496-
497- buildHeader ( stream , hrefFragment );
494+ private void exportEntries (EntryTypeIterator entries , OutputStream stream ,
495+ ExportFilter exportFilter , Class resourceClass , String hrefFragment )
496+ throws IOException {
498497
499- if (entries != null ) {
500-
501- while (entries .hasNext ()) {
502- try {
503- EntryType entry = entries .nextEntry (resourceClass );
504- exportEntry (entry , stream , exportFilter , hrefFragment );
505- } catch (Exception e ) {
506- stream .write ("/* The requested collection contains no resources */" .getBytes ());
507- stream .write ("</feed>" .getBytes ());
508- }
509-
510- }
511- }
512- stream .write ("</feed>" .getBytes ());
513- }
498+ buildHeader (stream , hrefFragment );
499+
500+ if (entries != null ) {
501+
502+ while (entries .hasNext ()) {
503+ try {
504+ EntryType entry = entries .nextEntry (resourceClass );
505+ exportEntry (entry , stream , exportFilter , hrefFragment );
506+ } catch (Exception e ) {
507+ stream .write ("/* The requested collection contains no resources */"
508+ .getBytes ());
509+ stream .write ("</feed>" .getBytes ());
510+ }
511+
512+ }
513+ }
514+ stream .write ("</feed>" .getBytes ());
515+ }
514516
515517 // to export a single entry (w/o the <feed>...</feed> wrappers
516518
517519 private void exportEntry (EntryType entry , OutputStream stream ,
518520 ExportFilter exportFilter , String hrefFragment ) throws IOException {
519521
522+ AtomMarshallerListener uriListener = new AtomMarshallerListener (applicationInformationService .getDataCustodianResourceEndpoint () + hrefFragment );
523+ fragmentMarshaller .setMarshallerListener (uriListener );
524+
520525 StreamResult result = new StreamResult (stream );
521526 try {
522527 if (exportFilter .matches (entry )) {
@@ -528,8 +533,10 @@ private void exportEntry(EntryType entry, OutputStream stream,
528533 }
529534
530535 private void exportEntriesFull (EntryTypeIterator entries , OutputStream stream , ExportFilter exportFilter , String hrefFragment ) throws IOException {
531-
532- buildHeader (stream , hrefFragment );
536+
537+ // construct the <feed> header components
538+ //
539+ buildHeader (stream , hrefFragment );
533540
534541 if (entries != null ) {
535542
@@ -550,8 +557,13 @@ private void exportEntriesFull(EntryTypeIterator entries, OutputStream stream, E
550557 // to export a single entry (w/o the <feed>...</feed> wrappers
551558
552559 private void exportEntryFull (EntryType entry , OutputStream stream ,
553- ExportFilter exportFilter , String hrefFragement ) throws IOException {
554-
560+ ExportFilter exportFilter , String hrefFragment ) throws IOException {
561+
562+ // setup a listener so that the adapters may later be fed the href fragment;
563+ //
564+ AtomMarshallerListener uriListener = new AtomMarshallerListener (applicationInformationService .getDataCustodianResourceEndpoint () + hrefFragment );
565+ fragmentMarshaller .setMarshallerListener (uriListener );
566+
555567 StreamResult result = new StreamResult (stream );
556568 try {
557569 if (exportFilter .matches (entry )) {
0 commit comments