source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/Helpers.java @ 3395

Last change on this file since 3395 was 3395, checked in by olhsha, 11 years ago

refactored DAO-s and creating an annotation in rest. Still 2 failures and 3 errors.

File size: 2.2 KB
Line 
1/*
2 * Copyright (C) 2013 DASISH
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18package eu.dasish.annotation.backend;
19
20import eu.dasish.annotation.schema.AnnotationBody;
21import java.sql.Timestamp;
22import java.util.GregorianCalendar;
23import java.util.Map;
24import javax.xml.datatype.DatatypeConfigurationException;
25import javax.xml.datatype.DatatypeFactory;
26import javax.xml.datatype.XMLGregorianCalendar;
27
28/**
29 *
30 * @author olhsha
31 */
32public class Helpers {
33
34    public static XMLGregorianCalendar setXMLGregorianCalendar(Timestamp timeStamp) throws DatatypeConfigurationException {
35            GregorianCalendar gc = new GregorianCalendar();
36            gc.setTime(timeStamp);
37            return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
38    }
39   
40       
41    // TODO: change when serialization mechanism for bodies is fixed
42    public static String serializeBody(AnnotationBody body) {
43        return body.getAny().get(0).toString();
44    }
45
46    // TODO: change when serialization mechanism for bodies is fixed
47    public static AnnotationBody deserializeBody(String bodyXml) {
48        AnnotationBody result = new AnnotationBody();
49        result.getAny().add(bodyXml);
50        return result;
51    }
52   
53     
54    public static String replace(String text, Map<String, String> pairs) {
55        String result = (new StringBuilder(text)).toString();
56        for (String tempSource : pairs.keySet()) {
57            result = result.replaceAll(tempSource, pairs.get(tempSource));
58        }
59        return result;
60    }
61   
62}
Note: See TracBrowser for help on using the repository browser.