Search in sources :

Example 1 with URLRewriteException

use of org.pentaho.reporting.engine.classic.core.modules.output.table.html.URLRewriteException in project pentaho-platform by pentaho.

the class PentahoURLRewriter method rewrite.

public String rewrite(final ContentEntity contentEntry, final ContentEntity dataEntity) throws URLRewriteException {
    try {
        final ArrayList<String> entityNames = new ArrayList<String>();
        entityNames.add(dataEntity.getName());
        ContentLocation location = dataEntity.getParent();
        while (location != null) {
            entityNames.add(location.getName());
            location = location.getParent();
        }
        final ArrayList<String> contentNames = new ArrayList<String>();
        location = dataEntity.getRepository().getRoot();
        while (location != null) {
            contentNames.add(location.getName());
            location = location.getParent();
        }
        // now remove all path elements that are equal ..
        while ((contentNames.isEmpty() == false) && (entityNames.isEmpty() == false)) {
            final String lastEntity = (String) entityNames.get(entityNames.size() - 1);
            final String lastContent = (String) contentNames.get(contentNames.size() - 1);
            if (lastContent.equals(lastEntity) == false) {
                break;
            }
            entityNames.remove(entityNames.size() - 1);
            contentNames.remove(contentNames.size() - 1);
        }
        final StringBuffer b = new StringBuffer();
        for (int i = entityNames.size() - 1; i >= 0; i--) {
            final String name = (String) entityNames.get(i);
            b.append(name);
            if (i != 0) {
                // $NON-NLS-1$
                b.append("/");
            }
        }
        if (pattern == null) {
            return b.toString();
        }
        return MessageFormat.format(pattern, new Object[] { b.toString() });
    } catch (ContentIOException cioe) {
        throw new URLRewriteException();
    }
}
Also used : ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) ArrayList(java.util.ArrayList) URLRewriteException(org.pentaho.reporting.engine.classic.core.modules.output.table.html.URLRewriteException) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException)

Aggregations

ArrayList (java.util.ArrayList)1 URLRewriteException (org.pentaho.reporting.engine.classic.core.modules.output.table.html.URLRewriteException)1 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)1 ContentLocation (org.pentaho.reporting.libraries.repository.ContentLocation)1