Ignore:
Timestamp:
Mar 29, 2011, 8:21:25 PM (13 years ago)
Author:
mlg
Message:

Complete rewriting of the api
The api now uses interfaces everywhere (for the dao, services and session manager). This allows the developer to use his own implementations if he wants.
Deletion of the singletons. There are now getters and setters. It allows to make dependency injection.
Use of sl4j in the api, instead of using log4j.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java

    r9902 r9919  
    4040import org.apache.sanselan.formats.jpeg.iptc.PhotoshopApp13Data;
    4141import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
     42import org.slf4j.Logger;
     43import org.slf4j.LoggerFactory;
    4244import org.w3c.dom.Document;
    4345import org.w3c.dom.Element;
     
    4648import org.xml.sax.SAXException;
    4749
     50import fr.mael.jiwigo.service.impl.CategoryServiceImpl;
    4851import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException;
    4952
     
    6871     * Logger
    6972     */
    70     public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(Tools.class);
     73    private static final Logger LOG = LoggerFactory.getLogger(CategoryServiceImpl.class);
    7174
    7275    /**
     
    97100    public static Document stringToDocument(String xmlSource) throws SAXException, ParserConfigurationException,
    98101            IOException {
     102        LOG.debug(xmlSource);
    99103        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    100104        DocumentBuilder builder = factory.newDocumentBuilder();
     
    327331    }
    328332
     333    public static Document readFileAsDocument(String filePath) {
     334        Document doc = null;
     335        try {
     336            DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
     337            DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
     338            doc = docBuilder.parse(filePath);
     339        } catch (Exception e) {
     340            LOG.error("Error converting file to Document : " + getStackTrace(e));
     341        }
     342        return doc;
     343    }
     344
     345    /**
     346     * Gets the value of a document node
     347     * @param element
     348     * @param tagName
     349     * @return
     350     */
    329351    public static String getStringValueDom(Element element, String tagName) {
    330352        Element el = (Element) element.getElementsByTagName(tagName).item(0);
    331353        return el.getFirstChild().getNodeValue();
    332354    }
     355
     356    /**
     357     * Sets the value of a document node
     358     * @param element
     359     * @param tagName
     360     * @param value
     361     */
     362    public static void setStringValueDom(Element element, String tagName, String value) {
     363        Element el = (Element) element.getElementsByTagName(tagName).item(0);
     364        el.setNodeValue(value);
     365    }
     366
     367    /**
     368     * Write an xml document to a file
     369     * @param doc document to write
     370     * @param filename file where to write the document
     371     */
     372    public static void writeXmlFile(Document doc, String filename) {
     373        try {
     374            Source source = new DOMSource(doc);
     375            File file = new File(filename);
     376            Result result = new StreamResult(file);
     377            Transformer xformer = TransformerFactory.newInstance().newTransformer();
     378            xformer.transform(source, result);
     379        } catch (TransformerConfigurationException e) {
     380            LOG.error(getStackTrace(e));
     381        } catch (TransformerException e) {
     382            LOG.error(getStackTrace(e));
     383        }
     384    }
    333385}
Note: See TracChangeset for help on using the changeset viewer.