List of usage examples for java.net URI toASCIIString
public String toASCIIString()
From source file:info.rmapproject.core.model.impl.openrdf.ORAdapterTest.java
@Test public void testOpenRdfIri2URI() { String urString = "http://rmap-project.info/rmap/"; IRI rIri = ORAdapter.getValueFactory().createIRI(urString); URI uri = ORAdapter.openRdfIri2URI(rIri); assertEquals(uri.toASCIIString(), rIri.stringValue()); }
From source file:org.apache.taverna.tavlang.tools.convert.ToJson.java
public ObjectNode toJson(WorkflowBundle wfBundle) { ObjectNode root = mapper.createObjectNode(); ArrayNode contextList = root.arrayNode(); root.put("@context", contextList); ObjectNode context = root.objectNode(); contextList.add("https://w3id.org/scufl2/context"); contextList.add(context);//from ww w. j a v a2 s.com URI base = wfBundle.getGlobalBaseURI(); context.put("@base", base.toASCIIString()); root.put("id", base.toASCIIString()); // root.put("name", wfBundle.getName()); // root.put("revisions", toJson(wfBundle.getCurrentRevision())); root.put("workflow", toJson(wfBundle.getMainWorkflow())); root.put("profile", toJson(wfBundle.getMainProfile())); return root; }
From source file:com.hp.autonomy.searchcomponents.hod.view.HodViewServerService.java
@Override public void viewDocument(final String reference, final ResourceIdentifier index, final OutputStream outputStream) throws IOException, HodErrorException { final GetContentRequestBuilder getContentParams = new GetContentRequestBuilder().setPrint(Print.all); final Documents<Document> documents = getContentService.getContent(Collections.singletonList(reference), index, getContentParams);//from w ww . j a v a 2s.c o m // This document will always exist because the GetContentService.getContent throws a HodErrorException if the // reference doesn't exist in the index final Document document = documents.getDocuments().get(0); final Map<String, Serializable> fields = document.getFields(); final Object urlField = fields.get(URL_FIELD); final String documentUrl = urlField instanceof List ? ((List<?>) urlField).get(0).toString() : document.getReference(); final UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES); InputStream inputStream = null; try { try { final URL url = new URL(documentUrl); final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null); final String encodedUrl = uri.toASCIIString(); if (urlValidator.isValid(encodedUrl)) { inputStream = viewDocumentService.viewUrl(encodedUrl, new ViewDocumentRequestBuilder()); } else { throw new URISyntaxException(encodedUrl, "Invalid URL"); } } catch (URISyntaxException | MalformedURLException e) { // URL was not valid, fall back to using the document content inputStream = formatRawContent(document); } catch (final HodErrorException e) { if (e.getErrorCode() == HodErrorCode.BACKEND_REQUEST_FAILED) { // HOD failed to read the url, fall back to using the document content inputStream = formatRawContent(document); } else { throw e; } } IOUtils.copy(inputStream, outputStream); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:org.apache.taverna.robundle.Bundles.java
public static Path setReference(Path path, URI ref) throws IOException { path = withExtension(path, DOT_URL); // We'll save a IE-like .url "Internet shortcut" in INI format. // HierarchicalINIConfiguration ini = new // HierarchicalINIConfiguration(); // ini.getSection(INI_INTERNET_SHORTCUT).addProperty(INI_URL, // ref.toASCIIString()); // Ini ini = new Wini(); // ini.getConfig().setLineSeparator("\r\n"); // ini.put(INI_INTERNET_SHORTCUT, INI_URL, ref.toASCIIString()); /*//from w w w. j a va 2 s . c o m * Neither of the above create a .url that is compatible with Safari on * Mac OS (which expects "URL=" rather than "URL = ", so instead we make * it manually with MessageFormat.format: */ // Includes a terminating double line-feed -- which Safari might also // need String iniTmpl = "[{0}]\r\n{1}={2}\r\n\r\n"; String ini = MessageFormat.format(iniTmpl, INI_INTERNET_SHORTCUT, INI_URL, ref.toASCIIString()); // NOTE: We use Latin1 here, but because of try (BufferedWriter w = newBufferedWriter(path, ASCII, TRUNCATE_EXISTING, CREATE)) { // ini.save(w); // ini.store(w); w.write(ini); // } catch (ConfigurationException e) { // throw new IOException("Can't write shortcut to " + path, e); } return path; }
From source file:com.viettel.viettellib.json.me.JSONParser.java
/** * /* ww w. ja va2 s .c om*/ * Mo ta chuc nang cua ham * @author: BangHN * @param address * @param method * @return * @throws URISyntaxException * @return: json string * @throws: */ public String excuteHttpRequest(String address, String method) { String jsonStr = ""; String url = null; //Tao duong dan truy cap try { URI uri = new URI("http", "maps.googleapis.com", "/maps/api/geocode/json", "address=" + address + "&sensor=true", null); url = uri.toASCIIString(); } catch (URISyntaxException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //1.truy vn server http://10.0.0.103/ltjoomla2106/index.php?option=com_json&format=json&id=15&task=requestdb /*to 1 client: chc nng ging nh trnh duyt*/ DefaultHttpClient client = new DefaultHttpClient(); /*to bin post y d liu: --> to header ca giao thc http*/ if (method == "POST") { HttpPost postObj = new HttpPost(url); /*t cc gi tr cn post vo bin http header*/ try { //ly v response l d liu chui JSON /*bm nt submit form trn trnh duyt*/ HttpResponse jsonString = client.execute(postObj); jsonStr = EntityUtils.toString(jsonString.getEntity()); Log.e("JSON STRiNG", jsonStr); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (method == "GET") { HttpGet getObj = new HttpGet(url); /*t cc gi tr cn post vo bin http header*/ try { //ly v response l d liu chui JSON /*bm nt submit form trn trnh duyt*/ HttpResponse jsonString = client.execute(getObj); jsonStr = EntityUtils.toString(jsonString.getEntity()); Log.e("JSON STRiNG", jsonStr); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return jsonStr; }
From source file:org.callimachusproject.xml.InputSourceResolver.java
@Override public Reader resolve(URI absoluteURI, String encoding, Configuration config) throws XPathException { try {//from w w w . ja v a 2 s .c o m InputSource source = resolve(absoluteURI.toASCIIString()); if (encoding != null && encoding.length() > 0) { source.setEncoding(encoding); } return source.getCharacterStream(); } catch (IOException e) { throw new XPathException(e.toString(), e); } }
From source file:info.rmapproject.core.model.impl.openrdf.ORAdapterTest.java
@Test public void testUri2OpenRdfIri() { String urString = "http://rmap-project.info/rmap/"; URI uri = null;// w w w .j a va 2s . com try { uri = new URI(urString); } catch (URISyntaxException e) { e.printStackTrace(); fail(); } IRI rIri = ORAdapter.uri2OpenRdfIri(uri); assertEquals(urString, rIri.stringValue()); URI uri2 = ORAdapter.openRdfIri2URI(rIri); assertEquals(urString, uri2.toASCIIString()); assertEquals(uri, uri2); }
From source file:com.basicservice.controller.UserController.java
@RequestMapping(value = "/register", method = RequestMethod.POST) public ResponseEntity<String> register(HttpServletRequest request, @RequestParam(value = "name") String name, @RequestParam(value = "email") EmailValidatedString email, @RequestParam(value = "password") String password) { if (email == null || email.getValue() == null || password == null) { return new ResponseEntity<String>(HttpStatus.FORBIDDEN); }/*from w ww. ja v a 2 s. co m*/ LOG.debug("Got register request: email:" + email.getValue() + ", pass:" + password + ", name:" + name); User user = null; try { user = userService.register(name, email.getValue(), password); } catch (UserRegistrationException e) { if (e.getReason() == UserRegistrationException.reason.EMAIL_EXISTS) { return new ResponseEntity<String>(HttpStatus.FORBIDDEN); } } if (user == null) { return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR); } LOG.debug("Preparing to save user to db"); final String id = userService.save(user); if (id != null) { String from = Constants.REGISTRATION_FROM_ADDRESS; String to = email.getValue(); Locale locale = LocaleContextHolder.getLocale(); String subject = messageLocalizationService.getMessage(Constants.MLS_REGISTRATION_CONFIRMATION_SUBJECT, locale); Object[] args = new String[1]; String path = Utils.getBasicPath(request); ConfirmationString cs = confirmationEmailService.getConfirmationString(user.getId()); URI uri = new UriTemplate("{requestUrl}/api/users/registrationConfirmation/?key={key}").expand(path, cs.getKey()); args[0] = uri.toASCIIString(); String messageHtml = messageLocalizationService.getMessage(Constants.MLS_REGISTRATION_CONFIRMATION_HTML, args, locale); try { mailService.sendEmail(from, to, subject, messageHtml); } catch (Exception e) { LOG.debug("Failed to send confirmation email to: " + to, e); } } final HttpHeaders headers = new HttpHeaders(); headers.add("Set-Cookie", Constants.AUTHENTICATED_USER_ID_COOKIE + "=" + id + "; Path=/"); return new ResponseEntity<String>(headers, HttpStatus.CREATED); }
From source file:info.rmapproject.core.model.impl.openrdf.ORAdapterTest.java
@Test public void testRMapIri2OpenRdfIri() throws RMapException, RMapDefectiveArgumentException { String urString = "http://rmap-project.info/rmap/"; URI uri = null;//ww w . j a va2 s . c o m try { uri = new URI(urString); } catch (URISyntaxException e) { e.printStackTrace(); fail(); } RMapIri rmIri = new RMapIri(uri); IRI rIri = ORAdapter.rMapIri2OpenRdfIri(rmIri); assertEquals(urString, rIri.stringValue()); URI uri2 = ORAdapter.openRdfIri2URI(rIri); assertEquals(urString, uri2.toASCIIString()); assertEquals(uri, uri2); }
From source file:com.serena.rlc.provider.jira.client.JiraClient.java
/** * @param path//from w ww.ja v a 2s . c o m * @return */ private String encodePath(String path) { String result; URI uri; try { uri = new URI(null, null, path, null); result = uri.toASCIIString(); } catch (Exception e) { result = path; } return result; }