cancel
Showing results for 
Search instead for 
Did you mean: 

Read text from content file

bindiya
Champ in-the-making
Champ in-the-making
Hi

I want to read text from the content and write or display it in jsp page.
Is this possible to do using webservices?


Thanks,
Bindiya
3 REPLIES 3

jtorres
Champ in-the-making
Champ in-the-making

   public String getData(String Id){
       String result = null;
        try {
            // Obtener el servicio adecuado.
            ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();       

            // Construimos la Referencia en base a su UUID.
            Node nodo = this.getNode(Id);
          Reference ref = nodo.getReference();
          
            // Leemos del repositorio el elemento.
         Content[] readResult = contentService.read(
                                             new Predicate(new Reference[]{ref}, STORE, null),
                                             Constants.PROP_CONTENT);
            Content content = readResult[0];
 
            // Obtenemos el contenido a partir de su URL y se muestra.
            System.out.println(ContentUtils.getContentAsString(content));
         result = ContentUtils.getContentAsString(content);
           
      } catch (ContentFault e) {
         System.out.println("No se ha podido leer el fichero.");
      } catch (RemoteException e) {
         System.out.println("Error de servicio.");
      }
         
      return result;
   }

And the function used to get the content node:

    protected Node getNode(String uuid){
      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();

      Node myNode = null;
      Reference reference = new Reference(STORE, uuid, null);
      Predicate predicate = new Predicate(new Reference[]{reference}, null, null);
      Node[] nodes;

      try {
         nodes = repositoryService.get(predicate);
         // Obtenemos el nodo.
         myNode = nodes[0];
      } catch (RepositoryFault e) {
         System.out.println("Datos no encontrados.");
      } catch (RemoteException e) {
         System.out.println("Error de servicio remoto.");
      }
      
      return myNode;
      
   }

bindiya
Champ in-the-making
Champ in-the-making
Thanks a lot for the quick response. This code helped me.

fmelero
Champ in-the-making
Champ in-the-making
Hi,

I'd like to know if with this two functions you wrote I can retrieve the content of a concrete file. How I should do it?

regards