Skip to content

Fix multilang wysiwyg #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
<groupId>com.silverpeas.builder</groupId>
<artifactId>configuration</artifactId>
<packaging>jar</packaging>
<version>5.12</version>
<version>5.12.1-SNAPSHOT</version>
<name>Silverpeas Configuration Tools - ${project.version}</name>

<scm>
Original file line number Diff line number Diff line change
@@ -64,15 +64,16 @@ public class ComponentAttachmentMigrator implements Callable<Long> {
+ "attachmentcontext, attachmentforeignkey, instanceid, attachmentcreationdate, "
+ "attachmentauthor, attachmenttitle, attachmentinfo, attachmentordernum, workerid, cloneid, "
+ "lang , reservationdate, alertdate, expirydate, xmlform FROM sb_attachment_attachment "
+ "WHERE instanceid = ? ORDER BY attachmentforeignkey, attachmentordernum";
+ "WHERE instanceid = ? ORDER BY attachmentforeignkey, attachmentphysicalname, attachmentordernum";
public static final String SELECT_ATTACHMENT_TRANSLATION = "SELECT id, attachmentid, lang, "
+ "attachmentphysicalname, attachmentlogicalname, attachmenttype, attachmentsize, "
+ "instanceid, attachmentcreationdate, attachmentauthor, attachmenttitle, attachmentinfo, "
+ "xmlform FROM sb_attachment_attachmenti18n WHERE attachmentid = ? ORDER BY lang";
public static final String DELETE_ATTACHMENT_TRANSLATIONS = "DELETE FROM sb_attachment_attachmenti18n "
public static final String DELETE_ATTACHMENT_TRANSLATIONS
= "DELETE FROM sb_attachment_attachmenti18n "
+ "WHERE attachmentid = ?";
public static final String DELETE_ATTACHMENT =
"DELETE FROM sb_attachment_attachment WHERE attachmentid = ?";
public static final String DELETE_ATTACHMENT
= "DELETE FROM sb_attachment_attachment WHERE attachmentid = ?";
private final String componentId;
private final AttachmentService service;
private final Console console;
@@ -113,7 +114,8 @@ protected long migrateComponent() throws SQLException, ParseException, IOExcepti
DateUtil.parse(rs.getString("reservationdate")),
DateUtil.parse(rs.getString("alertdate")), DateUtil.parse(rs.getString("expirydate")),
rs.getString("attachmentdescription"), attachment);
document.setDocumentType(DocumentType.fromOldContext(instanceId, rs.getString("attachmentcontext")));
document.setDocumentType(DocumentType.fromOldContext(instanceId, rs.getString(
"attachmentcontext")));
document.setUpdated(document.getCreated());
document.setUpdatedBy(author);
File file = getAttachmenFile(rs.getString("instanceid"), rs.getString("attachmentcontext"),
@@ -134,7 +136,7 @@ protected long migrateComponent() throws SQLException, ParseException, IOExcepti
}

