private Literal createDateLiteral(Date date) { if (date != null) { // Serialise the simple form DateFormat outputFormatter = new SimpleDateFormat("yyyy-MM-dd"); String dateStr = outputFormatter.format(date); return ResourceFactory.createTypedLiteral(dateStr, XSDDatatype.XSDdate); } return null; }
private RDFNode decodeNumber( JsonNumber jn ) { BigDecimal bd = (BigDecimal) jn.value(); try { return ResourceFactory.createTypedLiteral( bd.intValueExact() ); } catch (ArithmeticException e) { /* fall through on exception */ } try { return ResourceFactory.createTypedLiteral( bd.longValueExact() ); } catch (ArithmeticException e) { /* fall through on exception */ } try { return ResourceFactory.createTypedLiteral( bd.doubleValue() ); } catch (ArithmeticException e) { /* fall through on exception */ } return ResourceFactory.createTypedLiteral( bd ); }
@Override public RDFNode getNewTargetNode(Statement originalStatement, JComponent component) { String newText = ((JTextArea) component).getText(); if ((originalStatement == null) || !getObjectName(originalStatement).equals(newText)) return createTypedLiteral(newText); return null; }
@Override public RDFNode getNewTargetNode(Statement originalStatement, JComponent component) { String newText = ((JTextArea) component).getText(); if ((originalStatement == null) || !getObjectName(originalStatement).equals(newText)) return createTypedLiteral(newText); return null; }
@Override public RDFNode getNewTargetNode(Statement originalStatement, JComponent component) { JTextArea inputText = (JTextArea) component; String newText = inputText.getText(); if ((originalStatement == null) || !getObjectName(originalStatement).equals(newText)) return createTypedLiteral(newText); return null; }
@Override public RDFNode getNewTargetNode(Statement originalStatement, JComponent component) { JTextArea inputText = (JTextArea) component; String newText = inputText.getText(); if ((originalStatement == null) || !getObjectName(originalStatement).equals(newText)) return createTypedLiteral(newText); return null; }
@Override public RDFNode getNewTargetNode(Statement originalStatement, JComponent component) { JSpinner spinner = (JSpinner) component; Date d = (Date) spinner.getValue(); if ((originalStatement == null) || !originalStatement.getObject().asLiteral().getValue() .equals(d)) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(d); return createTypedLiteral(cal); } return null; }
@Override public RDFNode getNewTargetNode(Statement originalStatement, JComponent component) { JSpinner spinner = (JSpinner) component; Date d = (Date) spinner.getValue(); if ((originalStatement == null) || !originalStatement.getObject().asLiteral().getValue() .equals(d)) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(d); return createTypedLiteral(cal); } return null; }
/** Convert an javascript date string to an xsd:datetime or xsd:date. Dancing around to ensure that we can construct zoneless times (going via Date forcibly introduces a timezone, which we eliminate by turning it into an xsd:dateTime lexical form). @throws ParseException */ public static Literal parseDateTime(String lex, String type) throws ParseException { boolean hasTimeZone = hasTimeZone(lex); boolean isXSDDate = XSD.date.getURI().equals(type); SimpleDateFormat sdf = dateFormat(hasTimeZone, isXSDDate); Date date = sdf.parse(lex); if (isXSDDate) { return ResourceFactory.createTypedLiteral(xsdDateFormat().format(date), XSDDatatype.XSDdate); } else { if (hasTimeZone) { Calendar cal = Calendar.getInstance( TimeZone.getTimeZone("GMT") ); cal.setTime(date); XSDDateTime dt = new XSDDateTime(cal); return ResourceFactory.createTypedLiteral( dt ); } else { SimpleDateFormat f = new SimpleDateFormat( "yyyy-MM-dd'T'hh:mm:ss" ); String lf = f.format(date); Literal l = ResourceFactory.createTypedLiteral( lf, XSDDatatype.XSDdateTime ); return l; } } }
/** Returns the date/time object derived from the literal l. As a sop to literals of type xsd_Date which have an associated Time, if getting the value throws a datatype format exception, try again on a literal with the same lexical form but type xsd_dateTime. */ private static Object getTemporalValue(Literal l) { try { return l.getValue(); } catch (DatatypeFormatException e) { Literal lit = ResourceFactory.createTypedLiteral(l.getLexicalForm(), XSDDatatype.XSDdateTime ); return lit.getValue(); } }
return ResourceFactory.createTypedLiteral(jsonValue); } else if (jsonValue instanceof JsonBoolean) { JsonBoolean jb = (JsonBoolean) jsonValue; return ResourceFactory.createTypedLiteral( jb.value() ); } else if (jsonValue instanceof JsonNumber) { return decodeNumber( (JsonNumber) jsonValue ); } else if (jsonValue instanceof Boolean) { return ResourceFactory.createTypedLiteral(jsonValue); } else if (jsonValue instanceof JsonString) { return decodeValue( ((JsonString) jsonValue).value(), decoder, type ); String dtURI = lex.substring(split+2); lex = lex.substring(0, split); return ResourceFactory.createTypedLiteral(lex, new BaseDatatype(dtURI)); } else if (XSD.anyURI.getURI().equals(type)) { return ResourceFactory.createTypedLiteral(lex, XSDDatatype.XSDanyURI); } else if (XSD.date.getURI().equals(type) || XSD.dateTime.getURI().equals(type)) { try {
private Literal rename( Literal n ) { String typeURI = n.getDatatypeURI(); if (typeURI == null) return n; String newURI = pe.rename( typeURI ); if (typeURI == newURI) return n; return ResourceFactory.createTypedLiteral( n.getLexicalForm(), typeNamed(newURI) ); }
@Test public void testTimelessDateISORendering() { Literal l = ResourceFactory.createTypedLiteral("1999-05-31Z", XSDDatatype.XSDdate); assertEquals( "1999-05-31", RDFUtil.formatDateTime( l, true ) ); } }
@Test public void testTimelessDatetimeRendering() { Literal l = ResourceFactory.createTypedLiteral("1999-05-31Z", XSDDatatype.XSDdate); assertEquals( "Mon, 31 May 1999", RDFUtil.formatDateTime( l, false ) ); }
@Test public void testDateTimeISORendering() { Literal l = ResourceFactory.createTypedLiteral("1999-05-31T02:09:32Z", XSDDatatype.XSDdateTime); assertEquals("1999-05-31T02:09:32Z", RDFUtil.formatDateTime(l, true)); }
@Test public void testBasicSerialization() { Literal l = ResourceFactory.createTypedLiteral("1999-05-31T02:09:32Z", XSDDatatype.XSDdateTime); assertEquals("Mon, 31 May 1999 02:09:32 GMT+0000", RDFUtil.formatDateTime(l, false)); }
@Test public void testRoundTrip() throws ParseException { Literal l = ResourceFactory.createTypedLiteral("1999-05-31T02:09:32Z", XSDDatatype.XSDdateTime); String date = RDFUtil.formatDateTime(l, false); Literal lret = RDFUtil.parseDateTime(date, null); assertEquals(l, lret); }
@Test public void testRoundTripDate() throws ParseException { Literal l = ResourceFactory.createTypedLiteral("1999-05-31", XSDDatatype.XSDdate); String date = RDFUtil.formatDateTime(l, false); Literal lret = RDFUtil.parseDateTime(date, l.getDatatypeURI() ); assertEquals(l, lret); }
node = ResourceFactory.createTypedLiteral(value, TypeMapper.getInstance() .getTypeByName(TypeMap.getTypedString(datatype))); return;
evidenceIndividual, ResourceFactory.createProperty(DEFACTO_PROPERTY_EVIDENCE_SCORE), ResourceFactory.createTypedLiteral(evidence.getDeFactoScore()))); ResourceFactory.createTypedLiteral(evidence.defactoTimePeriod.getFrom().toString(), new XSDDatatype("gYear")))); ResourceFactory.createTypedLiteral(evidence.defactoTimePeriod.getTo().toString(), new XSDDatatype("gYear")))); defactoRun, ResourceFactory.createProperty(PROV_PROPERTY_STARTED_AT_TIME), ResourceFactory.createTypedLiteral(startTime))); outputModel.add(ResourceFactory.createStatement( defactoRun, ResourceFactory.createProperty(PROV_PROPERTY_ENDED_AT_TIME), ResourceFactory.createTypedLiteral(endTime))); proofIndividual, ResourceFactory.createProperty(DEFACTO_PROPERTY_PROOF_SCORE), ResourceFactory.createTypedLiteral(Double.valueOf(proof.getScore()))));