cancel
Showing results for 
Search instead for 
Did you mean: 

An oddness phenomenon

xietengfei
Champ in-the-making
Champ in-the-making
I do some thing  about  the  upload file with openoffice . And  now  i  open  the  upload  file  in http://locohost:8080/alfresco/webdav is what i want ;but i open with  the file linked  is  not same as i want . and  the file has  only  one version . the is  my code
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception.  You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.sample;

import java.util.List;

import net.sf.jooreports.openoffice.connection.OpenOfficeConnection;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sun.star.uno.UnoRuntime;

/**
* Logger action executer.
*
* This action will log a message to the application log file at the level specified.
*
* @author Roy Wetherall
*/
public class AdddocToOrigianlActionExecuter extends ActionExecuterAbstractBase
{
 
    /** The name of the action */
    public static final String NAME = "AdddocToOrigial-action";   
   
    /** The parameter names */

   private NodeService nodeService;
   private OpenOfficeConnection openOfficeConnection;
    /**
     * Set the node service
     *
     * @param nodeService  set the node service
     */
    public void setNodeService(NodeService nodeService)
   {
      this.nodeService = nodeService;
   }
    public void setOpenOfficeConnection(OpenOfficeConnection openOfficeConnection)
   {
      this.openOfficeConnection = openOfficeConnection;
   }
    /**
     * This action will take the log message and log it at the provided log level.
     *
     * If the log level is not provided the default will be INFO.
     *
     * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
     */
    @Override
    protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
    {
       ContentData contentData = (ContentData)this.nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_CONTENT);
       if(contentData !=null){
         String contentUrl =contentData.getContentUrl();
         System.out.println(contentUrl);
        
         //openoffice
         
         contentUrl = contentUrl.substring(7);
       
         //com.sun.star.frame.XDesktop oDesktop =getDesktop();
        
         String strFileUrl ="file:///D:/m.doc";
         com.sun.star.frame.XComponentLoader xComponentLoader = null;
         com.sun.star.lang.XComponent xComponent = null;
         xComponentLoader= openOfficeConnection.getDesktop();
         System.out.println("xComponentLoaderisOK");
         com.sun.star.beans.PropertyValue[] propertyValue =
              new com.sun.star.beans.PropertyValue[1];
          propertyValue[0] = new com.sun.star.beans.PropertyValue();
          propertyValue[0].Name = "Hidden";
          propertyValue[0].Value = new Boolean(true);
          try{
          xComponent =xComponentLoader.loadComponentFromURL(
                strFileUrl, "_blank", 0, propertyValue);
          }
          catch(Exception e){
             System.out.println("xComponentisFalse");
          }
         
         // com.sun.star.lang.XComponent aComponent= GetNewDocument(oDesktop,strFileUrl);
         
          com.sun.star.text.XTextDocument xTextDocument  = null;
        
          xTextDocument =GetTextdocument(xComponent);
          System.out.println("xTextDocumentIsOK");
       
          com.sun.star.text.XText xText = (com.sun.star.text.XText)xTextDocument.getText();
          String strtextFileURL = "file:///G:/alfresco-community-tomcat-2.1.0R1/alf_data/contentstore"+contentUrl;
          System.out.println(strtextFileURL);
          String strModelTopFileURL = "file:///D:/top.doc";
         
          InsertFile(xText,strtextFileURL,strModelTopFileURL);

                //替æ
9 REPLIES 9

derek
Star Contributor
Star Contributor
Hi,

Could you give a description of what you would like to have happen.  Particularly, what is the save method meant to be doing?

Regards

xietengfei
Champ in-the-making
Champ in-the-making
I  find  the  contentdata ,and  find the url, and  i have another MS OFFICE  TO insert it.and i open it in the  ui,it is the  same .
the same is do some things to do it

derek
Star Contributor
Star Contributor
OK.  I think I got that :wink:  You want to inject a header into a document.

In this case, you are trying to modify the underlying binary file directly.  This breaks the concurrency model completely.  Also, you are restricting users of your modified system from choosing the content store they wish to use.  You are forcing everyone onto a single filestore with possible concurrency problems.

You need to
    Get the ContentReader from the ContentService.
    Get a temporary file using TempFileProvider.  Make sure that you give the .doc extension.
    Create a FileContentWriter on top of the temp file.
    putContent(ContentReader) from the reader to the temp writer.
    Get the header text.
    Do your file manipulation against the temp file.
    Get a ContentWriter for the node using the ContentService.
    Write the temp file to the node's content using putContent(File).
This is the safe way to do it.  Take a look at the PdfBoxContentTransformer and the OpenOfficeContentTransformer for similar examples of manipulating files.  Absolutely do not attempt to modify the underlying binaries directly.

Regards

xietengfei
Champ in-the-making
Champ in-the-making
thanks,that is what i want

xietengfei
Champ in-the-making
Champ in-the-making
Get a temporary file using TempFileProvider. Make sure that you give the .doc extension.
Create a FileContentWriter on top of the temp file.

derek
Star Contributor
Star Contributor
TempFileProvider is just a convenience.  If you just create a temporary file directly, be sure to delete it safely in the method's finally block.

You can copy the content to the temporary file using reader.getContent(File) as well.

xietengfei
Champ in-the-making
Champ in-the-making
and  how  can  put the  head on the top ?

derek
Star Contributor
Star Contributor
That question is probably best asked on the OO dev forums.

xietengfei
Champ in-the-making
Champ in-the-making
thanks derek