From 08f0ed882c3c7a98c568ffce5e685376665d2e98 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Mon, 26 Nov 2007 17:17:01 +0000 Subject: [PATCH] Reversed incorrect checkin git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7438 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/exporter/ExporterComponent.java | 36 ++--- .../repo/importer/ImporterComponent.java | 25 ++-- .../org/alfresco/repo/jscript/ScriptNode.java | 132 +++++++++++++++++- .../repo/template/AbsoluteUrlMethod.java | 79 +++++++++++ 4 files changed, 232 insertions(+), 40 deletions(-) create mode 100644 source/java/org/alfresco/repo/template/AbsoluteUrlMethod.java diff --git a/source/java/org/alfresco/repo/exporter/ExporterComponent.java b/source/java/org/alfresco/repo/exporter/ExporterComponent.java index 2f14b6f33e..c0df6329f4 100644 --- a/source/java/org/alfresco/repo/exporter/ExporterComponent.java +++ b/source/java/org/alfresco/repo/exporter/ExporterComponent.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.alfresco.model.ContentModel; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.PropertyDefinition; @@ -178,8 +179,6 @@ public class ExporterComponent */ public void exportView(ExportPackageHandler exportHandler, ExporterCrawlerParameters parameters, Exporter progress) { - System.out.println("PATCHED EXPORTERCOMPONENT FOR MIKEF"); - ParameterCheck.mandatory("Stream Handler", exportHandler); // create exporter around export handler @@ -456,7 +455,6 @@ public class ExporterComponent if (parameters.isCrawlChildNodes()) { exporter.startAssocs(nodeRef); - QName prevAssocType = null; List childAssocs = nodeService.getChildAssocs(nodeRef); for (int i = 0; i < childAssocs.size(); i++) { @@ -471,20 +469,15 @@ public class ExporterComponent nodesWithSecondaryLinks.put(nodeRef, nodeRef); continue; } - if (prevAssocType == null || prevAssocType.equals(childAssocType) == false) + if (i == 0 || childAssocs.get(i - 1).getTypeQName().equals(childAssocType) == false) { - if (prevAssocType != null) - { - exporter.endAssoc(nodeRef, prevAssocType); - } exporter.startAssoc(nodeRef, childAssocType); - prevAssocType = childAssocType; } if (!isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssoc.getQName().getNamespaceURI())) { walkNode(childAssoc.getChildRef(), parameters, exporter, false); } - if (i == childAssocs.size() - 1) + if (i == childAssocs.size() - 1 || childAssocs.get(i + 1).getTypeQName().equals(childAssocType) == false) { exporter.endAssoc(nodeRef, childAssocType); } @@ -560,13 +553,12 @@ public class ExporterComponent { // export property of datatype CONTENT ContentReader reader = contentService.getReader(nodeRef, property); - if (true) + if (!parameters.isCrawlContent() || reader == null || reader.exists() == false) { // export an empty url for the content ContentData contentData = (ContentData)value; -// ContentData noContentURL = new ContentData("", contentData.getMimetype(), contentData.getSize(), contentData.getEncoding()); -// exporter.content(nodeRef, property, null, noContentURL, index); - exporter.value(nodeRef, property, contentData, index); + ContentData noContentURL = new ContentData("", contentData.getMimetype(), contentData.getSize(), contentData.getEncoding()); + exporter.content(nodeRef, property, null, noContentURL, index); exporter.warning("Skipped content for property " + property + " on node " + nodeRef); } else @@ -711,15 +703,15 @@ public class ExporterComponent */ private boolean isExcludeAspect(QName aspectQName) { -// if (aspectQName.equals(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT) || -// aspectQName.equals(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) -// { -// return true; -// } -// else -// { + if (aspectQName.equals(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT) || + aspectQName.equals(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) + { + return true; + } + else + { return false; -// } + } } /** diff --git a/source/java/org/alfresco/repo/importer/ImporterComponent.java b/source/java/org/alfresco/repo/importer/ImporterComponent.java index 3883b98f3f..d75fc62a85 100644 --- a/source/java/org/alfresco/repo/importer/ImporterComponent.java +++ b/source/java/org/alfresco/repo/importer/ImporterComponent.java @@ -220,7 +220,6 @@ public class ImporterComponent */ public void importView(Reader viewReader, Location location, ImporterBinding binding, ImporterProgress progress) { - System.out.println("PATCHED IMPORTERCOMPONENT FOR MIKEF"); NodeRef nodeRef = getNodeRef(location, binding); parserImport(nodeRef, location.getChildAssocType(), viewReader, new DefaultStreamHandler(), binding, progress); } @@ -230,7 +229,6 @@ public class ImporterComponent */ public void importView(ImportPackageHandler importHandler, Location location, ImporterBinding binding, ImporterProgress progress) throws ImporterException { - System.out.println("PATCHED IMPORTERCOMPONENT FOR MIKEF"); importHandler.startImport(); Reader dataFileReader = importHandler.getDataStream(); NodeRef nodeRef = getNodeRef(location, binding); @@ -662,18 +660,17 @@ public class ImporterComponent { DataTypeDefinition dataTypeDef = dictionaryService.getDataType(DataTypeDefinition.CONTENT); ContentData contentData = (ContentData)DefaultTypeConverter.INSTANCE.convert(dataTypeDef, importContentData); - nodeService.setProperty(nodeRef, propertyName, contentData); -// String contentUrl = contentData.getContentUrl(); -// if (contentUrl != null && contentUrl.length() > 0) -// { -// // import the content from the url -// InputStream contentStream = streamHandler.importStream(contentUrl); -// ContentWriter writer = contentService.getWriter(nodeRef, propertyName, true); -// writer.setEncoding(contentData.getEncoding()); -// writer.setMimetype(contentData.getMimetype()); -// writer.putContent(contentStream); -// reportContentCreated(nodeRef, contentUrl); -// } + String contentUrl = contentData.getContentUrl(); + if (contentUrl != null && contentUrl.length() > 0) + { + // import the content from the url + InputStream contentStream = streamHandler.importStream(contentUrl); + ContentWriter writer = contentService.getWriter(nodeRef, propertyName, true); + writer.setEncoding(contentData.getEncoding()); + writer.setMimetype(contentData.getMimetype()); + writer.putContent(contentStream); + reportContentCreated(nodeRef, contentUrl); + } } } diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index 9f29f65134..351467e6e2 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -70,7 +70,6 @@ import org.alfresco.service.cmr.version.VersionType; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; -import org.alfresco.util.Content; import org.alfresco.util.GUID; import org.alfresco.util.ParameterCheck; import org.alfresco.util.URLEncoder; @@ -2160,10 +2159,62 @@ public class ScriptNode implements Serializable, Scopeable // Inner Classes + /** + * Inner class for representing content + */ + public static abstract class ScriptContent implements Serializable + { + /** + * @return the content stream as a string + */ + public abstract String getContent(); + + public String jsGet_content() + { + return getContent(); + } + + /** + * @return the content mimetype + */ + public abstract String getMimetype(); + + public String jsGet_mimetype() + { + return getMimetype(); + } + + /** + * @return the content encoding + */ + public abstract String getEncoding(); + + public String jsGet_encoding() + { + return getEncoding(); + } + + /** + * @return the content size + */ + public abstract long getSize(); + + public long jsGet_size() + { + return getSize(); + } + + /** + * @return input stream onto content + */ + /*package*/ abstract InputStream getInputStream(); + } + + /** * Inner class wrapping and providing access to a ContentData property */ - public class ScriptContentData implements Content, Serializable + public class ScriptContentData extends ScriptContent implements Serializable { private static final long serialVersionUID = -7819328543933312278L; @@ -2190,7 +2241,7 @@ public class ScriptNode implements Serializable, Scopeable return (reader != null && reader.exists()) ? reader.getContentString() : ""; } - public InputStream getInputStream() + /*package*/ InputStream getInputStream() { ContentService contentService = services.getContentService(); ContentReader reader = contentService.getReader(nodeRef, property); @@ -2224,7 +2275,7 @@ public class ScriptNode implements Serializable, Scopeable * * @param content ScriptContent to set */ - public void write(Content content) + public void write(ScriptContent content) { ContentService contentService = services.getContentService(); ContentWriter writer = contentService.getWriter(nodeRef, this.property, true); @@ -2320,6 +2371,79 @@ public class ScriptNode implements Serializable, Scopeable private QName property; } + + /** + * Inner class wrapping and providing access to a Content stream + */ + public static class ScriptContentStream extends ScriptContent implements Serializable + { + private static final long serialVersionUID = -7819328543933312278L; + + /** + * Constructor + * + * @param stream content input stream + * @param mimetype content mimetype + */ + public ScriptContentStream(InputStream stream, String mimetype, String encoding) + { + this.stream = stream; + this.mimetype = mimetype; + this.encoding = encoding; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.jscript.ScriptNode.ScriptContent#getContent() + */ + public String getContent() + { + try + { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + FileCopyUtils.copy(stream, os); // both streams are closed + byte[] bytes = os.toByteArray(); + // get the encoding for the string + String encoding = getEncoding(); + // create the string from the byte[] using encoding if necessary + String content = (encoding == null) ? new String(bytes) : new String(bytes, encoding); + // done + return content; + } + catch (IOException e) + { + throw new ContentIOException("Failed to copy content to string", e); + } + } + + /*package*/ InputStream getInputStream() + { + return stream; + } + + public long getSize() + { + return -1; + } + + public String getMimetype() + { + return mimetype; + } + + public String getEncoding() + { + return encoding; + } + + + private InputStream stream; + + private String mimetype; + + private String encoding; + } + + /** * Interface contract for simple anonymous classes that implement document transformations */ diff --git a/source/java/org/alfresco/repo/template/AbsoluteUrlMethod.java b/source/java/org/alfresco/repo/template/AbsoluteUrlMethod.java new file mode 100644 index 0000000000..c7ea810323 --- /dev/null +++ b/source/java/org/alfresco/repo/template/AbsoluteUrlMethod.java @@ -0,0 +1,79 @@ +/* + * 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.repo.template; + +import java.util.List; + +import freemarker.template.TemplateMethodModelEx; +import freemarker.template.TemplateModelException; +import freemarker.template.TemplateScalarModel; + +/** + * @author David Caruana + * + * Custom FreeMarker Template language method. + *

+ * Render absolute url for the specified url (only if the url isn't already absolute). + *

+ * Usage: absurl(String url) + */ +public final class AbsoluteUrlMethod implements TemplateMethodModelEx +{ + private String basePath; + + /** + * Construct + * + * @param basePath base path used to construct absolute url + */ + public AbsoluteUrlMethod(String basePath) + { + this.basePath = basePath; + } + + + /** + * @see freemarker.template.TemplateMethodModel#exec(java.util.List) + */ + public Object exec(List args) throws TemplateModelException + { + String result = ""; + + if (args.size() == 1) + { + Object arg0 = args.get(0); + if (arg0 instanceof TemplateScalarModel) + { + result = ((TemplateScalarModel)arg0).getAsString(); + if (result.startsWith("/")) + { + result = basePath + result; + } + } + } + + return result; + } +}