@Override public String getString() throws IOException { return blob.getString(); }
@Override public void setBlob(Blob blob) { if (blob == null) { doc.getProperty(xPath).setValue(null); mt = null; } else { String string; try { string = blob.getString(); } catch (IOException e) { throw new NuxeoException(e); } // strip '\0 chars from text if (string.indexOf('\0') >= 0) { string = string.replace("\0", ""); } doc.getProperty(xPath).setValue(string); mt = blob.getMimeType(); } }
protected String getString(Blob blob) throws IOException { String s = guessEncoding(blob); if (s == null) { s = blob.getString(); // uses default charset } return s; }
protected String guessMimeType(Blob result, MimetypeRegistry mreg) { if (result == null) { return null; } String content; try { content = result.getString(); } catch (IOException e) { throw new NuxeoException(e); } if (XMLStartPattern.matcher(content).find()) { return "text/xml"; } if (HtmlTagPattern.matcher(content).find()) { return "text/html"; } return mreg.getMimetypeFromBlobWithDefault(result, "text/plain"); }
@Override public List<TemplateInput> getInitialParametersDefinition(Blob blob) throws IOException { List<TemplateInput> params = new ArrayList<TemplateInput>(); if (blob != null) { String xmlContent = blob.getString(); if (xmlContent != null) { List<String> vars = FreeMarkerVariableExtractor.extractVariables(xmlContent); for (String var : vars) { TemplateInput input = new TemplateInput(var); params.add(input); } } } return params; }
@Override public String getContent() { String encoding = "unset"; try { Blob blob = (Blob) doc.getPropertyValue("file:content"); if (blob == null) { return ""; } encoding = blob.getEncoding(); if (encoding == null || encoding.equals("")) { blob.setEncoding("utf-8"); } return blob.getString(); } catch (IOException | PropertyException e) { log.error("Error while reading content with encoding " + encoding, e); return "ERROR : " + e.getMessage(); } }
protected String getHtmlValue(BlobHolder bh) throws IOException { if (bh == null) { return ""; } Blob blob = bh.getBlob(); if (blob != null && "text/html".equals(blob.getMimeType())) { return blob.getString(); } ConversionService conversion = Framework.getService(ConversionService.class); BlobHolder htmlBh = conversion.convertToMimeType("text/html", bh, Collections.emptyMap()); if (htmlBh != null) { return htmlBh.getBlob().getString(); } if (blob != null && blob.getMimeType() != null && blob.getMimeType().startsWith("text/")) { return blob.getString(); } return ""; }
@Override public String getXmlFileContent() throws IOException { try { Blob xml = safeGet(Blob.class, "file:content", null); if (xml.getEncoding() == null || "".equals(xml.getEncoding())) { xml.setEncoding("utf-8"); } return xml.getString(); } catch (IOException e) { log.error("Error while reading blob", e); return ""; } }
@Override public TemplateCollectionModel values() throws TemplateModelException { try { List<Object> list = new ArrayList<Object>(keys.length); if (blob != null) { list.add(blob.getFilename()); list.add(blob.getString()); list.add(blob.getLength()); list.add(blob.getMimeType()); list.add(blob.getEncoding()); list.add(blob.getDigest()); } else { list.add(""); list.add(""); list.add(""); list.add(""); list.add(""); list.add(""); } return (TemplateCollectionModel) wrapper.wrap(list); } catch (IOException e) { throw new TemplateModelException("Failed to adapt complex property values", e); } }
@Override @SuppressWarnings("unchecked") public Map<String, String> getAttachments() { Map<String, String> attachments = new LinkedMap(); try { List<Map<String, Serializable>> atts = (List<Map<String, Serializable>>) doc.getPropertyValue("files:files"); if (atts != null) { for (Map<String, Serializable> att : atts) { Blob attBlob = (Blob) att.get("file"); if (attBlob.getEncoding() == null || attBlob.getEncoding().equals("")) { attBlob.setEncoding("utf-8"); } attachments.put((String) att.get("filename"), attBlob.getString()); } } } catch (IOException | PropertyException e) { log.error("Error while reading Attachments", e); } return attachments; }
@Override public String getManifest() { try { Blob mf = safeGet(Blob.class, "file:content", null); if (mf == null) { return "No MANIFEST.MF"; } if (mf.getEncoding() == null || "".equals(mf.getEncoding())) { mf.setEncoding("utf-8"); } return mf.getString(); } catch (IOException e) { log.error("Error while reading blob", e); return ""; } }
@Override public String getXml() { try { Blob xml = safeGet(Blob.class, "file:content", null); if (xml == null) { return ""; } if (xml.getEncoding() == null || "".equals(xml.getEncoding())) { xml.setEncoding("utf-8"); } return xml.getString(); } catch (IOException e) { log.error("Error while reading blob", e); return ""; } }
String initialBlobContent = blob.getString();
return ""; String string = resultBlob.getString();
String mdString = inputBlob.getString(); MarkDownParserAndSanitizer md = new MarkDownParserAndSanitizer(); StringBuilder html = new StringBuilder();
@OperationMethod public Blob run(Blob blob) throws OperationException, IOException { if (!ctx.getPrincipal().isAdministrator()) { throw new OperationException("Not allowed. You must be administrator to run scripts"); } Object r = null; if (type.equals("mvel")) { r = MvelScript.compile(blob.getString()).eval(ctx); } else if (type.equals("groovy")) { r = new GroovyScript(blob.getString()).eval(ctx); } else { throw new OperationException("Unknown scripting language " + type); } if (r != null) { Blob b = Blobs.createBlob(r.toString()); b.setFilename("result"); return b; } return null; }
@Override public Blob renderTemplate(TemplateBasedDocument templateBasedDocument, String templateName) throws IOException { Blob sourceTemplateBlob = getSourceTemplateBlob(templateBasedDocument, templateName); String fmTemplateKey = "main" + System.currentTimeMillis(); String ftl = sourceTemplateBlob.getString(); loader.putTemplate(fmTemplateKey, ftl); Map<String, Object> ctx = fmContextBuilder.build(templateBasedDocument, templateName); FMBindingResolver resolver = new FMBindingResolver(); resolver.resolve(templateBasedDocument.getParams(templateName), ctx, templateBasedDocument); StringWriter writer = new StringWriter(); try { getEngine().render(fmTemplateKey, ctx, writer); } catch (RenderingException e) { throw new IOException(e); } Blob result = Blobs.createBlob(writer.toString()); setBlobAttributes(result, templateBasedDocument); return result; }
@Override public TemplateModel get(String name) throws TemplateModelException { try { if (blob != null) { if (keys[0].equals(name)) { return new SimpleScalar(blob.getFilename()); } else if (keys[1].equals(name)) { return new SimpleScalar(blob.getString()); } else if (keys[2].equals(name)) { return new SimpleNumber(blob.getLength()); } else if (keys[3].equals(name)) { return new SimpleScalar(blob.getMimeType()); } else if (keys[4].equals(name)) { return new SimpleScalar(blob.getEncoding()); } else if (keys[5].equals(name)) { return new SimpleScalar(blob.getDigest()); } } return NOTHING; } catch (IOException e) { throw new TemplateModelException(e); } }
if (propValue != null && propValue instanceof Blob) { Blob blobValue = (Blob) propValue; context.put(param.getName(), blobValue.getString()); handleBlobField(param.getName(), blobValue);
throw new MarshallingException("Unable to parse the property " + property.getXPath()); return blob.getString();