Commit 2b645a99 authored by Ate Douma's avatar Ate Douma

Merge branch 'bugfix/ESSENTIALS-994'

parents 755b07ba 82efb281
/*
* Copyright 2014 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -21,6 +21,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayDeque;
......@@ -32,6 +33,10 @@ import javax.inject.Inject;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.EventBus;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.onehippo.cms7.essentials.dashboard.ctx.PluginContext;
......@@ -46,14 +51,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.EventBus;
@Component
@XmlRootElement(name = "file", namespace = EssentialConst.URI_ESSENTIALS_INSTRUCTIONS)
public class FileInstruction extends PluginInstruction {
public static final Set<String> VALID_ACTIONS = new ImmutableSet.Builder<String>()
.add(COPY)
.add(DELETE)
......@@ -140,7 +141,7 @@ public class FileInstruction extends PluginInstruction {
} else {
final String content = GlobalUtils.readStreamAsText(stream);
final String replacedData = TemplateUtils.replaceTemplateData(content, context.getPlaceholderData());
FileUtils.copyInputStreamToFile(IOUtils.toInputStream(replacedData), destination);
FileUtils.copyInputStreamToFile(IOUtils.toInputStream(replacedData, StandardCharsets.UTF_8), destination);
}
sendEvents();
return InstructionStatus.SUCCESS;
......
/*
* Copyright 2014 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -18,6 +18,7 @@ package org.onehippo.cms7.essentials.dashboard.instruction;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
......@@ -29,6 +30,10 @@ import javax.jcr.Session;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.EventBus;
import org.apache.commons.io.IOUtils;
import org.onehippo.cms7.essentials.dashboard.ctx.PluginContext;
import org.onehippo.cms7.essentials.dashboard.event.InstructionEvent;
......@@ -44,14 +49,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.eventbus.EventBus;
/**
* @version "$Id$"
*/
@Component
@XmlRootElement(name = "xml", namespace = EssentialConst.URI_ESSENTIALS_INSTRUCTIONS)
public class XmlInstruction extends PluginInstruction {
......@@ -124,10 +121,9 @@ public class XmlInstruction extends PluginInstruction {
return InstructionStatus.SKIPPED;
}
// Import XML with replaced NAMESPACE placeholder
final String myData = TemplateUtils.replaceTemplateData(GlobalUtils.readStreamAsText(stream), context.getPlaceholderData());
session.importXML(destination.getPath(), IOUtils.toInputStream(myData), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.importXML(destination.getPath(), IOUtils.toInputStream(myData, StandardCharsets.UTF_8), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.save();
log.info("Added node to: {}", destination.getPath());
sendEvents();
......
/*
* Copyright 2014-2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -23,6 +23,7 @@ import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
......@@ -37,6 +38,9 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import org.apache.commons.io.IOUtils;
import org.hippoecm.repository.HippoRepository;
import org.hippoecm.repository.HippoRepositoryFactory;
......@@ -44,10 +48,6 @@ import org.onehippo.cms7.essentials.dashboard.config.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.CharMatcher;
import com.google.common.base.Charsets;
import com.google.common.base.Strings;
/**
* @version "$Id$"
*/
......@@ -93,7 +93,7 @@ public final class GlobalUtils {
if (stream == null) {
return null;
}
return IOUtils.toString(stream);
return IOUtils.toString(stream, StandardCharsets.UTF_8);
} catch (IOException e) {
log.error("Error reading files", e);
} finally {
......@@ -126,7 +126,7 @@ public final class GlobalUtils {
public static StringBuilder readTextFile(final Path path) {
final StringBuilder builder = new StringBuilder();
try {
final List<String> strings = Files.readAllLines(path, Charsets.UTF_8);
final List<String> strings = Files.readAllLines(path, StandardCharsets.UTF_8);
for (String string : strings) {
builder.append(string).append(System.getProperty("line.separator"));
}
......@@ -143,7 +143,7 @@ public final class GlobalUtils {
* @param path path to save file to
*/
public static void writeToFile(final CharSequence content, final Path path) {
try (BufferedWriter writer = Files.newBufferedWriter(path, Charsets.UTF_8)) {
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
writer.append(content);
writer.flush();
} catch (IOException e) {
......
/*
* Copyright 2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2015-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,6 +17,7 @@ package org.onehippo.cms7.essentials.dashboard.utils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
......@@ -38,7 +39,7 @@ public class TranslationsUtils {
private TranslationsUtils() {}
public static void importTranslations(String json, Session session) throws RepositoryException, IOException {
final Collection<BundleInfo> bundleInfos = BundleFileInfo.readInfo(new ByteArrayInputStream(json.getBytes())).getBundleInfos();
final Collection<BundleInfo> bundleInfos = BundleFileInfo.readInfo(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))).getBundleInfos();
for (BundleInfo bundleInfo : bundleInfos) {
getOrCreateResourceBundle(bundleInfo, session);
}
......
/*
* Copyright 2014 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,6 +17,7 @@
package org.onehippo.cms7.essentials.dashboard.utils;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
......@@ -67,7 +68,7 @@ public class XmlUtilsTest extends BaseResourceTest {
final XmlNode xmlNode = findPluginNode(templateDocuments);
final String xml = XmlUtils.xmlNodeToString(xmlNode);
assertNotNull(xml);
final XmlNode myXml = XmlUtils.parseXml(IOUtils.toInputStream(xml));
final XmlNode myXml = XmlUtils.parseXml(IOUtils.toInputStream(xml, StandardCharsets.UTF_8));
assertNotNull(myXml);
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2014-2015 Hippo B.V. (http://www.onehippo.com)
Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -33,7 +33,7 @@
<properties>
<javax.inject.version>1</javax.inject.version>
<maven-model.version>3.2.1</maven-model.version>
<commons-io.version>2.3</commons-io.version>
<commons-io.version>2.5</commons-io.version>
<core.jdt.version>3.10.0</core.jdt.version>
<mustache.version>0.8.16</mustache.version>
<swagger-jaxrs_2.10.version>1.3.0</swagger-jaxrs_2.10.version>
......
/*
* Copyright 2014 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,6 +17,7 @@
package org.onehippo.cms7.essentials.plugins.relateddocuments;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
......@@ -35,6 +36,9 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import org.apache.commons.io.IOUtils;
import org.onehippo.cms7.essentials.dashboard.ctx.PluginContext;
import org.onehippo.cms7.essentials.dashboard.ctx.PluginContextFactory;
......@@ -48,9 +52,6 @@ import org.onehippo.cms7.essentials.dashboard.utils.TemplateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
/**
* @version "$Id$"
*/
......@@ -102,10 +103,10 @@ public class RelatedDocumentsResource extends BaseResource {
templateData.put("numberOfSuggestions", suggestions[idx]);
// import field:
final String fieldData = TemplateUtils.replaceStringPlaceholders(templateRelatedDocs, templateData);
session.importXML(fieldImportPath, IOUtils.toInputStream(fieldData), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.importXML(fieldImportPath, IOUtils.toInputStream(fieldData, StandardCharsets.UTF_8), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
// import suggest field:
final String suggestData = TemplateUtils.replaceStringPlaceholders(templateSuggestDocs, templateData);
session.importXML(fieldImportPath, IOUtils.toInputStream(suggestData), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.importXML(fieldImportPath, IOUtils.toInputStream(suggestData, StandardCharsets.UTF_8), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.save();
changedDocuments.add(document);
idx++;
......
/*
* Copyright 2014-2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,6 +17,7 @@
package org.onehippo.cms7.essentials.plugins.selection;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.*;
......@@ -377,7 +378,8 @@ public class SelectionResource extends BaseResource {
final InputStream stream = getClass().getResourceAsStream(resourcePath);
final String processedXml = TemplateUtils.replaceStringPlaceholders(GlobalUtils.readStreamAsText(stream), placeholderMap);
destination.getSession().importXML(destination.getPath(), IOUtils.toInputStream(processedXml),
destination.getSession().importXML(destination.getPath(),
IOUtils.toInputStream(processedXml, StandardCharsets.UTF_8),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
}
......
/*
* Copyright 2014-2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,6 +17,7 @@
package org.onehippo.cms7.essentials.plugins.tagging;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
......@@ -39,8 +40,6 @@ import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import org.apache.commons.io.IOUtils;
import org.hippoecm.repository.api.HippoSession;
import org.hippoecm.repository.api.ImportReferenceBehavior;
import org.onehippo.cms7.essentials.dashboard.ctx.PluginContext;
import org.onehippo.cms7.essentials.dashboard.ctx.PluginContextFactory;
import org.onehippo.cms7.essentials.dashboard.rest.BaseResource;
......@@ -114,14 +113,14 @@ public class TaggingResource extends BaseResource {
final String tagsPath = fieldImportPath + '/' + TAGS_FIELD;
if (!session.nodeExists(tagsPath)) {
final String fieldData = TemplateUtils.replaceStringPlaceholders(templateTags, templateData);
session.importXML(fieldImportPath, IOUtils.toInputStream(fieldData), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.importXML(fieldImportPath, IOUtils.toInputStream(fieldData, StandardCharsets.UTF_8), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
}
// import suggest field:
final String suggestPath = fieldImportPath + '/' + TAGSUGGEST_FIELD;
if (!session.nodeExists(suggestPath)) {
final String suggestData = TemplateUtils.replaceStringPlaceholders(templateSuggest, templateData);
session.importXML(fieldImportPath, IOUtils.toInputStream(suggestData), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
session.importXML(fieldImportPath, IOUtils.toInputStream(suggestData, StandardCharsets.UTF_8), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
}
// import field translations
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment