List of usage examples for org.xml.sax SAXException getMessage
public String getMessage()
From source file:org.xchain.framework.util.AttributesUtil.java
public static void validateAttributeValueTemplate(String attributeValueTemplate, NamespaceContext namespaceContext) throws JXPathException { List<String> parsedAvt = null; try {/* ww w . ja va 2 s.c o m*/ parsedAvt = parseAttributeValueTemplate(attributeValueTemplate); } catch (SAXException saxe) { throw new JXPathException(saxe.getMessage()); } // validate the xpaths nested in the attribute value template. for (int i = 1; i < parsedAvt.size(); i += 2) { JXPathValidator.validate(parsedAvt.get(i), namespaceContext); } }
From source file:se.skl.skltpservices.npoadapter.mapper.AbstractMapper.java
protected void initialiseValidator(String... xsds) { List<Source> schemaFiles = new ArrayList<Source>(); for (String xsd : xsds) { schemaFiles.add(new StreamSource(getClass().getResourceAsStream(xsd))); }/*from w w w. j av a 2 s.com*/ // Note - SchemaFactory is not threadsafe SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { // Note - Schema is threadsafe schema = factory.newSchema(schemaFiles.toArray(new StreamSource[schemaFiles.size()])); } catch (SAXException s) { throw new RuntimeException( new InstantiationException("Failed to instantiate schema: " + s.getMessage())); } }
From source file:se.skl.skltpservices.npoadapter.mapper.AbstractMapper.java
protected void validateXmlAgainstSchema(String xml, Logger log) { if (schemaValidationActivated) { if (StringUtils.isBlank(xml)) { log.error("Attempted to validate empty string"); } else {/*from www . ja v a 2s . c o m*/ try { // Validator is not threadsafe - create new one for each invocation Validator validator = schema.newValidator(); validator.validate(new StreamSource(new StringReader(xml))); log.debug("response passed schema validation"); } catch (SAXException e) { log.error("response failed schema validation: " + e.getMessage()); log.debug(xml); } catch (IOException e) { throw new RuntimeException("Unexpected exception whilst validating xml against schema", e); } catch (Exception e) { log.error("response failed schema validation - unexpected error " + e.getMessage(), e); } } } }
From source file:sos.insert.InsertObservation.java
/** check observations format and insert observations in sos server * /*w w w.j a va2 s. c o m*/ * @param snannySostServerConfig the sos server configuration * @param contentPost the content post with one or more observations * @param response Http Servlet response * @param out PrintWriter for Http Servlet Response * @param sampleBean * @throws SnannySostServerException if insertion failed */ public synchronized void insert(SnannySostServerConfig snannySostServerConfig, String contentPost, HttpServletResponse response, PrintWriter out) throws SnannySostServerException { Uuids uuids; insertObservation.reset(); try { InputSource is = new InputSource(new StringReader(contentPost)); postParser.parse(is, insertObservation); } catch (SAXException ex) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_PARSE_INSERT, Status.BAD_REQUEST); } catch (IOException ex) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_IO_INSERT, Status.SERVICE_UNAVAILABLE); } for (String oem : oems) { // validate xml SosValidation.singleton(snannySostServerConfig).xsdValidateOem(oem); SosValidation.singleton(snannySostServerConfig).schematronValidateOem(oem); uuids = SensorMLOemUuid.singleton().getUuids(oem); if (snannySostServerConfig.isCouchbase()) { try { JsonObject jsonObject = JsonObject.empty(); if (snannySostServerConfig.isJsonObject()) { jsonObject.put(SnannySostServerConfig.FilejsonField, jsonTranscoder.stringToJsonObject(JSONML.toJSONObject(oem).toString())); } else { jsonObject.put(SnannySostServerConfig.FilejsonField, jsonArrayTranscoder.stringToJsonArray(JSONML.toJSONArray(oem).toString())); } jsonObject.put(SnannySostServerConfig.AuthorNameField, SnannySostServerConfig.AuthorNameValue); CouchbaseManager.getObservationBucket().upsert( JsonDocument.create(uuids.getOeMuuid(), jsonObject), snannySostServerConfig.getCouchbaseTimeOutMS(), TimeUnit.MILLISECONDS); Sos.SAMPLE_OBSERVATION_UUID = uuids.getOeMuuid(); } catch (Exception ex) { throw new SnannySostServerException( SnannySostServerMessages.ERROR_COUCHBASE_ERROR + ex.getMessage(), Status.SERVICE_UNAVAILABLE); } } else { // write xml try { File dir = snannySostServerConfig.newSensorMlDir(uuids); if (!dir.isDirectory()) { dir.mkdir(); } OutputStreamWriter outputStreamWriter = new OutputStreamWriter( new FileOutputStream(snannySostServerConfig.newOemFile(uuids)), snannySostServerConfig.getCharset()); outputStreamWriter.write(oem); outputStreamWriter.close(); } catch (IOException ex) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_STORE_INSERT, Status.SERVICE_UNAVAILABLE); } } if (snannySostServerConfig.isCouchbase()) { Success.submit(uuids.getOeMuuid() + SnannySostServerMessages.IMPORT_OBSERVATION_OK_3of3, response, out, snannySostServerConfig); } else { Success.submit( SnannySostServerMessages.IMPORT_OBSERVATION_OK_1of3 + uuids.getSensorMLuuid() + SnannySostServerMessages.IMPORT_OBSERVATION_OK_2of3 + uuids.getOeMuuid() + SnannySostServerMessages.IMPORT_OBSERVATION_OK_3of3, response, out, snannySostServerConfig); } } }
From source file:sos.insert.InsertSensor.java
/** Check format, convert from JSON to XML as needed, insert sensor in sos server * /* w w w. j av a 2 s . c om*/ * @param snannySostServerConfig the sos server configuration * @param contentPost the content post with sensor in JSON or XML format * @param response Http Servlet response * @param out PrintWriter for Http Servlet Response * @param sampleBean * @throws SnannySostServerException if insertion failed */ public synchronized void insert(SnannySostServerConfig snannySostServerConfig, String contentPost, HttpServletResponse response, PrintWriter out) throws SnannySostServerException { String uuid = ""; insertSensor.reset(); // parse post content try { InputSource is = new InputSource(new StringReader(contentPost)); postParser.parse(is, insertSensor); } catch (SAXException ex) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_PARSE_INSERT, Status.BAD_REQUEST); } catch (IOException ex) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_IO_INSERT, Status.SERVICE_UNAVAILABLE); } // if json content convert it to xml if (format.isEmpty()) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_POST_FORMAT_REQUIRED + SosFormat.getAvailableSosResponseFormats(), Status.BAD_REQUEST); } SOSFORMAT sosformat = SosFormat.getFormat(format); try { switch (sosformat) { case JSON: if (snannySostServerConfig.isJsonObject()) { JSONObject jSONOject = new JSONObject(StringEscapeUtils.unescapeXml(sensorML)); sensorML = JSONML.toString(jSONOject); } else { JSONArray jsonArray = new JSONArray(StringEscapeUtils.unescapeXml(sensorML)); sensorML = JSONML.toString(jsonArray); } break; case XML: break; } } catch (Exception ex) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_JSON_INSERT + ex.getMessage(), Status.BAD_REQUEST); } // validate xml SosValidation.singleton(snannySostServerConfig).xsdValidateSensorMl(sensorML); SosValidation.singleton(snannySostServerConfig).schematronValidateSensorMl(sensorML); uuid = SensorMlUuid.singleton().getUuid(sensorML); if (snannySostServerConfig.isCouchbase()) { try { JsonObject jsonObject = JsonObject.empty(); if (snannySostServerConfig.isJsonObject()) { jsonObject.put(SnannySostServerConfig.FilejsonField, jsonTranscoder.stringToJsonObject(JSONML.toJSONObject(sensorML).toString())); } else { jsonObject.put(SnannySostServerConfig.FilejsonField, jsonArrayTranscoder.stringToJsonArray(JSONML.toJSONArray(sensorML).toString())); } jsonObject.put(SnannySostServerConfig.AuthorNameField, SnannySostServerConfig.AuthorNameValue); CouchbaseManager.getSystemBucket().upsert(JsonDocument.create(uuid, jsonObject), snannySostServerConfig.getCouchbaseTimeOutMS(), TimeUnit.MILLISECONDS); Sos.SAMPLE_SYSTEM_UUID = uuid; } catch (Exception ex) { throw new SnannySostServerException( SnannySostServerMessages.ERROR_COUCHBASE_ERROR + ex.getMessage(), Status.SERVICE_UNAVAILABLE); } } else { // write xml try { OutputStreamWriter outputStreamWriter = new OutputStreamWriter( new FileOutputStream(snannySostServerConfig.newSensorMlFile(uuid)), snannySostServerConfig.getCharset()); outputStreamWriter.write(sensorML); outputStreamWriter.close(); } catch (IOException ex) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_STORE_INSERT, Status.SERVICE_UNAVAILABLE); } } Success.submit(SnannySostServerMessages.IMPORT_SENSOR_OK_1of2 + uuid + SnannySostServerMessages.IMPORT_SENSOR_OK_2of2, response, out, snannySostServerConfig); }
From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.XSLTEntityHandler.java
/** * Serialises the rendered content of the RWiki Object to SAX * /*from w ww .ja v a 2 s . c o m*/ * @param rwo * @param ch * @param withBreadCrumb */ public void renderToXML(RWikiObject rwo, final ContentHandler ch, boolean withBreadCrumb, boolean escapeXML) throws SAXException, IOException { String renderedPage; try { renderedPage = render(rwo, withBreadCrumb); } catch (Exception e) { renderedPage = Messages.getString("XSLTEntityHandler.32") + rwo.getName() //$NON-NLS-1$ + Messages.getString("XSLTEntityHandler.33") + e.getClass() //$NON-NLS-1$ + Messages.getString("XSLTEntityHandler.34") + e.getMessage(); //$NON-NLS-1$ log.info(renderedPage, e); } String contentDigest = DigestHtml.digest(renderedPage); if (contentDigest.length() > 500) { contentDigest = contentDigest.substring(0, 500); } if (renderedPage == null || renderedPage.trim().length() == 0) { renderedPage = Messages.getString("XSLTEntityHandler.35"); //$NON-NLS-1$ } if (contentDigest == null || contentDigest.trim().length() == 0) { contentDigest = Messages.getString("XSLTEntityHandler.36"); //$NON-NLS-1$ } String cdataEscapedRendered = renderedPage.replaceAll("]]>", "]]>]]><![CDATA["); //$NON-NLS-1$ //$NON-NLS-2$ String cdataContentDigest = contentDigest.replaceAll("]]>", "]]>]]><![CDATA["); //$NON-NLS-1$ //$NON-NLS-2$ /* http://jira.sakaiproject.org/browse/SAK-13281 * ensure all page content is escaped or double escaped before it goes into the parser, * if this is not done then the parser will unescape html entities during processing */ renderedPage = "<content><rendered>" //$NON-NLS-1$ + (escapeXML ? StringEscapeUtils.escapeXml(renderedPage) : renderedPage) + "</rendered><rendered-cdata><![CDATA[" + cdataEscapedRendered //$NON-NLS-1$ + "]]></rendered-cdata><contentdigest><![CDATA[" + cdataContentDigest //$NON-NLS-1$ + "]]></contentdigest></content>"; //$NON-NLS-1$ try { parseToSAX(renderedPage, ch); } catch (SAXException ex) { SimpleCoverage.cover("Failed to parse renderedPage from " + rwo.getName()); //$NON-NLS-1$ Attributes dummyAttributes = new AttributesImpl(); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERROR, SchemaNames.EL_NSERROR, dummyAttributes); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERRORDESC, SchemaNames.EL_NSERRORDESC, dummyAttributes); String s = Messages.getString("XSLTEntityHandler.46") //$NON-NLS-1$ + ex.getMessage(); ch.characters(s.toCharArray(), 0, s.length()); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERRORDESC, SchemaNames.EL_NSERRORDESC); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RAWCONTENT, SchemaNames.EL_NSRAWCONTENT, dummyAttributes); ch.characters(renderedPage.toCharArray(), 0, renderedPage.length()); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RAWCONTENT, SchemaNames.EL_NSRAWCONTENT); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERROR, SchemaNames.EL_NSERROR); } // SimpleCoverage.cover("Failed to parse ::\n" + renderedPage // + "\n:: from ::\n" + rwo.getContent()); // Attributes dummyAttributes = new AttributesImpl(); // ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERROR, // SchemaNames.EL_NSERROR, dummyAttributes); // ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERRORDESC, // SchemaNames.EL_NSERRORDESC, dummyAttributes); // String s = "The Rendered Content did not parse correctly " // + ex.getMessage(); // ch.characters(s.toCharArray(), 0, s.length()); // ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERRORDESC, // SchemaNames.EL_NSERRORDESC); // ch.startElement(SchemaNames.NS_CONTAINER, // SchemaNames.EL_RAWCONTENT, SchemaNames.EL_NSRAWCONTENT, // dummyAttributes); // ch.characters(renderedPage.toCharArray(), 0, renderedPage.length()); // ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RAWCONTENT, // SchemaNames.EL_NSRAWCONTENT); // ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERROR, // SchemaNames.EL_NSERROR); }
From source file:uk.ac.ebi.bioinvindex.utils.datasourceload.DataSourceLoader.java
public void loadAll(InputStream inputStream) throws InvalidConfigurationException { ReferenceSource isaTabSource = null; Collection<AssayTypeDataLocation> locations = null; try {// ww w . j a va2 s.c o m DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(inputStream); // normalize text representation doc.getDocumentElement().normalize(); isaTabSource = parseISATabLocation(doc); locations = parseDataSources(doc); } catch (SAXParseException err) { throw new InvalidConfigurationException("Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId() + ":" + err.getMessage(), err); } catch (SAXException e) { throw new InvalidConfigurationException( "Invalid data file location configuration file:" + e.getMessage(), e); } catch (IOException e) { throw new InvalidConfigurationException( "Invalid data file location configuration file" + e.getMessage(), e); } catch (ParserConfigurationException e) { throw new InvalidConfigurationException( "Invalid data file location configuration file" + e.getMessage(), e); } persistLocations(isaTabSource, locations); }
From source file:validation.xslt.handler.XsltResultHandler.java
/** Extract errors from xml resulting of schematron validation via xslt. * // www.j a v a2 s . c om * @param xsltResult xml resulting of schematron validation via xslt * @return null if xml is schematron valid, errors elsewhere */ public synchronized String analyse(String xsltResult) { try { InputSource is = new InputSource(new StringReader(xsltResult)); xsltResultHandler.reset(); parser.parse(is, xsltResultHandler); } catch (SAXException ex) { if (ex.getMessage().compareTo(NORMAL_STATUS) == 0) { return (buffer.toString()); } throw new SnannySostServerException(SnannySostServerMessages.ERROR_PARSE_XSLT, Status.BAD_REQUEST); } catch (IOException ex) { throw new SnannySostServerException(SnannySostServerMessages.ERROR_IO_XSLT, Status.SERVICE_UNAVAILABLE); } return (null); }
From source file:velo.reconcilidation.SyncTargetImporter.java
public SyncTargetData getSyncedData() throws SyncListImporterException { Digester d = new Digester(); //URL url = getClass().getResource("/qflow_sync.xml"); //File f = new File(url.getFile()); try {/*from ww w.java 2 s . c o m*/ SyncTargetData tsList = new SyncTargetData(); d.push(tsList); addRules(d); d.parse(syncFile); /* for (resource currTs : tsList.getResources()) { System.out.println("Parsed resources short name: " + currTs.getShortName()); for (Account currAcc : currTs.getAccounts()) { System.out.println("Found account name: " + currAcc.getName()); Map<String,Attribute> attrs = currAcc.getAccountAttributes(); System.out.println("Size of account's attributes: " + attrs.size()); for (Map.Entry pairs : attrs.entrySet()) { Attribute currAttr = (Attribute)pairs.getValue(); try { System.out.println("Attr name: " + pairs.getKey() + ", value: " + currAttr.getValueObject().getStringValue()); } catch (MultipleAttributeValueVaiolation mvv) { mvv.printStackTrace(); } } } } */ return tsList; } catch (SAXException saxe) { throw new SyncListImporterException( "There was a SAX exception while trying to import the sync XML file, failed with message: " + saxe.getMessage()); } catch (IOException ioe) { throw new SyncListImporterException( "Cannot import sync list file, an IO exception has occured, failed with message: " + ioe.getMessage()); } }
From source file:xml2rdf.example.TestCustomized1.java
public static void main(String[] args) { SAXParserFactory factory = SAXParserFactory.newInstance(); MutableObject prefix1 = new MutableObject("aml"); MutableObject url = new MutableObject("https://github.com/igg777/automationml/blob/master/aml.ttl/#"); MutableObject prefix2 = new MutableObject("dc"); MutableObject url2 = new MutableObject("http://purl.org/dc/elements/1.1/"); MutableObject prefix3 = new MutableObject("schema"); MutableObject url3 = new MutableObject("http://schema.org/"); try {//from ww w . j av a2 s . c o m long SumTime = 0; int runTimes = 1; for (int i = 0; i < runTimes; ++i) { long startTime = System.currentTimeMillis(); SAXParser saxParser = factory.newSAXParser(); CustomizedSAXYFilterHandler handler = new CustomizedSAXYFilterHandler(); TemplateRDF template = new TemplateRDF(); // For STELL-I.rtml template.setDefaultNameSpace("http://example.org/"); // template.setNameSpaceMapping(prefix1, url); // template.setNameSpaceMapping(prefix2, url2); // template.setNameSpaceMapping(prefix3, url3); NameSpaceMapping aml = new NameSpaceMapping(prefix1.getValue().toString(), url.getValue().toString()); NameSpaceMapping dc = new NameSpaceMapping(prefix2.getValue().toString(), url2.getValue().toString()); NameSpaceMapping schema = new NameSpaceMapping(prefix3.getValue().toString(), url3.getValue().toString()); // NameSpaceMapping prefix1 = new NameSpaceMapping("aml","https://github.com/igg777/automationml/blob/master/aml.ttl"); // template.addTriplePattern("RTMLData", null, "type", null, "/RTML/Telescope/Camera/FilterWheel/Filter/@type", null); // template.addTriplePattern(prefix1,"/RTML/Telescope/Camera/FilterWheel/Filter/@type", null, prefix2,"FocalLength", null, null,"/RTML/Telescope/FocalLength/text()",XSDDatatype.XSDdouble); // template.addTriplePattern("/RTML/Telescope/Camera/FilterWheel/Filter/@type", null, "FocalLength", null, "/RTML/Telescope/FocalLength/text()",XSDDatatype.XSDdouble); //template.addTriplePattern(aml,"/RTML/Telescope/Camera/FilterWheel/Filter/@type", null, aml,"FocalLength", null,null, "/RTML/Telescope/FocalLength/text()",XSDDatatype.XSDdouble); //template.addTriplePattern(aml,"AdditionalInformation", null, aml,"hasWriterName", null, aml,"/CAEXFile/AdditionalInformation/WriterHeader/WriterName/text()",XSDDatatype.XSDstring); //CAEX file template.addTriplePattern(":CAEXFile", null, "aml:hasFileName", null, "/CAEXFile/@FileName", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile", null, "aml:hasSchemaVersion", null, "/CAEXFile/@SchemaVersion", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile", null, "aml:hasAdditionalInformation", null, ":CAEXFile/AdditionalInformation", null); template.addTriplePattern(":CAEXFile", null, "aml:hasExternalReference", null, ":CAEXFile/ExternalReference", null); template.addTriplePattern(":CAEXFile", null, "aml:hasInstanceHierarchy", null, ":CAEXFile/InstanceHierarchy", null); template.addTriplePattern(":CAEXFile", null, "aml:hasInterfaceClassLib", null, ":CAEXFile/InterfaceClassLib", null); template.addTriplePattern(":CAEXFile", null, "aml:hasRoleClassLib", null, ":CAEXFile/RoleClassLib", null); template.addTriplePattern(":CAEXFile", null, "aml:hasSystemUnitClassLib", null, ":CAEXFile/SystemUnitClassLib", null); //additional information template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasAutomationMLVersion", null, "/CAEXFile/AdditionalInformation/@AutomationMLVersion", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasWriterName", null, "/CAEXFile/AdditionalInformation/WriterHeader/WriterName/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasWriterId", null, "/CAEXFile/AdditionalInformation/WriterHeader/WriterID/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasWriterVendor", null, "/CAEXFile/AdditionalInformation/WriterHeader/WriterVendor/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasWriterURL", null, "/CAEXFile/AdditionalInformation/WriterHeader/WriterVendorURL/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasWriterVersion", null, "/CAEXFile/AdditionalInformation/WriterHeader/WriterVersion/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasWriterRelease", null, "/CAEXFile/AdditionalInformation/WriterHeader/WriterRelease/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:lastWritingDate", null, "/CAEXFile/AdditionalInformation/WriterHeader/LastWritingDateTime/text()", XSDDatatype.XSDdateTime); // hasProject(blank node?) template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasProjectID", null, "/CAEXFile/AdditionalInformation/WriterHeader/WriterProjectID/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/AdditionalInformation", null, "aml:hasProjectTitle", null, "/CAEXFile/AdditionalInformation/WriterHeader/WriterProjectTitle/text()", XSDDatatype.XSDstring); //ExternalReference template.addTriplePattern(":CAEXFile/ExternalReference", null, "aml:externalReferencePath", null, "/CAEXFile/ExternalReference/@Path", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/ExternalReference", null, "aml:externalReferenceAlias", null, "/CAEXFile/ExternalReference/@Alias", XSDDatatype.XSDstring); //InstanceHierarchy // template.addTriplePattern("/CAEXFile/InstanceHierarchy/InternalElement/@Name", null,"schema:name", null,"/CAEXFile/InstanceHierarchy/InternalElement/@ID",null);// smart interpretation example //InternalElement template.addTriplePattern(":CAEXFile/InstanceHierarchy", null, "aml:hasInternalElement", null, ":CAEXFile/InstanceHierarchy/InternalElement_1", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy", null, "aml:hasInternalElement", null, ":CAEXFile/InstanceHierarchy/InternalElement_2", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_2", null, "dc:identifier", null, "/CAEXFile/InstanceHierarchy/InternalElement[@Name='secondScrewdriver']/@ID", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1", null, "dc:identifier", null, "/CAEXFile/InstanceHierarchy/InternalElement[@Name='firstScrewdriver']/@ID", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_2", null, "schema:name", null, "/CAEXFile/InstanceHierarchy/InternalElement[@ID='{19dcf818-4716-4fc1-a85f-28e1938c4c3a}']/@Name", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1", null, "schema:name", null, "/CAEXFile/InstanceHierarchy/InternalElement[@ID='{788eb291-f103-4fdc-aba0-4893b599f556}']/@Name", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1", null, "aml:RefBaseSystemUnitPath", null, "/CAEXFile/InstanceHierarchy/InternalElement[@ID='{788eb291-f103-4fdc-aba0-4893b599f556}']/@RefBaseSystemUnitPath", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_2", null, "aml:RefBaseSystemUnitPath", null, "/CAEXFile/InstanceHierarchy/InternalElement[@ID='{19dcf818-4716-4fc1-a85f-28e1938c4c3a}']/@RefBaseSystemUnitPath", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1/ExternalInterface1", null, "schema:name", null, "/CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface[@ID='{5f535d4c-dd46-4c1c-898c-4e58419048b6}']/@Name", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_2/ExternalInterface2", null, "schema:name", null, "/CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface[@ID='50e10905-ac18-413c-afab-ad8ed1569fff']/@Name", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1/ExternalInterface1", null, "dc:identifier", null, "/CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface[@ID='{5f535d4c-dd46-4c1c-898c-4e58419048b6}']/@ID", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_2/ExternalInterface2", null, "dc:identifier", null, "/CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface[@ID='50e10905-ac18-413c-afab-ad8ed1569fff']/@ID", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1/ExternalInterface1", null, "aml:refBaseClassPath", null, "/CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface[@ID='{5f535d4c-dd46-4c1c-898c-4e58419048b6}']/@RefBaseClassPath", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_2/ExternalInterface2", null, "aml:refBaseClassPath", null, "/CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface[@ID='50e10905-ac18-413c-afab-ad8ed1569fff']/@RefBaseClassPath", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1/ExternalInterface1", null, "aml:supportedRoleClass", null, ":CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface/SupportedRoleClass1", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_2/ExternalInterface2", null, "aml:supportedRoleClass", null, ":CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface/SupportedRoleClass1", null); template.addTriplePattern( ":CAEXFile/InstanceHierarchy/InternalElement/ExternalInterface/SupportedRoleClass1", null, "aml:refRoleClassPath", null, "/CAEXFile/InstanceHierarchy/InternalElement/SupportedRoleClass/@RefRoleClassPath", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1", null, "aml:hasRoleRequeriment", null, ":CAEXFile/InstanceHierarchy/InternalElement/RoleRequirements_1", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_2", null, "aml:hasRoleRequeriment", null, ":CAEXFile/InstanceHierarchy/InternalElement/RoleRequirements_1", null); template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1", null, "aml:refBaseRoleClassPath", null, "/CAEXFile/InstanceHierarchy/InternalElement/RoleRequirements/@RefBaseRoleClassPath", null); //InterfaceClassLib template.addTriplePattern(":CAEXFile", null, "aml:hasInterfaceClassLib", null, ":CAEXFile/InterfaceClassLib", null); template.addTriplePattern(":CAEXFile/InterfaceClassLib", null, "schema:name", null, "/CAEXFile/InterfaceClassLib/@Name", null); template.addTriplePattern(":CAEXFile/InterfaceClassLib", null, "aml:hasInterfaceClass", null, ":CAEXFile/InterfaceClassLib/InterfaceClass", null); template.addTriplePattern(":CAEXFile/InterfaceClassLib", null, "aml:hasVersion", null, "/CAEXFile/InterfaceClassLib/Version/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/InterfaceClassLib/InterfaceClass", null, "aml:refBaseClassPath", null, "/CAEXFile/InterfaceClassLib/InterfaceClass/@RefBaseClassPath", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/InterfaceClassLib/InterfaceClass", null, "schema:name", null, "/CAEXFile/InterfaceClassLib/InterfaceClass/@Name", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile", null, "aml:hasRoleClassLib", null, ":CAEXFile/RoleClassLib_1", null); template.addTriplePattern(":CAEXFile/RoleClassLib_1", null, "schema:name", null, "/CAEXFile/RoleClassLib/@Name", null); template.addTriplePattern(":CAEXFile/RoleClassLib_1", null, "aml:hasVersion", null, "/CAEXFile/RoleClassLib/Version/text()", XSDDatatype.XSDstring); template.addTriplePattern(":CAEXFile/RoleClassLib_1", null, "aml:hasRoleclass_1", null, ":CAEXFile/RoleClassLib/RoleClass_1", null); template.addTriplePattern(":CAEXFile/RoleClassLib_1/RoleClass_1", null, "schema:name", null, "/CAEXFile/RoleClassLib/RoleClass/@Name", null); template.addTriplePattern(":CAEXFile/RoleClassLib_1/RoleClass_1", null, "aml:refBaseClassPath", null, "/CAEXFile/RoleClassLib/RoleClass/@RefBaseClassPath", null); template.addTriplePattern(":CAEXFile", null, "aml:hasSystemUnitClassLib", null, ":CAEXFile/SystemUnitClassLib_1", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib_1", null, "schema:name", null, "/CAEXFile/SystemUnitClassLib/@Name", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib_1", null, "aml:hasVersion", null, "/CAEXFile/SystemUnitClassLib/Version/text()", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib_1", null, "aml:hasSystemUnitClass", null, ":CAEXFile/SystemUnitClassLib/SystemUnitClass_1", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib/SystemUnitClass_1", null, "schema:name", null, "/CAEXFile/SystemUnitClassLib/SystemUnitClass/@Name", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib/SystemUnitClass_1", null, "aml:hasExternalInterface", null, ":CAEXFile/SystemUnitClassLib/SystemUnitClass/ExternalInterface_2", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib/SystemUnitClass_1/ExternalInterface_2", null, "schema:name", null, "/CAEXFile/SystemUnitClassLib/SystemUnitClass/ExternalInterface/@Name", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib/SystemUnitClass_1/ExternalInterface_2", null, "dc:identifier", null, "/CAEXFile/SystemUnitClassLib/SystemUnitClass/ExternalInterface/@ID", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib/SystemUnitClass_1/ExternalInterface_2", null, "aml:refBaseClassPath", null, "/CAEXFile/SystemUnitClassLib/SystemUnitClass/ExternalInterface/@RefBaseClassPath", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib/SystemUnitClass_1", null, "aml:supportedRoleClass", null, ":CAEXFile/SystemUnitClassLib/SystemUnitClass/SupportedRoleClass1", null); template.addTriplePattern(":CAEXFile/SystemUnitClassLib/SystemUnitClass_1/SupportedRoleClass1", null, "aml:refRoleClassPath", null, "/CAEXFile/SystemUnitClassLib/SystemUnitClass/SupportedRoleClass/@RefRoleClassPath", null); //blank node(attribute) //template.addTriplePattern(":CAEXFile/InstanceHierarchy/InternalElement_1", null,"aml:hasAttribute ", null,"_:Attribute_1",null); //template.addTriplePattern("_:Attribute_1", null,"schema:name ", null,"/CAEXFile/InstanceHierarchy/InternalElement/Attribute/@Name",null); // template.addTriplePattern("/RTML/Telescope/Camera/FilterWheel/Filter/@type", null, "units", null, "meters",XSDDatatype.XSDstring); // template.addTriplePattern("Author", null, "a", null, "person",XSDDatatype.XSDstring); //template.addTriplePattern("/RTML/Telescope/Camera/FilterWheel/Filter/@name", null,"type", null,"CameraType",XSDDatatype.XSDstring); //template.addTriplePattern("FocalLength", null,"hasvalue", null,"/RTML/Telescope/FocalLength/test()",XSDDatatype.XSDdouble); // template.addTriplePattern("/RTML/Telescope/Camera/FilterWheel/Filter/@name", null,"modelType", null,"/RTML/Telescope/Camera/FilterWheel/Filter/@type",XSDDatatype.XSDstring); // For publicatios.xml. It's subject is realted to :OpenAIREDataModel. // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, "a", null, "bibo:Publication", null); // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, "swpo:hasTitle", null, "/response/results/result/metadata/oaf:entity/oaf:result/title/text()", XSDDatatype.XSDstring); // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, ":objectIdentifier", null, "/response/results/result/header/dri:objIdentifier/text()",null); // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, ":dateofacceptance", null, "/response/results/result/metadata/oaf:entity/oaf:result/dateofacceptance/text()",XSDDatatype.XSDdate); // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, ":language", null, "/response/results/result/metadata/oaf:entity/oaf:result/language/@classname",XSDDatatype.XSDstring); // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, ":hasPublisher", null, "/response/results/result/metadata/oaf:entity/oaf:result/publisher/text()",XSDDatatype.XSDstring); // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, ":description", null, "/response/results/result/metadata/oaf:entity/oaf:result/description/text()",XSDDatatype.XSDstring); // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, ":license", null, "/response/results/result/metadata/oaf:entity/oaf:result/bestlicense/@classid",XSDDatatype.XSDstring); // template.addTriplePattern("/response/results/result/header/dri:objIdentifier/text()", null, ":licenseType", null, "/response/results/result/metadata/oaf:entity/oaf:result/bestlicense/@classname",XSDDatatype.XSDstring); // Not support // template.addTriplePattern(":OpenAIREDataModel", null, ":hasAuthor", null, "/response/results/result/metadata/oaf:entity/oaf:result/rels/rel/to[class="hasAuthor"]/text()",XSDDatatype.XSDstring); // handler.setTemplateRDF(template); // End of publications.xml // End of publications.xml. It's subject is related to :OpenAIREDataModel. handler.setTemplateRDF(template); //InputStream xmlInput = new FileInputStream("publications_template.xml"); //InputStream xmlInput = new FileInputStream("STELL-I_3.rtml"); InputStream xmlInput = new FileInputStream("ExampleTopology.xml"); //InputStream xmlInput = new FileInputStream("publications.xml"); //InputStream xmlInput = new FileInputStream("dblp_small.xml"); //myFilter.AppendXPath("/RTML/Telescope/Camera//*"); //myFilter.AppendXPath("/RTML/Telescope/Camera/"); // myFilter.AppendXPath("/response/header/page"); // For STELL-I_3.rtml. // myFilter.AppendXPath("//Camera/FilterWheel"); // myFilter.AppendXPath("//Filter"); // For publicaitons.xml /* myFilter.AppendXPath("//metadata"); myFilter.AppendXPath("//publisher"); myFilter.AppendXPath("//journal"); myFilter.AppendXPath("//title"); myFilter.AppendXPath("//originalId"); myFilter.AppendXPath("//dateofacceptance"); */ // For dblp_small.xml /* myFilter.AppendXPath("//author"); myFilter.AppendXPath("//title"); myFilter.AppendXPath("//journal"); myFilter.AppendXPath("//booktitle"); myFilter.AppendXPath("//volume"); myFilter.AppendXPath("//year"); myFilter.AppendXPath("//month"); myFilter.AppendXPath("//pages"); */ //handler.setFilter(myFilter); //long startTime = System.currentTimeMillis(); saxParser.parse(xmlInput, handler); long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; SumTime += elapsedTime; //handler.model.write(new FileWriter("dblp_small_customized.rdf"), "RDF/XML-ABBREV"); System.out.println("@prefix : " + template.getDefaultNameSpace()); System.out.println("@prefix aml: " + url.toString()); System.out.println("@prefix dc: " + url2.toString()); System.out.println("@prefix schema: " + url3.toString() + "\n\n\n"); handler.model.write(System.out, "TTL"); //RDFDataMgr.write(System.out, handler.model, Lang.TURTLE); //RDFDataMgr.write(System.out,model, "TURTLE"); // System.out.println("prefix: " + template.prefixSet.iterator()); // //System.out.println("prefix num: "+ template.prefixSet.size()); // System.out.println(SAXYFilterHandler.outputStream); //TimeUnit.MILLISECONDS.sleep(2000); } System.out.println("Time elapsed: " + SumTime / runTimes); } catch (SAXException e) { System.out.println(e.getMessage()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }