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); } }
@Test(expected=IllegalArgumentException.class) public void name_cannotContainColon() throws Exception { new Clob("with a colon : in it", "application", "xml", "abc"); }
@Test public void happyCase() throws Exception { new Clob("validName", "application", "xml", "abc"); }
@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); }
@Action( semantics = SemanticsOf.SAFE ) public Clob exportAsXml( final ToDoAppDashboard dashboard, String fileName ) { if(!fileName.endsWith(".xml")) { fileName += ".xml"; } final XmlSnapshotService.Builder builder = xmlSnapshotService.builderFor(dashboard); builder.includePath("notYetComplete"); final XmlSnapshotService.Snapshot snapshot = builder.build(); return new Clob( fileName, "application/xml", snapshot.getXmlDocumentAsString()); }
@Action( semantics = SemanticsOf.SAFE, domainEvent = ActionDomainEvent.class ) @ActionLayout(named = "Download") public Clob $$() { return new Clob(document.getName(), document.getMimeType(), document.getText()); }
@javax.jdo.annotations.NotPersistent @Property( notPersisted = true, // exclude from auditing domainEvent = ClobDomainEvent.class, editing = Editing.DISABLED ) public Clob getClob() { return new Clob(getName(), getMimeType(), getClobChars()); } @Programmatic
@javax.jdo.annotations.NotPersistent @Property( notPersisted = true, // exclude from auditing domainEvent = ClobDomainEvent.class, editing = Editing.DISABLED ) public Clob getClob() { return new Clob(getName(), getMimeType(), getClobChars()); } @Programmatic
@Action( semantics = SemanticsOf.SAFE, domainEvent = ActionDomainEvent.class ) @ActionLayout(named = "Download") public Clob $$() { return new Clob(document.getName(), document.getMimeType(), document.getText()); }
@Action(semantics = SemanticsOf.SAFE) public Clob exportAsXml( final ToDoItem toDoItem, String fileName ) { if(!fileName.endsWith(".xml")) { fileName += ".xml"; } final XmlSnapshotService.Builder builder = xmlSnapshotService.builderFor(toDoItem); builder.includePath("dependencies"); builder.includePath("similarTo"); final XmlSnapshotService.Snapshot snapshot = builder.build(); return new Clob( fileName, "application/xml", snapshot.getXmlDocumentAsString()); }
@Action( domainEvent = DownloadMetaModelEvent.class, semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING ) @ActionLayout( cssClassFa = "fa-download", named = "Download Meta Model (CSV)" ) @MemberOrder(sequence="500.500.1") public Clob downloadMetaModel( @ParameterLayout(named = ".csv file name") final String csvFileName) { final List<DomainMember> rows = metaModelService.export(); final List<String> list = asList(rows); final StringBuilder buf = asBuf(list); return new Clob( Util.withSuffix(csvFileName, "csv"), mimeTypeTextCsv, buf.toString().toCharArray()); }
@Action( domainEvent = DownloadPotFileDomainEvent.class, semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING ) @ActionLayout( cssClassFa = "fa-download" ) @MemberOrder(sequence="500.700.1") public Clob downloadTranslations( @ParameterLayout(named = ".pot file name") final String potFileName) { final String chars = translationService.toPot(); return new Clob(Util.withSuffix(potFileName, "pot"), "text/plain", chars); }
@Action( domainEvent = ActionDomainEvent.class, semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING ) @ActionLayout( contributed = Contributed.AS_ACTION, cssClassFa = "fa-download" ) @MemberOrder(sequence = "500.1") public Object act( @ParameterLayout(named = "File name") final String fileName) { final String xml = jaxbService.toXml(dto); return new Clob(Util.withSuffix(fileName, "xml"), "text/xml", xml); }
@Programmatic public Clob downloadAsClob(final Document document) { try { final URL url = new URL(document.getExternalUrl()); final HttpURLConnection httpConn = openConnection(url); if (httpConn == null) { return null; } final String contentType = httpConn.getContentType(); final MimeType mimeType = determineMimeType(contentType); if (mimeType == null) { return null; } final Charset charset = determineCharset(contentType); if (charset == null) { return null; } httpConn.disconnect(); final CharSource charSource = Resources.asCharSource(url, charset); final String chars = charSource.read(); return new Clob(document.getName(), mimeType.getBaseType(), chars); } catch (IOException e) { messageService.warnUser(TranslatableString.tr( "Could not download from URL"), UrlDownloadService.class, "downloadExternalUrlAsClob"); return null; } }
@Action( domainEvent = DownloadMenuBarsLayoutDomainEvent.class, semantics = SemanticsOf.SAFE, restrictTo = RestrictTo.PROTOTYPING ) @ActionLayout( cssClassFa = "fa-download", named = "Download Menu Bars Layout (XML)" ) @MemberOrder(sequence="500.400.2") public Clob downloadMenuBarsLayout( @ParameterLayout(named = "File name") final String fileName, final MenuBarsService.Type type) { final String xml = layoutService.toMenuBarsXml(type); return new Clob(Util.withSuffix(fileName, ".xml"), "text/xml", xml); }
@Programmatic public Clob downloadAsClob(final Document document) { try { final URL url = new URL(document.getExternalUrl()); final HttpURLConnection httpConn = openConnection(url); if (httpConn == null) { return null; } final String contentType = httpConn.getContentType(); final MimeType mimeType = determineMimeType(contentType); if (mimeType == null) { return null; } final Charset charset = determineCharset(contentType); if (charset == null) { return null; } httpConn.disconnect(); final CharSource charSource = Resources.asCharSource(url, charset); final String chars = charSource.read(); return new Clob(document.getName(), mimeType.getBaseType(), chars); } catch (IOException e) { messageService.warnUser(TranslatableString.tr( "Could not download from URL"), UrlDownloadService.class, "downloadExternalUrlAsClob"); return null; } }
public Object getObject(ExecutionContext ec, ResultSet resultSet, int[] exprIndex) { try { // Check for null entries if (getDatastoreMapping(0).getObject(resultSet, exprIndex[0]) == null) { return null; } } catch (Exception e) { // Do nothing } final String name = getDatastoreMapping(0).getString(resultSet, exprIndex[0]); final String mimeTypeBase = getDatastoreMapping(1).getString(resultSet, exprIndex[1]); final String str = getDatastoreMapping(2).getString(resultSet, exprIndex[2]); if(name == null || mimeTypeBase == null || str == null) { return null; } return new Clob(name, mimeTypeBase, str.toCharArray()); } }
@Action( semantics = SemanticsOf.SAFE, domainEvent = DownloadSwaggerSpecDomainEvent.class, restrictTo = RestrictTo.PROTOTYPING ) @ActionLayout( cssClassFa = "fa-download" ) @MemberOrder(sequence="500.600.3") public Clob downloadSwaggerSchemaDefinition( @ParameterLayout(named = "Filename") final String fileNamePrefix, final SwaggerService.Visibility visibility, final SwaggerService.Format format) { final String fileName = Util.buildFileName(fileNamePrefix, visibility, format); final String spec = swaggerService.generateSwaggerSpec(visibility, format); return new Clob(fileName, format.mediaType(), spec); }
@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())); } }
@Before public void setUpObjects() throws Exception { clob = new Clob("myfile1.xml", "application", "xml", "abcdef"); allowMockAdapterToReturn(clob); holder = new FacetHolderImpl(); setValue(value = new ClobValueSemanticsProvider(holder, mockServicesInjector)); }