librepository-1.1.6/ 0000755 0001750 0001750 00000000000 11636162376 013104 5 ustar rene rene librepository-1.1.6/source/ 0000755 0001750 0001750 00000000000 11365605442 014377 5 ustar rene rene librepository-1.1.6/source/org/ 0000755 0001750 0001750 00000000000 11365605442 015166 5 ustar rene rene librepository-1.1.6/source/org/pentaho/ 0000755 0001750 0001750 00000000000 11365605442 016624 5 ustar rene rene librepository-1.1.6/source/org/pentaho/reporting/ 0000755 0001750 0001750 00000000000 11365605442 020635 5 ustar rene rene librepository-1.1.6/source/org/pentaho/reporting/libraries/ 0000755 0001750 0001750 00000000000 11365605442 022611 5 ustar rene rene librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/ 0000755 0001750 0001750 00000000000 11365605442 025030 5 ustar rene rene librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zip/ 0000755 0001750 0001750 00000000000 11365605442 025632 5 ustar rene rene librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zip/ZipContentLocation.java 0000644 0001750 0001750 00000023271 11365605442 032270 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zip; import java.util.Date; import java.util.HashMap; import java.util.zip.ZipEntry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.repository.ContentCreationException; import org.pentaho.reporting.libraries.repository.ContentEntity; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; import org.pentaho.reporting.libraries.base.util.IOUtils; public class ZipContentLocation implements ContentLocation { private static final Log logger = LogFactory.getLog(ZipContentLocation.class); private ZipRepository repository; private ZipContentLocation parent; private String comment; private String name; private long size; private long time; private String entryName; private HashMap entries; public ZipContentLocation(final ZipRepository repository, final ZipContentLocation parent, final String entryName) { if (repository == null) { throw new NullPointerException(); } if (entryName == null) { throw new NullPointerException(); } this.repository = repository; this.parent = parent; this.entryName = entryName; this.entries = new HashMap(); this.name = RepositoryUtilities.buildName(this, "/") + '/'; this.time = System.currentTimeMillis(); } public ZipContentLocation(ZipRepository repository, ZipContentLocation parent, ZipEntry zipEntry) { if (repository == null) { throw new NullPointerException(); } if (parent == null) { throw new NullPointerException(); } if (zipEntry == null) { throw new NullPointerException(); } this.repository = repository; this.parent = parent; this.entryName = IOUtils.getInstance().getFileName(zipEntry.getName()); this.comment = zipEntry.getComment(); this.size = zipEntry.getSize(); this.time = zipEntry.getTime(); this.entries = new HashMap(); this.name = RepositoryUtilities.buildName(this, "/") + '/'; } private void updateMetaData(final ZipEntry zipEntry) { this.comment = zipEntry.getComment(); this.size = zipEntry.getSize(); this.time = zipEntry.getTime(); } public void updateDirectoryEntry(final String[] name, final int index, final ZipEntry zipEntry) { if (name == null) { throw new NullPointerException(); } if (zipEntry == null) { throw new NullPointerException(); } final String path = name[index]; final Object entry = entries.get(path); if (entry instanceof ContentItem) { logger.warn("Directory-Entry with the same name as a Content-Entry encountered: " + path); return; } final ZipContentLocation location; if (entry == null) { location = new ZipContentLocation(repository, this, path); entries.put(path, location); } else { location = (ZipContentLocation) entry; } final int nextNameIdx = index + 1; if (nextNameIdx < name.length) { location.updateDirectoryEntry(name, nextNameIdx, zipEntry); } else if (nextNameIdx == name.length) { location.updateMetaData(zipEntry); } } public void updateEntry(final String[] name, final int index, final ZipEntry zipEntry, final byte[] data) { if (name == null) { throw new NullPointerException(); } if (zipEntry == null) { throw new NullPointerException(); } if (data == null) { throw new NullPointerException(); } final String path = name[index]; final Object entry = entries.get(path); final int nextNameIdx = index + 1; if (nextNameIdx < name.length) { if (entry instanceof ContentItem) { logger.warn("Directory-Entry with the same name as a Content-Entry encountered: " + path); return; } final ZipContentLocation location; if (entry == null) { location = new ZipContentLocation(repository, this, path); entries.put(path, location); } else { location = (ZipContentLocation) entry; } if (nextNameIdx < name.length) { location.updateEntry(name, nextNameIdx, zipEntry, data); } } else if (nextNameIdx == name.length) { if (entry instanceof ContentItem) { logger.warn("Duplicate Content-Entry encountered: " + path); return; } else if (entry != null) { logger.warn("Replacing Directory-Entry with the same name as a Content-Entry: " + path); } final ZipContentItem contentItem = new ZipContentItem(repository, this, zipEntry, data); entries.put(path, contentItem); } } public ContentEntity[] listContents() throws ContentIOException { return (ContentEntity[]) entries.values().toArray(new ContentEntity[entries.size()]); } public ContentEntity getEntry(final String name) throws ContentIOException { return (ContentEntity) entries.get(name); } public boolean exists(final String name) { return entries.containsKey(name); } public ContentItem createItem(final String name) throws ContentCreationException { if (entries.containsKey(name)) { throw new ContentCreationException("An entry with name '" + name + "' already exists."); } if (name.indexOf('/') != -1) { throw new ContentCreationException("The entry-name '" + name + "' is invalid."); } if ("".equals(name) || ".".equals(name) || "..".equals(name)) { throw new ContentCreationException("The entry-name '" + name + "' is invalid."); } final ZipContentItem value = new ZipContentItem(repository, this, name); entries.put(name, value); return value; } public ContentLocation createLocation(final String name) throws ContentCreationException { if (entries.containsKey(name)) { throw new ContentCreationException("An entry with name '" + name + "' already exists."); } if (entries.containsKey(name)) { throw new ContentCreationException("An entry with name '" + name + "' already exists."); } if (name.indexOf('/') != -1) { throw new ContentCreationException("The entry-name '" + name + "' is invalid."); } if ("".equals(name) || ".".equals(name) || "..".equals(name)) { throw new ContentCreationException("The entry-name '" + name + "' is invalid."); } final ZipContentLocation value = new ZipContentLocation(repository, this, name); entries.put(name, value); return value; } public String getName() { return entryName; } public Object getContentId() { return name; } public Object getAttribute(final String domain, final String key) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.SIZE_ATTRIBUTE.equals(key)) { return new Long(size); } else if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { return new Date(time); } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { return comment; } } return null; } public boolean setAttribute(final String domain, final String key, final Object value) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { if (value instanceof Date) { final Date n = (Date) value; time = n.getTime(); return true; } else if (value instanceof Number) { final Number n = (Number) value; time = n.longValue(); return true; } } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { if (value != null) { comment = String.valueOf(value); return true; } else { comment = null; return true; } } } return false; } public ContentLocation getParent() { return parent; } public Repository getRepository() { return repository; } public boolean delete() { if (parent == null) { return false; } return parent.removeEntity(this); } public boolean removeEntity(final ContentEntity entity) { return (entries.remove(entity.getName()) != null); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zip/ZipEntryOutputStream.java 0000644 0001750 0001750 00000006007 11365605442 032661 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zip; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.zip.CRC32; import java.util.zip.DeflaterOutputStream; /** * A fully buffered stream. * * @author Thomas Morgner */ public class ZipEntryOutputStream extends OutputStream { private ByteArrayOutputStream outputStream; private DeflaterOutputStream deflaterOutputStream; private boolean closed; private ZipContentItem item; private CRC32 crc32; private long size; public ZipEntryOutputStream(final ZipContentItem item) { if (item == null) { throw new NullPointerException(); } this.item = item; this.outputStream = new ByteArrayOutputStream(); this.deflaterOutputStream = new DeflaterOutputStream(outputStream); this.crc32 = new CRC32(); this.size = 0; } public void write(final int b) throws IOException { if (closed) { throw new IOException("Already closed"); } deflaterOutputStream.write(b); crc32.update(b); size += 1; } public void write(final byte[] b, final int off, final int len) throws IOException { if (closed) { throw new IOException("Already closed"); } deflaterOutputStream.write(b, off, len); crc32.update(b, off, len); size += len; } public void close() throws IOException { if (closed) { // A duplicate close is just a NO-OP as with all other output streams. return; } deflaterOutputStream.close(); item.setRawData(outputStream.toByteArray(), size, crc32.getValue()); closed = true; outputStream = null; deflaterOutputStream = null; } public void write(final byte[] b) throws IOException { if (closed) { throw new IOException("Already closed"); } deflaterOutputStream.write(b); crc32.update(b); size += b.length; } public void flush() throws IOException { if (closed) { throw new IOException("Already closed"); } deflaterOutputStream.flush(); } public long getSize() { return size; } public long getCrc() { return crc32.getValue(); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zip/ZipRepository.java 0000644 0001750 0001750 00000007706 11365605442 031351 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zip; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.DefaultMimeRegistry; import org.pentaho.reporting.libraries.repository.MimeRegistry; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * A read-write repository based on ZIP streams. The repository can be created using a existing * zip file as initial content. The repository will be fully buffered, so nothing is written until * the whole repository is closed. For a streaming solution use the zipwriter-repository instead. * * @author Thomas Morgner */ public class ZipRepository implements Repository { private ZipContentLocation root; private MimeRegistry mimeRegistry; public ZipRepository() { this(new DefaultMimeRegistry()); } public ZipRepository(final MimeRegistry mimeRegistry) { if (mimeRegistry == null) { throw new NullPointerException(); } this.mimeRegistry = mimeRegistry; this.root = new ZipContentLocation(this, null, ""); } public ZipRepository(final InputStream in) throws IOException { this(in, new DefaultMimeRegistry()); } public ZipRepository(final InputStream in, final MimeRegistry mimeRegistry) throws IOException { this(mimeRegistry); final ZipInputStream zipIn = new ZipInputStream(in); ZipEntry nextEntry = zipIn.getNextEntry(); while (nextEntry != null) { final String[] buildName = RepositoryUtilities.splitPath(nextEntry.getName(), "/"); if (nextEntry.isDirectory()) { root.updateDirectoryEntry(buildName, 0, nextEntry); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(bos, new Deflater(nextEntry.getMethod())); IOUtils.getInstance().copyStreams(zipIn, dos); dos.flush(); dos.close(); root.updateEntry(buildName, 0, nextEntry, bos.toByteArray()); } zipIn.closeEntry(); nextEntry = zipIn.getNextEntry(); } } public ContentLocation getRoot() throws ContentIOException { return root; } public MimeRegistry getMimeRegistry() { return mimeRegistry; } public void write(final OutputStream outputStream) throws IOException, ContentIOException { RepositoryUtilities.writeAsZip(outputStream, this); } public void writeToZipStream(final ZipOutputStream zipOutputStream, final Repository repository) throws IOException, ContentIOException { RepositoryUtilities.writeToZipStream(zipOutputStream, repository); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zip/ZipContentItem.java 0000644 0001750 0001750 00000017342 11365605442 031420 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zip; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Date; import java.util.zip.Deflater; import java.util.zip.InflaterInputStream; import java.util.zip.ZipEntry; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * Todo: Document Me * * @author Thomas Morgner */ public class ZipContentItem implements ContentItem { private static final byte[] EMPTY_BYTES = new byte[0]; private String comment; private String name; private long size; private long time; private ZipRepository repository; private byte[] rawData; private ZipContentLocation parent; private String entryName; private Integer method; private int compression; private long crc32; public ZipContentItem(final ZipRepository repository, final ZipContentLocation parent, final ZipEntry zipEntry, final byte[] bytes) { if (repository == null) { throw new NullPointerException(); } if (zipEntry == null) { throw new NullPointerException(); } if (bytes == null) { throw new NullPointerException(); } if (parent == null) { throw new NullPointerException(); } this.parent = parent; this.repository = repository; this.comment = zipEntry.getComment(); this.name = RepositoryUtilities.buildName(this, "/"); this.entryName = IOUtils.getInstance().getFileName(name); this.size = zipEntry.getSize(); this.crc32 = zipEntry.getCrc(); this.time = zipEntry.getTime(); this.rawData = bytes; final int method = zipEntry.getMethod(); if (method == ZipEntry.STORED || method == ZipEntry.DEFLATED) { this.method = new Integer(method); } else { this.method = new Integer(ZipEntry.DEFLATED); } this.compression = Deflater.DEFAULT_COMPRESSION; } public ZipContentItem(final ZipRepository repository, final ZipContentLocation parent, final String name) { if (repository == null) { throw new NullPointerException(); } if (parent == null) { throw new NullPointerException(); } if (name == null) { throw new NullPointerException(); } this.repository = repository; this.parent = parent; this.entryName = name; this.name = RepositoryUtilities.buildName(this, "/"); this.time = System.currentTimeMillis(); this.comment = null; this.size = 0; this.rawData = EMPTY_BYTES; this.method = LibRepositoryBoot.ZIP_METHOD_DEFLATED; this.compression = Deflater.DEFAULT_COMPRESSION; } /** * This method is a internal method. The raw-data array must be a valid Deflater-output or the content-item will * not be able to read the data. * * @param rawData * @param size * @param crc32 */ public void setRawData(final byte[] rawData, long size, long crc32) { if (rawData == null) { throw new NullPointerException(); } this.rawData = rawData; this.size = size; this.crc32 = crc32; this.time = System.currentTimeMillis(); } public String getMimeType() throws ContentIOException { return repository.getMimeRegistry().getMimeType(this); } public OutputStream getOutputStream() throws ContentIOException, IOException { return new ZipEntryOutputStream(this); } public InputStream getInputStream() throws ContentIOException, IOException { return new InflaterInputStream(new ByteArrayInputStream(rawData)); } public boolean isReadable() { return true; } public boolean isWriteable() { return true; } public String getName() { return entryName; } public Object getContentId() { return name; } public Object getAttribute(String domain, String key) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.SIZE_ATTRIBUTE.equals(key)) { return new Long(size); } else if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { return new Date(time); } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { return comment; } if (LibRepositoryBoot.ZIP_CRC32_ATTRIBUTE.equals(key)) { return new Long(crc32); } else if (LibRepositoryBoot.ZIP_METHOD_ATTRIBUTE.equals(key)) { return method; } else if (LibRepositoryBoot.ZIP_COMPRESSION_ATTRIBUTE.equals(key)) { return new Integer(compression); } } return null; } public boolean setAttribute(String domain, String key, Object value) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { if (value instanceof Date) { final Date n = (Date) value; time = n.getTime(); return true; } else if (value instanceof Number) { final Number n = (Number) value; time = n.longValue(); return true; } } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { if (value != null) { comment = String.valueOf(value); return true; } else { comment = null; return true; } } if (LibRepositoryBoot.ZIP_METHOD_ATTRIBUTE.equals(key)) { if (LibRepositoryBoot.ZIP_METHOD_STORED.equals(value)) { method = LibRepositoryBoot.ZIP_METHOD_STORED; return true; } else if (LibRepositoryBoot.ZIP_METHOD_DEFLATED.equals(value)) { method = LibRepositoryBoot.ZIP_METHOD_DEFLATED; return true; } } if (LibRepositoryBoot.ZIP_COMPRESSION_ATTRIBUTE.equals(key)) { if (value instanceof Integer) { final Integer valueInt = (Integer) value; final int compression = valueInt.intValue(); if (compression >= 0 && compression <= 9) { this.compression = compression; return true; } } } } return false; } public ContentLocation getParent() { return parent; } public Repository getRepository() { return repository; } public boolean delete() { return parent.removeEntity(this); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/ContentIOException.java 0000644 0001750 0001750 00000003310 11365605442 031411 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; import org.pentaho.reporting.libraries.base.util.StackableException; /** * A Exception that indicates repository related errors. * * @author Thomas Morgner */ public class ContentIOException extends StackableException { private static final long serialVersionUID = 2947843470210463760L; /** * Creates a ContentIOException with no message and no parent. */ public ContentIOException() { } /** * Creates an ContentIOException. * * @param message the exception message. * @param ex the parent exception. */ public ContentIOException(final String message, final Exception ex) { super(message, ex); } /** * Creates an ContentIOException. * * @param message the exception message. */ public ContentIOException(final String message) { super(message); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/ContentItem.java 0000644 0001750 0001750 00000007606 11365605442 030135 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * A content item holds the actual content. On a file system, this would be a * file. Whether reading and writing the same content item at the same time is * allowed is implementation specific. * * @author Thomas Morgner */ public interface ContentItem extends ContentEntity { /** * Returns the mime type for the content entity. If the repository does not store mimetypes, this call usually * uses the repositories MimeRegistry to resolve the mimetype. * * @return the mime type. * @throws ContentIOException if an error occured. */ public String getMimeType() throws ContentIOException; /** * Tries to open and return a output stream for writing into the content item. This call will fail if the * item is not writeable. Whether opening multiple output streams at the same time is possible is implementation * dependent, but it is generally not recommended to try this. *
* Having both an input and output stream open at the same time is not guaranteed to work. Generally if you need * to append data, first open the inputstream and copy the content to a temporary location and then write the * content along with the appended content to the new output stream. * * @return the output stream for writing the item. * @throws ContentIOException if an repository related error prevents the creation of the output stream. * @throws IOException if an IO error occurs. */ public OutputStream getOutputStream() throws ContentIOException, IOException; /** * Tries to open and return a input stream for reading from the content item. This call will fail if the * item is not readable. Whether opening multiple input streams at the same time is possible is implementation * dependent. * * Having both an input and output stream open at the same time is not guaranteed to work. Generally if you need * to append data, first open the inputstream and copy the content to a temporary location and then write the * content along with the appended content to the new output stream. * * @return the input stream for reading from the item. * @throws ContentIOException if an repository related error prevents the creation of the input stream. * @throws IOException if an IO error occurs. */ public InputStream getInputStream() throws ContentIOException, IOException; /** * Checks, whether the content item is readable. A content item that is not readable will never return a valid * inputstream and any call to getInputStream is bound to fail. * * @return true, if the content item is readable, false otherwise. */ public boolean isReadable(); /** * Checks, whether the content item is writable. A content item that is not writable will never return a valid * outputstream and any call to getOutputStream is bound to fail. * * @return true, if the content item is writeable, false otherwise. */ public boolean isWriteable(); } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/NameGenerator.java 0000644 0001750 0001750 00000003157 11365605442 030430 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; /** * A name generator is a general service to generate unique names within * an content location. * * @author Thomas Morgner */ public interface NameGenerator { /** * Generates a new name for the location. The name-generator may use both the name-hint and mimetype to compute * the new name. * * @param nameHint the name hint, usually a identifier for the new filename (can be null). * @param mimeType the mime type of the new filename. Usually used to compute a suitable file-suffix. * @return the generated name, never null. * @throws ContentIOException if the name could not be generated for any reason. */ public String generateName(String nameHint, String mimeType) throws ContentIOException; } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/ContentEntity.java 0000644 0001750 0001750 00000006073 11365605442 030510 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; /** * A content entity is the base interface for both data items and directory items. * * @author Thomas Morgner */ public interface ContentEntity { /** * Returns the name of the entry. * * @return the name, never null. */ public String getName(); /** * Returns a unique identifier. This can be canonical filename or a database key. It must be guaranteed that * within the same repository the key will be unique. * * @return the unique content ID. */ public Object getContentId(); /** * Returns a attribute value for the given domain (namespace) and attribute-name. Some generic attribute domains * and names are defined as constants in the {@link LibRepositoryBoot} class. * * @param domain the attribute domain. * @param key the name of the attribute. * @return the value or null, if the content-entity does not have a value for this attribute. */ public Object getAttribute(String domain, String key); /** * Updates the attribute value for the given attribute domain and name. If the element is not writable or the * attribute could not be updated for any other reason, the method will return false. This method only returns * true, if the attribute has been updated successfully. * * @param domain the attribute domain. * @param key the attribute name * @param value the new attribute value. * @return true, if the update was successful, false otherwise. */ public boolean setAttribute(String domain, String key, Object value); /** * Returns a reference to the parent location. If this entity represents the root directory, this method will * return null. * * @return the parent or null, if this is the root-directory. */ public ContentLocation getParent(); /** * Returns the current repository, to which tis entity belongs. * * @return the repository. */ public Repository getRepository(); /** * Attempts to delete the entity. After an entity has been deleted, any call to any of the methods of the * entity may produce undefined results. * * @return true, if the entity was deleted and detached from the repository, false otherwise. */ public boolean delete(); } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/UrlRepository.java 0000644 0001750 0001750 00000002707 11365605442 030543 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; import java.net.MalformedURLException; import java.net.URL; /** * A repository that can be globally identified by an URL. * * @author Thomas Morgner */ public interface UrlRepository extends Repository { /** * Returns the URL that represents this repository. The meaning of the URL returned here is implementation * specific and is probably not suitable to resolve names to global objects. * * @return the repository's URL. * @throws MalformedURLException if the URL could not be computed. */ public URL getURL() throws MalformedURLException; } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/LibRepositoryInfo.java 0000644 0001750 0001750 00000004213 11365605442 031315 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; import org.pentaho.reporting.libraries.base.LibBaseInfo; import org.pentaho.reporting.libraries.base.versioning.ProjectInformation; /** * The LibRepositoryInfo class contains all dependency information and some * common information like version, license and contributors about the * library itself. * * @author Thomas Morgner */ public class LibRepositoryInfo extends ProjectInformation { private static LibRepositoryInfo instance; /** * Returns the singleton instance of the ProjectInformation-class. * * @return the singleton ProjectInformation. */ public static synchronized ProjectInformation getInstance() { if (instance == null) { instance = new LibRepositoryInfo(); instance.initialize(); } return instance; } /** * Constructs an empty project info object. */ private LibRepositoryInfo() { super("librepository", "LibRepository"); } /** * Initialized the project info object. */ private void initialize() { setLicenseName("LGPL"); setInfo("http://reporting.pentaho.org/librepository/"); setCopyright("(C)opyright 2006-2010, by Pentaho Corporation and Contributors"); setBootClass(LibRepositoryBoot.class.getName()); addLibrary(LibBaseInfo.getInstance()); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/RepositoryUtilities.java 0000644 0001750 0001750 00000046306 11365605442 031757 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.StringTokenizer; import java.util.zip.Deflater; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * A collection of repository related helper methods that make it easier to work with repositories. * * @author Thomas Morgner */ public class RepositoryUtilities { /** * Private constructor to prevent object creation. */ private RepositoryUtilities() { } /** * Returns the content entity for the given path name. * * @param repository the repository from where to retrieve the content entity. * @param name the path name as array of name-segments. * @return the entity at the position, never null. * @throws ContentIOException if the path did not point to a valid content entity. * @see RepositoryUtilities#splitPath(String, String) */ public static ContentEntity getEntity(final Repository repository, final String[] name) throws ContentIOException { if (repository == null) { throw new NullPointerException("Repository given must not be null."); } if (name == null) { throw new NullPointerException("Path-Name array must not be null."); } final int length = name.length; if (length == 0) { return repository.getRoot(); } ContentLocation node = repository.getRoot(); for (int i = 0; i < length - 1; i++) { final String nameItem = name[i]; final ContentEntity entry = node.getEntry(nameItem); if (entry instanceof ContentLocation == false) { // its ok, if we hit the last item throw new ContentIOException("No such item: " + nameItem + " in " + node.getContentId()); } node = (ContentLocation) entry; } return node.getEntry(name[length - 1]); } /** * Checks whether a given pathname points to a valid content entity. * * @param repository the repository from where to retrieve the content entity. * @param name the path name as array of name-segments. * @return true, if the entity exists, false otherwise. * @throws ContentIOException if an unexpected repository error occured. * @see RepositoryUtilities#splitPath(String, String) */ public static boolean isExistsEntity(final Repository repository, final String[] name) throws ContentIOException { if (repository == null) { throw new NullPointerException("Repository given must not be null."); } if (name == null) { throw new NullPointerException("Path-Name array must not be null."); } final int length = name.length; if (length == 0) { return true; } ContentLocation node = repository.getRoot(); for (int i = 0; i < length - 1; i++) { final String nameItem = name[i]; if (node.exists(nameItem) == false) { // if there is no such path segment, indicate non-existence return false; } final ContentEntity entry = node.getEntry(nameItem); if (entry instanceof ContentLocation == false) { // if the inner path segment is a leaf, indicate non-existence return false; } node = (ContentLocation) entry; } // finally check for the last item... return node.exists(name[length - 1]); } /** * Tries to create a content item with the given path-name in the repository. This call will succeed if and only * if all but the last segment of the name point to Content-Locations and if the content-item does not yet exist. * * @param repository the repository in which a new entity should be created. * @param name the name of the new entity as path name. * @return the newly created content-item. * @throws ContentIOException if an repository error occured or if the path was not valid. */ public static ContentItem createItem(final Repository repository, final String[] name) throws ContentIOException { if (repository == null) { throw new NullPointerException("Repository given must not be null."); } if (name == null) { throw new NullPointerException("Path-Name array must not be null."); } final int length = name.length; if (length == 0) { throw new IllegalArgumentException("Empty name not permitted."); } ContentLocation node = repository.getRoot(); for (int i = 0; i < length - 1; i++) { final String nameItem = name[i]; if (node.exists(nameItem) == false) { // create it node = node.createLocation(nameItem); } else { final ContentEntity entry = node.getEntry(nameItem); if (entry instanceof ContentLocation == false) { // its ok, if we hit the last item throw new ContentIOException("No such item."); } node = (ContentLocation) entry; } } return node.createItem(name[length - 1]); } /** * Tries to create a content location with the given path-name in the repository. This call will succeed if and only * if all but the last segment of the name point to Content-Locations and if the content-entity does not yet exist. * * @param repository the repository in which a new entity should be created. * @param name the name of the new entity as path name. * @return the newly created content-location. * @throws ContentIOException if an repository error occured or if the path was not valid. */ public static ContentLocation createLocation(final Repository repository, final String[] name) throws ContentIOException { if (repository == null) { throw new NullPointerException("Repository given must not be null."); } if (name == null) { throw new NullPointerException("Path-Name array must not be null."); } final int length = name.length; if (length == 0) { throw new IllegalArgumentException("Empty name not permitted."); } ContentLocation node = repository.getRoot(); for (int i = 0; i < length - 1; i++) { final String nameItem = name[i]; if (node.exists(nameItem) == false) { // create it node = node.createLocation(nameItem); } else { final ContentEntity entry = node.getEntry(nameItem); if (entry instanceof ContentLocation == false) { // its ok, if we hit the last item throw new ContentIOException("No such item."); } node = (ContentLocation) entry; } } return node.createLocation(name[length - 1]); } /** * Splits a string on the given separator. Multiple occurences of the separator are unified into a single * separator. * * @param name the path name. * @param separator the separator on which to split. * @return the name as array of atomar path elements. */ public static String[] splitPath(final String name, final String separator) { if (name == null) { throw new NullPointerException("Path-Name must not be null."); } if (separator == null) { throw new NullPointerException("Separator must not be null."); } final StringTokenizer strtok = new StringTokenizer(name, separator, false); final int tokenCount = strtok.countTokens(); final String[] retval = new String[tokenCount]; int i = 0; boolean emptyTokenRemoved = false; while (strtok.hasMoreTokens()) { final String token = strtok.nextToken(); retval[i] = token; if ("".equals(token) == false) { i += 1; } else { emptyTokenRemoved = true; } } if (emptyTokenRemoved == false) { return retval; } final String[] reducedArray = new String[i]; System.arraycopy(retval, 0, reducedArray, 0, i); return reducedArray; } /** * Splits a string on the given separator. Multiple occurences of the separator result in empty strings as path * elements in the returned array. * * @param name the path name. * @param separator the separator on which to split. * @return the name as array of atomar path elements. */ public static String[] split(final String name, final String separator) { if (name == null) { throw new NullPointerException("Path-Name must not be null."); } if (separator == null) { throw new NullPointerException("Separator must not be null."); } final StringTokenizer strtok = new StringTokenizer(name, separator, false); final int tokenCount = strtok.countTokens(); final String[] retval = new String[tokenCount]; int i = 0; while (strtok.hasMoreTokens()) { final String token = strtok.nextToken(); retval[i] = token; i += 1; } return retval; } /** * Builds a absolute pathname for the given entity. * * @param entity the entity for which the pathname should be computed. * @return the absolute path. */ public static String[] buildNameArray(ContentEntity entity) { if (entity == null) { throw new NullPointerException("Entity given must not be null."); } final ArrayList collector = new ArrayList(20); while (entity != null) { final ContentLocation parent = entity.getParent(); if (parent != null) { // this filters out the root .. collector.add(0, entity.getName()); } entity = parent; } return (String[]) collector.toArray(new String[collector.size()]); } /** * Builds a string of an absolute pathname for the given entity and using the given separator to separate filename * segments.. * * @param entity the entity for which the pathname should be computed. * @param separator the filename separator. * @return the absolute path. */ public static String buildName(ContentEntity entity, final String separator) { if (entity == null) { throw new NullPointerException("ContentEntity must not be null."); } if (separator == null) { throw new NullPointerException("Separator must not be null."); } int size = 0; final ArrayList collector = new ArrayList(); while (entity != null) { final ContentLocation parent = entity.getParent(); if (parent != null) { // this filters out the root .. final String name = entity.getName(); if (name.length() == 0) { throw new IllegalStateException("ContentLocation with an empty name"); } if (isInvalidPathName(name)) { throw new IllegalStateException("ContentLocation with an illegal name: " + name); } collector.add(name); size += 1; size += name.length(); } entity = parent; } final StringBuffer builder = new StringBuffer(size); final int maxIdx = collector.size() - 1; for (int i = maxIdx; i >= 0; i--) { final String s = (String) collector.get(i); if (i != maxIdx) { builder.append(separator); } builder.append(s); } return builder.toString(); } /** * Checks whether the given entity name is valid for filesystems. This method rejects filenames that either * contain a slash ('/') or backslash ('\') which both are commonly used path-separators and it rejects * filenames that contain only dots (as the dot names are used as directory traversal names). * * @param name the filename that should be tested. This name must be a single name section, not a full path. * @return true, if the pathname is valid, false otherwise. */ public static boolean isInvalidPathName(String name) { if (name == null) { throw new NullPointerException("Name must not be null."); } boolean onlyDots = true; for (int i = 0; i < name.length(); i++) { final char c = name.charAt(i); if (onlyDots && c != '.') { onlyDots = false; } if (c == '\\' || c == '/') { return true; } } return onlyDots; } /** * Writes the given repository as ZIP-File into the given output stream. * * @param outputStream the output stream that should receive the zipfile. * @param repository the repository that should be written. * @throws IOException if an IO error prevents the writing of the file. * @throws ContentIOException if a repository related IO error occurs. */ public static void writeAsZip(final OutputStream outputStream, final Repository repository) throws IOException, ContentIOException { final ZipOutputStream zipout = new ZipOutputStream(outputStream); writeToZipStream(zipout, repository); zipout.finish(); zipout.flush(); } /** * Writes the given repository to the given ZIP-output stream. * * @param zipOutputStream the output stream that represents the ZipFile to be generated. * @param repository the repository that should be written. * @throws IOException if an IO error prevents the writing of the file. * @throws ContentIOException if a repository related IO error occurs. */ public static void writeToZipStream(final ZipOutputStream zipOutputStream, final Repository repository) throws IOException, ContentIOException { writeLocation(repository.getRoot(), zipOutputStream); } /** * Recursively writes the given contentlocation and all content-items into the given Zip output stream. * * @param outputStream the output stream that should receive the zipfile. * @param location the content location that should be written. * @throws IOException if an IO error prevents the writing of the file. * @throws ContentIOException if a repository related IO error occurs. */ private static void writeLocation(final ContentLocation location, final ZipOutputStream outputStream) throws IOException, ContentIOException { final ContentEntity[] contentEntities = location.listContents(); for (int i = 0; i < contentEntities.length; i++) { final ContentEntity entity = contentEntities[i]; final String fullName = RepositoryUtilities.buildName(entity, "/"); if (entity instanceof ContentLocation) { final ContentLocation childlocation = (ContentLocation) entity; final ZipEntry dirEntry = new ZipEntry(fullName + '/'); final Object comment = entity.getAttribute(LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE); if (comment != null) { dirEntry.setComment(String.valueOf(comment)); } final Object version = entity.getAttribute (LibRepositoryBoot.REPOSITORY_DOMAIN, LibRepositoryBoot.VERSION_ATTRIBUTE); if (version instanceof Date) { final Date date = (Date) version; dirEntry.setTime(date.getTime()); } outputStream.putNextEntry(dirEntry); writeLocation(childlocation, outputStream); } else if (entity instanceof ContentItem) { final ContentItem item = (ContentItem) entity; final ZipEntry itemEntry = new ZipEntry(fullName); final Object comment = entity.getAttribute(LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE); if (comment != null) { itemEntry.setComment(String.valueOf(comment)); } final Object version = entity.getAttribute (LibRepositoryBoot.REPOSITORY_DOMAIN, LibRepositoryBoot.VERSION_ATTRIBUTE); if (version instanceof Date) { final Date date = (Date) version; itemEntry.setTime(date.getTime()); } // need the CRC and the size if method is "stored". final Object crc32 = entity.getAttribute (LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_CRC32_ATTRIBUTE); final Object size = entity.getAttribute (LibRepositoryBoot.REPOSITORY_DOMAIN, LibRepositoryBoot.SIZE_ATTRIBUTE); if (crc32 instanceof Long && size instanceof Long) { final Long crc32Long = (Long) crc32; final Long sizeLong = (Long) size; itemEntry.setSize(sizeLong.longValue()); itemEntry.setCrc(crc32Long.longValue()); final int method = getZipMethod(item); final int compression = getZipLevel(item); outputStream.setMethod(method); outputStream.setLevel(compression); } outputStream.putNextEntry(itemEntry); final InputStream inputStream = item.getInputStream(); try { IOUtils.getInstance().copyStreams(inputStream, outputStream); } finally { inputStream.close(); } outputStream.closeEntry(); } } } /** * Computes the declared Zip-Compression level for the given content-item. If the content-items attributes * do not contain a definition, the default compression is used instead. * * @param item the content item for which the compression factor should be computed. * @return the compression level. */ public static int getZipLevel(final ContentItem item) { final Object method = item.getAttribute(LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_COMPRESSION_ATTRIBUTE); if (method instanceof Number == false) { return Deflater.DEFAULT_COMPRESSION; } final Number n = (Number) method; final int level = n.intValue(); if (level < 0 || level > 9) { return Deflater.DEFAULT_COMPRESSION; } return level; } /** * Computes the declared Zip-Compression mode for the given content-item. If the content-items attributes * do not contain a valid definition, the default compression is used instead. * * @param item the content item for which the compression mode should be computed. * @return the compression mode, either ZipOutputStream.DEFLATED or ZipOutputStream.STORED. */ public static int getZipMethod(final ContentItem item) { final Object method = item.getAttribute(LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_METHOD_ATTRIBUTE); if (method instanceof Number == false) { return ZipOutputStream.DEFLATED; } final Number n = (Number) method; final int level = n.intValue(); if (level != ZipOutputStream.STORED) { return ZipOutputStream.DEFLATED; } return ZipOutputStream.STORED; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipwriter/ 0000755 0001750 0001750 00000000000 11365605442 027067 5 ustar rene rene ././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipwriter/ZipContentLocation.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipwriter/ZipContentLocation.j0000644 0001750 0001750 00000014020 11365605442 033025 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zipwriter; import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.zip.ZipEntry; import org.pentaho.reporting.libraries.repository.ContentCreationException; import org.pentaho.reporting.libraries.repository.ContentEntity; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; /** * Creation-Date: 01.12.2006, 21:13:24 * * @author Thomas Morgner */ public class ZipContentLocation implements ContentLocation { private HashMap entries; private String name; private String contentId; private ContentLocation parent; private ZipRepository repository; private String comment; private long time; public ZipContentLocation(final ZipRepository repository, final ContentLocation parent, final String name) { if (repository == null) { throw new NullPointerException(); } if (name == null) { throw new NullPointerException(); } this.repository = repository; this.parent = parent; this.name = name; this.entries = new HashMap(); this.contentId = RepositoryUtilities.buildName(this, "/") + '/'; } public ContentEntity[] listContents() throws ContentIOException { return (ContentEntity[]) entries.values().toArray (new ContentEntity[entries.size()]); } public ContentEntity getEntry(final String name) throws ContentIOException { final ContentEntity contentEntity = (ContentEntity) entries.get(name); if (contentEntity == null) { throw new ContentIOException("Not found:" + name); } return contentEntity; } /** * Creates a new data item in the current location. This method must never * return null. * * @param name * @return * @throws org.pentaho.reporting.libraries.repository.ContentCreationException * if the item could not be created. */ public ContentItem createItem(final String name) throws ContentCreationException { if (entries.containsKey(name)) { throw new ContentCreationException("Entry already exists"); } if (RepositoryUtilities.isInvalidPathName(name)) { throw new ContentCreationException("Entry-Name is not valid"); } final ZipContentItem item = new ZipContentItem(name, repository, this); entries.put(name, item); return item; } public ContentLocation createLocation(final String name) throws ContentCreationException { if (entries.containsKey(name)) { throw new ContentCreationException("Entry already exists"); } if (RepositoryUtilities.isInvalidPathName(name)) { throw new ContentCreationException("Entry-Name is not valid"); } final ZipContentLocation item = new ZipContentLocation(repository, this, name); entries.put(name, item); if ("/".equals(this.contentId) == false) { try { final ZipEntry entry = new ZipEntry(contentId + name + '/'); repository.writeDirectory(entry); } catch (IOException e) { throw new ContentCreationException("Failed to create directory.", e); } } return item; } public boolean exists(final String name) { return entries.containsKey(name); } public String getName() { return name; } public Object getContentId() { return contentId; } public Object getAttribute(final String domain, final String key) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { return new Date(time); } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { return comment; } } return null; } public boolean setAttribute(final String domain, final String key, final Object value) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { if (value instanceof Date) { final Date n = (Date) value; time = n.getTime(); return true; } else if (value instanceof Number) { final Number n = (Number) value; time = n.longValue(); return true; } } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { if (value != null) { comment = String.valueOf(value); return true; } else { comment = null; return true; } } } return false; } public ContentLocation getParent() { return parent; } public Repository getRepository() { return repository; } public boolean delete() { return false; } } ././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipwriter/ZipEntryOutputStream.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipwriter/ZipEntryOutputStream0000644 0001750 0001750 00000010622 11365605442 033174 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zipwriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Date; import java.util.zip.CRC32; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; import java.util.zip.ZipEntry; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; /** * A fully buffered stream. * * @author Thomas Morgner */ public class ZipEntryOutputStream extends OutputStream { private ByteArrayOutputStream outputStream; private DeflaterOutputStream deflaterOutputStream; private boolean closed; private ZipContentItem item; private CRC32 crc32; private long size; public ZipEntryOutputStream(final ZipContentItem item) { if (item == null) { throw new NullPointerException(); } this.item = item; this.outputStream = new ByteArrayOutputStream(); this.deflaterOutputStream = new DeflaterOutputStream (outputStream, new Deflater(RepositoryUtilities.getZipLevel(item))); this.crc32 = new CRC32(); this.size = 0; } public void write(final int b) throws IOException { if (closed) { throw new IOException("Already closed"); } deflaterOutputStream.write(b); crc32.update(b); size += 1; } public void write(final byte[] b, final int off, final int len) throws IOException { if (closed) { throw new IOException("Already closed"); } deflaterOutputStream.write(b, off, len); crc32.update(b, off, len); size += len; } public void close() throws IOException { if (closed) { // A duplicate close is just a NO-OP as with all other output streams. return; } deflaterOutputStream.close(); final byte[] data = outputStream.toByteArray(); final ByteArrayInputStream bin = new ByteArrayInputStream(data); final InflaterInputStream infi = new InflaterInputStream(bin); final ZipRepository repository = (ZipRepository) item.getRepository(); final String contentId = (String) item.getContentId(); final ZipEntry zipEntry = new ZipEntry(contentId); final Object comment = item.getAttribute(LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE); if (comment != null) { zipEntry.setComment(String.valueOf(comment)); } final Object version = item.getAttribute(LibRepositoryBoot.REPOSITORY_DOMAIN, LibRepositoryBoot.VERSION_ATTRIBUTE); if (version instanceof Date) { final Date date = (Date) version; zipEntry.setTime(date.getTime()); } final int zipMethod = RepositoryUtilities.getZipMethod(item); zipEntry.setCrc(crc32.getValue()); if (zipMethod == Deflater.NO_COMPRESSION) { zipEntry.setCompressedSize(size); zipEntry.setSize(size); } else { zipEntry.setSize(size); } repository.writeContent(zipEntry, infi, zipMethod, RepositoryUtilities.getZipLevel(item)); infi.close(); closed = true; outputStream = null; deflaterOutputStream = null; } public void write(final byte[] b) throws IOException { if (closed) { throw new IOException("Already closed"); } deflaterOutputStream.write(b); crc32.update(b); size += b.length; } public void flush() throws IOException { if (closed) { throw new IOException("Already closed"); } deflaterOutputStream.flush(); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipwriter/ZipRepository.java 0000644 0001750 0001750 00000006400 11365605442 032574 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zipwriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.Deflater; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.DefaultMimeRegistry; import org.pentaho.reporting.libraries.repository.MimeRegistry; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * Creation-Date: 01.12.2006, 21:12:39 * * @author Thomas Morgner */ public class ZipRepository implements Repository { private ZipOutputStream zipOutputStream; private MimeRegistry mimeRegistry; private ZipContentLocation root; public ZipRepository(final OutputStream out, final int level, final MimeRegistry mimeRegistry) { if (out == null) { throw new NullPointerException(); } if (mimeRegistry == null) { throw new NullPointerException(); } this.mimeRegistry = mimeRegistry; this.zipOutputStream = new ZipOutputStream(out); this.zipOutputStream.setLevel(level); this.root = new ZipContentLocation(this, null, ""); } public ZipRepository(final OutputStream out, final int level) { this(out, level, new DefaultMimeRegistry()); } public ZipRepository(final OutputStream out) { this(out, Deflater.DEFAULT_COMPRESSION, new DefaultMimeRegistry()); } public ContentLocation getRoot() throws ContentIOException { return root; } public MimeRegistry getMimeRegistry() { return mimeRegistry; } public void close() throws IOException { zipOutputStream.finish(); zipOutputStream.flush(); } public void writeDirectory(final ZipEntry entry) throws IOException { zipOutputStream.putNextEntry(entry); } public void writeContent(final ZipEntry entry, final InputStream in, int method, int compression) throws IOException { zipOutputStream.setMethod(method); zipOutputStream.setLevel(compression); zipOutputStream.putNextEntry(entry); IOUtils.getInstance().copyStreams(in, zipOutputStream); zipOutputStream.closeEntry(); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipwriter/ZipContentItem.java 0000644 0001750 0001750 00000013440 11365605442 032650 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zipwriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Date; import java.util.zip.Deflater; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; /** * Creation-Date: 01.12.2006, 21:23:25 * * @author Thomas Morgner */ public class ZipContentItem implements ContentItem { private boolean newItem; private String name; private String contentId; private ZipRepository repository; private ZipContentLocation parent; private String comment; private long time; private Integer method; private int compression; public ZipContentItem(final String name, final ZipRepository repository, final ZipContentLocation parent) { if (name == null) { throw new NullPointerException(); } if (repository == null) { throw new NullPointerException(); } if (parent == null) { throw new NullPointerException(); } this.time = System.currentTimeMillis(); this.name = name; this.repository = repository; this.parent = parent; this.contentId = RepositoryUtilities.buildName(this, "/"); this.newItem = true; this.method = LibRepositoryBoot.ZIP_METHOD_DEFLATED; this.compression = Deflater.DEFAULT_COMPRESSION; } public String getMimeType() throws ContentIOException { return getRepository().getMimeRegistry().getMimeType(this); } public OutputStream getOutputStream() throws ContentIOException, IOException { if (newItem == false) { throw new ContentIOException("This item is no longer writeable."); } newItem = false; return new ZipEntryOutputStream(this); } public InputStream getInputStream() throws ContentIOException, IOException { throw new ContentIOException("This item is not readable."); } public boolean isReadable() { return false; } public boolean isWriteable() { return newItem; } public String getName() { return name; } public Object getContentId() { return contentId; } public Object getAttribute(final String domain, final String key) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { return new Date(time); } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { return comment; } else if (LibRepositoryBoot.ZIP_METHOD_ATTRIBUTE.equals(key)) { return method; } else if (LibRepositoryBoot.ZIP_COMPRESSION_ATTRIBUTE.equals(key)) { return new Integer(compression); } } return null; } public boolean setAttribute(final String domain, final String key, final Object value) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { if (value instanceof Date) { final Date n = (Date) value; time = n.getTime(); return true; } else if (value instanceof Number) { final Number n = (Number) value; time = n.longValue(); return true; } } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { if (value != null) { comment = String.valueOf(value); return true; } else { comment = null; return true; } } if (LibRepositoryBoot.ZIP_METHOD_ATTRIBUTE.equals(key)) { if (LibRepositoryBoot.ZIP_METHOD_STORED.equals(value)) { method = LibRepositoryBoot.ZIP_METHOD_STORED; return true; } else if (LibRepositoryBoot.ZIP_METHOD_DEFLATED.equals(value)) { method = LibRepositoryBoot.ZIP_METHOD_DEFLATED; return true; } } if (LibRepositoryBoot.ZIP_COMPRESSION_ATTRIBUTE.equals(key)) { if (value instanceof Integer) { final Integer valueInt = (Integer) value; final int compression = valueInt.intValue(); if (compression >= 0 && compression <= 9) { this.compression = compression; return true; } } } } return false; } public Repository getRepository() { return repository; } public ContentLocation getParent() { return parent; } public boolean delete() { return false; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/email/ 0000755 0001750 0001750 00000000000 11365605442 026117 5 ustar rene rene ././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/email/EmailContentLocation.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/email/EmailContentLocation.jav0000644 0001750 0001750 00000007144 11365605442 032702 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.repository.email; import java.util.HashMap; import org.pentaho.reporting.libraries.repository.ContentCreationException; import org.pentaho.reporting.libraries.repository.ContentEntity; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; /** * Creation-Date: 17.09.2008, 15:00:00 * * @author Pedro Alves - WebDetails */ public class EmailContentLocation implements ContentLocation { private HashMap entries; private String name; private String contentId; private ContentLocation parent; private EmailRepository repository; public EmailContentLocation(final EmailRepository repository, final ContentLocation parent, final String name) { this.repository = repository; this.parent = parent; this.name = name; this.entries = new HashMap(); this.contentId = RepositoryUtilities.buildName(this, "/") + '/'; } public ContentEntity[] listContents() throws ContentIOException { return (ContentEntity[]) entries.values().toArray(new ContentEntity[entries.size()]); } public ContentEntity getEntry(final String name) throws ContentIOException { return (ContentEntity) entries.get(name); } /** * Creates a new data item in the current location. This method must never return null. * * @param name * @return * @throws ContentCreationException if the item could not be created. */ public ContentItem createItem(final String name) throws ContentCreationException { if (entries.containsKey(name)) { throw new ContentCreationException("Entry already exists"); } final EmailContentItem item = new EmailContentItem(name, repository, this); entries.put(name, item); return item; } public ContentLocation createLocation(final String name) throws ContentCreationException { throw new ContentCreationException("createLocation not Implemented yet"); } public boolean exists(final String name) { return entries.containsKey(name); } public String getName() { return name; } public Object getContentId() { return contentId; } public Object getAttribute(final String domain, final String key) { return null; } public boolean setAttribute(final String domain, final String key, final Object value) { return false; } public ContentLocation getParent() { return parent; } public Repository getRepository() { return repository; } public boolean delete() { return false; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/email/EmailContentItem.java 0000644 0001750 0001750 00000006753 11365605442 032176 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.repository.email; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; /** * Creation-Date: 17.09.2008, 15:00:00 * * @author Pedro Alves - WebDetails */ public class EmailContentItem implements ContentItem { private boolean newItem; private String name; private String contentId; private EmailRepository repository; private EmailContentLocation parent; private String contentType; public EmailContentItem(final String name, final EmailRepository repository, final EmailContentLocation parent) { this.name = name; this.repository = repository; this.parent = parent; this.contentId = RepositoryUtilities.buildName(this, "/"); this.newItem = true; } public String getMimeType() throws ContentIOException { return getRepository().getMimeRegistry().getMimeType(this); } public OutputStream getOutputStream() throws ContentIOException, IOException { if (newItem == false) { throw new ContentIOException("This item is no longer writeable."); } newItem = false; return new EmailEntryOutputStream(this); } public InputStream getInputStream() throws ContentIOException, IOException { throw new ContentIOException("This item is not readable."); } public boolean isReadable() { return false; } public boolean isWriteable() { return newItem; } public String getName() { return name; } public Object getContentId() { return contentId; } public Object getAttribute(final String domain, final String key) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain) && LibRepositoryBoot.CONTENT_TYPE.equals(key)) { return this.contentType; } return null; } public boolean setAttribute(final String domain, final String key, final Object value) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain) && LibRepositoryBoot.CONTENT_TYPE.equals(key)) { this.contentType = (String) value; return true; } return false; } public Repository getRepository() { return repository; } public ContentLocation getParent() { return parent; } public boolean delete() { return false; } } ././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/email/EmailEntryOutputStream.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/email/EmailEntryOutputStream.j0000644 0001750 0001750 00000007120 11365605442 032740 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.repository.email; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.activation.DataHandler; import javax.mail.internet.MimeBodyPart; import javax.mail.util.ByteArrayDataSource; /** * Creation-Date: 17.09.2008, 15:00:00 * * @author Pedro Alves - WebDetails */ public class EmailEntryOutputStream extends OutputStream { private ByteArrayOutputStream outputStream; private boolean closed; private EmailContentItem item; public EmailEntryOutputStream(final EmailContentItem item) { this.item = item; this.outputStream = new ByteArrayOutputStream(); } public void write(final int b) throws IOException { if (closed) { throw new IOException("Already closed"); } outputStream.write(b); } public void write(final byte[] b, final int off, final int len) throws IOException { if (closed) { throw new IOException("Already closed"); } outputStream.write(b, off, len); } public void close() throws IOException { if (closed) { throw new IOException("Already closed"); } outputStream.close(); final byte[] data = outputStream.toByteArray(); final EmailRepository repository = (EmailRepository) item.getRepository(); try { // if name == index.html, use this as the emailHTMLBody if (repository.isTreatHtmlContentAsBody() && item.getMimeType().endsWith("text/html")) { final MimeBodyPart messageBodyPart = repository.getBodypart(); final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, item.getMimeType()); messageBodyPart.setDataHandler(new DataHandler(dataSource)); } else { // Normal Content final ByteArrayInputStream bin = new ByteArrayInputStream(data); final String contentId = (String) item.getContentId(); final ByteArrayDataSource dataSource = new ByteArrayDataSource(bin, item.getMimeType()); final MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setDataHandler(new DataHandler(dataSource)); messageBodyPart.setHeader("Content-ID", contentId); repository.getMultipart().addBodyPart(messageBodyPart); bin.close(); } } catch (Exception e) { throw new IOException("Error closing stream: " + e.getMessage()); } closed = true; } public void write(final byte[] b) throws IOException { if (closed) { throw new IOException("Already closed"); } outputStream.write(b); } public void flush() throws IOException { if (closed) { throw new IOException("Already closed"); } outputStream.flush(); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/email/EmailRepository.java 0000644 0001750 0001750 00000010337 11365605442 032115 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2009 Pentaho Corporation. All rights reserved. */ package org.pentaho.reporting.libraries.repository.email; import java.io.OutputStream; import java.io.IOException; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMultipart; import javax.mail.Session; import javax.mail.MessagingException; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.DefaultMimeRegistry; import org.pentaho.reporting.libraries.repository.MimeRegistry; import org.pentaho.reporting.libraries.repository.Repository; /** * Creation-Date: 17.09.2008, 15:00:00 * * @author Pedro Alves - WebDetails */ public class EmailRepository implements Repository { private MimeRegistry mimeRegistry; private EmailContentLocation root; private MimeMessage htmlEmail; private boolean treatHtmlContentAsBody; private MimeMultipart multipart; private MimeBodyPart bodypart; public EmailRepository(final MimeRegistry mimeRegistry, final Session mailSession) throws ContentIOException, MessagingException { if (mimeRegistry == null) { throw new NullPointerException(); } this.mimeRegistry = mimeRegistry; this.root = new EmailContentLocation(this, null, ""); this.htmlEmail = new MimeMessage(mailSession); this.bodypart = new MimeBodyPart(); this.multipart = new MimeMultipart("related"); this.multipart.addBodyPart(bodypart); this.htmlEmail.setContent(multipart); this.treatHtmlContentAsBody = true; } public EmailRepository(final MimeMessage htmlEmail, final MimeRegistry mimeRegistry) throws ContentIOException, IOException, MessagingException { if (htmlEmail == null) { throw new NullPointerException(); } if (mimeRegistry == null) { throw new NullPointerException(); } this.htmlEmail = htmlEmail; final Object content = this.htmlEmail.getContent(); if (content instanceof MimeMultipart == false) { this.multipart = new MimeMultipart("related"); } else { this.multipart = (MimeMultipart) content; } this.treatHtmlContentAsBody = true; this.mimeRegistry = mimeRegistry; this.root = new EmailContentLocation(this, null, ""); } public EmailRepository(final MimeMessage htmlEmail) throws ContentIOException, IOException, MessagingException { this(htmlEmail, new DefaultMimeRegistry()); } public EmailRepository(final Session session) throws ContentIOException, MessagingException { this(new DefaultMimeRegistry(), session); } public ContentLocation getRoot() throws ContentIOException { return root; } public MimeRegistry getMimeRegistry() { return mimeRegistry; } public void writeEmail(final OutputStream out) throws ContentIOException { try { htmlEmail.writeTo(out); } catch (Exception ex) { throw new ContentIOException(ex.getMessage(), ex); } } public MimeMessage getEmail() { return htmlEmail; } public MimeMultipart getMultipart() { return multipart; } public boolean isTreatHtmlContentAsBody() { return treatHtmlContentAsBody; } public void setTreatHtmlContentAsBody(final boolean treatHtmlContentAsBody) { this.treatHtmlContentAsBody = treatHtmlContentAsBody; } public MimeBodyPart getBodypart() { return bodypart; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/DefaultNameGenerator.java 0000644 0001750 0001750 00000010265 11365605442 031733 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; import java.security.SecureRandom; import java.util.Random; public class DefaultNameGenerator implements NameGenerator { private ContentLocation location; private String defaultNameHint; private String defaultSuffix; private Random randomGenerator; public DefaultNameGenerator(final ContentLocation location) { this(location, "file", null); } public DefaultNameGenerator(final ContentLocation location, final String defaultNameHint) { if (location == null) { throw new NullPointerException(); } if (defaultNameHint == null) { throw new NullPointerException(); } this.location = location; // a leading point is not a sufix! final int pos = defaultNameHint.lastIndexOf('.'); if (defaultSuffix == null && pos > 0) { if (pos < (defaultNameHint.length() - 1)) { this.defaultNameHint = defaultNameHint.substring(0, pos); this.defaultSuffix = defaultNameHint.substring(pos + 1); } else { this.defaultNameHint = defaultNameHint.substring(0, pos); this.defaultSuffix = null; } } else { this.defaultNameHint = defaultNameHint; this.defaultSuffix = null; } } public DefaultNameGenerator(final ContentLocation location, final String defaultNameHint, final String defaultSuffix) { if (location == null) { throw new NullPointerException(); } if (defaultNameHint == null) { throw new NullPointerException(); } this.location = location; this.defaultNameHint = defaultNameHint; this.defaultSuffix = defaultSuffix; } /** * Generates a new, unique name for storing resources in the output * repository. Assuming that proper synchronization has been applied, the * generated name will be unique within that repository. * * @param nameHint a user defined name for that resource. * @param mimeType the mime type of the resource to be stored in the * repository. * @return the generated, fully qualified name. */ public String generateName(final String nameHint, final String mimeType) throws ContentIOException { final String name; if (nameHint != null) { name = nameHint; } else { name = defaultNameHint; } final String suffix; if (defaultSuffix != null) { suffix = defaultSuffix; } else { suffix = getSuffixForType(mimeType, location); } final String firstFileName = name + '.' + suffix; if (location.exists(firstFileName) == false) { return firstFileName; } if (randomGenerator == null) { randomGenerator = new SecureRandom(); } while (true) { final int counter = randomGenerator.nextInt() & 0x7FFFFFFF; final String filename = name + counter + '.' + suffix; if (location.exists(filename) == false) { return filename; } } } private String getSuffixForType(final String mimeType, final ContentLocation location) { final Repository repository = location.getRepository(); final MimeRegistry mimeRegistry = repository.getMimeRegistry(); return mimeRegistry.getSuffix(mimeType); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/librepository.properties 0000644 0001750 0001750 00000002734 11365605442 032062 0 ustar rene rene org.pentaho.report.libraries.repository.mime-registry.suffix.wmf=application/x-msmetafile org.pentaho.report.libraries.repository.mime-registry.suffix.svg=image/svg+xml org.pentaho.report.libraries.repository.mime-registry.suffix.png=image/png org.pentaho.report.libraries.repository.mime-registry.suffix.jpg=image/jpeg org.pentaho.report.libraries.repository.mime-registry.suffix.jpeg=image/jpeg org.pentaho.report.libraries.repository.mime-registry.suffix.gif=image/gif org.pentaho.report.libraries.repository.mime-registry.suffix.txt=text/plain org.pentaho.report.libraries.repository.mime-registry.suffix.html=text/html org.pentaho.report.libraries.repository.mime-registry.suffix.htm=text/html org.pentaho.report.libraries.repository.mime-registry.suffix.xhtml=text/html org.pentaho.report.libraries.repository.mime-registry.suffix.xml=text/xml org.pentaho.report.libraries.repository.mime-registry.suffix.css=text/css org.pentaho.report.libraries.repository.mime-registry.suffix.rtf=application/rtf org.pentaho.report.libraries.repository.mime-registry.suffix.xls=application/vnd.ms-excel org.pentaho.report.libraries.repository.mime-registry.suffix.pdf=application/pdf org.pentaho.report.libraries.repository.mime-registry.suffix.csv=text/csv org.pentaho.report.libraries.repository.mime-registry.suffix.zip=application/zip org.pentaho.report.libraries.repository.mime-registry.default-mimetype=application/octet-stream org.pentaho.report.libraries.repository.mime-registry.default-suffix=bin librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/Repository.java 0000644 0001750 0001750 00000003105 11365605442 030051 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; /** * A repository represents a abstract view on a filesystem. It always has a single root-entry and grants access * to a repository-specific mime-registry. * * @author Thomas Morgner */ public interface Repository { /** * Returns the repositories root directory entry. * * @return the root directory. * @throws ContentIOException if an error occurs. */ public ContentLocation getRoot() throws ContentIOException; /** * Returns the repositories MimeRegistry, which is used return basic content-type information about the items stored * in this repository. * * @return the mime registry. * @see MimeRegistry */ public MimeRegistry getMimeRegistry(); } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/dummy/ 0000755 0001750 0001750 00000000000 11365605442 026163 5 ustar rene rene librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/dummy/NullOutputStream.java 0000644 0001750 0001750 00000004230 11365605442 032334 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.dummy; import java.io.IOException; import java.io.OutputStream; import java.io.Serializable; /** * A null output stream. All data written to this stream is ignored. * * @author Thomas Morgner */ public class NullOutputStream extends OutputStream implements Serializable { /** * Default constructor. */ public NullOutputStream() { } /** * Writes to the stream (in this case, does nothing). * * @param i the value. * @throws java.io.IOException if there is an I/O problem. */ public void write(final int i) throws IOException { // no i wont do anything here ... } /** * Writes to the stream (in this case, does nothing). * * @param bytes the bytes. * @throws java.io.IOException if there is an I/O problem. */ public void write(final byte[] bytes) throws IOException { // no i wont do anything here ... } /** * Writes to the stream (in this case, does nothing). * * @param bytes the bytes. * @param off the start offset in the data. * @param len the number of bytes to write. * @throws java.io.IOException if there is an I/O problem. */ public void write(final byte[] bytes, final int off, final int len) throws IOException { // no i wont do anything here ... } } ././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/dummy/DummyContentLocation.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/dummy/DummyContentLocation.jav0000644 0001750 0001750 00000014533 11365605442 033012 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.dummy; import java.io.Serializable; import org.pentaho.reporting.libraries.repository.ContentCreationException; import org.pentaho.reporting.libraries.repository.ContentEntity; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; /** * A dummy content location holds references to all dummy items. It does allow to create any items, but always * reports itself as empty location. This implementation only serves as data-sink in case the generated content * is not needed anywhere. * * @author Thomas Morgner */ public class DummyContentLocation implements ContentLocation, Serializable { private String name; private ContentLocation parent; private Repository repository; private static final ContentEntity[] EMPTY_CONTENT_ENTITY = new ContentEntity[0]; /** * Creates a new DummyContentLocation with the given parent and name. The location * will inherit the repository from its parent. * * @param parent the parent location. * @param name the name of this location. */ public DummyContentLocation(final ContentLocation parent, final String name) { if (parent == null) { throw new NullPointerException("Parent must not be null"); } this.repository = parent.getRepository(); this.parent = parent; this.name = name; } /** * Creates a new root DummyContentLocation with the given repository and name. * * @param repository the repository. * @param name the name of this location. */ public DummyContentLocation(final Repository repository, final String name) { this.repository = repository; this.name = name; } /** * Returns all content entities stored in this content-location. This always returns an empty array. * * @return the content entities for this location, an empty array. * @throws ContentIOException if an repository error occured. */ public ContentEntity[] listContents() throws ContentIOException { return EMPTY_CONTENT_ENTITY; } /** * Returns the content entity with the given name. This always throws the ContentIOException, as this implementation * claims to not know any of its childs. * * @param name the name of the entity to be retrieved. * @return the content entity for this name, never null. * @throws ContentIOException if an repository error occured. */ public ContentEntity getEntry(final String name) throws ContentIOException { throw new ContentIOException(); } /** * Creates a new data item in the current location. This method must never * return null. This method will fail if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentItem createItem(final String name) throws ContentCreationException { return new DummyContentItem(this, name); } /** * Creates a new content location in the current location. This method must never * return null. This method will fail if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentLocation createLocation(final String name) throws ContentCreationException { return new DummyContentLocation(this, name); } /** * A dummy location does not have children, therefore this method always returns false. * * @param name the name of the item. * @return false. */ public boolean exists(final String name) { return false; } /** * Returns the name of the entry. * * @return the name, never null. */ public String getName() { return name; } /** * Returns the full pathname of the location. * * @return the full pathname. */ public Object getContentId() { return RepositoryUtilities.buildName(this, "/"); } /** * Dummy locations do not have attributes, therefore this method always returns null. * * @param domain the attribute domain. * @param key the name of the attribute. * @return the value or null, if the content-entity does not have a value for this attribute. */ public Object getAttribute(final String domain, final String key) { return null; } /** * Dummy locations do not allow to set attributes, therefore this method always returns false. * * @param domain the attribute domain. * @param key the attribute name * @param value the new attribute value. * @return false. */ public boolean setAttribute(final String domain, final String key, final Object value) { return false; } /** * Returns the parent, if there is any. * * @return the parent. */ public ContentLocation getParent() { return parent; } /** * Returns the parent repository for this location. * * @return the repository. */ public Repository getRepository() { return repository; } /** * A dummy location does not have content and therefore does not support the delete command. * * @return always false. */ public boolean delete() { return false; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/dummy/DummyContentItem.java 0000644 0001750 0001750 00000011317 11365605442 032276 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.dummy; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; /** * A dummy content item, that does not provide any input and that does swallow all content fed into it. * * @author Thomas Morgner */ public class DummyContentItem implements ContentItem, Serializable { private ContentLocation parent; private String name; private static final byte[] EMPTY_BUFFER = new byte[0]; /** * Creates a new dummy item for the given parent and having the given name. * * @param parent the parent. * @param name the name of the new item. */ public DummyContentItem(final ContentLocation parent, final String name) { if (parent == null) { throw new NullPointerException("Parent must not be null"); } this.parent = parent; this.name = name; } /** * Returns the mime type for the content entity. If the repository does not store mimetypes, this call usually * uses the repositories MimeRegistry to resolve the mimetype. * * @return the mime type. * @throws ContentIOException if an error occured. */ public String getMimeType() throws ContentIOException { return getRepository().getMimeRegistry().getMimeType(this); } /** * Returns a NullOutputStream that ignores all content given to it. * * @return the output stream. */ public OutputStream getOutputStream() { return new NullOutputStream(); } /** * Returns an new empty input stream that does not allow to read a single byte from it. * * @return the input stream. */ public InputStream getInputStream() { return new ByteArrayInputStream(EMPTY_BUFFER); } /** * Claims that the item is readable. * * @return true. */ public boolean isReadable() { return true; } /** * Claims that the item is writable. * * @return true. */ public boolean isWriteable() { return true; } /** * Returns the name of the entry. * * @return the name, never null. */ public String getName() { return name; } /** * Returns the full pathname of the location. * * @return the full pathname. */ public Object getContentId() { return RepositoryUtilities.buildName(this, "/"); } /** * Dummy locations do not have attributes, therefore this method always returns null. * * @param domain the attribute domain. * @param key the name of the attribute. * @return the value or null, if the content-entity does not have a value for this attribute. */ public Object getAttribute(final String domain, final String key) { return null; } /** * Dummy locations do not allow to set attributes, therefore this method always returns false. * * @param domain the attribute domain. * @param key the attribute name * @param value the new attribute value. * @return false. */ public boolean setAttribute(final String domain, final String key, final Object value) { return false; } /** * Returns the parent, if there is any. * * @return the parent. */ public ContentLocation getParent() { return parent; } /** * Returns the parent repository for this location. * * @return the repository. */ public Repository getRepository() { return parent.getRepository(); } /** * A dummy location does not have content and therefore does not support the delete command. * * @return always false. */ public boolean delete() { return false; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/dummy/DummyRepository.java 0000644 0001750 0001750 00000004101 11365605442 032215 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.dummy; import java.io.Serializable; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.DefaultMimeRegistry; import org.pentaho.reporting.libraries.repository.MimeRegistry; import org.pentaho.reporting.libraries.repository.Repository; /** * A dummy repositor is a empty repository that swallows all content fed into it. * * @author Thomas Morgner */ public class DummyRepository implements Repository, Serializable { private DummyContentLocation location; private MimeRegistry mimeRegistry; /** * Creates a new dummy repository. */ public DummyRepository() { location = new DummyContentLocation(this, ""); mimeRegistry = new DefaultMimeRegistry(); } /** * Returns the repositories root directory entry. * * @return the root directory. */ public ContentLocation getRoot() { return location; } /** * Returns the repositories MimeRegistry, which is used return basic content-type information about the items stored * in this repository. * * @return the mime registry. * @see MimeRegistry */ public MimeRegistry getMimeRegistry() { return mimeRegistry; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/ContentCreationException.java 0000644 0001750 0001750 00000003320 11365605442 032647 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; /** * A exception that indicates that a new ContentEntry could not be created in the repository. * * @author Thomas Morgner */ public class ContentCreationException extends ContentIOException { private static final long serialVersionUID = 8817127426694197164L; /** * Creates a ContentCreationException with no message and no parent. */ public ContentCreationException() { } /** * Creates an ContentCreationException. * * @param message the exception message. * @param ex the parent exception. */ public ContentCreationException(final String message, final Exception ex) { super(message, ex); } /** * Creates an ContentCreationException. * * @param message the exception message. */ public ContentCreationException(final String message) { super(message); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipreader/ 0000755 0001750 0001750 00000000000 11365605442 027015 5 ustar rene rene ././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipreader/ZipReadContentItem.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipreader/ZipReadContentItem.j0000644 0001750 0001750 00000010204 11365605442 032675 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zipreader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Date; import java.util.zip.InflaterInputStream; import java.util.zip.ZipEntry; import org.pentaho.reporting.libraries.repository.ContentCreationException; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * Creation-Date: 17.12.2007, 12:19:20 * * @author Thomas Morgner */ public class ZipReadContentItem implements ContentItem { private String comment; private String name; private long size; private long time; private ZipReadRepository repository; private byte[] rawData; private ZipReadContentLocation parent; private String entryName; public ZipReadContentItem(final ZipReadRepository repository, final ZipReadContentLocation parent, final ZipEntry zipEntry, final byte[] bytes) { if (repository == null) { throw new NullPointerException(); } if (zipEntry == null) { throw new NullPointerException(); } if (bytes == null) { throw new NullPointerException(); } this.parent = parent; this.repository = repository; this.comment = zipEntry.getComment(); this.name = zipEntry.getName(); this.entryName = IOUtils.getInstance().getFileName(name); this.size = zipEntry.getSize(); this.time = zipEntry.getTime(); this.rawData = bytes; } public String getMimeType() throws ContentIOException { return repository.getMimeRegistry().getMimeType(this); } public OutputStream getOutputStream() throws ContentIOException, IOException { throw new ContentCreationException("This repository is read-only"); } public InputStream getInputStream() throws ContentIOException, IOException { return new InflaterInputStream(new ByteArrayInputStream(rawData)); } public boolean isReadable() { return true; } public boolean isWriteable() { return false; } public String getName() { return entryName; } public Object getContentId() { return name; } public Object getAttribute(String domain, String key) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.SIZE_ATTRIBUTE.equals(key)) { return new Long(size); } else if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { return new Date(time); } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { return comment; } } return null; } public boolean setAttribute(String domain, String key, Object value) { return false; } public ContentLocation getParent() { return parent; } public Repository getRepository() { return repository; } public boolean delete() { return false; } } ././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011567 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipreader/ZipReadRepository.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipreader/ZipReadRepository.ja0000644 0001750 0001750 00000006370 11365605442 032775 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zipreader; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.DefaultMimeRegistry; import org.pentaho.reporting.libraries.repository.MimeRegistry; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * Provides read-only access to ZIP files. The whole zip-file is cached in memory so this input * method will fail badly on huge zuip-files. * * @author Thomas Morgner */ public class ZipReadRepository implements Repository { private ZipReadContentLocation root; private MimeRegistry mimeRegistry; public ZipReadRepository(final InputStream in) throws IOException { this(in, new DefaultMimeRegistry()); } public ZipReadRepository(final InputStream in, final MimeRegistry mimeRegistry) throws IOException { this.mimeRegistry = mimeRegistry; root = new ZipReadContentLocation(this, null, ""); final ZipInputStream zipIn = new ZipInputStream(in); ZipEntry nextEntry = zipIn.getNextEntry(); if (nextEntry == null) { throw new IOException("This repository is empty or does not point to a ZIP file"); } while (nextEntry != null) { final String[] buildName = RepositoryUtilities.splitPath(nextEntry.getName(), "/"); if (nextEntry.isDirectory()) { root.updateDirectoryEntry(buildName, 0, nextEntry); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(bos, new Deflater(nextEntry.getMethod())); IOUtils.getInstance().copyStreams(zipIn, dos); dos.flush(); dos.close(); root.updateEntry(buildName, 0, nextEntry, bos.toByteArray()); } zipIn.closeEntry(); nextEntry = zipIn.getNextEntry(); } } public ContentLocation getRoot() throws ContentIOException { return root; } public MimeRegistry getMimeRegistry() { return mimeRegistry; } } ././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011565 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipreader/ZipReadContentLocation.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/zipreader/ZipReadContentLocati0000644 0001750 0001750 00000017262 11365605442 032775 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.zipreader; import java.util.Date; import java.util.HashMap; import java.util.zip.ZipEntry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.pentaho.reporting.libraries.repository.ContentCreationException; import org.pentaho.reporting.libraries.repository.ContentEntity; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * * */ public class ZipReadContentLocation implements ContentLocation { private static final Log logger = LogFactory.getLog(ZipReadContentLocation.class); private ZipReadRepository repository; private ZipReadContentLocation parent; private String comment; private String name; private long size; private long time; private String entryName; private HashMap entries; public ZipReadContentLocation(final ZipReadRepository repository, final ZipReadContentLocation parent, final String entryName) { if (repository == null) { throw new NullPointerException(); } if (entryName == null) { throw new NullPointerException(); } this.repository = repository; this.parent = parent; this.entryName = entryName; this.entries = new HashMap(); this.name = RepositoryUtilities.buildName(this, "/") + '/'; } public ZipReadContentLocation(ZipReadRepository repository, ZipReadContentLocation parent, ZipEntry zipEntry) { if (repository == null) { throw new NullPointerException(); } if (parent == null) { throw new NullPointerException(); } if (zipEntry == null) { throw new NullPointerException(); } this.repository = repository; this.parent = parent; this.comment = zipEntry.getComment(); this.size = zipEntry.getSize(); this.time = zipEntry.getTime(); this.entries = new HashMap(); this.entryName = IOUtils.getInstance().getFileName(zipEntry.getName()); this.name = RepositoryUtilities.buildName(this, "/") + '/'; } private void updateMetaData(final ZipEntry zipEntry) { this.comment = zipEntry.getComment(); this.size = zipEntry.getSize(); this.time = zipEntry.getTime(); } public void updateDirectoryEntry(final String[] name, final int index, final ZipEntry zipEntry) { if (name == null) { throw new NullPointerException(); } if (zipEntry == null) { throw new NullPointerException(); } final String path = name[index]; final Object entry = entries.get(path); if (entry instanceof ContentItem) { logger.warn("Directory-Entry with the same name as a Content-Entry encountered: " + path); return; } final ZipReadContentLocation location; if (entry == null) { location = new ZipReadContentLocation(repository, this, path); entries.put(path, location); } else { location = (ZipReadContentLocation) entry; } final int nextNameIdx = index + 1; if (nextNameIdx < name.length) { location.updateDirectoryEntry(name, nextNameIdx, zipEntry); } else if (nextNameIdx == name.length) { location.updateMetaData(zipEntry); } } public void updateEntry(final String[] name, final int index, final ZipEntry zipEntry, final byte[] data) { if (name == null) { throw new NullPointerException(); } if (zipEntry == null) { throw new NullPointerException(); } if (data == null) { throw new NullPointerException(); } final String path = name[index]; final Object entry = entries.get(path); final int nextNameIdx = index + 1; if (nextNameIdx < name.length) { if (entry instanceof ContentItem) { logger.warn("Directory-Entry with the same name as a Content-Entry encountered: " + path); return; } final ZipReadContentLocation location; if (entry == null) { location = new ZipReadContentLocation(repository, this, path); entries.put(path, location); } else { location = (ZipReadContentLocation) entry; } if (nextNameIdx < name.length) { location.updateEntry(name, nextNameIdx, zipEntry, data); } } else if (nextNameIdx == name.length) { if (entry instanceof ContentItem) { logger.warn("Duplicate Content-Entry encountered: " + path); return; } else if (entry != null) { logger.warn("Replacing Directory-Entry with the same name as a Content-Entry: " + path); } final ZipReadContentItem contentItem = new ZipReadContentItem(repository, this, zipEntry, data); entries.put(path, contentItem); } } public ContentEntity[] listContents() throws ContentIOException { return (ContentEntity[]) entries.values().toArray(new ContentEntity[entries.size()]); } public ContentEntity getEntry(final String name) throws ContentIOException { final ContentEntity contentEntity = (ContentEntity) entries.get(name); if (contentEntity == null) { throw new ContentIOException("Not found:" + name); } return contentEntity; } public boolean exists(final String name) { return entries.containsKey(name); } public ContentItem createItem(final String name) throws ContentCreationException { throw new ContentCreationException(); } public ContentLocation createLocation(final String name) throws ContentCreationException { throw new ContentCreationException(); } public String getName() { return entryName; } public Object getContentId() { return name; } public Object getAttribute(final String domain, final String key) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.SIZE_ATTRIBUTE.equals(key)) { return new Long(size); } else if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { return new Date(time); } } else if (LibRepositoryBoot.ZIP_DOMAIN.equals(domain)) { if (LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE.equals(key)) { return comment; } } return null; } public boolean setAttribute(final String domain, final String key, final Object value) { return false; } public ContentLocation getParent() { return parent; } public Repository getRepository() { return repository; } public boolean delete() { return false; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/file/ 0000755 0001750 0001750 00000000000 11365605442 025747 5 ustar rene rene librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/file/FileRepository.java 0000644 0001750 0001750 00000007347 11365605442 031604 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.file; import java.io.File; import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.DefaultMimeRegistry; import org.pentaho.reporting.libraries.repository.MimeRegistry; import org.pentaho.reporting.libraries.repository.UrlRepository; /** * A file-repository uses a subset of the local filesystem to provide a repository view on top of it. This repository * type is the most commonly used repository, as most applications are allowed to access the local filsystem. * * @author Thomas Morgner */ public class FileRepository implements UrlRepository, Serializable { private static final long serialVersionUID = -6221548332596506480L; private MimeRegistry mimeRegistry; private FileContentLocation root; /** * Creates a new repository for the given file. The file must point to a directory. This constructor uses the * default mime-registry. * * @param file the directory, which should form the root of the repository. * @throws ContentIOException if an error prevents the repository creation. */ public FileRepository(final File file) throws ContentIOException { this(file, new DefaultMimeRegistry()); } /** * Creates a new repository for the given file. The file must point to a directory. * * @param file the directory, which should form the root of the repository. * @param mimeRegistry the mime registry to be used. * @throws ContentIOException if an error prevents the repository creation. */ public FileRepository(final File file, final MimeRegistry mimeRegistry) throws ContentIOException { if (mimeRegistry == null) { throw new NullPointerException("MimeRegistry must be given"); } if (file == null) { throw new NullPointerException("File must be given"); } this.mimeRegistry = mimeRegistry; this.root = new FileContentLocation(this, file); } /** * Returns the mime-registry for the repository. * * @return the mime-registry. */ public MimeRegistry getMimeRegistry() { return mimeRegistry; } /** * Returns the repositories root directory entry. * * @return the root directory. * @throws ContentIOException if an error occurs. */ public ContentLocation getRoot() throws ContentIOException { return root; } /** * Returns the URL that represents this repository. The meaning of the URL returned here is implementation * specific and is probably not suitable to resolve names to global objects. * * @return the repository's URL. * @throws MalformedURLException if the URL could not be computed. */ public URL getURL() throws MalformedURLException { return root.getBackend().toURL(); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/file/FileContentLocation.java 0000644 0001750 0001750 00000017604 11365605442 032525 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.file; import java.io.File; import java.io.IOException; import org.pentaho.reporting.libraries.repository.ContentCreationException; import org.pentaho.reporting.libraries.repository.ContentEntity; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.Repository; import org.pentaho.reporting.libraries.repository.RepositoryUtilities; import org.pentaho.reporting.libraries.base.util.IOUtils; /** * A content-location that uses a directory as backend. * * @author Thomas Morgner */ public class FileContentLocation extends FileContentEntity implements ContentLocation { private static final long serialVersionUID = -5452372293937107734L; /** * Creates a new location for the given parent and directory. * * @param parent the parent location. * @param backend the backend. * @throws ContentIOException if an error occured or the file did not point to a directory. */ public FileContentLocation(final ContentLocation parent, final File backend) throws ContentIOException { super(parent, backend); if (backend.exists() == false || backend.isDirectory() == false) { throw new ContentIOException("The given backend-file is not a directory."); } } /** * Creates a new root-location for the given repository and directory. * * @param repository the repository for which a location should be created. * @param backend the backend. * @throws ContentIOException if an error occured or the file did not point to a directory. */ public FileContentLocation(final Repository repository, final File backend) throws ContentIOException { super(repository, backend); if (backend.exists() == false || backend.isDirectory() == false) { throw new ContentIOException("The given backend-file is not a directory."); } } /** * Lists all content entities stored in this content-location. This method filters out all files that have an * invalid name (according to the repository rules). * * @return the content entities for this location. * @throws ContentIOException if an repository error occured. */ public ContentEntity[] listContents() throws ContentIOException { final File file = getBackend(); final File[] files = file.listFiles(); final ContentEntity[] entities = new ContentEntity[files.length]; for (int i = 0; i < files.length; i++) { final File child = files[i]; if (RepositoryUtilities.isInvalidPathName(child.getName())) { continue; } if (child.isDirectory()) { entities[i] = new FileContentLocation(this, child); } else if (child.isFile()) { entities[i] = new FileContentLocation(this, child); } } return entities; } /** * Returns the content entity with the given name. If the entity does not exist, an Exception will be raised. * * @param name the name of the entity to be retrieved. * @return the content entity for this name, never null. * @throws ContentIOException if an repository error occured. */ public ContentEntity getEntry(final String name) throws ContentIOException { if (RepositoryUtilities.isInvalidPathName(name)) { throw new IllegalArgumentException("The name given is not valid."); } final File file = getBackend(); final File child = new File(file, name); if (child.exists() == false) { throw new ContentIOException("Not found:" + child); } try { if (IOUtils.getInstance().isSubDirectory(file, child) == false) { throw new ContentIOException("The given entry does not point to a sub-directory of this content-location"); } } catch (IOException e) { throw new ContentIOException("IO Error.", e); } if (child.isDirectory()) { return new FileContentLocation(this, child); } else if (child.isFile()) { return new FileContentItem(this, child); } else { throw new ContentIOException("Not File nor directory."); } } /** * Creates a new data item in the current location. This method must never * return null. This method will fail if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentItem createItem(final String name) throws ContentCreationException { if (RepositoryUtilities.isInvalidPathName(name)) { throw new IllegalArgumentException("The name given is not valid."); } final File file = getBackend(); final File child = new File(file, name); if (child.exists()) { if (child.length() == 0) { // probably one of the temp files created by the pentaho-system return new FileContentItem(this, child); } throw new ContentCreationException("File already exists: " + child); } try { if (child.createNewFile() == false) { throw new ContentCreationException("Unable to create the file."); } return new FileContentItem(this, child); } catch (IOException e) { throw new ContentCreationException("IOError while create", e); } } /** * Creates a new content location in the current location. This method must never * return null. This method will fail if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentLocation createLocation(final String name) throws ContentCreationException { if (RepositoryUtilities.isInvalidPathName(name)) { throw new IllegalArgumentException("The name given is not valid."); } final File file = getBackend(); final File child = new File(file, name); if (child.exists()) { throw new ContentCreationException("Directory already exists."); } if (child.mkdir() == false) { throw new ContentCreationException("Unable to create the directory"); } try { return new FileContentLocation(this, child); } catch (ContentIOException e) { throw new ContentCreationException("Failed to create the content-location", e); } } /** * Checks, whether an content entity with the given name exists in this content location. This method * will report invalid filenames as non-existent. * * @param name the name of the new entity. * @return true, if an entity exists with this name, false otherwise. */ public boolean exists(final String name) { if (RepositoryUtilities.isInvalidPathName(name)) { return false; } final File file = getBackend(); final File child = new File(file, name); return (child.exists()); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/file/FileContentEntity.java 0000644 0001750 0001750 00000014155 11365605442 032227 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.file; import java.io.File; import java.io.Serializable; import java.util.Date; import org.pentaho.reporting.libraries.repository.ContentEntity; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.LibRepositoryBoot; import org.pentaho.reporting.libraries.repository.Repository; /** * A content-entity that uses a java.io.File as backend. The entity can read the * {@link LibRepositoryBoot#SIZE_ATTRIBUTE} and can read and write the * {@link LibRepositoryBoot#VERSION_ATTRIBUTE}. * * @author Thomas Morgner */ public abstract class FileContentEntity implements ContentEntity, Serializable { private File backend; private ContentLocation parent; private Repository repository; private static final long serialVersionUID = 3962114134995757847L; /** * Creates a new content-entity for the given file using the given content location as parent. * * @param parent the content location representing the parent directory. * @param backend the file representing this entity. */ protected FileContentEntity(final ContentLocation parent, final File backend) { if (backend == null) { throw new NullPointerException("Backend file must be given."); } if (parent == null) { throw new NullPointerException("Parent file must be given."); } this.repository = parent.getRepository(); this.parent = parent; this.backend = backend; } /** * Creates a new root content-entity for the given file using the given content location as parent. * * @param repository the repository for which this entity is created. * @param backend the file representing this entity. */ protected FileContentEntity(final Repository repository, final File backend) { if (backend == null) { throw new NullPointerException("Backend file must be given."); } if (repository == null) { throw new NullPointerException("Repository file must be given."); } this.repository = repository; this.backend = backend; } /** * Returns the current repository, to which tis entity belongs. * * @return the repository. */ public Repository getRepository() { return repository; } /** * Returns the name of the file. * * @return the name, never null. */ public String getName() { return backend.getName(); } /** * Returns the file that provides the backend of this entity. * * @return the file, never null. */ protected File getBackend() { return backend; } /** * Returns a unique identifier. This can be canonical filename or a database key. It must be guaranteed that * within the same repository the key will be unique. * * @return the unique content ID. */ public Object getContentId() { return backend; } /** * Returns a attribute value for the given domain (namespace) and attribute-name. Some generic attribute domains * and names are defined as constants in the {@link LibRepositoryBoot} class. * * @param domain the attribute domain. * @param key the name of the attribute. * @return the value or null, if the content-entity does not have a value for this attribute. */ public Object getAttribute(final String domain, final String key) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.SIZE_ATTRIBUTE.equals(key)) { return new Long(backend.length()); } else if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { return new Date(backend.lastModified()); } } return null; } /** * Updates the attribute value for the given attribute domain and name. If the element is not writable or the * attribute could not be updated for any other reason, the method will return false. This method only returns * true, if the attribute has been updated successfully. * * @param domain the attribute domain. * @param key the attribute name * @param value the new attribute value. * @return true, if the update was successful, false otherwise. */ public boolean setAttribute(final String domain, final String key, final Object value) { if (LibRepositoryBoot.REPOSITORY_DOMAIN.equals(domain)) { if (LibRepositoryBoot.VERSION_ATTRIBUTE.equals(key)) { if (value instanceof Date) { final Date date = (Date) value; return backend.setLastModified(date.getTime()); } else if (value instanceof Number) { final Number time = (Number) value; return backend.setLastModified(time.longValue()); } } } return false; } /** * Returns a reference to the parent location. If this entity represents the root directory, this method will * return null. * * @return the parent or null, if this is the root-directory. */ public ContentLocation getParent() { return parent; } /** * Attempts to delete the entity. After an entity has been deleted, any call to any of the methods of the * entity may produce undefined results. * * @return true, if the entity was deleted and detached from the repository, false otherwise. */ public boolean delete() { return backend.delete(); } } ././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/file/TempFileNameGenerator.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/file/TempFileNameGenerator.jav0000644 0001750 0001750 00000003536 11365605442 032635 0 ustar rene rene package org.pentaho.reporting.libraries.repository.file; import java.io.File; import java.io.IOException; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.MimeRegistry; import org.pentaho.reporting.libraries.repository.NameGenerator; /** * Todo: Document me! * * Date: 15.04.2010 * Time: 16:35:38 * * @author Thomas Morgner. */ public class TempFileNameGenerator implements NameGenerator { private FileContentLocation fileContentLocation; public TempFileNameGenerator(final FileContentLocation fileContentLocation) { if (fileContentLocation == null) { throw new NullPointerException(); } this.fileContentLocation = fileContentLocation; } /** * Generates a new name for the location. The name-generator may use both the name-hint and mimetype to compute * the new name. * * @param nameHint the name hint, usually a identifier for the new filename (can be null). * @param mimeType the mime type of the new filename. Usually used to compute a suitable file-suffix. * @return the generated name, never null. * @throws org.pentaho.reporting.libraries.repository.ContentIOException * if the name could not be generated for any reason. */ public String generateName(final String nameHint, final String mimeType) throws ContentIOException { final MimeRegistry mimeRegistry = fileContentLocation.getRepository().getMimeRegistry(); final File targetDirectory = fileContentLocation.getBackend(); final String suffix = mimeRegistry.getSuffix(mimeType); try { final File tempFile = File.createTempFile(nameHint, "." + suffix, targetDirectory); return tempFile.getName(); } catch (IOException e) { throw new ContentIOException("Unable to generate a name for the data file", e); } } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/file/FileContentItem.java 0000644 0001750 0001750 00000004553 11365605442 031652 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.file; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; /** * A content item wrapping a file. * * @author Thomas Morgner */ public class FileContentItem extends FileContentEntity implements ContentItem { private static final long serialVersionUID = 5080072160607835550L; /** * Creates a new file based content item for the given file and parent location. * * @param parent the parent. * @param backend the backend. */ public FileContentItem(final ContentLocation parent, final File backend) { super(parent, backend); } public String getMimeType() throws ContentIOException { final FileRepository fileRepository = (FileRepository) getRepository(); return fileRepository.getMimeRegistry().getMimeType(this); } public OutputStream getOutputStream() throws ContentIOException, IOException { return new FileOutputStream(getBackend()); } public InputStream getInputStream() throws ContentIOException, IOException { return new FileInputStream(getBackend()); } public boolean isReadable() { return getBackend().canRead(); } public boolean isWriteable() { return getBackend().canWrite(); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/MimeRegistry.java 0000644 0001750 0001750 00000003453 11365605442 030320 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; /** * The MimeRegistry encodes content-type information and allows to detect or query the file type of a given * content item. It also assists in naming files by providing a default suffix for a given mime-type. * * @author Thomas Morgner */ public interface MimeRegistry { /** * Queries the mime-type for a given content-item. Some repositories store mime-type information along with * the content data, while others might resort to heuristics based on the filename or actual data stored in the * item. * * @param item the content item for which Mime-Data should be queried. * @return the mime-type never null. */ public String getMimeType(ContentItem item); /** * Returns the default suffix for files with the given content type. * * @param mimeType the mime-type for which a suffix is queried. * @return the suffix, never null. */ public String getSuffix(String mimeType); } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/DefaultMimeRegistry.java 0000644 0001750 0001750 00000010376 11365605442 031627 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; import java.io.Serializable; import java.util.Iterator; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.base.util.IOUtils; import org.pentaho.reporting.libraries.base.util.ObjectUtilities; /** * The default-mime registry contains a list of well-known file types and returns mime-information for them. This * implementation recognizes a couple of image types and CSS, XML and HTML files. The content is recognized by its * filename, not by its actual content. * * @author Thomas Morgner */ public class DefaultMimeRegistry implements MimeRegistry, Serializable { private static final long serialVersionUID = 2815922456302361614L; private static final String SUFFIX_KEY_PREFIX = "org.pentaho.report.libraries.repository.mime-registry.suffix"; private static final String SUFFIX_KEY_PREFIX_WDOT = SUFFIX_KEY_PREFIX + "."; private static final Configuration configuration = LibRepositoryBoot.getInstance().getGlobalConfig(); private static final String defaultMimeType = configuration.getConfigProperty ("org.pentaho.report.libraries.repository.mime-registry.default-mimetype", "application/octet-stream"); /** * Default Constructor. */ public DefaultMimeRegistry() { } /** * Queries the mime-type for a given content-item. Some repositories store mime-type information along with the * content data, while others might resort to heuristics based on the filename or actual data stored in the item. * * @param item the content item for which Mime-Data should be queried. * @return the mime-type never null. */ public String getMimeType(final ContentItem item) { final String name = item.getName(); if (name == null) { return defaultMimeType; } final String extension = IOUtils.getInstance().getFileExtension(name).toLowerCase(); return configuration.getConfigProperty(SUFFIX_KEY_PREFIX + extension, "application/octet-stream"); } /** * Queries the mime-type for a given filename. Some repositories store mime-type information along with the * content data, while others might resort to heuristics based on the filename or actual data stored in the item. * * @param filename the content item for which Mime-Data should be queried. * @return the mime-type never null. */ public String getMimeType(final String filename) { if (filename == null) { return defaultMimeType; } final String extension = IOUtils.getInstance().getFileExtension(filename).toLowerCase(); return configuration.getConfigProperty(SUFFIX_KEY_PREFIX + extension, "application/octet-stream"); } /** * Returns the default suffix for files with the given content type. * * @param mimeType the mime-type for which a suffix is queried. * @return the suffix, never null. */ public String getSuffix(final String mimeType) { final Iterator propertyKeys = configuration.findPropertyKeys(SUFFIX_KEY_PREFIX_WDOT); while (propertyKeys.hasNext()) { final String key = (String) propertyKeys.next(); final String keyMimeType = configuration.getConfigProperty(key); if (ObjectUtilities.equal(keyMimeType, mimeType)) { return key.substring(SUFFIX_KEY_PREFIX_WDOT.length()); } } return configuration.getConfigProperty ("org.pentaho.report.libraries.repository.mime-registry.default-suffix", "bin"); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/LibRepositoryBoot.java 0000644 0001750 0001750 00000010155 11365605442 031327 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; import java.util.zip.ZipOutputStream; import org.pentaho.reporting.libraries.base.boot.AbstractBoot; import org.pentaho.reporting.libraries.base.config.Configuration; import org.pentaho.reporting.libraries.base.versioning.ProjectInformation; /** * The LibRepositoryBoot class is used to initialize the library before it is * first used. This loads all configurations and initializes all factories. * * Without booting, basic services like logging and the global configuration * will not be availble. * * @author Thomas Morgner */ public class LibRepositoryBoot extends AbstractBoot { /** A attribute domain name for managing ZIP-Attributes. */ public static final String ZIP_DOMAIN = "org.jfree.repository.zip"; /** A attribute name representing a ZIP compression method. */ public static final String ZIP_METHOD_ATTRIBUTE = "method"; /** A attribute name representing a ZIP attribute value. */ public static final Integer ZIP_METHOD_STORED = new Integer(ZipOutputStream.STORED); /** A attribute name representing a ZIP attribute value. */ public static final Integer ZIP_METHOD_DEFLATED = new Integer(ZipOutputStream.DEFLATED); /** A attribute name representing a ZIP compression level. */ public static final String ZIP_COMPRESSION_ATTRIBUTE = "compression"; /** A attribute name representing a ZIP entry comment. */ public static final String ZIP_COMMENT_ATTRIBUTE = "comment"; /** A attribute name representing a ZIP attribute. */ public static final String ZIP_CRC32_ATTRIBUTE = "crc32"; /** A attribute domain name for managing general attributes. */ public static final String REPOSITORY_DOMAIN = "org.jfree.repository"; /** A attribute name representing the content-item size. This should always return a Number. */ public static final String SIZE_ATTRIBUTE = "size"; /** * A attribute name representing the content-entity versioning information. The object used as versioning * information is implementation-specific and should only be used to compare equality. */ public static final String VERSION_ATTRIBUTE = "version"; /** A attribute name representing the content-entities mime-type information (if stored in the repository). */ public static final String CONTENT_TYPE = "content-type"; private static LibRepositoryBoot instance; /** * Returns the singleton instance of the boot-class. * * @return the singleton booter. */ public static synchronized LibRepositoryBoot getInstance() { if (instance == null) { instance = new LibRepositoryBoot(); } return instance; } /** * Private constructor prevents object creation. */ private LibRepositoryBoot() { } /** * Loads the configuration. * * @return The configuration. */ protected Configuration loadConfiguration() { return createDefaultHierarchicalConfiguration ("/org/pentaho/reporting/libraries/repository/librepository.properties", "/librepository.properties", true, LibRepositoryBoot.class); } /** * Performs the boot. */ protected void performBoot() { } /** * Returns the project info. * * @return The project info. */ protected ProjectInformation getProjectInfo() { return LibRepositoryInfo.getInstance(); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/stream/ 0000755 0001750 0001750 00000000000 11365605442 026323 5 ustar rene rene librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/stream/StreamContentItem.java 0000644 0001750 0001750 00000016150 11365605442 032576 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.stream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.Repository; /** * A stream-content item that wraps around the input and output streams given in the repository. Depending on which * stream are given, this item reports itself as read or writable. * * @author Thomas Morgner */ public class StreamContentItem implements ContentItem { private WrappedInputStream inputStream; private WrappedOutputStream outputStream; private ContentLocation parent; private String name; /** * Creates a new stream-content item. The item will have the given name and parent and will wrap around the * provided streams. * * @param name the name of the content item. * @param parent the parent location. * @param inputStream the (optional) input stream. * @param outputStream the (optional) output stream. */ public StreamContentItem(final String name, final ContentLocation parent, final WrappedInputStream inputStream, final WrappedOutputStream outputStream) { if (name == null) { throw new NullPointerException(); } if (parent == null) { throw new NullPointerException(); } this.name = name; this.parent = parent; this.inputStream = inputStream; this.outputStream = outputStream; } /** * Checks, whether the content item is readable. A content item that is not readable will never return a valid * inputstream and any call to getInputStream is bound to fail. * * @return true, if the content item is readable, false otherwise. */ public boolean isReadable() { if (inputStream == null) { return false; } return inputStream.isClosed() == false; } /** * Checks, whether the content item is writable. A content item that is not writable will never return a valid * outputstream and any call to getOutputStream is bound to fail. * * @return true, if the content item is writeable, false otherwise. */ public boolean isWriteable() { if (outputStream == null) { return false; } return outputStream.isClosed() == false; } /** * Returns the mime type for the content entity. If the repository does not store mimetypes, this call usually * uses the repositories MimeRegistry to resolve the mimetype. * * @return the mime type. * @throws ContentIOException if an error occured. */ public String getMimeType() throws ContentIOException { return getRepository().getMimeRegistry().getMimeType(this); } /** * Tries to open and return a output stream for writing into the content item. This call will fail if the * item is not writeable. Whether opening multiple output streams at the same time is possible is implementation * dependent, but it is generally not recommended to try this. * * Having both an input and output stream open at the same time is not guaranteed to work. Generally if you need * to append data, first open the inputstream and copy the content to a temporary location and then write the * content along with the appended content to the new output stream. * * @return the output stream for writing the item. * @throws ContentIOException if an repository related error prevents the creation of the output stream. * @throws IOException if an IO error occurs. */ public OutputStream getOutputStream() throws ContentIOException, IOException { return outputStream; } /** * Tries to open and return a input stream for reading from the content item. This call will fail if the * item is not readable. Whether opening multiple input streams at the same time is possible is implementation * dependent. * * Having both an input and output stream open at the same time is not guaranteed to work. Generally if you need * to append data, first open the inputstream and copy the content to a temporary location and then write the * content along with the appended content to the new output stream. * * @return the input stream for reading from the item. * @throws ContentIOException if an repository related error prevents the creation of the input stream. * @throws IOException if an IO error occurs. */ public InputStream getInputStream() throws ContentIOException, IOException { return inputStream; } /** * Returns the name of the entry. * * @return the name, never null. */ public String getName() { return name; } /** * Returns a unique identifier. This can be canonical filename or a database key. It must be guaranteed that * within the same repository the key will be unique. * * @return the unique content ID. */ public Object getContentId() { return parent.getName() + '/' + name; } /** * Stream-Repositories do not support attributes. * * @param domain the attribute domain. * @param key the name of the attribute. * @return always null. */ public Object getAttribute(final String domain, final String key) { return null; } /** * Stream-Repositories do not support attributes. * * @param domain the attribute domain. * @param key the attribute name * @param value the new attribute value. * @return always false. */ public boolean setAttribute(final String domain, final String key, final Object value) { return false; } /** * Returns a reference to the parent location. If this entity represents the root directory, this method will * return null. * * @return the parent or null, if this is the root-directory. */ public ContentLocation getParent() { return parent; } /** * Returns the current repository, to which tis entity belongs. * * @return the repository. */ public Repository getRepository() { return parent.getRepository(); } /** * Stream-repositories do not support the deletion of entries. * * @return always false. */ public boolean delete() { return false; } } ././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/stream/StreamContentLocation.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/stream/StreamContentLocation.j0000644 0001750 0001750 00000016627 11365605442 032771 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.stream; import org.pentaho.reporting.libraries.repository.ContentCreationException; import org.pentaho.reporting.libraries.repository.ContentEntity; import org.pentaho.reporting.libraries.repository.ContentIOException; import org.pentaho.reporting.libraries.repository.ContentItem; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.Repository; /** * A content location that wraps around a single stream. The location will reject any attempts to create new * entities or to access entities other than the single entity. * * @author Thomas Morgner */ public class StreamContentLocation implements ContentLocation { private ContentItem contentItem; private StreamRepository repository; private static final ContentEntity[] EMPTY_CONTENT_ENTITY = new ContentEntity[0]; /** * Creates a new stream-location. There can be only one location per stream-repository. * * @param repository the repository for which a location is created. */ public StreamContentLocation(final StreamRepository repository) { if (repository == null) { throw new NullPointerException(); } this.repository = repository; } /** * Returns all content entities stored in this content-location. This returns a array that has at most * one entry. If the repository is a write-only repository and no item has been created yet, the method * returns an empty array. * * @return the content entities for this location. * @throws ContentIOException if an repository error occured. */ public ContentEntity[] listContents() throws ContentIOException { final WrappedInputStream in = repository.getInputStream(); if (in != null && contentItem == null) { this.contentItem = new StreamContentItem (repository.getContentName(), this, in, repository.getOutputStream()); } if (contentItem == null) { return EMPTY_CONTENT_ENTITY; } else { return new ContentEntity[]{contentItem}; } } /** * Returns the content entity with the given name. If the entity does not exist, an Exception will be raised. * * @param name the name of the entity to be retrieved. * @return the content entity for this name, never null. * @throws ContentIOException if an repository error occured. */ public ContentEntity getEntry(final String name) throws ContentIOException { final WrappedInputStream in = repository.getInputStream(); if (in != null && contentItem == null) { this.contentItem = new StreamContentItem (repository.getContentName(), this, in, repository.getOutputStream()); } if (contentItem == null) { throw new ContentIOException("No such item"); } if (contentItem.getName().equals(name)) { return contentItem; } throw new ContentIOException("No such item"); } /** * Creates a new data item in the current location. This method must never * return null. This method will fail if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentItem createItem(final String name) throws ContentCreationException { final WrappedInputStream in = repository.getInputStream(); final WrappedOutputStream outputStream = repository.getOutputStream(); if (in != null && contentItem == null) { this.contentItem = new StreamContentItem(repository.getContentName(), this, in, outputStream); } if (contentItem == null && outputStream != null) { contentItem = new StreamContentItem(name, this, in, outputStream); return contentItem; } throw new ContentCreationException ("Failed to create the item. Item already exists or the repository is read-only"); } /** * This method always throws an exception, as stream-repositories cannot create sub-locations. * * @param name the name. * @return nothing. * @throws ContentCreationException always, as stream-repositories cannot create sub-locations. */ public ContentLocation createLocation(final String name) throws ContentCreationException { throw new ContentCreationException("A stream repository never creates sub-locations"); } /** * Checks, whether an content entity with the given name exists in this content location. * * @param name the name of the new entity. * @return true, if an entity exists with this name, false otherwise. */ public boolean exists(final String name) { if (contentItem != null) { return contentItem.getName().equals(name); } final WrappedInputStream in = repository.getInputStream(); if (in != null) { // if we are in input mode, the content name must not be null. return repository.getContentName().equals(name); } return false; } /** * Returns the generic name of this location. * * @return the name. */ public String getName() { return "root"; } /** * Returns a unique identifier. This can be canonical filename or a database key. It must be guaranteed that * within the same repository the key will be unique. * * @return the unique content ID. */ public Object getContentId() { return getName(); } /** * Stream-Repositories do not support attributes. * * @param domain the attribute domain. * @param key the name of the attribute. * @return always null. */ public Object getAttribute(final String domain, final String key) { return null; } /** * Stream-Repositories do not support attributes. * * @param domain the attribute domain. * @param key the attribute name * @param value the new attribute value. * @return always false. */ public boolean setAttribute(final String domain, final String key, final Object value) { return false; } /** * Returns a reference to the parent location. If this entity represents the root directory, this method will * return null. * * @return the parent or null, if this is the root-directory. */ public ContentLocation getParent() { return null; } /** * Returns the current repository, to which tis entity belongs. * * @return the repository. */ public Repository getRepository() { return repository; } /** * Stream-repositories do not support the deletion of entries. * * @return always false. */ public boolean delete() { return false; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/stream/StreamRepository.java 0000644 0001750 0001750 00000011214 11365605442 032520 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.stream; import java.io.InputStream; import java.io.OutputStream; import org.pentaho.reporting.libraries.repository.ContentLocation; import org.pentaho.reporting.libraries.repository.DefaultMimeRegistry; import org.pentaho.reporting.libraries.repository.MimeRegistry; import org.pentaho.reporting.libraries.repository.Repository; /** * A repository that feeds a single source. * * @author Thomas Morgner */ public class StreamRepository implements Repository { private MimeRegistry mimeRegistry; private WrappedOutputStream outputStream; private WrappedInputStream inputStream; private StreamContentLocation rootLocation; private String contentName; /** * Creates a new repository that potentially allows both read and write access. If an input stream is given, then * a content name must be given as well. * * @param inputStream the inputstream from which to read from. * @param outputStream the output stream to which to write to. * @param contentName the content name by which the content should be accessed. */ public StreamRepository(final InputStream inputStream, final OutputStream outputStream, final String contentName) { if (contentName == null) { throw new NullPointerException(); } if (inputStream != null) { this.inputStream = new WrappedInputStream(inputStream); } if (outputStream != null) { this.outputStream = new WrappedOutputStream(outputStream); } this.contentName = contentName; this.mimeRegistry = new DefaultMimeRegistry(); this.rootLocation = new StreamContentLocation(this); } /** * Creates a new read/write repository with a hardcoded name for the input stream. * * @param inputStream the input stream from where to read the data (can be null). * @param outputStream the output stream where data is written to (can be null). * @deprecated This constructor should not be used, as it hardcodes the filename for the input stream. * Use one of the other constructors instead. */ public StreamRepository(final InputStream inputStream, final OutputStream outputStream) { this(inputStream, outputStream, "content.data"); } /** * Creates a new read-only repository. * * @param inputStream the input stream from where to read the data (can be null). * @param contentName the content name by which the content should be accessed. */ public StreamRepository(final InputStream inputStream, final String contentName) { this(inputStream, null, contentName); } /** * Creates a new write-only repository. * * @param outputStream the output stream to which to write to. */ public StreamRepository(final OutputStream outputStream) { this(null, outputStream, "content.data"); } /** * Returns the optional content name by which the data in the input-stream should be accessed. * * @return the content name or null, if this repository is write-only. */ public String getContentName() { return contentName; } /** * Returns the optional output stream. * * @return the stream or null, if this repository is read-only. */ public WrappedOutputStream getOutputStream() { return outputStream; } /** * Returns the optional input stream. * * @return the stream or null, if this repository is write-only. */ public WrappedInputStream getInputStream() { return inputStream; } /** * Returns the content root of this repository. * * @return the content root. */ public ContentLocation getRoot() { return rootLocation; } /** * Returns the mime registry for this repository. * * @return the mime-registry. */ public MimeRegistry getMimeRegistry() { return mimeRegistry; } } ././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/stream/WrappedOutputStream.java librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/stream/WrappedOutputStream.jav0000644 0001750 0001750 00000003513 11365605442 033026 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.stream; import java.io.IOException; import java.io.OutputStream; /** * Creation-Date: 13.11.2006, 17:30:06 * * @author Thomas Morgner */ public class WrappedOutputStream extends OutputStream { private OutputStream stream; private boolean closed; public WrappedOutputStream(final OutputStream stream) { if (stream == null) { throw new NullPointerException(); } this.stream = stream; } public void write(final int b) throws IOException { stream.write(b); } public void write(final byte[] b) throws IOException { stream.write(b); } public void write(final byte[] b, final int off, final int len) throws IOException { stream.write(b, off, len); } public void flush() throws IOException { stream.flush(); } public void close() throws IOException { closed = true; stream.close(); } public boolean isClosed() { return closed; } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/stream/WrappedInputStream.java0000644 0001750 0001750 00000004227 11365605442 032771 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository.stream; import java.io.IOException; import java.io.InputStream; /** * Creation-Date: 13.11.2006, 17:28:24 * * @author Thomas Morgner */ public class WrappedInputStream extends InputStream { private boolean closed; private InputStream parent; public WrappedInputStream(final InputStream parent) { if (parent == null) { throw new NullPointerException(); } this.parent = parent; } public int read() throws IOException { return parent.read(); } public int read(final byte[] b) throws IOException { return parent.read(b); } public int read(final byte[] b, final int off, final int len) throws IOException { return parent.read(b, off, len); } public long skip(final long n) throws IOException { return parent.skip(n); } public int available() throws IOException { return parent.available(); } public void close() throws IOException { closed = true; parent.close(); } public boolean isClosed() { return closed; } public void mark(final int readlimit) { parent.mark(readlimit); } public void reset() throws IOException { parent.reset(); } public boolean markSupported() { return parent.markSupported(); } } librepository-1.1.6/source/org/pentaho/reporting/libraries/repository/ContentLocation.java 0000644 0001750 0001750 00000005561 11365605442 031005 0 ustar rene rene /* * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2009 Pentaho Corporation and Contributors. All rights reserved. */ package org.pentaho.reporting.libraries.repository; /** * This represents a container in the repository. If the repository is a * filesystem, this will be a directory. * * @author Thomas Morgner */ public interface ContentLocation extends ContentEntity { /** * Returns all content entities stored in this content-location. * * @return the content entities for this location. * @throws ContentIOException if an repository error occured. */ public ContentEntity[] listContents() throws ContentIOException; /** * Returns the content entity with the given name. If the entity does not exist, an Exception will be raised. * * @param name the name of the entity to be retrieved. * @return the content entity for this name, never null. * @throws ContentIOException if an repository error occured. */ public ContentEntity getEntry(String name) throws ContentIOException; /** * Creates a new data item in the current location. This method must never * return null. This method will fail if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentItem createItem(String name) throws ContentCreationException; /** * Creates a new content location in the current location. This method must never * return null. This method will fail if an entity with the same name exists in this location. * * @param name the name of the new entity. * @return the newly created entity, never null. * @throws ContentCreationException if the item could not be created. */ public ContentLocation createLocation(String name) throws ContentCreationException; /** * Checks, whether an content entity with the given name exists in this content location. * * @param name the name of the new entity. * @return true, if an entity exists with this name, false otherwise. */ public boolean exists(final String name); } librepository-1.1.6/licence-LGPL.txt 0000644 0001750 0001750 00000063476 11365605442 016016 0 ustar rene rene GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.