@Override public ExternalBinaryValue getBinaryValue( String id ) { try { File f = createFileForUrl(new URL(id)); return binaryFor(f); } catch (IOException | URISyntaxException e) { throw new DocumentStoreException(id, e); } }
@Override public ExternalBinaryValue getBinaryValue( String id ) { try { File f = createFileForUrl(new URL(id)); return binaryFor(f); } catch (IOException | URISyntaxException e) { throw new DocumentStoreException(id, e); } }
@Override public Map<Name, Property> getProperties( String id ) { File sidecarFile = sidecarFile(id); if (!sidecarFile.exists()) return NO_PROPERTIES; try { Document document = read(new FileInputStream(sidecarFile)); Map<Name, Property> results = new HashMap<Name, Property>(); translator.getProperties(document, results); return results; } catch (IOException e) { throw new DocumentStoreException(id, e); } }
@Override public Map<Name, Property> getProperties( String id ) { File sidecarFile = sidecarFile(id); if (!sidecarFile.exists()) return NO_PROPERTIES; try { Document document = read(new FileInputStream(sidecarFile)); Map<Name, Property> results = new HashMap<Name, Property>(); translator.getProperties(document, results); return results; } catch (IOException e) { throw new DocumentStoreException(id, e); } }
/** * Utility method for determining the node identifier for the supplied file. Subclasses may override this method to change the * format of the identifiers, but in that case should also override the {@link #fileFor(String)}, * {@link #isContentNode(String)}, and {@link #isRoot(String)} methods. * * @param file the file; may not be null * @return the node identifier; never null * @see #isRoot(String) * @see #isContentNode(String) * @see #fileFor(String) */ protected String idFor( File file ) { String path = file.getAbsolutePath(); if (!path.startsWith(directoryAbsolutePath)) { if (directory.getAbsolutePath().equals(path)) { // This is the root return DELIMITER; } String msg = JcrI18n.fileConnectorNodeIdentifierIsNotWithinScopeOfConnector.text(getSourceName(), directoryPath, path); throw new DocumentStoreException(path, msg); } String id = path.substring(directoryAbsolutePathLength); id = id.replaceAll(Pattern.quote(FILE_SEPARATOR), DELIMITER); assert id.startsWith(DELIMITER); return id; }
/** * Utility method for determining the node identifier for the supplied file. Subclasses may override this method to change the * format of the identifiers, but in that case should also override the {@link #fileFor(String)}, * {@link #isContentNode(String)}, and {@link #isRoot(String)} methods. * * @param file the file; may not be null * @return the node identifier; never null * @see #isRoot(String) * @see #isContentNode(String) * @see #fileFor(String) */ protected String idFor( File file ) { String path = file.getAbsolutePath(); if (!path.startsWith(directoryAbsolutePath)) { if (directory.getAbsolutePath().equals(path)) { // This is the root return DELIMITER; } String msg = JcrI18n.fileConnectorNodeIdentifierIsNotWithinScopeOfConnector.text(getSourceName(), directoryPath, path); throw new DocumentStoreException(path, msg); } String id = path.substring(directoryAbsolutePathLength); id = id.replaceAll(Pattern.quote(FILE_SEPARATOR), DELIMITER); assert id.startsWith(DELIMITER); return id; }
protected Map<Name, Property> load( String id, File propertiesFile ) { if (!propertiesFile.exists() || !propertiesFile.canRead()) return NO_PROPERTIES; try { String content = IoUtil.read(propertiesFile); Map<Name, Property> result = new HashMap<Name, Property>(); for (String line : StringUtil.splitLines(content)) { // Parse each line ... Property property = parse(line, result); if (property != null) { result.put(property.getName(), property); } } return result; } catch (Throwable e) { throw new DocumentStoreException(id, e); } }
@Override public void storeProperties( String id, Map<Name, Property> properties ) { File sidecarFile = sidecarFile(id); try { if (!sidecarFile.exists()) { if (properties.isEmpty()) return; sidecarFile.createNewFile(); } EditableDocument document = Schematic.newDocument(); for (Property property : properties.values()) { if (property == null) continue; translator.setProperty(document, property, null, null); } write(document, new FileOutputStream(sidecarFile)); } catch (IOException e) { throw new DocumentStoreException(id, e); } }
@Override public void storeProperties( String id, Map<Name, Property> properties ) { File sidecarFile = sidecarFile(id); try { if (!sidecarFile.exists()) { if (properties.isEmpty()) return; sidecarFile.createNewFile(); } EditableDocument document = Schematic.newDocument(); for (Property property : properties.values()) { if (property == null) continue; translator.setProperty(document, property, null, null); } write(document, new FileOutputStream(sidecarFile)); } catch (IOException e) { throw new DocumentStoreException(id, e); } }
@Override public void storeProperties( String id, Map<Name, Property> properties ) { String names = null; int count = 0; for (Map.Entry<Name, Property> entry : properties.entrySet()) { if (entry.getValue() != null) { String name = strings.create(entry.getKey()); if (names == null) names = name; else names = ", " + name; ++count; } } if (count == 0) return; String msg = null; if (count == 1) { msg = JcrI18n.couldNotStoreProperty.text(sourceName, id, names); } else { msg = JcrI18n.couldNotStoreProperties.text(sourceName, id, names); } throw new DocumentStoreException(id, msg); }
/** * Utility method to ensure that the file is writable by this connector. * * @param id the identifier of the node * @param file the file * @throws DocumentStoreException if the file is expected to be writable but is not or is excluded, or if the connector is * readonly */ protected void checkFileNotExcluded( String id, File file ) { if (isExcluded(file)) { String msg = JcrI18n.fileConnectorCannotStoreFileThatIsExcluded.text(getSourceName(), id, file.getAbsolutePath()); throw new DocumentStoreException(id, msg); } }
/** * Utility method to ensure that the file is writable by this connector. * * @param id the identifier of the node * @param file the file * @throws DocumentStoreException if the file is expected to be writable but is not or is excluded, or if the connector is * readonly */ protected void checkFileNotExcluded( String id, File file ) { if (isExcluded(file)) { String msg = JcrI18n.fileConnectorCannotStoreFileThatIsExcluded.text(getSourceName(), id, file.getAbsolutePath()); throw new DocumentStoreException(id, msg); } }
protected Map<Name, Property> load( String id, File propertiesFile ) { if (!propertiesFile.exists() || !propertiesFile.canRead()) return NO_PROPERTIES; try { String content = IoUtil.read(propertiesFile); Map<Name, Property> result = new HashMap<Name, Property>(); for (String line : StringUtil.splitLines(content)) { // Parse each line ... Property property = parse(line, result); if (property != null) { result.put(property.getName(), property); } } return result; } catch (Throwable e) { throw new DocumentStoreException(id, e); } }
@Override public void storeProperties( String id, Map<Name, Property> properties ) { String names = null; int count = 0; for (Map.Entry<Name, Property> entry : properties.entrySet()) { if (entry.getValue() != null) { String name = strings.create(entry.getKey()); if (names == null) names = name; else names = ", " + name; ++count; } } if (count == 0) return; String msg = null; if (count == 1) { msg = JcrI18n.couldNotStoreProperty.text(sourceName, id, names); } else { msg = JcrI18n.couldNotStoreProperties.text(sourceName, id, names); } throw new DocumentStoreException(id, msg); }
throw new DocumentStoreException(id, e);
throw new DocumentStoreException(id, e);
@Override public void updateProperties( String id, Map<Name, Property> properties ) { File sidecarFile = sidecarFile(id); try { EditableDocument document = null; if (!sidecarFile.exists()) { if (properties.isEmpty()) return; sidecarFile.createNewFile(); document = Schematic.newDocument(); } else { Document existing = read(new FileInputStream(sidecarFile)); document = Schematic.newDocument(existing); } for (Map.Entry<Name, Property> entry : properties.entrySet()) { Property property = entry.getValue(); if (property == null) { translator.removeProperty(document, entry.getKey(), null, null); } else { translator.setProperty(document, property, null, null); } } write(document, new FileOutputStream(sidecarFile)); } catch (IOException e) { throw new DocumentStoreException(id, e); } }
@Override public void updateProperties( String id, Map<Name, Property> properties ) { File sidecarFile = sidecarFile(id); try { EditableDocument document = null; if (!sidecarFile.exists()) { if (properties.isEmpty()) return; sidecarFile.createNewFile(); document = Schematic.newDocument(); } else { Document existing = read(new FileInputStream(sidecarFile)); document = Schematic.newDocument(existing); } for (Map.Entry<Name, Property> entry : properties.entrySet()) { Property property = entry.getValue(); if (property == null) { translator.removeProperty(document, entry.getKey(), null, null); } else { translator.setProperty(document, property, null, null); } } write(document, new FileOutputStream(sidecarFile)); } catch (IOException e) { throw new DocumentStoreException(id, e); } }
@Override public Document getChildren( PageKey pageKey ) { String id = pageKey.getParentId(); CallSpecification callSpec = new CallSpecification(id); PageableGitFunction function = pageableFunctions.get(callSpec.getFunctionName()); if (function == null) return null; try { // Set up the document writer ... PageWriter writer = newPageDocument(pageKey); // Now call the function ... return function.execute(repository, git, callSpec, writer, values, pageKey); } catch (Throwable e) { throw new DocumentStoreException(id, e); } }
String parentPath = parent.getAbsolutePath(); String msg = JcrI18n.fileConnectorCannotWriteToDirectory.text(getSourceName(), getClass(), parentPath); throw new DocumentStoreException(id, msg); throw new DocumentStoreException(id, e);