Skip to content

Commit

Permalink
exists implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Apr 28, 2016
1 parent e9f1427 commit 930d3b2
Showing 1 changed file with 28 additions and 12 deletions.
Expand Up @@ -61,18 +61,14 @@ public View getView(String viewId) throws Exception {
* Get collection (directory listing) as XML
*/
private InputStream getContentXML() throws Exception {
String yanelPath = getResourceConfigProperty("yanel-path");
StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
try {
if (yanelPath != null) {
if (yanelPath.startsWith("file:")) {
log.info("List children of actual file system directory '" + yanelPath + "' ...");
sb.append(getContentXMLOfFileSystemDirectory(yanelPath.substring(5)));
} else {
sb.append(getContentXMLOfYarepNode(yanelPath));
}
String yanelPath = getCollectionPath();
if (yanelPath.startsWith("file:")) {
log.info("List children of actual file system directory '" + yanelPath + "' ...");
sb.append(getContentXMLOfFileSystemDirectory(yanelPath.substring(5)));
} else {
sb.append(getContentXMLOfYarepNode(getPath()));
sb.append(getContentXMLOfYarepNode(yanelPath));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
Expand All @@ -81,6 +77,18 @@ private InputStream getContentXML() throws Exception {
return new java.io.StringBufferInputStream(sb.toString());
}

/**
*
*/
private String getCollectionPath() throws Exception {
String yanelPath = getResourceConfigProperty("yanel-path");
if (yanelPath != null) {
return yanelPath;
} else {
return getPath();
}
}

/**
* Get file system directory listing as XML
* @param path File system path (without 'file:' scheme/protocol)
Expand All @@ -105,6 +113,7 @@ private StringBuilder getContentXMLOfFileSystemDirectory(String path) throws Exc

// TODO: Make ordering/sorting configurable!
log.warn("TODO: Make order/sorting configurable!");
log.warn("DEBUG: Path: " + path);
File[] children = new File(path).listFiles();
Calendar calendar = Calendar.getInstance();
if (children != null) {
Expand Down Expand Up @@ -296,11 +305,18 @@ protected String[] getI18NCatalogueNames() throws Exception {
}

/**
*
* @see org.wyona.yanel.core.api.attributes.ViewableV2#exists()
*/
public boolean exists() throws Exception {
log.warn("Not implemented yet!");
return true;
String yanelPath = getCollectionPath();
if (yanelPath.startsWith("file:") && new File(yanelPath.substring(5)).isDirectory()) {
return true;
}
if (getRealm().getRepository().existsNode(yanelPath)) {
return true;
}
log.warn("No such collection '" + yanelPath + "'!");
return false;
}

/**
Expand Down

0 comments on commit 930d3b2

Please sign in to comment.