cancel
Showing results for 
Search instead for 
Did you mean: 

Word template fill-up

ivo_costa
Champ in-the-making
Champ in-the-making
HI

I'm trying to have some word template filled with data that the users enters as metadata.
I'm looked into POI that I think Alfresco uses but I can't find any documentation for this

what I need is something like this

1) user selects create new content
2) if possible user selects "information template" (in the box where you can choose html, xml, etc)
3) user fills up the metadata (name, serial-number(already calculated using behavior), etc)
4) word comes up with a document already partially filled up by alfresco (this might be done some other way but document must have data writen through alfresco)

any Ideia on number 2 and number 4???

edit: couldn't find any afterCreateNodePolicy… is there such thing?? any alternatives?
edit2: onUpdateProperties might work, but will it be triggered by a onCreateNode behavior that updates some properties???
7 REPLIES 7

ivo_costa
Champ in-the-making
Champ in-the-making
Hi…

I've been trying to access the file's content using the ContentService, unfortunely I can't get the stream to the content…
I always get a failed to get stream to content

can any-one help?

here is some some source code

    public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
    {
       System.out.println("Update1");
      ContentService cs = serviceRegistry.getContentService();
      System.out.println("Update2");
      ContentReader cr = cs.getReader(nodeRef, ContentModel.PROP_CONTENT);
      System.out.println("Update3");
      System.out.println(cr.getContentString()); //debug de leitura
      System.out.println("Update4");
      
      //cr = FileContentReader.
      
      //.getSafeContentReader(cr,Application.getMessage(req.getSession(), MSG_ERROR_CONTENT_MISSING),   nodeRef, cr);
      try
      {
         InputStream is = cr.getContentInputStream();
      }
      catch(ContentIOException e)
      {
         System.out.println("error: " + e.getMessage());
         System.out.println("Stack trace: " + e.getStackTrace().toString());
      }
   }

ivo_costa
Champ in-the-making
Champ in-the-making
Found a way of doing something similar based on the Openoffice connection already existing in Alfresco
Only thing missing is adding the "Information Template" in the wizard's box of "Mime/type"

sebpeanut
Champ in-the-making
Champ in-the-making
Hi ivo.costa,

I'm aiming to the same thing. Could you give me a tip of where to look to implement this ?

Thanks

Seb

ivo_costa
Champ in-the-making
Champ in-the-making
Hi Seb

this solution I've found is some-what based on the Office data extracter  existing code on the Alfresco project, right now I can recall what was the file's name but I'm sure that you can easely find it.

Take a look on the OpenOffice API Documentation

Here are some samples from my own code:
      tempFromFile = TempFileProvider.createTempFile(
            "OpenOfficeMetadataExtracter-", ".ott");

      reader.getContent(tempFromFile);

      String sourceUrl = toUrl(tempFromFile, connection);

      XComponentLoader desktop = connection.getDesktop();

      PropertyValue[] loadProps = new PropertyValue[2];
      loadProps[0] = new PropertyValue();
      loadProps[0].Name = "AsTemplate";
      loadProps[0].Value = new Boolean(true);
      loadProps[1] = new PropertyValue();
      loadProps[1].Name = "Hidden";
      loadProps[1].Value = new Boolean(true);

      // load
      return desktop.loadComponentFromURL(sourceUrl, "_blank", 0, loadProps);
      System.out.println("Added Template needed Information");
      // load template with User fields
      XComponent xTemplateComponent = template;

      XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime
            .queryInterface(XTextFieldsSupplier.class, xTemplateComponent);

      // access the TextFields and the TextFieldMasters collections
      XNameAccess xNamedFieldMasters = xTextFieldsSupplier
            .getTextFieldMasters();
      XEnumerationAccess xEnumeratedFields = xTextFieldsSupplier
            .getTextFields();

      // iterate over hashtable and insert values into field masters
                // recipient is Hashtable with the data needed by the template
      java.util.Enumeration<String> keys = recipient.keys();
      while (keys.hasMoreElements()) {
         // get column name
         String key = (String) keys.nextElement();
         System.out.println("Adding " + key);

         // access corresponding field master
         Object fieldMaster = xNamedFieldMasters
               .getByName("com.sun.star.text.FieldMaster.User." + key);

         // query the XPropertySet interface, we need to set the Content
         // property
         XPropertySet xPropertySet = (XPropertySet) UnoRuntime
               .queryInterface(XPropertySet.class, fieldMaster);

         System.out.println("Before Add");
         // insert the column value into field master
         xPropertySet.setPropertyValue("Content", recipient.get(key));
         // System.out.println("After Add " + recipient.get(key).toString());
      }

      // afterwards we must refresh the textfields collection
      XRefreshable xRefreshable = (XRefreshable) UnoRuntime.queryInterface(
            XRefreshable.class, xEnumeratedFields);
      xRefreshable.refresh();

Sorry but the code is a little messy right now

hope it helps, and if you have any questions just post them , and I'll try my best to help you

Regards…

Ivo Costa

sebpeanut
Champ in-the-making
Champ in-the-making
That looks like a neat solution indeed !
I suppose/hope it's possible to save it (convert ?) as a .doc file .. !?

Thanks a lot,

Seb

ivo_costa
Champ in-the-making
Champ in-the-making
Hi Seb

you can save in .doc, it took me some time to find out how to do it, but yesterday I found the export parameter needed
had to make a full print of the API response using some code I've found

it was actually easier than I've thought

here are the parameters
PropertyValue[] storeProps = new PropertyValue[1];
       storeProps[0] = new PropertyValue();
       storeProps[0].Name = "FilterName";
       storeProps[0].Value = "MS Word 97";      

all you have to do is add these to the writer method

if you find a way of using a Word Template in place of the OpenOffice Template that I'm using right now, please do post here Smiley Wink
I'm still missing that part

Thanks

mviswam
Champ in-the-making
Champ in-the-making
HI ivo.costa / Seb,

I think I am also searching for a similar solution. We have decided to implement Alfresco for our Document Management. However we are currently using a set of MS-Word templates.

Will I be able to use the same templates in Alfresco also, if not what is a better alternative. we are implementing alfresco 4.0.

Please guide/help.

Mahesh