String textEmail= "Hi, \n this is an automatic message \n from sender.
StringBuffer buffer = sb.append("BEGIN:VCALENDAR\n" +
"PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
"ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" +emailAdressTo+"\n" +
"ORGANIZER:MAILTO:XX#gmail.com\n" +
"DTSTART:" + meetingStartTime + "\n"+
"DTEND:" + meetingEndTime + "\n"+
"LOCATION: Room FR PAR-New York\n" +
"TRANSP:OPAQUE\n" +
"SEQUENCE:0\n" +
"UID:"+ uniqueId +"\n" +
"DTSTAMP:"+ meetingEndTime + "\n" +
"CATEGORIES:Meeting\n" +
"DESCRIPTION:"+textEmail +"\n" +
"SUMMARY:"+subjectEmail+"\n" +
"PRIORITY:5\n" +
"CLASS:PUBLIC\n" +
"BEGIN:VALARM\n" +
"TRIGGER:PT1440M\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:Reminder\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR");
email.setContent(buffer.toString(),"text/calendar");
email.setCharset("UTF-8");
the linebreaks breaks are not taken in consideration and my output is just:
"Hi,this is an automatic message from sender"
I have tried every think in this post:
[1]How do I format a String in an email so Outlook will print the line breaks? but still same result Any help would be apreciated, thks
List item
Related
builder.append("BEGIN:VCALENDAR\n" +
"METHOD:REQUEST\n" +
"PRODID:Microsoft Exchange Server 2010\n" +
"VERSION:2.0\n" +
"BEGIN:VTIMEZONE\n" +
"TZID:Eastern Time\n" +
"END:VTIMEZONE\n" +
"BEGIN:VEVENT\n" +
"ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" + calendarRequest.getToEmail() + "\n" +
"ORGANIZER;CN=ORGANIZER:MAILTO:" + fromEmail + "\n" +
"DESCRIPTION;LANGUAGE=en-US:" + calendarRequest.getBody() + "\n" +
"UID:"+calendarRequest.getUid()+"\n" +
"SUMMARY;LANGUAGE=en-US:Discussion\n" +
"DTSTART:" + formatter.format(MeetingStartTime).replace(" ", "T") + "\n" +
"DTEND:" + formatter.format(MeetingEndTime).replace(" ", "T") + "\n" +
"CLASS:PUBLIC\n" +
"PRIORITY:5\n" +
"DTSTAMP:20200922T105302Z\n" +
"TRANSP:OPAQUE\n" +
"STATUS:CONFIRMED\n" +
"SEQUENCE:$sequenceNumber\n" +
"LOCATION;LANGUAGE=en-US:Microsoft Teams Meeting\n" +
"BEGIN:VALARM\n" +
"DESCRIPTION:REMINDER\n" +
"TRIGGER;RELATED=START:-PT15M\n" +
"ACTION:DISPLAY\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR");
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
messageBodyPart.setHeader("Content-ID", "calendar_message");
messageBodyPart.setDataHandler(new DataHandler(
new ByteArrayDataSource(builder.toString(), "text/calendar;method=REQUEST;name=\"invite.ics\"")));
Here I am trying to send an outlook invitation through java code it's showing an error "not supported invite.ics".
I have checked form and organizer email both are same.
I am using outlook 2016.
I created an app that uses Leaflet in it.
In the screen where the map is, there is also a progressBar where I allow uses to search in a specific radius.
The moment they change the value in the progressBar, it changes the size of the circle marker inside the map.
I had like that my map will change its zoom to fit that circle in it.
My code for loading the map is:
String Map_HTML = "<html>\n" +
"<head>\n" +
"\n" +
" <title>Quick Start - Leaflet</title>\n" +
"\n" +
" <meta charset=\"utf-8\" />\n" +
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
"\n" +
" <link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"docs/images/favicon.ico\" />\n" +
"\n" +
" <link rel=\"stylesheet\" href=\"https://unpkg.com/leaflet#1.4.0/dist/leaflet.css\" integrity=\"sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==\" crossorigin=\"\"/>\n" +
" <script src=\"https://unpkg.com/leaflet#1.4.0/dist/leaflet.js\" integrity=\"sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg==\" crossorigin=\"\"></script>\n" +
"\n" +
"\n" +
"\n" +
"<style>\n" +
"body {\n" +
"padding: 0;\n" +
"margin: 0;\n" +
"}\n" +
"html, body, #map {\n" +
"height: 100%;\n" +
"width: 100%;\n" +
"}\n" +
"</style>\n" +
"</head>\n" +
"<body>\n" +
"\n" +
"\n" +
"\n" +
"<div id=\"mapid\" style=\"width: " + dpWidth + "px; height: " + dpHeight * 0.3 + "px;\"></div>\n" +
"<script>\n" +
"\n" +
"var mymap = L.map('mapid',{zoomControl: false}).setView([" + Lat + ", " + Lon + "], 10);\n" +
"\n" +
" L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {\n" +
" minZoom: 7,\n" +
" maxZoom: 17,\n" +
" attribution: '© OpenStreetMap contributors' \n" +
" }).addTo(mymap);\n" +
"\n" +
"mymap.attributionControl.setPosition('topleft')\n" +
"L.control.zoom({\n" +
"position: 'bottomright'\n" +
"}).addTo(mymap);\n" +
"L.marker([" + Lat + ", " + Lon + "]).addTo(mymap)\n" +
" .bindPopup(\"<b>My Location</b>\").openPopup();\n" +
"\n" +
"L.circle([" + Lat + ", " + Lon + "], " + Radius + ", {\n" +
" color: 'red',\n" +
" fillColor: '#8275FE',\n" +
" fillOpacity: 0.4,\n" +
" weight: '0'\n" +
"}).addTo(mymap);\n" +
"\n" +
"\n" +
"var popup = L.popup();\n" +
"\n" +
"</script>\n" +
"\n" +
"</body>\n" +
"</html>";
where Radius is a parameter I insert based on the value of the progressBar.
Right now it always initializes the map with zoom: 10 because I don't know how to change it dynamically as I want.
Any way to do so?
Thank you
the map can fit to the bounds of the circle with mymap.fitBounds(circle.getBounds());.
Change your code to:
"var circle = L.circle([" + Lat + ", " + Lon + "], " + Radius + ", {\n" +
" color: 'red',\n" +
" fillColor: '#8275FE',\n" +
" fillOpacity: 0.4,\n" +
" weight: '0'\n" +
"}).addTo(mymap);\n" +
"mymap.fitBounds(circle.getBounds());\n" +
I have the following data, which is a list of lists:
"segmentation": [[239.97,260.24,222.04,270.49,199.84,253.41,213.5,227.79,259.62,200.46,274.13,202.17,277.55,210.71,249.37,253.41,237.41,264.51,242.54,261.95,228.87,271.34]]
What I need to do is to parse the information to a JSON object without removing the second braces.
I tried it with Jackson, but this fails with any data types.
Do you have any idea how to handle this?
Parse to JsonNode will work. I think u try with invalid json. check:
String value = "{\n" +
" \"segmentation\": [\n" +
" [\n" +
" 239.97,\n" +
" 260.24,\n" +
" 222.04,\n" +
" 270.49,\n" +
" 199.84,\n" +
" 253.41,\n" +
" 213.5,\n" +
" 227.79,\n" +
" 259.62,\n" +
" 200.46,\n" +
" 274.13,\n" +
" 202.17,\n" +
" 277.55,\n" +
" 210.71,\n" +
" 249.37,\n" +
" 253.41,\n" +
" 237.41,\n" +
" 264.51,\n" +
" 242.54,\n" +
" 261.95,\n" +
" 228.87,\n" +
" 271.34\n" +
" ]\n" +
" ]\n" +
"}";
JsonNode jsonNode = new ObjectMapper().readTree(value);
I am trying to have a string that when i print it, has multiple lines and different left indents.
String test = "Zone 0:" +
"Gear{" + "gearType=" + gearType + ", weight=" + weight}" +
"Zone 1:" +
"Gear{" + "gearType=" + gearType + ", weight=" +weight}";
System.out.println(test);
Expected Output: (without the dashes but with a left indent)
Zone 0:
------Gear{gearType=RAIN_JACKET, weight=HIGH}
Zone 1:
------Gear{gearType=SHELTER, weight=HIGH}
You can make use of "\n" new line character and "\t" for tab. Like:
final String test = "Zone 0:\n" + "\tGear{" + "gearType=" + gearType + ", weight=" + weight +"}\n" + "Zone 1:\n"
+ "\tGear{" + "gearType=" + gearType + ", weight=" + weight + "}\n";
As well as after weight there should be + sign and a double quote ". (as in above String)
you can use the "\n" for new line and "\t" for tabulation space :
String test = "Zone 0:\n" + "\tGear{" + "gearType=" +
gearType + ", weight=" + "weight}\n" +
"Zone 1:\n" + "\tGear{" + "gearType=" +
gearType + ", weight=" + "weight}";
output :
Zone 0:
Gear{gearType=test, weight=weight}
Zone 1:
Gear{gearType=test, weight=weight}
You may also refer to the official Formatter documentation. There you'll get all the other options and details for formatting a String in Java.
Presumably you'd want the lines to use the appropriate line terminator for your platform, i.e. \r\n for Windows and \n for Linux.
There are two ways to do that:
Use System.lineSeparator():
String test = "Zone 0:" + System.lineSeparator() +
" Gear{gearType=" + gearType + ", weight=" + weight + "}" + System.lineSeparator() +
"Zone 1:" + System.lineSeparator() +
" Gear{gearType=" + gearType + ", weight=" + weight + "}" + System.lineSeparator();
Use String.format(String format, Object... args) and the %n format specifier:
String test = String.format("Zone 0:%n" +
" Gear{gearType=%s, weight=%s}%n" +
"Zone 1:%n" +
" Gear{gearType=%s, weight=%s}%n",
gearType, weight, gearType, weight);
I'd recommend the second approach, since it's more readable.
May be an idea to rather use a StringBuilder (though from what I understand the Java compiler uses StringBuilder under the hood for String concatenation), so it really becomes more of a readability issue.
StringBuilder output = new StringBuilder()
.append(System.lineSeparator()).append("Zone 0:")
.append(System.lineSeparator()).append("\tGear{gearType=").append(gearType).append(", weight=").append(weight).append("}")
.append(System.lineSeparator()).append("Zone 1:")
.append(System.lineSeparator()).append("\tGear{gearType=").append(gearType).append(", weight=").append(weight).append("}");
System.out.print(output.toString());
For newlines it's good practice to use System.lineSeparator()
I would like to insert a carriage return into a cell of a xls file.
So I have written this code
address = rs.getString(16) + " " + rs.getString(17) + "
"
+ rs.getString(18) + " " + rs.getString(19) + " (" +
rs.getString(20) + ")";
"writer.write("<ss:Cell><ss:Data ss:Type=\"String\">" + address + "</ss:Data></ss:Cell>");`
but in the Excel File the result is that the carriage return is replaced with a "square symbol". In which mode can I resolve this issue?
Thanks,
Stefano
In excel, to enter a new line in a cell, you need to insert ASCII characters 13 + 10 (constant CrLf on this page : http://msdn.microsoft.com/en-us/library/f63200h0%28v=vs.80%29.aspx).
Have you tried:
String crLf = Character.toString((char)13) + Character.toString((char)10);
address = rs.getString(16) + " " + rs.getString(17) + crLf
+ rs.getString(18) + " " + rs.getString(19) + " (" +
rs.getString(20) + ")";