- Timestamp:
- Mar 29, 2011, 8:21:25 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo-ws-api/src/main/java/fr/mael/jiwigo/transverse/util/Tools.java
r9902 r9919 40 40 import org.apache.sanselan.formats.jpeg.iptc.PhotoshopApp13Data; 41 41 import org.apache.sanselan.formats.tiff.write.TiffOutputSet; 42 import org.slf4j.Logger; 43 import org.slf4j.LoggerFactory; 42 44 import org.w3c.dom.Document; 43 45 import org.w3c.dom.Element; … … 46 48 import org.xml.sax.SAXException; 47 49 50 import fr.mael.jiwigo.service.impl.CategoryServiceImpl; 48 51 import fr.mael.jiwigo.transverse.exception.FileAlreadyExistsException; 49 52 … … 68 71 * Logger 69 72 */ 70 p ublic 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); 71 74 72 75 /** … … 97 100 public static Document stringToDocument(String xmlSource) throws SAXException, ParserConfigurationException, 98 101 IOException { 102 LOG.debug(xmlSource); 99 103 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 100 104 DocumentBuilder builder = factory.newDocumentBuilder(); … … 327 331 } 328 332 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 */ 329 351 public static String getStringValueDom(Element element, String tagName) { 330 352 Element el = (Element) element.getElementsByTagName(tagName).item(0); 331 353 return el.getFirstChild().getNodeValue(); 332 354 } 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 } 333 385 }
Note: See TracChangeset
for help on using the changeset viewer.