use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepository method addLocalizationFile.
@Override
public void addLocalizationFile(final String domainId, final String locale, final InputStream inputStream, final boolean overwrite) throws DomainStorageException {
if (logger.isDebugEnabled()) {
logger.debug("addLocalizationFile(" + domainId + ", " + locale + ", inputStream)");
}
if (null != inputStream) {
if (StringUtils.isEmpty(domainId) || StringUtils.isEmpty(locale)) {
throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
}
lock.writeLock().lock();
try {
// Check for duplicates
final RepositoryFile localeFile = metadataMapping.getLocaleFile(domainId, locale);
if (!overwrite && localeFile != null) {
throw new DomainStorageException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0009_LOCALE_ALREADY_EXISTS", domainId, locale), null);
}
final SimpleRepositoryFileData data = new SimpleRepositoryFileData(inputStream, DEFAULT_ENCODING, LOCALE_MIME_TYPE);
if (localeFile == null) {
final RepositoryFile newLocaleFile = createUniqueFile(domainId, locale, data);
metadataMapping.addLocale(domainId, locale, newLocaleFile);
} else {
repository.updateFile(localeFile, data, null);
}
// This invalidates any cached information
flushDomains();
} finally {
lock.writeLock().unlock();
}
}
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class ActionSequenceJCRHelper method getURL.
public String getURL(String filePath) {
RepositoryFile file = repository.getFile(filePath);
if (file == null || !file.getName().endsWith(".url")) {
// $NON-NLS-1$
return "";
}
SimpleRepositoryFileData data = null;
data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
StringWriter writer = new StringWriter();
try {
IOUtils.copy(data.getStream(), writer);
} catch (IOException e) {
// $NON-NLS-1$
return "";
}
String props = writer.toString();
// $NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(props, "\n");
while (tokenizer.hasMoreTokens()) {
String line = tokenizer.nextToken();
int pos = line.indexOf('=');
if (pos > 0) {
String propname = line.substring(0, pos);
String value = line.substring(pos + 1);
if ((value != null) && (value.length() > 0) && (value.charAt(value.length() - 1) == '\r')) {
value = value.substring(0, value.length() - 1);
}
if ("URL".equalsIgnoreCase(propname)) {
// $NON-NLS-1$
return value;
}
}
}
// No URL found
return "";
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class ActionSequenceJCRHelper method getLocaleText.
protected String getLocaleText(final String key, final RepositoryFile file) throws IOException {
if (file != null) {
SimpleRepositoryFileData data = null;
data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
Properties p = new Properties();
p.load(data.getStream());
String localeText = p.getProperty(key.substring(1));
if (localeText == null) {
localeText = p.getProperty(key);
}
if (localeText != null) {
return localeText;
}
}
return null;
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class ActionSequenceJCRHelper method getSolutionDocument.
public Document getSolutionDocument(final String documentPath, final RepositoryFilePermission actionOperation) {
RepositoryFile file = repository.getFile(documentPath);
Document document = null;
SimpleRepositoryFileData data = null;
if (file != null) {
data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
if (data != null) {
try {
document = XmlDom4JHelper.getDocFromStream(data.getStream());
} catch (Throwable t) {
logger.error(Messages.getInstance().getErrorString("ActionSequenceJCRHelper.ERROR_0017_INVALID_XML_DOCUMENT", documentPath), // $NON-NLS-1$
t);
return null;
}
} else {
logger.error(Messages.getInstance().getErrorString("ActionSequenceJCRHelper.ERROR_0019_NO_DATA_IN_FILE", // $NON-NLS-1$
file.getName()));
return null;
}
if ((document == null) && (file != null) && (data != null)) {
// the document exists but cannot be parsed
logger.error(Messages.getInstance().getErrorString("ActionSequenceJCRHelper.ERROR_0009_INVALID_DOCUMENT", // $NON-NLS-1$
documentPath));
return null;
}
localizeDoc(document, file);
}
return document;
}
use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.
the class SimpleRepositoryFileDataTest method testNoEncoding.
@Test
public void testNoEncoding() {
file = new SimpleRepositoryFileData(inputStreamSpy, "", MIME_TYPE);
assertNotNull(file.toString());
verify(inputStreamSpy).markSupported();
verify(inputStreamSpy).mark(Integer.MAX_VALUE);
try {
verify(inputStreamSpy, atLeastOnce()).read(any(byte[].class));
verify(inputStreamSpy).reset();
} catch (Exception e) {
fail("No exception should be thrown.");
}
}
Aggregations