A quoi font référence les 'this' dans la fonction?
Comment est-il possible d'appeler cette fonction?
ackage org.alfresco.community.utility.document;
import java.awt.Color;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.faces.context.FacesContext;
import org.alfresco.community.config.GetConfig;
import org.alfresco.community.definitions.CommunityConstante;
import org.alfresco.community.repo.Content;
import org.alfresco.community.util.MyLogger;
import org.alfresco.community.util.OfficeTransform;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NoTransformerException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.rule.RuleServiceException;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.TempFileProvider;
import org.alfresco.web.bean.repository.Repository;
import org.apache.log4j.Logger;
import org.pdfbox.exceptions.COSVisitorException;
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.pdmodel.PDPage;
import org.pdfbox.pdmodel.edit.PDPageContentStream;
import org.pdfbox.pdmodel.font.PDFont;
import org.pdfbox.pdmodel.font.PDTrueTypeFont;
import org.pdfbox.pdmodel.graphics.xobject.PDJpeg;
import org.pdfbox.pdmodel.graphics.xobject.PDXObjectImage;
public class PDFTools {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(PDFTools.class);
private static final String MIMETYPE_WORD_2007 = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
private static final String MIMETYPE_EXCEL_2007 = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
// Get Services
static NodeService nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
//static NamespaceService namespaceService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNamespaceService();
static ContentService contentService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getContentService();
static MimetypeService mimetypeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getMimetypeService();
static CopyService copyService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getCopyService();
/**
* Executed in a new transaction so that failures don't cause the entire transaction to rollback.
* @param sourceNodeRef
* @param contentReader
* @param destinationNodeRef
* @param contentWriter
*/
private static void doTransform(NodeRef sourceNodeRef, ContentReader contentReader,
NodeRef destinationNodeRef, ContentWriter contentWriter)
{
// Transformation options
//TransformationOptions options = new TransformationOptions(sourceNodeRef, ContentModel.PROP_NAME, destinationNodeRef, ContentModel.PROP_NAME);
// try to pre-empt the lack of a transformer
if (contentService.isTransformable(contentReader, contentWriter) == false)
{
throw new NoTransformerException(contentReader.getMimetype(), contentWriter.getMimetype());
}
// transform
contentService.transform(contentReader, contentWriter);
}
/**
* Transform name from original extension to new extension
* @param mimetypeService
* @param original
* @param newMimetype
* @param alwaysAdd
* @return
*/
//public static String transformName(MimetypeService mimetypeService, String original, String newMimetype, boolean alwaysAdd)
public static String transformName(String original, String newMimetype, boolean alwaysAdd)
{
// get the current extension
int dotIndex = original.lastIndexOf('.');
StringBuilder sb = new StringBuilder(original.length());
if (dotIndex > -1)
{
// we found it
sb.append(original.substring(0, dotIndex));
// add the new extension
String newExtension = mimetypeService.getExtension(newMimetype);
sb.append('.').append(newExtension);
}
else
{
// no extension so dont add a new one
sb.append(original);
if (alwaysAdd == true)
{
// add the new extension
String newExtension = mimetypeService.getExtension(newMimetype);
sb.append('.').append(newExtension);
}
}
// done
return sb.toString();
}
/**
* Make PDF
* @param sourceNodeRef
* @param copyNodeRef
* @throws COSVisitorException
* @throws IOException
*/
public static void makePDF(NodeRef sourceNodeRef, NodeRef destNodeRef) throws COSVisitorException, IOException {
MyLogger.debugInfo("Published in PDF format", 2, 14);
ContentReader contentReader = contentService.getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
if(contentReader != null) {
// get the writer and set it up
ContentWriter contentWriter = contentService.getWriter(destNodeRef, ContentModel.PROP_CONTENT, true);
// Only do the transformation if some content is avalaible
contentWriter.setMimetype(MimetypeMap.MIMETYPE_PDF); // new mimeType
contentWriter.setEncoding(contentReader.getEncoding()); // original encoding
// Try and transform the content - failure are caught and allow to fail silently
// This is unique to this action, and is essentially a broken pattern.
// Client should rather get the exception and then decide to replay with rules/action turned off or not.
// TODO: Check failure patterns for actions.
String mymetype = contentService.getWriter(sourceNodeRef, ContentModel.PROP_CONTENT, true).getMimetype().toString();
try {
if (GetConfig.msoffice() && (mymetype.equals(MimetypeMap.MIMETYPE_WORD) ||
mymetype.equals(MIMETYPE_WORD_2007) ||
mymetype.equals(MimetypeMap.MIMETYPE_EXCEL) ||
mymetype.equals(MIMETYPE_EXCEL_2007))) {
//try {
OfficeTransform.convertToPDF(sourceNodeRef,contentReader, destNodeRef, contentWriter);
/* } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
else {
doTransform(sourceNodeRef,contentReader,destNodeRef,contentWriter);
}
}
catch(NoTransformerException e) {
if (logger.isDebugEnabled()) {
logger.debug("No transformer found to execute rule: \n" +
" reader: " + contentReader + "\n" +
" writer: " + contentWriter + "\n"); // +
//" action: " + this);
}
}
}
…
}
PDFTools.makePDF(NodeRefSource(), NodeRefPDF());
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.