List of usage examples for org.joda.time Period parse
@FromString public static Period parse(String str)
From source file:org.n52.web.ctrl.TimeseriesDataController.java
License:Open Source License
private void checkAgainstTimespanRestriction(String timespan) { Duration duration = Period.parse(requestIntervalRestriction).toDurationFrom(new DateTime()); if (duration.getMillis() < Interval.parse(timespan).toDurationMillis()) { throw new BadRequestException("Requested timespan is to long, please use a period shorter than '" + requestIntervalRestriction + "'"); }//from w w w. ja va 2 s . co m }
From source file:org.n52.web.ctrl.TimeseriesDataController.java
License:Open Source License
public void setRequestIntervalRestriction(String requestIntervalRestriction) { // validate requestIntervalRestriction, if it's no period an exception occured Period.parse(requestIntervalRestriction); this.requestIntervalRestriction = requestIntervalRestriction; }
From source file:org.n52.wps.commons.PropertyUtil.java
License:Apache License
public long extractPeriodAsMillis(String valueKey, long valueDefault) { String periodAsString;/*from www. j a v a2 s . c o m*/ if (systemPropertyRoot != null) { String systemPropertyName = JOINER.join(systemPropertyRoot, valueKey); periodAsString = System.getProperty(systemPropertyName); if (periodAsString != null) { try { Period period = Period.parse(periodAsString); if (period != null) { long periodMillis = period.toStandardDuration().getMillis(); LOGGER.info("System property \"{}\" exists, using value of: {} ({}ms) ", systemPropertyName, periodAsString, periodMillis); return periodMillis; } else { LOGGER.error("System property \"{}\" exists but unable to parse \"{}\" as ISO8601 period", systemPropertyName, periodAsString); } } catch (Exception e) { LOGGER.error("System property \"{}\" exists but unable to parse \"{}\" as ISO8601 period", systemPropertyName, periodAsString); } } else { LOGGER.debug("System property \"{}\" not present", systemPropertyName); } } else { LOGGER.debug("System property root not present, skipping system property lookup for {}", valueKey); } PropertyDocument.Property property = propertyNameMap.get(valueKey); if (property != null) { if (property.getActive()) { periodAsString = property.getStringValue(); if (periodAsString != null) { try { Period period = Period.parse(periodAsString); if (period != null) { long periodMillis = period.toStandardDuration().getMillis(); LOGGER.info("Config property for \"{}\" exists, using value of: {} ({}ms) ", valueKey, periodAsString, periodMillis); return periodMillis; } else { LOGGER.error( "Config property for \"{}\" exists but unable to parse \"{}\" as ISO8601 period", valueKey, periodAsString); } } catch (Exception e) { LOGGER.error( "Config property for \"{}\" exists but unable to parse \"{}\" as ISO8601 period", valueKey, periodAsString); } } else { LOGGER.error("Config property for \"{}\" exists but unable to parse \"{}\" as ISO8601 period", valueKey, periodAsString); } } else { LOGGER.warn("Config property for \"{}\" exists but is not active, ignoring", valueKey); } } else { LOGGER.debug("Config property for \"{}\" not present", valueKey); } LOGGER.info("Using default value for \"{}\" of {}ms", valueKey, valueDefault); return valueDefault; }
From source file:org.springframework.format.datetime.joda.PeriodFormatter.java
License:Apache License
@Override public Period parse(String text, Locale locale) throws ParseException { return Period.parse(text); }
From source file:test.utilities.GraphUtils.java
License:Apache License
/** * TODO: work in progress decoding a triple *//*from ww w .j a v a2 s . co m*/ protected static void decodeTriple(Triple triple) { if (triple == null) return; // left in here just to keep the code consistent StringBuilder sb = new StringBuilder(); boolean usePrefixes = true; Node subject = triple.getSubject(); Node predicate = triple.getPredicate(); Node obj = triple.getObject(); RDFDatatype datatype; String typeURI = ""; verboseDebug(System.out, "subject: " + subject.toString()); verboseDebug(System.out, "predicate: " + predicate.toString()); if (usePrefixes) sb.append(simplifyWithNamespace(subject.toString())); else sb.append(subject.toString()); sb.append(" "); if (usePrefixes) sb.append(simplifyWithNamespace(predicate.toString())); else sb.append(predicate.toString()); sb.append(" "); if (obj.isLiteral()) { // Literal literal = obj.getLiteral(); datatype = obj.getLiteralDatatype(); if (datatype == null) { // String str = literal.getString(); String str = obj.toString(); verboseDebug(System.out, "is plain literal:"); verboseDebug(System.out, " str is " + str); sb.append("\""); sb.append(str); sb.append("\""); sb.append(" . \n"); } else { String dUri = datatype.getURI(); // String str = literal.getString(); String str = obj.toString(); Object o = obj.getLiteralValue(); verboseDebug(System.out, "is a typed literal:"); verboseDebug(System.out, " dUri is " + dUri); verboseDebug(System.out, " data is " + str); verboseDebug(System.out, " dataTypeURI is " + obj.getLiteralDatatypeURI()); verboseDebug(System.out, " lexical form is " + obj.getLiteralLexicalForm()); verboseDebug(System.out, " object type: " + o.getClass().getName()); Class c = datatype.getJavaClass(); if (c != null) { verboseDebug(System.out, " java class: " + datatype.getJavaClass().getName()); } else { verboseDebug(System.out, " appears to be classless"); } if (o instanceof Integer) { // int v = literal.getInt(); int v = ((Integer) o).intValue(); verboseDebug(System.out, " int: " + v); } else if (o instanceof Long) { long v = ((Long) o).longValue(); verboseDebug(System.out, " long: " + v); } else if (o instanceof Double) { double v = ((Double) o).doubleValue(); verboseDebug(System.out, " double: " + v); } else if (o instanceof Float) { float v = ((Float) o).floatValue(); verboseDebug(System.out, " float: " + v); } else if (o instanceof Boolean) { boolean v = ((Boolean) o).booleanValue(); verboseDebug(System.out, " boolean: " + v); } else if (o instanceof Short) { short v = ((Short) o).shortValue(); verboseDebug(System.out, " short: " + v); } else if (o instanceof XSDDateTime) { String v = obj.toString(); verboseDebug(System.out, " dateTime: " + v); // figure out if this is a date or a time if (datatype == XSDDatatype.XSDdateTime) { v = obj.getLiteralLexicalForm(); DateTime dtime = new DateTime(v); verboseDebug(System.out, " dateTime obj: " + dtime.toString()); } if (datatype == XSDDatatype.XSDdate) { v = obj.getLiteralLexicalForm(); DateTime dtime = new DateTime(v); verboseDebug(System.out, " dateTime obj: " + dtime.toString()); } if (datatype == XSDDatatype.XSDtime) { v = obj.getLiteralLexicalForm(); LocalTime ltime = LocalTime.parse(v); verboseDebug(System.out, " LocalTime obj: " + ltime.toString()); } } else if (o instanceof XSDDuration) { String v = obj.toString(); v = obj.getLiteralLexicalForm(); Period period = Period.parse(v); verboseDebug(System.out, " period duration: " + period); } else { String v = obj.toString(); verboseDebug(System.out, " HUH? somehow we missed" + v); } sb.append("\""); sb.append(str); sb.append("\"^^"); if (usePrefixes) sb.append(simplifyWithNamespace(dUri)); else sb.append(dUri); sb.append(" .\n"); } } else { typeURI = obj.toString(); verboseDebug(System.out, "not a literal:"); verboseDebug(System.out, " typeURI = " + typeURI); verboseDebug(System.out, " simplified = " + simplifyWithNamespace(typeURI)); sb.append(simplifyWithNamespace(typeURI)); sb.append(" .\n"); } }
From source file:test.utilities.GraphUtils.java
License:Apache License
/** * TODO: work in progress decoding a triple *///from www.j av a 2 s .co m public static Object extractTriple(Triple triple) { Object rObj = null; if (triple == null) return rObj; // left in here just to keep the code consistent StringBuilder sb = new StringBuilder(); boolean usePrefixes = true; Node subject = triple.getSubject(); Node predicate = triple.getPredicate(); Node obj = triple.getObject(); RDFDatatype datatype; String typeURI = ""; verboseDebug(System.out, "subject: " + subject.toString()); verboseDebug(System.out, "predicate: " + predicate.toString()); // if (usePrefixes) // sb.append(simplifyWithNamespace(subject.toString())); // else // sb.append(subject.toString()); // sb.append(" "); // if (usePrefixes) // sb.append(simplifyWithNamespace(predicate.toString())); // else // sb.append(predicate.toString()); // sb.append(" "); if (obj.isLiteral()) { // Literal literal = obj.getLiteral(); datatype = obj.getLiteralDatatype(); if (datatype == null) { // String str = literal.getString(); String str = obj.toString(); rObj = str; // verboseDebug(System.out, "is plain literal:"); // verboseDebug(System.out, " str is " + str); // sb.append("\""); // sb.append(str); // sb.append("\""); // sb.append(" . \n"); } else { String dUri = datatype.getURI(); // String str = literal.getString(); String str = obj.toString(); Object o = obj.getLiteralValue(); rObj = o; // verboseDebug(System.out, "is a typed literal:"); // verboseDebug(System.out, " dUri is " + dUri); // verboseDebug(System.out, " data is " + str); // verboseDebug(System.out, " dataTypeURI is " + obj.getLiteralDatatypeURI()); // verboseDebug(System.out, " lexical form is " + obj.getLiteralLexicalForm()); // verboseDebug(System.out, " object type: " + o.getClass().getName()); Class c = datatype.getJavaClass(); if (c != null) { // verboseDebug(System.out, " java class: " + datatype.getJavaClass().getName()); } else { // verboseDebug(System.out, " appears to be classless"); } if (o instanceof Integer) { // int v = literal.getInt(); int v = ((Integer) o).intValue(); // verboseDebug(System.out, " int: " + v); } else if (o instanceof Long) { long v = ((Long) o).longValue(); // verboseDebug(System.out, " long: " + v); } else if (o instanceof Double) { double v = ((Double) o).doubleValue(); // verboseDebug(System.out, " double: " + v); } else if (o instanceof Float) { float v = ((Float) o).floatValue(); // verboseDebug(System.out, " float: " + v); } else if (o instanceof Boolean) { boolean v = ((Boolean) o).booleanValue(); // verboseDebug(System.out, " boolean: " + v); } else if (o instanceof Short) { short v = ((Short) o).shortValue(); // verboseDebug(System.out, " short: " + v); } else if (o instanceof XSDDateTime) { String v = obj.toString(); // verboseDebug(System.out, " dateTime: " + v); // figure out if this is a date or a time if (datatype == XSDDatatype.XSDdateTime) { v = obj.getLiteralLexicalForm(); DateTime dtime = new DateTime(v); rObj = dtime; // verboseDebug(System.out, " dateTime obj: " + dtime.toString()); } if (datatype == XSDDatatype.XSDdate) { v = obj.getLiteralLexicalForm(); DateTime dtime = new DateTime(v); rObj = dtime; // verboseDebug(System.out, " dateTime obj: " + dtime.toString()); } if (datatype == XSDDatatype.XSDtime) { v = obj.getLiteralLexicalForm(); LocalTime ltime = LocalTime.parse(v); rObj = ltime; // verboseDebug(System.out, " LocalTime obj: " + ltime.toString()); } } else if (o instanceof XSDDuration) { String v = obj.toString(); v = obj.getLiteralLexicalForm(); Period period = Period.parse(v); rObj = period; // verboseDebug(System.out, " period duration: " + period); } else { String v = obj.toString(); rObj = v; // verboseDebug(System.out, " HUH? somehow we missed" + v); } // sb.append("\""); // sb.append(str); // sb.append("\"^^"); // if (usePrefixes) // sb.append(simplifyWithNamespace(dUri)); // else // sb.append(dUri); // sb.append(" .\n"); } } else { typeURI = obj.toString(); rObj = obj; // verboseDebug(System.out, "not a literal:"); // verboseDebug(System.out, " typeURI = " + typeURI); // verboseDebug(System.out, " simplified = " + simplifyWithNamespace(typeURI)); // sb.append(simplifyWithNamespace(typeURI)); // sb.append(" .\n"); } return rObj; }
From source file:test.utilities.GraphUtils.java
License:Apache License
/** * TODO: move this to ModelUtils/*from www . java2 s . c o m*/ * TODO: make a version that converts it to an Array of Strings */ protected static String convertModelToTriplesString(Model m, boolean usePrefixes) { System.out.println("GraphUtils.convertModelToTriplesString"); StringBuilder sb = new StringBuilder(); StmtIterator stmtIterator = m.listStatements(); while (stmtIterator.hasNext()) { Statement statement = stmtIterator.nextStatement(); Resource subject = statement.getSubject(); Property predicate = statement.getPredicate(); RDFNode obj = statement.getObject(); RDFDatatype datatype; String typeURI = ""; verboseDebug(System.out, "subject: " + subject.toString()); verboseDebug(System.out, "predicate: " + predicate.toString()); if (usePrefixes) sb.append(simplifyWithNamespace(subject.toString())); else sb.append(subject.toString()); sb.append(" "); if (usePrefixes) sb.append(simplifyWithNamespace(predicate.toString())); else sb.append(predicate.toString()); sb.append(" "); if (obj.isLiteral()) { Literal literal = obj.asLiteral(); datatype = literal.getDatatype(); if (datatype == null) { String str = literal.getString(); verboseDebug(System.out, "is plain literal:"); verboseDebug(System.out, " str is " + str); sb.append("\""); sb.append(str); sb.append("\""); sb.append(" . \n"); } else { String dUri = datatype.getURI(); String str = literal.getString(); Object o = literal.getValue(); verboseDebug(System.out, "is a typed literal:"); verboseDebug(System.out, " dUri is " + dUri); verboseDebug(System.out, " data is " + str); verboseDebug(System.out, " dataTypeURI is " + literal.getDatatypeURI()); verboseDebug(System.out, " lexical form is " + literal.getLexicalForm()); verboseDebug(System.out, " literal as string: " + literal.toString()); verboseDebug(System.out, " object type: " + o.getClass().getName()); Class c = datatype.getJavaClass(); if (c != null) { verboseDebug(System.out, " java class: " + datatype.getJavaClass().getName()); } else { verboseDebug(System.out, " appears to be classless"); } if (o instanceof Integer) { int v = literal.getInt(); verboseDebug(System.out, " int: " + v); } else if (o instanceof Long) { long v = literal.getLong(); verboseDebug(System.out, " long: " + v); } else if (o instanceof Double) { double v = literal.getDouble(); verboseDebug(System.out, " double: " + v); } else if (o instanceof Float) { float v = literal.getFloat(); verboseDebug(System.out, " float: " + v); } else if (o instanceof Boolean) { boolean v = literal.getBoolean(); verboseDebug(System.out, " boolean: " + v); } else if (o instanceof Short) { short v = literal.getShort(); verboseDebug(System.out, " short: " + v); } else if (o instanceof XSDDateTime) { String v = literal.getString(); verboseDebug(System.out, " dateTime: " + v); // figure out if this is a date or a time if (datatype == XSDDatatype.XSDdateTime) { DateTime dtime = new DateTime(v); verboseDebug(System.out, " dateTime obj: " + dtime.toString()); } if (datatype == XSDDatatype.XSDdate) { DateTime dtime = new DateTime(v); verboseDebug(System.out, " dateTime obj: " + dtime.toString()); } if (datatype == XSDDatatype.XSDtime) { LocalTime ltime = LocalTime.parse(v); verboseDebug(System.out, " LocalTime obj: " + ltime.toString()); } } else if (o instanceof XSDDuration) { String v = literal.getString(); Period period = Period.parse(v); verboseDebug(System.out, " period duration: " + period); } else { String v = literal.getString(); verboseDebug(System.out, " HUH? somehow we missed" + v); } sb.append("\""); sb.append(str); sb.append("\"^^"); if (usePrefixes) sb.append(simplifyWithNamespace(dUri)); else sb.append(dUri); sb.append(" .\n"); } } else { typeURI = obj.toString(); verboseDebug(System.out, "not a literal:"); verboseDebug(System.out, " typeURI = " + typeURI); verboseDebug(System.out, " simplified = " + simplifyWithNamespace(typeURI)); sb.append(simplifyWithNamespace(typeURI)); sb.append(" .\n"); } } verboseDebug(System.out, "convertModelToTriplesString:"); verboseDebug(System.out, sb.toString()); return sb.toString(); }