mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
partially removed need for sample instance xml - i'm doing a bunch of hacks at the moment to get around it - basically using xmlbeans to generate the sample xml, and then cleaning it up. ended up not needing to do insane things in javascript with this approach. emailed joern at chiba to see if he has suggestions for how others deal with this issue. serializing the template configuration using object serialization for now. it'll work good for the demo and we'll do something more robust/human readable post demo. this required a bunch of refactoring and springifying the TemplateService, but we're now reading back xsds and xsls from the repository which is sorta a nice thing i think. remove the preview form wizard step from create xml content type flow. tried getting rid of a temporary file in generating the xform but failed. need to find a way to get an url to a noderef that the xform can use to reference the xsd. emailed london people about that. but still did some refactoring along those lines. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3558 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
118 lines
3.7 KiB
Java
118 lines
3.7 KiB
Java
/*
|
|
* Copyright (C) 2005 Alfresco, Inc.
|
|
*
|
|
* Licensed under the Mozilla Public License version 1.1
|
|
* with a permitted attribution clause. You may obtain a
|
|
* copy of the License at
|
|
*
|
|
* http://www.alfresco.org/legal/license.txt
|
|
*
|
|
* Unless required by applicable law or agreed to in writing,
|
|
* software distributed under the License is distributed on an
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
* either express or implied. See the License for the specific
|
|
* language governing permissions and limitations under the
|
|
* License.
|
|
*/
|
|
package org.alfresco.web.templating;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.ResourceBundle;
|
|
|
|
import javax.faces.context.FacesContext;
|
|
import javax.faces.event.ValueChangeEvent;
|
|
import javax.faces.model.SelectItem;
|
|
|
|
import org.alfresco.config.Config;
|
|
import org.alfresco.config.ConfigElement;
|
|
import org.alfresco.config.ConfigService;
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.web.app.AlfrescoNavigationHandler;
|
|
import org.alfresco.web.app.Application;
|
|
import org.alfresco.web.bean.repository.Node;
|
|
import org.alfresco.web.data.IDataContainer;
|
|
import org.alfresco.web.data.QuickSort;
|
|
import org.alfresco.web.templating.*;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.service.cmr.model.FileInfo;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
import java.io.OutputStreamWriter;
|
|
import org.alfresco.web.app.servlet.FacesHelper;
|
|
import org.alfresco.service.cmr.model.FileFolderService;
|
|
import org.alfresco.service.cmr.repository.ContentService;
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
import org.w3c.dom.Document;
|
|
import org.alfresco.repo.avm.*;
|
|
|
|
public class OutputUtil
|
|
{
|
|
private static final Log LOGGER = LogFactory.getLog(OutputUtil.class);
|
|
|
|
public static void generate(Document xml,
|
|
TemplateType tt,
|
|
String fileName,
|
|
NodeRef containerNodeRef,
|
|
FileFolderService fileFolderService,
|
|
ContentService contentService,
|
|
NodeService nodeService)
|
|
throws Exception
|
|
{
|
|
try {
|
|
// get the node ref of the node that will contain the content
|
|
fileName = fileName + "-generated.html";
|
|
FileInfo fileInfo =
|
|
fileFolderService.create(containerNodeRef,
|
|
fileName,
|
|
ContentModel.TYPE_CONTENT);
|
|
NodeRef fileNodeRef = fileInfo.getNodeRef();
|
|
|
|
if (LOGGER.isDebugEnabled())
|
|
LOGGER.debug("Created file node for file: " +
|
|
fileName);
|
|
|
|
// get a writer for the content and put the file
|
|
ContentWriter writer = contentService.getWriter(fileNodeRef,
|
|
ContentModel.PROP_CONTENT, true);
|
|
// set the mimetype and encoding
|
|
writer.setMimetype("text/html");
|
|
writer.setEncoding("UTF-8");
|
|
TemplateOutputMethod tom = tt.getOutputMethods().get(0);
|
|
OutputStreamWriter out =
|
|
new OutputStreamWriter(writer.getContentOutputStream());
|
|
tom.generate(xml, tt, out);
|
|
out.close();
|
|
nodeService.setProperty(fileNodeRef,
|
|
TemplatingService.TT_QNAME,
|
|
tt.getName());
|
|
|
|
LOGGER.debug("generated " + fileName + " using " + tom);
|
|
|
|
AVMService avmService = AVMContext.fgInstance.getAVMService();
|
|
String parentPath = "repo-1:/repo-1/alice/appBase/avm_webapps/my_webapp";
|
|
try
|
|
{
|
|
out = new OutputStreamWriter(avmService.createFile(parentPath, fileName));
|
|
}
|
|
catch (AVMExistsException e)
|
|
{
|
|
out = new OutputStreamWriter(avmService.getFileOutputStream(parentPath + "/" + fileName));
|
|
}
|
|
LOGGER.debug("generating " + fileName + " to avm");
|
|
tom.generate(xml, tt, out);
|
|
out.close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LOGGER.error(e);
|
|
e.printStackTrace();
|
|
throw e;
|
|
}
|
|
}
|
|
} |