Snippets

Jonathan Hult WebCenter Content - ZipRenditionsHandlerExtended - override to alter file names

Created by Jonathan Hult last modified
import intradoc.common.DataStreamWrapper;
import intradoc.common.ServiceException;
import intradoc.data.DataException;
import intradoc.data.DataResultSet;
import intradoc.server.FileService;
import intradoc.server.ServiceData;
import java.io.IOException;
import java.util.Vector;
import ziprenditions.ZipRenditionsHandler;

import static intradoc.common.LocaleResources.getString;
import static intradoc.server.ServiceManager.createService;
import static intradoc.server.ServiceManager.getFullService;

/**
 * @author Jonathan Hult
 */

// Class needed so we can override default functionality of GET_ZIP_BUNDLE
// This class should be used as a ServiceHandler for a new service
public class ZipRenditionsHandlerExtended extends ZipRenditionsHandler {

private final String TRACE_SECTION = "ZipRenditionsHandlerExtended";

	// Remove zipFilePath from temp files; otherwise, this gets removed during service.cleanUp
	// Add zipFilePath to LocalData so we can easily fetch if from other ServiceHandler
	public void createRenditionBundleExtended() throws DataException, ServiceException {
		super.createRenditionBundle();

		final DataStreamWrapper streamWrapper = m_service.getDownloadStream(false);
		final String zipFilePath = streamWrapper.m_filePath;
		Report.trace(TRACE_SECTION, "zipFilePath: " + zipFilePath, null);

		if (hasText(zipFilePath)) {
			m_binder.putLocal("zipFilePath", zipFilePath);
			m_binder.m_tempFiles.remove(zipFilePath);
		} else {
			Report.trace(TRACE_SECTION, "Could not find zip path", null);
			Report.trace(TRACE_SECTION, "DataBinder: " + m_binder.getLocalData().toString(), null);
			throw new ServiceException(getString("FailureCreatingZip_StrResource", m_service));
		}
	}

	public void createResultSetFromParamListExtended() throws DataException, ServiceException {
		super.createResultSetFromParamList();
	}

	/**
	 * Override to alter entries to change pkgEntryName (used as file name in zip).
	 *
	 * @param service
	 * @param entries
	 * @param fileSizeTotal
	 * @throws IOException
	 * @throws DataException
	 * @throws ServiceException
	 */
	@Override
	public void addEntry(FileService service, Vector entries, long[] fileSizeTotal) throws IOException, DataException, ServiceException {
		//super.addEntry(service, entries, fileSizeTotal);

        for (int = 0; i < entries.size(); i++) {
            Object fileName = entries.get(i);

            // do logic to alter file name
            String fileNameModified = ((String)fileName).toUpperCase();
              
            // Set new file name in vector
            vector.set(i, fileNameModified);
		}
	}

	// Pass in UserData - this is missing in Oracle's code and causes major problems
	@Override
	public FileService createAndExecuteService(final String command) throws DataException, ServiceException {
		final ServiceData serviceData = getFullService(command);
		final FileService service = (FileService) createService(serviceData.m_classID, m_workspace, m_service.getOutput(), m_binder, serviceData);
		service.setConditionVar("ForceDownloadStreamToFilepath", true);
		service.initDelegatedObjects();
		m_service.getRequestImplementor().doRequestInternalEx(service, m_service.getUserData(), false);
		return service;
	}
}

Comments (4)

  1. Dharmendra Kumar

    Hi Hult,

    I putted your code in Jdeveloper IDE and add library in IDE like idcserver.jar, classes-ZipRenditionManagement.jar and other WCC jars, but in line 30 trace("zipFilePath: " + zipFilePath); in line 32 hasText(zipFilePath), line 36 nd 37 trace("Could not find zip path"); trace("DataBinder: " + m_binder.getLocalData().toString()); line 64 String fileNameModified = fileName.toUpperCase(); method not found error message see on JDev and at line 67 vector.set(i, fileNameModified); vector variable not found error message is seen.

    I think trace() method is not belong to any java package and it is printStackTrace method, Please clear it. and will be appreciable if I get correct code for try service handler I am using this first time . Also when I changed vector with Vector then I get error in set() method.

    Thanks Dharmendra

  2. Dharmendra Kumar

    Hi Jonathan,

    Thanks for refine code, Now I want to tell to you how I am using this code. I create a custom component in which I am using static resource with merge Service handler in serviceName I give the FileService and Handler name the class name, Also add service GET_ZIP_BUNDLE. I put class ZipRenditionsHandlerExtended in classes folder of the component and related library in lib folder. When I run the service using RIDC from a java app the I got the error as added in community thread https://community.oracle.com/thread/3958774 . Now want to know what mistake i made to build the component in result I am getting error, will be appreciable if you guide me on it. Also I have some questions in community thread.

    Thanks You dharmendra

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.