001/* 002 * (C) Copyright 2006-2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 */ 020package org.nuxeo.template.processors; 021 022import java.io.File; 023 024import org.apache.commons.io.FileUtils; 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027 028import org.nuxeo.common.Environment; 029import org.nuxeo.ecm.core.api.Blob; 030import org.nuxeo.runtime.api.Framework; 031import org.nuxeo.template.api.TemplateProcessor; 032import org.nuxeo.template.api.adapters.TemplateBasedDocument; 033 034/** 035 * Common code between the implementations of {@link TemplateProcessor} 036 * 037 * @author Tiry ([email protected]) 038 */ 039public abstract class AbstractTemplateProcessor implements TemplateProcessor { 040 041 protected static final int BUFFER_SIZE = 1024 * 64; // 64K 042 043 protected static final Log log = LogFactory.getLog(AbstractTemplateProcessor.class); 044 045 protected File getWorkingDir() { 046 File workingDir = new File(Environment.getDefault().getTemp(), "NXTemplateProcessor" 047 + System.currentTimeMillis()); 048 if (workingDir.exists()) { 049 FileUtils.deleteQuietly(workingDir); 050 } 051 workingDir.mkdirs(); 052 Framework.trackFile(workingDir, workingDir); 053 return workingDir; 054 } 055 056 protected Blob getSourceTemplateBlob(TemplateBasedDocument templateBasedDocument, String templateName) { 057 return templateBasedDocument.getTemplateBlob(templateName); 058 } 059 060}