List of usage examples for javax.xml.datatype DatatypeFactory newInstance
public static DatatypeFactory newInstance() throws DatatypeConfigurationException
From source file:com.inmobi.grill.server.metastore.TestMetastoreService.java
private XCube createTestCube(String cubeName) throws Exception { GregorianCalendar c = new GregorianCalendar(); c.setTime(new Date()); final XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); c.add(GregorianCalendar.DAY_OF_MONTH, 7); final XMLGregorianCalendar endDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); XCube cube = cubeObjectFactory.createXCube(); cube.setName(cubeName);// w w w . ja v a 2 s . c om cube.setWeight(100.0); XDimensions xdims = cubeObjectFactory.createXDimensions(); XDimension xd1 = cubeObjectFactory.createXDimension(); xd1.setName("dim1"); xd1.setType("string"); xd1.setStartTime(startDate); // Don't set endtime on this dim to validate null handling on server side xd1.setCost(10.0); XDimension xd2 = cubeObjectFactory.createXDimension(); xd2.setName("dim2"); xd2.setType("int"); // Don't set start time on this dim to validate null handling on server side xd2.setEndTime(endDate); xd2.setCost(5.0); xdims.getDimensions().add(xd1); xdims.getDimensions().add(xd2); cube.setDimensions(xdims); XMeasures measures = cubeObjectFactory.createXMeasures(); XMeasure xm1 = new XMeasure(); xm1.setName("msr1"); xm1.setType("double"); xm1.setCost(10.0); // Don't set start time and end time to validate null handling on server side. //xm1.setStarttime(startDate); //xm1.setEndtime(endDate); xm1.setDefaultAggr("sum"); XMeasure xm2 = new XMeasure(); xm2.setName("msr2"); xm2.setType("int"); xm2.setCost(10.0); xm2.setStartTime(startDate); xm2.setEndTime(endDate); xm2.setDefaultAggr("max"); measures.getMeasures().add(xm1); measures.getMeasures().add(xm2); cube.setMeasures(measures); XProperties properties = cubeObjectFactory.createXProperties(); XProperty xp1 = cubeObjectFactory.createXProperty(); xp1.setName("foo"); xp1.setValue("bar"); properties.getProperties().add(xp1); cube.setProperties(properties); return cube; }
From source file:com.marklogic.client.test.EvalTest.java
private void runAndTestXQuery(ServerEvaluationCall call) throws JsonProcessingException, IOException, SAXException, ParserConfigurationException, DatatypeConfigurationException { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(this.getClass().getClassLoader().getResourceAsStream("1-empty-1.0.xml")); call = call.addNamespace("myPrefix", "http://marklogic.com/test").addVariable("myPrefix:myString", "Mars") .addVariable("myArray", new JacksonHandle().with(new ObjectMapper().createArrayNode().add("item1").add("item2"))) .addVariable("myObject", new JacksonHandle().with(new ObjectMapper().createObjectNode().put("item1", "value1"))) .addVariable("myAnyUri", "http://marklogic.com/a") .addVariable("myBinary", DatatypeConverter.printHexBinary(",".getBytes())) .addVariable("myBase64Binary", DatatypeConverter.printBase64Binary(new byte[] { 1, 2, 3 })) .addVariable("myHexBinary", DatatypeConverter.printHexBinary(new byte[] { 1, 2, 3 })) .addVariable("myDuration", "P100D").addVariable("myDocument", new DOMHandle(document)) .addVariable("myQName", "myPrefix:a") //.addVariable("myAttribute", "<a a=\"a\"/>") .addVariable("myComment", "<!--a-->").addVariable("myElement", "<a a=\"a\"/>") .addVariable("myProcessingInstruction", "<?a?>") .addVariable("myText", new StringHandle("a").withFormat(Format.TEXT)) // the next three use built-in methods of ServerEvaluationCall .addVariable("myBool", true).addVariable("myInteger", 1234567890123456789l) .addVariable("myBigInteger", "123456789012345678901234567890") .addVariable("myDecimal", "1111111111111111111.9999999999") .addVariable("myDouble", 11111111111111111111.7777777777).addVariable("myFloat", 1.1) .addVariable("myGDay", "---01").addVariable("myGMonth", "--01") .addVariable("myGMonthDay", "--01-01").addVariable("myGYear", "1901") .addVariable("myGYearMonth", "1901-01").addVariable("myDate", "2014-09-01") .addVariable("myDateTime", DatatypeFactory.newInstance().newXMLGregorianCalendar(septFirst).toString()) .addVariable("myTime", "00:01:01"); EvalResultIterator results = call.eval(); try {//from w ww .j a v a 2 s . com EvalResult result = results.next(); assertEquals("myString should = 'Mars'", "Mars", result.getAs(String.class)); assertEquals("myString should be Type.STRING", EvalResult.Type.STRING, result.getType()); assertEquals("myString should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myArray should = [\"item1\",\"item2\"]", new ObjectMapper().readTree("[\"item1\",\"item2\"]"), result.getAs(JsonNode.class)); assertEquals("myArray should be Type.JSON", EvalResult.Type.JSON, result.getType()); assertEquals("myArray should be Format.JSON", Format.JSON, result.getFormat()); result = results.next(); assertEquals("myObject should = {\"item1\":\"value1\"}", new ObjectMapper().readTree("{\"item1\":\"value1\"}"), result.getAs(JsonNode.class)); assertEquals("myObject should be Type.JSON", EvalResult.Type.JSON, result.getType()); assertEquals("myObject should be Format.JSON", Format.JSON, result.getFormat()); result = results.next(); assertEquals("myAnyUri looks wrong", "http://marklogic.com/a", result.getString()); assertEquals("myAnyUri should be Type.ANYURI", EvalResult.Type.ANYURI, result.getType()); assertEquals("myAnyUri should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myBinary looks wrong", ",", result.getString()); assertEquals("myBinary should be Type.BINARY", EvalResult.Type.BINARY, result.getType()); assertEquals("myBinary should be Format.UNKNOWN", Format.UNKNOWN, result.getFormat()); result = results.next(); assertArrayEquals("myBase64Binary should = 1, 2, 3", new byte[] { 1, 2, 3 }, DatatypeConverter.parseBase64Binary(result.getString())); assertEquals("myBase64Binary should be Type.BASE64BINARY", EvalResult.Type.BASE64BINARY, result.getType()); assertEquals("myBase64Binary should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertArrayEquals("myHexBinary should = 1, 2, 3", new byte[] { 1, 2, 3 }, DatatypeConverter.parseHexBinary(result.getString())); assertEquals("myHexBinary should be Type.HEXBINARY", EvalResult.Type.HEXBINARY, result.getType()); assertEquals("myHexBinary should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myDuration should = P100D", "P100D", result.getString()); assertEquals("myDuration should be Type.DURATION", EvalResult.Type.DURATION, result.getType()); assertEquals("myDuration should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myQName doesn't look right", "myPrefix:a", result.getString()); assertEquals("myQName should be Type.QNAME", EvalResult.Type.QNAME, result.getType()); assertEquals("myQName should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myDocument doesn't look right", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<search:options xmlns:search=\"http://marklogic.com/appservices/search\"/>", result.getString()); assertEquals("myDocument should be Type.XML", EvalResult.Type.XML, result.getType()); assertEquals("myDocument should be Format.XML", Format.XML, result.getFormat()); result = results.next(); assertEquals("myAttribute looks wrong", "a", result.getString()); assertEquals("myAttribute should be Type.ATTRIBUTE", EvalResult.Type.ATTRIBUTE, result.getType()); assertEquals("myAttribute should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myComment should = <!--a-->", "<!--a-->", result.getString()); assertEquals("myComment should be Type.COMMENT", EvalResult.Type.COMMENT, result.getType()); assertEquals("myComment should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myElement looks wrong", "<a a=\"a\"/>", result.getString()); assertEquals("myElement should be Type.XML", EvalResult.Type.XML, result.getType()); assertEquals("myElement should be Format.XML", Format.XML, result.getFormat()); result = results.next(); assertEquals("myProcessingInstruction should = <?a?>", "<?a?>", result.getString()); assertEquals("myProcessingInstruction should be Type.PROCESSINGINSTRUCTION", EvalResult.Type.PROCESSINGINSTRUCTION, result.getType()); assertEquals("myProcessingInstruction should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myText should = a", "a", result.getString()); assertEquals("myText should be Type.TEXTNODE", EvalResult.Type.TEXTNODE, result.getType()); assertEquals("myText should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myBool should = true", true, result.getBoolean()); assertEquals("myBool should be Type.BOOLEAN", EvalResult.Type.BOOLEAN, result.getType()); assertEquals("myBool should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myInteger should = 1234567890123456789l", 1234567890123456789l, result.getNumber().longValue()); assertEquals("myInteger should be Type.INTEGER", EvalResult.Type.INTEGER, result.getType()); assertEquals("myInteger should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myBigInteger looks wrong", new BigInteger("123456789012345678901234567890"), new BigInteger(result.getString())); assertEquals("myBigInteger should be Type.STRING", EvalResult.Type.STRING, result.getType()); assertEquals("myBigInteger should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myDecimal looks wrong", 1111111111111111111.9, result.getNumber().doubleValue(), .001); assertEquals("myDecimal should be Type.DECIMAL", EvalResult.Type.DECIMAL, result.getType()); assertEquals("myDecimal should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myDouble looks wrong", 1.11111111111111E19, result.getNumber().doubleValue(), .001); assertEquals("myDouble should be Type.DOUBLE", EvalResult.Type.DOUBLE, result.getType()); assertEquals("myDouble should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myFloat looks wrong", 1.1, result.getNumber().floatValue(), .001); assertEquals("myFloat should be Type.FLOAT", EvalResult.Type.FLOAT, result.getType()); assertEquals("myFloat should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGDay looks wrong", "---01", result.getString()); assertEquals("myGDay should be Type.GDAY", EvalResult.Type.GDAY, result.getType()); assertEquals("myGDay should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGMonth looks wrong", "--01", result.getString()); assertEquals("myGMonth should be Type.GMONTH", EvalResult.Type.GMONTH, result.getType()); assertEquals("myGMonth should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGMonthDay looks wrong", "--01-01", result.getString()); assertEquals("myGMonthDay should be Type.GMONTHDAY", EvalResult.Type.GMONTHDAY, result.getType()); assertEquals("myGMonthDay should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGYear looks wrong", "1901", result.getString()); assertEquals("myGYear should be Type.GYEAR", EvalResult.Type.GYEAR, result.getType()); assertEquals("myGYear should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGYearMonth looks wrong", "1901-01", result.getString()); assertEquals("myGYearMonth should be Type.GYEARMONTH", EvalResult.Type.GYEARMONTH, result.getType()); assertEquals("myGYearMonth should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); // the lexical format MarkLogic uses to serialize a date assertEquals("myDate should = '2014-09-01", "2014-09-01", result.getString()); assertEquals("myDate should be Type.DATE", EvalResult.Type.DATE, result.getType()); assertEquals("myDate should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); // the lexical format MarkLogic uses to serialize a dateTime assertEquals("myDateTime should = '2014-09-01T00:00:00+02:00'", "2014-09-01T00:00:00+02:00", result.getString()); assertEquals("myDateTime should be Type.DATETIME", EvalResult.Type.DATETIME, result.getType()); assertEquals("myDateTime should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myTime looks wrong", "00:01:01", result.getString()); assertEquals("myTime should be Type.TIME", EvalResult.Type.TIME, result.getType()); assertEquals("myTime should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myCtsQuery should be Type.OTHER", EvalResult.Type.OTHER, result.getType()); assertEquals("myCtsQuery should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myFunction should be Type.OTHER", EvalResult.Type.OTHER, result.getType()); assertEquals("myFunction should be Format.TEXT", Format.TEXT, result.getFormat()); } finally { results.close(); } }
From source file:name.persistent.behaviours.RemoteGraphSupport.java
private void store(String type, HttpResponse resp, String... origins) throws Exception { ObjectConnection con = getObjectConnection(); con.addDesignation(this, RemoteGraph.class); String via = getHeader(resp, "Via"); if (via == null) { String url = getResource().stringValue(); String authority = new ParsedURI(url).getAuthority(); setPurlVia(PROTOCOL + " " + authority); } else {// w w w . j a v a2 s . co m setPurlVia(via); } setPurlContentType(type); setPurlEtag(getHeader(resp, "ETag")); setPurlCacheControl(getHeader(resp, "Cache-Control")); DatatypeFactory df = DatatypeFactory.newInstance(); GregorianCalendar gc = new GregorianCalendar(); setPurlLastValidated(df.newXMLGregorianCalendar(gc)); gc.setTime(getDateHeader(resp, "Last-Modified")); setPurlLastModified(df.newXMLGregorianCalendar(gc)); if (origins != null) { ObjectFactory of = con.getObjectFactory(); for (String origin : origins) { if (origin != null) { Domain o = of.createObject(origin, Domain.class); getPurlAllowedOrigins().add(o); } } } for (Header hd : resp.getHeaders("Warning")) { if (hd.getValue().contains("111")) { // 111 "Revalidation failed" con.addDesignation(this, Unresolvable.class); } } }
From source file:eu.prestoprime.p4gui.connection.AccessConnection.java
public static Date checkDataTypeAvailability(P4Service service, String id, String dataType) { String path = service.getURL() + "/access/dip/" + id + "/" + dataType; try {/*w w w . j a va 2 s .c o m*/ P4HttpClient client = new P4HttpClient(service.getUserID()); HttpRequestBase request = new HttpGet(path); HttpResponse response = client.executeRequest(request); HttpEntity entity = response.getEntity(); if (entity != null) { String line; BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); if ((line = reader.readLine()) != null) { XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(line.trim()); return cal.toGregorianCalendar().getTime(); } } } catch (Exception e) { logger.error("Unable to parse the date..."); } return null; }
From source file:org.apache.cxf.cwiki.SiteExporter.java
public boolean checkRSS() throws Exception { if (forceAll || pages == null || pages.isEmpty()) { return false; }/* w w w . j a va 2 s. co m*/ URL url = new URL(ROOT + "/createrssfeed.action?types=page&types=blogpost&types=mail&" //+ "types=comment&" //cannot handle comment updates yet + "types=attachment&statuses=created&statuses=modified" + "&spaces=" + spaceKey + "&rssType=atom&maxResults=20&timeSpan=2" + "&publicFeed=true"); InputStream ins = url.openStream(); Document doc = StaxUtils.read(ins); ins.close(); List<Element> els = DOMUtils.getChildrenWithName(doc.getDocumentElement(), "http://www.w3.org/2005/Atom", "entry"); // XMLUtils.printDOM(doc); for (Element el : els) { Element e2 = DOMUtils.getFirstChildWithName(el, "http://www.w3.org/2005/Atom", "updated"); String val = DOMUtils.getContent(e2); XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(val); e2 = DOMUtils.getFirstChildWithName(el, "http://www.w3.org/2005/Atom", "title"); String title = DOMUtils.getContent(e2); Page p = findPage(title); if (p != null) { //found a modified page - need to rebuild if (cal.compare(p.getModifiedTime()) > 0) { System.out.println("(" + spaceKey + ") Changed page found: " + title); return false; } } else { BlogEntrySummary entry = findBlogEntry(title); if (entry != null) { // we don't have modified date so just assume it's modified // we'll use version number to actually figure out if page is modified or not System.out.println("(" + spaceKey + ") Possible changed blog page found: " + title); return false; } else { System.out.println("(" + spaceKey + ") Did not find page for: " + title); return false; } } } return true; }
From source file:org.openmrs.module.dhisconnector.api.impl.DHISConnectorServiceImpl.java
private AdxDataValueSet convertDHISDataValueSetToAdxDataValueSet(DHISDataValueSet valueSet) { AdxDataValueSet adx = null;/*from w w w . j a va 2 s . c o m*/ if (valueSet != null) { try { String dataSet = getCodeFromClazz(DHISDataSet.class, DATASETS_PATH + valueSet.getDataSet() + JSON_POST_FIX); String orgUnit = getCodeFromClazz(DHISOrganisationUnit.class, ORGUNITS_PATH + valueSet.getOrgUnit() + JSON_POST_FIX); String period = valueSet.getPeriod(); AdxDataValueGroup group = new AdxDataValueGroup(); XMLGregorianCalendar exported = DatatypeFactory.newInstance() .newXMLGregorianCalendar(new GregorianCalendar()); AdxDataValueGroupPeriod adxPeriod = new AdxDataValueGroupPeriod(period); adx = new AdxDataValueSet(); adx.setExported(exported); group.setOrgUnit(orgUnit); group.setDataSet(dataSet); group.setPeriod(adxPeriod); group.setCompleteDate(adxPeriod.getdHISAdxEndDate()); for (DHISDataValue dv : valueSet.getDataValues()) { AdxDataValue adxDv = new AdxDataValue(); String dataElement = getCodeFromClazz(DHISDataElement.class, DATA_ELEMETS_PATH + dv.getDataElement() + JSON_POST_FIX); if (StringUtils.isNotBlank(dataElement)) { adxDv.setDataElement(dataElement); adxDv.setValue(new BigDecimal(Integer.parseInt(dv.getValue()))); if (StringUtils.isNotBlank(dv.getCategoryOptionCombo())) { DHISCategoryCombo c = getCategoryComboFromOption(dv.getCategoryOptionCombo()); DHISCategoryOptionCombo oc = getCategoryOptionCombo(dv.getCategoryOptionCombo()); if (c != null && oc != null) adxDv.getOtherAttributes().put( new QName(StringUtils.isNotBlank(c.getCode()) ? c.getCode() : c.getId()), StringUtils.isNotBlank(oc.getCode()) ? oc.getCode() : oc.getId()); } group.getDataValues().add(adxDv); } } adx.getGroups().add(group); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } } return adx; }
From source file:org.apache.lens.regression.util.Util.java
public static XMLGregorianCalendar getXMLGregorianCalendar(Date d) { if (d == null) { return null; }/*from w ww . j a v a 2 s. c o m*/ GregorianCalendar c1 = new GregorianCalendar(); c1.setTime(d); try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(c1); } catch (DatatypeConfigurationException e) { log.info("Error converting date " + d, e); return null; } }
From source file:eu.dasish.annotation.backend.dao.impl.JdbcResourceDao.java
protected XMLGregorianCalendar timeStampToXMLGregorianCalendar(String ts) { String tsAdjusted = ts.replace(' ', 'T') + "Z"; try {//from w w w . j ava2s .c o m return DatatypeFactory.newInstance().newXMLGregorianCalendar(tsAdjusted); } catch (DatatypeConfigurationException dtce) { _logger.error(" ", dtce); return null; } }
From source file:gov.nih.nci.integration.caaers.CaAERSAdverseEventServiceClientIntegrationTest.java
private CourseType getCourseType() throws DatatypeConfigurationException { final GregorianCalendar gcal2 = new GregorianCalendar(2012, 06, 12); final XMLGregorianCalendar xgcal2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal2); final GregorianCalendar gcal3 = new GregorianCalendar(2012, 06, 15); final XMLGregorianCalendar xgcal3 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal3); final CourseType course = new CourseType(); course.setStartDateOfThisCourse(xgcal2); course.setEndDateOfThisCourse(xgcal3); course.setTreatmentType("Treatment"); course.setTreatmentAssignmentCode("TAC"); return course; }