use of org.phoebus.logbook.Attachment in project phoebus by ControlSystemStudio.
the class OlogAttributeProvider method setAttributes.
/**
* Processes image nodes to prepend the service root URL, where needed. For table nodes the olog-table
* class is added in order to give it some styling.
*
* @param node The {@link org.commonmark.node.Node} being processed.
* @param s The HTML tag, e.g. p, img, strong etc.
* @param map Map of attributes for the node.
*/
@Override
public void setAttributes(org.commonmark.node.Node node, String s, Map<String, String> map) {
if (node instanceof TableBlock) {
map.put("class", "olog-table");
}
// Relative paths must be prepended with service root URL, while absolute URLs must not be changed.
if (node instanceof org.commonmark.node.Image) {
String src = map.get("src");
if (!src.toLowerCase().startsWith("http") && !this.preview) {
if (serviceUrl.endsWith("/")) {
serviceUrl = serviceUrl.substring(0, serviceUrl.length() - 1);
}
src = serviceUrl + "/" + src;
}
// has to be converted to 'file://attachment_path'
if (src.startsWith("attachment") && this.preview) {
String attachmentId = src.substring(11, src.length());
for (Attachment attachment : attachments) {
if (attachment.getId().equals(attachmentId)) {
src = "file://" + FilenameUtils.separatorsToUnix(attachment.getFile().getAbsolutePath());
}
}
}
map.put("src", src);
}
}
use of org.phoebus.logbook.Attachment in project phoebus by ControlSystemStudio.
the class SendLogbookAction method submitLogEntry.
private void submitLogEntry(final Node parent, final String title, final String body, final File image_file) {
OlogLog ologLog = new OlogLog();
ologLog.setTitle(title != null ? title : "");
ologLog.setDescription(body != null ? body : "");
if (image_file != null) {
try {
final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
List<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
ologLog.setAttachments(attachments);
} catch (FileNotFoundException ex) {
logger.log(Level.WARNING, "Cannot attach " + image_file, ex);
}
}
new LogEntryEditorStage(parent, ologLog).show();
}
Aggregations