Skip to content
Snippets Groups Projects
Commit 9720e5a6 authored by Arnaud Jelmoni's avatar Arnaud Jelmoni
Browse files

Common StringFormater

parent 3742a9bc
No related branches found
No related tags found
No related merge requests found
......@@ -743,6 +743,9 @@ public class SnapManagerApi {
public static SnapAttributeExtract[] getSnapValues(final int idSnap, final String... attributeNames)
throws SnapshotingException {
if (snapDataBase == null) {
throw new SnapshotingException(DATA_BASE_API_NOT_INIT);
}
final SnapAttributeExtract[] conf = snapDataBase.getAttributeConfig(attributeNames);
snapDataBase.getSnapResults(Arrays.asList(conf), idSnap);
return conf;
......
/*
* Synchrotron Soleil
*
* File : StringFormater.java
*
* Project : apiDev
*
* Description :
*
* Author : SOLEIL
*
* Original : 28 févr. 2006
*
* Revision: Author:
* Date: State:
*
* Log: StringFormater.java,v
*/
package fr.soleil.archiving.snap.api.tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StringFormater {
final static Logger logger = LoggerFactory.getLogger(StringFormater.class);
// Special characters
private final static String[] protect = { "[", "]", ",", ";", "'", "\"", "~", "\n" };
// Associated code : in fact, the corresponding xml code number (ISO 8859/1)
private final static String[] code = { "91", "93", "44", "59", "39", "34", "126", "10" };
// transforms #code# -> corresponding character
public static String formatStringToRead(String toFormat) {
String result;
if (toFormat != null) {
result = toFormat;
for (int i = 0; i < code.length; i++) {
result = result.replaceAll("#" + code[i] + "#", protect[i]);
}
} else {
result = "";
}
return result;
}
// transforms character -> corresponding #code#
public static String formatStringToWrite(String toFormat) {
String result;
if (toFormat != null) {
result = toFormat;
for (int i = 0; i < protect.length; i++) {
result = result.replaceAll("\\" + protect[i], "#" + code[i] + "#");
}
} else {
result = "";
}
return result;
}
public static void main(String[] args) {
String toto1 = "toto \n toto";
String toto2 = formatStringToWrite(toto1);
String toto3 = formatStringToRead(toto2);
logger.debug("toto1 = |" + toto1 + "|");
logger.debug("toto2 = |" + toto2 + "|");
logger.debug("toto3 = |" + toto3 + "|");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment