1 7 8 package com.hp.hpl.jena.xmloutput.impl; 9 10 import com.hp.hpl.jena.rdf.model.*; 11 import com.hp.hpl.jena.vocabulary.*; 12 13 import java.io.*; 14 17 29 public class Abbreviated extends BaseXMLWriter implements RDFErrorHandler { 30 31 private Resource types[] = 32 new Resource[] { 33 DAML_OIL.Ontology, 34 OWL.Ontology, 35 DAML_OIL.Datatype, 36 RDFS.Datatype, 38 DAML_OIL.Class, 39 RDFS.Class, 40 OWL.Class, 41 DAML_OIL.Property, 42 OWL.ObjectProperty, 43 RDF.Property, 44 DAML_OIL.ObjectProperty, 45 OWL.DatatypeProperty, 46 DAML_OIL.DatatypeProperty, 47 OWL.TransitiveProperty, 48 OWL.SymmetricProperty, 49 OWL.FunctionalProperty, 50 OWL.InverseFunctionalProperty, 51 DAML_OIL.TransitiveProperty, 52 DAML_OIL.UnambiguousProperty, 53 DAML_OIL.UniqueProperty, 54 }; 55 56 boolean sReification; 57 58 59 boolean sIdAttr; 60 boolean sDamlCollection; 61 boolean sParseTypeCollectionPropertyElt; 62 boolean sListExpand; 63 boolean sParseTypeLiteralPropertyElt; 64 boolean sParseTypeResourcePropertyElt; 65 boolean sPropertyAttr; 66 67 68 boolean sResourcePropertyElt; 69 70 void unblockAll() { 71 sDamlCollection = false; 72 sReification = false; 73 sResourcePropertyElt = false; 74 sParseTypeLiteralPropertyElt = false; 75 sParseTypeResourcePropertyElt = false; 76 sParseTypeCollectionPropertyElt = false; 77 sIdAttr = false; 78 sPropertyAttr = false; 79 sListExpand = false; 80 } 81 { 82 unblockAll(); 83 blockRule(RDFSyntax.propertyAttr); 84 } 85 void blockRule(Resource r) { 86 if (r.equals(RDFSyntax.sectionReification)) sReification=true; 87 else if (r.equals(RDFSyntax.sectionListExpand)) sListExpand=true; 89 else if (r.equals(RDFSyntax.parseTypeLiteralPropertyElt)) sParseTypeLiteralPropertyElt=true; 90 else if (r.equals(RDFSyntax.parseTypeResourcePropertyElt)) sParseTypeResourcePropertyElt=true; 91 else if (r.equals(RDFSyntax.parseTypeCollectionPropertyElt)) sParseTypeCollectionPropertyElt=true; 92 else if (r.equals(RDFSyntax.idAttr)) { 93 sIdAttr=true; 94 sReification = true; 95 } 96 else if (r.equals(RDFSyntax.propertyAttr)) sPropertyAttr=true; 97 else if (r.equals(DAML_OIL.collection)) sDamlCollection=true; 98 else { 99 logger.warn("Cannot block rule <"+r.getURI()+">"); 100 } 101 } 102 Resource[] setTypes(Resource[] propValue) { 103 Resource[] rslt = types; 104 types = (Resource[]) propValue; 105 return rslt; 106 } 107 108 synchronized public void write(Model baseModel, Writer out, String base) 109 { 110 if (baseModel.getGraph().getCapabilities().findContractSafe() == false) 111 { 112 logger.warn( "Workaround for bugs 803804 and 858163: using RDF/XML (not RDF/XML-ABBREV) writer for unsafe graph " + baseModel.getGraph().getClass() ); 113 baseModel.write( out, "RDF/XML", base ); 114 } 115 else 116 super.write( baseModel, out, base ); 117 } 118 119 void writeBody( 120 Model model, 121 PrintWriter pw, 122 String base, 123 boolean useXMLBase) { 124 Unparser unp = new Unparser(this, base, model, pw); 125 126 unp.setTopLevelTypes(types); 127 if (useXMLBase) 129 unp.setXMLBase(base); 130 unp.write(); 131 } 132 133 public void error(Exception e) { 135 errorHandler.error(e); 136 } 137 138 public void warning(Exception e) { 139 errorHandler.warning(e); 140 } 141 142 public void fatalError(Exception e) { 143 errorHandler.fatalError(e); 144 } 145 146 static public void main(String args[]) throws Exception { 147 System.out.println("Test code for bug 77"); 148 Model m = new com.hp.hpl.jena.mem.ModelMem(); 149 m.read( 150 new FileInputStream("modules/rdf/regression/arp/bug51_0.rdf"), 151 "http://example.org/file"); 152 RDFWriter pw = m.getWriter("RDF/XML-ABBREV"); 153 m.setNsPrefix("eg", "http://example.org/"); 154 m.setNsPrefix("eg2", "http://example.org/foo#"); 155 pw.write(m, System.out, "http://example.org/file"); 156 } 157 158 } 159 188 | Popular Tags |