protected Set<File> createTranslations(SimpleDocument document, String context) throws
SQLException,ParseException, IOException {
SQLException, ParseException, IOException {
Set<File> files = new HashSet<File>(5);
PreparedStatement pstmt = null;
ResultSet rs = null;
@@ -155,12 +157,17 @@ protected Set<File> createTranslations(SimpleDocument document, String context)
if (!StringUtil.isDefined(author)) {
author = "0";
}
String language = rs.getString("lang");
if (!StringUtil.isDefined(language)) {
language = ConverterUtil.extractLanguage(rs.getString("attachmentlogicalname"));
}
language = ConverterUtil.checkLanguage(language);
SimpleAttachment attachment = new SimpleAttachment(rs.getString("attachmentlogicalname"),
ConverterUtil.checkLanguage(rs.getString("lang")), rs.getString("attachmenttitle"),
rs.getString("attachmentinfo"), rs.getLong("attachmentsize"), contentType, author,
DateUtil.parse(rs.getString("attachmentcreationdate")), rs.getString("xmlform"));
language, rs.getString("attachmenttitle"), rs.getString("attachmentinfo"),
rs.getLong("attachmentsize"), contentType, author, DateUtil.parse(rs.getString(
"attachmentcreationdate")), rs.getString("xmlform"));
document.setFile(attachment);
document.setUpdated(attachment.getCreated());
document.setUpdated(attachment.getCreated());
document.setUpdatedBy(author);
File file = getAttachmenFile(rs.getString("instanceid"), context, rs.getString(
"attachmentphysicalname"));
@@ -239,7 +246,7 @@ protected void cleanAll(long oldSilverpeasId, Set<File> files) throws SQLExcepti
deleteAttachment = connection.prepareStatement(DELETE_ATTACHMENT);
deleteAttachment.setLong(1, oldSilverpeasId);
deleteAttachment.executeUpdate();
for (File file : files) {
for (File file : files) {
ConverterUtil.deleteFile(file);
}
connection.commit();
Original file line number Diff line number Diff line change
@@ -162,19 +162,51 @@ public SimpleDocument findExistingDocument(SimpleDocumentPK pk, String fileName,
* Shutdowns the repository.
*/
public void shutdown();

/**
* Delete a given attachment.
*
* @param document the document to deleted.
*/
* Delete a given attachment.
*
* @param document the document to deleted.
*/
void deleteAttachment(SimpleDocument document);

/**
* Find document image, and move to Attachment context
*
* @param primaryKey the primary key of the document.
* @param console to print message.
/**
* Find document image, and move to Attachment context
*
* @param primaryKey the primary key of the document.
* @param console to print message.
*/
public void moveImageContext(SimpleDocumentPK primaryKey, Console console);

/**
* Find all components that contains wysiwyg.
*
* @return list all component ids with wysiwyg.
*/
public List<String> listComponentIdsWithWysiwyg();

/**
* Find all basenames for wysiwyg content.
*
* @param instanceId the component containing the wysiwyg.
* @return list all the wysiwyg basenames.
*/
public List<String> listBasenames(String instanceId);

/**
* Merge the documents into the document.
*
* @param source the document into which the document will be merged.
* @param toMerge the documents to merge.
* @return the merged document.
*/
public SimpleDocument mergeDocument(SimpleDocument source, SimpleDocument toMerge);

/**
*
* @param basename
* @param instanceId
* @return
*/
public List<SimpleDocument> listWysiwygForBasename(String basename, String instanceId);
}
Original file line number Diff line number Diff line change
@@ -33,6 +33,12 @@
import java.util.Date;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.silverpeas.dbbuilder.sql.ConnectionFactory;
import org.silverpeas.util.DateUtil;
import org.silverpeas.util.StringUtil;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.io.FileUtils;
@@ -41,19 +47,36 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.silverpeas.dbbuilder.sql.ConnectionFactory;
import org.silverpeas.util.DateUtil;
import org.silverpeas.util.StringUtil;

/**
* Utility class for path and date conversions between JCR and Slverpeas Pojo.
*
* @author Emmanuel Hugonnet
* @version $revision$
*/
public class ConverterUtil {

private static final Logger logger = LoggerFactory.getLogger(ConverterUtil.class);
public static String defaultLanguage = "fr";
public static final String defaultLanguage = "fr";
private static final Pattern WysiwygLangPattern = Pattern
.compile("[0-9]+wysiwyg_([a-z][a-z])\\.txt");
private static final Pattern WysiwygBaseNamePattern = Pattern.compile(
"([0-9]+wysiwyg).*\\.txt");

public static String extractLanguage(String filename) {
Matcher matcher = WysiwygLangPattern.matcher(filename);
if (matcher.matches()) {
return matcher.group(1);
}
return null;
}

public static String extractBaseName(String filename) {
Matcher matcher = WysiwygBaseNamePattern.matcher(filename);
if (matcher.matches()) {
return matcher.group(1);
}
return null;
}

public static String checkLanguage(String language) {
String lang = language;
@@ -76,6 +99,7 @@ public static String checkLanguage(String language) {

/**
* Encodes the JCR path to a Xpath compatible path.
*
* @param path the JCR path to be encoded for Xpath.
* @return the corresponding xpath.
*/
@@ -85,6 +109,7 @@ public static final String encodeJcrPath(String path) {

/**
* Replace all whitespace to SPACE_TOKEN.
*
* @param name the String o be converted.
* @return the resulting String.
*/
@@ -109,6 +134,7 @@ public static String escapeIllegalJcrChars(String name) {

/**
* Replace all %39 with the char'
*
* @param text
* @return a String with all %39 replaced by quotes
*/
@@ -118,6 +144,7 @@ public static String unescapeQuote(String text) {

/**
* Replace all SPACE_TOKEN to whitespace.
*
* @param name the String o be converted.
* @return the resulting String.
*/
@@ -127,6 +154,7 @@ public static String convertFromJcrPath(String name) {

/**
* Parse a String of format yyyy/MM/dd and return the corresponding Date.
*
* @param date the String to be parsed.
* @return the corresponding date.
* @throws ParseException
@@ -137,6 +165,7 @@ public static Date parseDate(String date) throws ParseException {

/**
* Format a Date to a String of format yyyy/MM/dd.
*
* @param date the date to be formatted.
* @return the formatted String.
*/
@@ -146,6 +175,7 @@ public static String formatDate(Date date) {

/**
* Format a Calendar to a String of format yyyy/MM/dd.
*
* @param calend the date to be formatted.
* @return the formatted String.
*/
@@ -156,6 +186,7 @@ public static String formatDate(Calendar calend) {
/**
* Parse a String of format HH:mm and set the corresponding hours and minutes to the specified
* Calendar.
*
* @param time the String to be parsed.
* @param calend the calendar to be updated.
*/
@@ -165,6 +196,7 @@ public static void setTime(Calendar calend, String time) {

/**
* Format a Date to a String of format HH:mm.
*
* @param date the date to be formatted.
* @return the formatted String.
*/
@@ -174,6 +206,7 @@ public static String formatTime(Date date) {

/**
* Format a Calendar to a String of format HH:mm.
*
* @param calend the date to be formatted.
* @return the formatted String.
*/
@@ -322,11 +355,11 @@ private static int getMaxFromTable(Connection con, String tableName, String idNa
DbUtils.closeQuietly(prepStmt);
}
}

public static void deleteFile(File file) {
File parent = file.getParentFile();
FileUtils.deleteQuietly(file);
if(parent.isDirectory() && parent.list().length == 0) {
if (parent.isDirectory() && parent.list().length == 0) {
FileUtils.deleteQuietly(parent);
}
}
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@
import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
import javax.jcr.nodetype.NodeTypeExistsException;

import org.silverpeas.util.SilverpeasHomeResolver;

import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.api.JackrabbitRepository;
@@ -47,8 +49,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.silverpeas.util.SilverpeasHomeResolver;

/**
* @author ehugonnet
*/
@@ -107,8 +107,7 @@ private final void initRepository(String repositoryHome, String conf) throws Rep
}

public Session getSession() throws RepositoryException {
return repository.
login(new SimpleCredentials("admin", "admin".toCharArray())/* new SilverpeasSystemCredentials() */);
return repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
}

public void logout(Session session) {
Loading
Oops, something went wrong.