/** * A helper method that serializes the element object. * * @param stream * the stream to which the element should be serialized. * @throws IOException * if an IO error occured or a property was not serializable. */ private void writeObject( final ObjectOutputStream stream ) throws IOException { stream.defaultWriteObject(); try { final DocumentBundle bundle = getBundle(); stream.writeObject( bundle.getMetaData().getBundleType() ); final MemoryDocumentBundle mem = new MemoryDocumentBundle(); BundleUtilities.copyStickyInto( mem, bundle ); BundleUtilities.copyInto( mem, bundle, LegacyBundleResourceRegistry.getInstance().getRegisteredFiles(), true ); BundleUtilities.copyMetaData( mem, bundle ); mem.getWriteableDocumentMetaData().setBundleType( "application/vnd.pentaho.serialized-bundle" ); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BundleUtilities.writeAsZip( outputStream, mem ); stream.writeObject( outputStream.toByteArray() ); } catch ( ContentIOException e ) { throw new IOException( "Unable to serialize the bundle", e ); } }
/** * Returns an unique name for the given pattern, producing a file relative to the parent file name. The returned path * will be an <b>absolute</b> path starting from the root of the bundle. When linking to this path via href-references * that imply relative paths, use {@link org.pentaho.reporting.libraries.base.util.IOUtils#createRelativePath(java * .lang.String, * java.lang.String)} to transform the absolute path returned here into a path relative to your current context. * * @param bundle the document bundle for which we seek a new unique file name. * @param parent the parent path to which the pattern is relative to. * @param pattern the file name pattern. We expect one parameter only. * @return the unique file name, never null. * @throws IllegalStateException if the first 2 million entries we test do not yield a unique name we can use. */ public static String getUniqueName( final DocumentBundle bundle, final String parent, final String pattern ) { final String fullPattern = IOUtils.getInstance().getAbsolutePath( pattern, parent ); return getUniqueName( bundle, fullPattern ); }
public RepositoryResourceBundleLoader( final Repository repository, final ResourceKey outsideContextKey ) { if ( repository == null ) { throw new NullPointerException(); } this.repository = repository; final HashMap<FactoryParameterKey, Object> map = new HashMap<FactoryParameterKey, Object>(); map.put( new FactoryParameterKey( "repository" ), repository ); map.put( new FactoryParameterKey( "repository-loader" ), this ); this.bundleKey = new ResourceKey( outsideContextKey, SCHEMA, new Object(), map ); final String bundleType = BundleUtilities.getBundleType( repository ); final String bundleMapping = BundleUtilities.getBundleMapping( bundleType ); if ( bundleMapping == null ) { throw new IllegalStateException( "Invalid configuration: No Bundle-Mapping for the bundle-type " + bundleType ); } this.mainKey = new ResourceKey( bundleKey, INNER_SCHEMA, bundleMapping, null ); }
/** * Returns the object for this element. * * @return the object. */ public Object getObject() { if ( "float".equals( valueType ) ) { try { return new BigDecimal( value ); } catch ( NumberFormatException nfe ) { try { final double val = new Double( value ).doubleValue(); return new BigDecimal( val ); } catch ( NumberFormatException nfe2 ) { return null; } } } else if ( "date".equals( valueType ) ) { return BundleUtilities.parseDate( value ); } else if ( "time".equals( valueType ) ) { return BundleUtilities.parseDuration( value ); } else if ( "boolean".equals( valueType ) ) { if ( value.equals( "true" ) ) { return new UserDefinedAttribute( name, Boolean.TRUE ); } return new UserDefinedAttribute( name, Boolean.FALSE ); } else { return new UserDefinedAttribute( name, value ); } }
BundleUtilities.copyStickyInto( mem, bundle ); BundleUtilities.copyInto( mem, bundle, LegacyBundleResourceRegistry.getInstance().getRegisteredFiles(), true ); BundleUtilities.copyMetaData( mem, bundle ); mem.getWriteableDocumentMetaData().setBundleType( bundleType ); setBundle( mem );
public static void writeAsZip( final File target, final DocumentBundle bundle ) throws IOException, ContentIOException { if ( target == null ) { throw new NullPointerException(); } if ( bundle == null ) { throw new NullPointerException(); } final FileOutputStream fout = new FileOutputStream( target ); final BufferedOutputStream bout = new BufferedOutputStream( fout ); try { writeAsZip( bout, bundle ); } finally { bout.close(); } }
public static void copyInto( final WriteableDocumentBundle targetBundle, final DocumentBundle sourceBundle, final String[] files, final boolean ignoreSticky ) throws IOException { if ( targetBundle == null ) { throw new NullPointerException(); } if ( sourceBundle == null ) { throw new NullPointerException(); } if ( files == null ) { throw new NullPointerException(); } final HashSet<String> fileSet = new HashSet<String>( Arrays.asList( files ) ); final WriteableDocumentMetaData targetBundleMetaData = targetBundle.getWriteableDocumentMetaData(); final DocumentMetaData bundleMetaData = sourceBundle.getMetaData(); targetBundleMetaData.setBundleType( bundleMetaData.getBundleType() ); // copy the meta-data final String[] namespaces = bundleMetaData.getMetaDataNamespaces(); for ( int namespaceIdx = 0; namespaceIdx < namespaces.length; namespaceIdx++ ) { final String namespace = namespaces[ namespaceIdx ]; final String[] dataNames = bundleMetaData.getMetaDataNames( namespace ); for ( int dataNameIdx = 0; dataNameIdx < dataNames.length; dataNameIdx++ ) { final String dataName = dataNames[ dataNameIdx ]; final Object value = bundleMetaData.getBundleAttribute( namespace, dataName ); targetBundleMetaData.setBundleAttribute( namespace, dataName, value ); } }
if ( attributeValue instanceof ResourceKey ) { final ResourceKey path = (ResourceKey) attributeValue; final boolean linked = BundleUtilities.isSameBundle( elementSource, path ); return new ResourceReference[] { new ResourceReference( path, linked ) }; } else if ( attributeValue instanceof String && contentBase != null ) { final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) {
/** * Returns the object for this element. * * @return the object. */ public Object getObject() { return BundleUtilities.parseDate( getResult() ); } }
public static Date parseDate( final String date ) { if ( date.startsWith( "PT" ) ) { return parseDuration( date ); } final SimpleDateFormat dateFormat = new SimpleDateFormat(); dateFormat.setLenient( false ); for ( int i = 0; i < DATEFORMATS.length; i++ ) { try { final String dateformat = DATEFORMATS[ i ]; dateFormat.applyPattern( dateformat ); return dateFormat.parse( date ); } catch ( ParseException e ) { // ignore } } return null; }
/** * Writes a certain aspect into a own file. The name of file inside the bundle is returned as string. The file name * returned is always absolute and can be made relative by using the IOUtils of LibBase. If the writer-handler did not * generate a file on its own, it should return null. * * @param bundle * the bundle where to write to. * @param state * the writer state to hold the current processing information. * @return the name of the newly generated file or null if no file was created. * @throws IOException * if any error occured * @throws BundleWriterException * if a bundle-management error occured. */ public String writeReport( final WriteableDocumentBundle bundle, final BundleWriterState state ) throws IOException, BundleWriterException { BundleUtilities.copyStickyInto( bundle, state.getGlobalBundle() ); // Process all nodes starting at the top processSection( bundle, state.getMasterReport(), state.getMasterReport() ); // Don't return anything ... we may have created none-or-more files return null; }
public static void writeReportToZipFile( final MasterReport report, final File file ) throws IOException, BundleWriterException, ContentIOException { if ( report == null ) { throw new NullPointerException(); } if ( file == null ) { throw new NullPointerException(); } final MemoryDocumentBundle outputBundle = new MemoryDocumentBundle(); final BundleWriter writer = new BundleWriter(); writer.writeReport( outputBundle, report ); BundleUtilities.writeAsZip( file, outputBundle ); }
final String relativePath = IOUtils.getInstance().createRelativePath( identifierString, contentBasePath ); try { BundleUtilities.copyInto( bundle, relativePath, path, resourceManager ); } catch ( Exception e ) { throw new BundleWriterException( "Failed to copy content from key " + path, e );
if ( attributeValue instanceof ResourceKey ) { final ResourceKey path = (ResourceKey) attributeValue; final boolean linked = BundleUtilities.isSameBundle( elementSource, path ); return new ResourceReference[] { new ResourceReference( path, linked ) }; } else if ( attributeValue instanceof String && contentBase != null ) { final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) {
final String name = BundleUtilities.getUniqueName( documentBundle, pattern );
public static void writeReportToZipStream( final MasterReport report, final OutputStream out ) throws IOException, BundleWriterException, ContentIOException { if ( report == null ) { throw new NullPointerException(); } if ( out == null ) { throw new NullPointerException(); } final MemoryDocumentBundle documentBundle = new MemoryDocumentBundle(); final BundleWriter writer = new BundleWriter(); writer.writeReport( documentBundle, report ); BundleUtilities.writeAsZip( out, documentBundle ); }
final String bundleType = BundleUtilities.getBundleType( repository ); final String bundleMapping = BundleUtilities.getBundleMapping( bundleType );
final String relativePath = IOUtils.getInstance().createRelativePath( identifierString, contentBasePath ); try { BundleUtilities.copyInto( bundle, relativePath, path, resourceManager ); } catch ( Exception e ) { throw new BundleWriterException( "Failed to copy content from key " + path, e );
if ( attributeValue instanceof ResourceKey ) { final ResourceKey path = (ResourceKey) attributeValue; final boolean linked = BundleUtilities.isSameBundle( elementSource, path ); return new ResourceReference[] { new ResourceReference( path, linked ) }; } else if ( attributeValue instanceof String && contentBase != null ) { final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) { final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) }; } catch ( ResourceKeyCreationException rce ) {
BundleUtilities.getUniqueName( bundle, state.getFileName(), "datasources/external-ds{0}.xml" ); if ( fileName == null ) { throw new IOException( "Unable to generate unique name for External-Data-Source" );