Source code: com/sonoma/RDFContent.java
1 package com.sonoma;
2 import java.io.FileInputStream;
3 import java.io.ByteArrayInputStream;
4
5
6 import java.io.FileInputStream;
7 import java.util.Vector;
8 import java.util.Date;
9
10 import java.io.FileNotFoundException;
11 import org.apache.xerces.parsers.DOMParser;
12 import org.w3c.dom.Document;
13 import org.w3c.dom.Node;
14 import org.w3c.dom.Element;
15 import org.w3c.dom.NamedNodeMap;
16 import org.w3c.dom.NodeList;
17 import org.xml.sax.SAXException;
18 import org.xml.sax.InputSource;
19
20 /**
21 * Creates RDF type of nodes (item nodes) and attributes for topics and calendar xml files.
22 * Other classes and JSP pages use this object instead of Xerces or XML.
23 * dbRDF.java
24 * @author Roy Hoobler
25 * @version 1.1 04/7/2002
26 */
27 public class RDFContent extends Object {
28
29 /** Creates new dbRDF */
30 public RDFContent() {
31 }
32 /** Creates new Article Node for Topics.xml file
33 *@param sFileName full path to the topics.xml file
34 *@param art is a Sonoma object representing a DocBook article and a collection of paragraphs
35 */
36 public Document createArticle(String sFileName, com.sonoma.objects.dbNewArticle art){
37 XMLUtility mfXML = new XMLUtility();
38 Document doc;
39 Node xmlNode;
40 Node newNode;
41 Node ndTitle;
42 Node ndLink;
43 Node ndDescription;
44 try{
45 doc = mfXML.loadDoc(sFileName);
46 xmlNode = doc.getDocumentElement();
47 if (xmlNode==null){
48 System.out.println("xmlNode is null");
49 return null;
50 }
51 newNode = doc.createElement("item");
52 ndTitle = mfXML.createTextElement(doc,"title",art.getTitle());
53 newNode.appendChild(ndTitle);
54 ndLink = mfXML.createTextElement(doc,"link",art.getURL());
55 newNode.appendChild(ndLink);
56 ndDescription = mfXML.createTextElement(doc,"description",art.getDescription());
57 newNode.appendChild(ndDescription);
58 setRDFAttributes(newNode,art.getDay(),art.getMonth(),art.getYear(),art.getTime(),art.getTimePart(),art.getGroup());
59 xmlNode.appendChild(newNode);
60 return doc;
61 }catch(Exception e){
62 e.printStackTrace();
63 return null;
64 }
65 }
66 /** Sets attributes for Item nodes in Topics.xml file */
67 private boolean setRDFAttributes(Node ndItem,String day, String month, String year, String time, String timePart, String about){
68 Element el = (Element) ndItem;
69 el.setAttribute("day",day);
70 el.setAttribute("month",month);
71 el.setAttribute("year",year);
72 el.setAttribute("time",time);
73 el.setAttribute("part",timePart);
74 el.setAttribute("rdf:about",about);
75 el.setAttribute("rdf:id",String.valueOf(new Date().getTime()));
76 return true;
77 }
78
79 }