Domanda

sto disperatamente cercando di utilizzare la seguente libreria: ofx4j . Ma la documentazione relativa ad analisi un file OFX è un po 'lite. Si dice: Se hai un file o altra risorsa flusso, si può leggere tramite un'istanza di net.sf.ofx4j.io.OFXReader

Ok, ma come faccio a fare?

Si precisa inoltre quanto segue:. Se si desidera unmarshalling OFX direttamente ad un oggetto Java, utilizzare il net.sf.ofx4j.io.AggregateUnmarshaller

Va bene, ma questo è un po 'complicato per me. C'è qualcosa di ovvio che ho perso? Quando provo a utilizzare l'unmarshaller, mi chiede di implementare un'interfaccia.

Qualcuno mi potrebbe puntare a una risorsa online che spiega i bit che mi manca? O meglio, cosa ne capisce dalle dichiarazioni precedenti relativi alla ofxreader e l'unmarshaller?

Per favore, non mi bash, sto imparando java con il play framework e sarei davvero grato di essere in grado di analizzare i file OFX.

grazie in anticipo.

È stato utile?

Soluzione

Non vedo una pianura vecchio tutorial, ma non c'è codice di esempio nella prova directory che illustra OFXReader e AggregateUnmarshaller.

La frase "un esempio di net.sf.ofx4j.io.OFXReader " significa uno dei noti classi esecuzione", come NanoXMLOFXReader , che è testato qui . un test per AggregateUnmarshaller è qui .

Il API e archivi di posta sono buone risorse, anche. Sembra un sacco di istituzioni partecipare.

Altri suggerimenti

Per coloro che inciampa su questo come ho fatto io quando non ho potuto ottenere i risultati attesi dal AggregateUnmarshaller ... Ecco un esempio.

//Using a multipart file, but using a regular file is similar.
public void parse(MultipartFile file) throws IOException {
  //Use ResponseEnvelope to start.
  AggregateUnmarshaller<ResponseEnvelope> unmarshaller = new AggregateUnmarshaller<ResponseEnvelope>(
    ResponseEnvelope.class);

  try {
    ResponseEnvelope envelope = unmarshaller.unmarshal(file.getInputStream());
    //Assume we are just interested in the credit card info.  Make sure to cast.
    CreditCardResponseMessageSet messageSet = (CreditCardResponseMessageSet) envelope
      .getMessageSet(MessageSetType.creditcard);

    List<CreditCardStatementResponseTransaction> responses = messageSet.getStatementResponses();
    for (CreditCardStatementResponseTransaction response : responses) {
      CreditCardStatementResponse message = response.getMessage();
      String currencyCode = message.getCurrencyCode();
      List<Transaction> transactions = message.getTransactionList().getTransactions();
      for (Transaction transaction : transactions) {
        System.out.println(transaction.getName() + " " + transaction.getAmount() + " "
          + currencyCode);
      }
    }
  }
  catch (OFXParseException e) {
    e.printStackTrace();
  }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top