private static Clob asClob(final String fileName) { final URL resource = Resources.getResource(IsisBlobs.class, "clobs/" + fileName); final CharSource charSource = Resources.asCharSource(resource, Charsets.US_ASCII); final String chars; try { chars = charSource.read(); return new Clob(fileName, mimeTypeFor(fileName), chars); } catch (IOException e) { throw new RuntimeException(e); } }
public Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, Object value) { Clob clob = ((Clob)value); switch (index) { case 0: return clob.getName(); case 1: return clob.getMimeType().getBaseType(); case 2: return clob.getChars(); } throw new IndexOutOfBoundsException(); }
public Clob(String name, String primaryType, String subType, CharSequence chars) { this(name, newMimeType(primaryType, subType), chars); }
private static IResourceStream resourceStreamFor(final Clob clob) { final IResourceStream resourceStream = new StringResourceStream(clob.getChars(), clob.getMimeType().toString()); return resourceStream; }
@Test public void when_clob_is_not_null() { final Clob val = new Clob("image.png", "image/png", new char[]{1,2,3,4,5}); CommonDtoUtils.setValueOn(valueDto, ValueType.CLOB, val, mockBookmarkService); final ClobDto clobDto = valueDto.getClob(); Assert.assertThat(clobDto, is(notNullValue())); Assert.assertThat(clobDto.getChars(), is(val.getChars())); Assert.assertThat(clobDto.getName(), is(val.getName())); Assert.assertThat(clobDto.getMimeType(), is(val.getMimeType().toString())); } }
@Override public String asChars(final DocumentAbstract<?> document) { final FactoryService factoryService = document.factoryService; final Clob clob = factoryService.mixin(Document_downloadExternalUrlAsClob.class, document).$$(); final CharSequence chars = clob.getChars(); return chars instanceof String ? (String) chars : chars.toString(); } };
private static IResourceStream resourceStreamFor(final Clob clob) { final IResourceStream resourceStream = new StringResourceStream(clob.getChars(), clob.getMimeType().toString()); return resourceStream; }
@Override public String asChars(final DocumentAbstract<?> document) { final FactoryService factoryService = document.factoryService; final Clob clob = factoryService.mixin(Document_downloadExternalUrlAsClob.class, document).$$(); final CharSequence chars = clob.getChars(); return chars instanceof String ? (String) chars : chars.toString(); } };
@Override public String toString() { return getName() + " [" + getMimeType().getBaseType() + "]: " + getChars().length() + " chars"; }
@Test(expected=IllegalArgumentException.class) public void name_cannotContainColon() throws Exception { new Clob("with a colon : in it", "application", "xml", "abc"); }
@Action( semantics = SemanticsOf.IDEMPOTENT, domainEvent = ActionDomainEvent.class ) @ActionLayout(contributed = Contributed.AS_ACTION) public DocumentTemplate $$( @ParameterLayout(named = "File") final Clob clob ) { documentTemplate.setMimeType(clob.getMimeType().toString()); documentTemplate.setClobChars(clob.getChars().toString()); return documentTemplate; }
public Clob(String name, String mimeTypeBase, CharSequence chars) { this(name, newMimeType(mimeTypeBase), chars); }
@Programmatic public void modifyClob(Clob clob) { setName(clob.getName()); setMimeType(clob.getMimeType().toString()); setClobChars(clob.getChars().toString()); setSort(DocumentSort.CLOB); }
@Test public void happyCase() throws Exception { new Clob("validName", "application", "xml", "abc"); }
@Action( semantics = SemanticsOf.IDEMPOTENT, domainEvent = ActionDomainEvent.class ) @ActionLayout(contributed = Contributed.AS_ACTION) public DocumentTemplate $$( @ParameterLayout(named = "File") final Clob clob ) { documentTemplate.setMimeType(clob.getMimeType().toString()); documentTemplate.setClobChars(clob.getChars().toString()); return documentTemplate; }
@Programmatic public void modifyClob(Clob clob) { setName(clob.getName()); setMimeType(clob.getMimeType().toString()); setClobChars(clob.getChars().toString()); setSort(DocumentSort.CLOB); }
return new Clob(Util.withSuffix(fileName, "xsd"), "text/xml", entry.getValue());
public void setObject(ExecutionContext ec, PreparedStatement preparedStmt, int[] exprIndex, Object value) { Clob clob = ((Clob)value); if (clob == null) { getDatastoreMapping(0).setObject(preparedStmt, exprIndex[0], null); getDatastoreMapping(1).setObject(preparedStmt, exprIndex[1], null); getDatastoreMapping(2).setObject(preparedStmt, exprIndex[2], null); } else { getDatastoreMapping(0).setString(preparedStmt, exprIndex[0], clob.getName()); getDatastoreMapping(1).setString(preparedStmt, exprIndex[1], clob.getMimeType().getBaseType()); getDatastoreMapping(2).setObject(preparedStmt, exprIndex[2], clob.getChars().toString()); } }
@Action( domainEvent = ActionDomainEvent.class, semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING ) @ActionLayout( contributed = Contributed.AS_ACTION, cssClassFa = "fa-download", position = ActionLayout.Position.PANEL_DROPDOWN ) @MemberOrder(name = "datanucleusIdLong", sequence = "700.1") public Object act( @ParameterLayout(named = "File name") final String fileName, final LayoutService.Style style) { final String xml = layoutService.toXml(object.getClass(), style); return new Clob(Util.withSuffix(fileName, style.name().toLowerCase() + ".xml"), "text/xml", xml); }
@Test public void testEncode_and_decode() { String encoded = value.toEncodedString(clob); assertEquals("myfile1.xml:application/xml:abcdef", encoded); Clob decoded = value.fromEncodedString(encoded); assertThat(decoded.getName(), is("myfile1.xml")); assertThat(decoded.getMimeType().getPrimaryType(), is("application")); assertThat(decoded.getMimeType().getSubType(), is("xml")); assertThat(decoded.getChars(), is((CharSequence)"abcdef")); }