@Override public String getName() { if (path != null) { return path.lastSegment(); } return null; }
@Override public String getPathAsString() { if (path != null) { return path.toString(); } return null; }
@Override public void setPathInfo(String parentPath, String name) { path = new Path(parentPath == null ? name : parentPath + '/' + name); }
@Override public DocumentRef getParentRef() { if (parentRef == null && path != null) { if (path.isAbsolute()) { Path parentPath = path.removeLastSegments(1); parentRef = new PathRef(parentPath.toString()); } // else keep parentRef null } return parentRef; }
@Override public Property resolvePath(Path path) throws PropertyNotFoundException { if (path.isAbsolute()) { return getRoot().resolvePath(path.makeRelative()); String[] segments = path.segments(); String segment = segments[i]; if (property.isScalar()) { throw new PropertyNotFoundException(path.toString(), "segment " + segment + " points to a scalar property"); int p = segment.lastIndexOf('['); if (p == -1) { throw new PropertyNotFoundException(path.toString(), "Parse error: no matching '[' was found"); property = property.get(segment); if (property == null) { throw new PropertyNotFoundException(path.toString(), "segment " + segment + " cannot be resolved");
protected Path collectPath(Path path) { String name = getName(); if (parent != null) { if (parent.isList()) { int i = ((ListProperty) parent).children.indexOf(this); name = name + '[' + i + ']'; } path = ((AbstractProperty) parent).collectPath(path); } return path.append(name); }
@Override public String generatePathSegment(String s) { return IdUtils.generateId(s, "-", true, getMaxSize()); }
protected static String escapeEntryPath(String path) { String zipEntryEncoding = Framework.getProperty(ZIP_ENTRY_ENCODING_PROPERTY); if (zipEntryEncoding != null && zipEntryEncoding.equals(ZIP_ENTRY_ENCODING_OPTIONS.ascii.toString())) { return StringUtils.toAscii(path, true); } return path; }
@Override public String generatePathSegment(String s) { if (s == null) { s = ""; } s = s.trim(); if (s.length() > getMaxSize()) { s = s.substring(0, getMaxSize()).trim(); } s = s.replace('/', '-'); s = s.replace('\\', '-'); if (stupidRegexp.matcher(s).matches()) { return IdUtils.generateStringId(); } return s; }
protected static void zip(Blob blob, ZipOutputStream out) throws IOException { String entry = getFileName(blob); InputStream in = blob.getStream(); try { ZipUtils._zip(entry, in, out); } finally { in.close(); } }
/** * Initializes the cache. * * @param maxSizeStr the maximum size of the cache (as a String) * @param maxCountStr the maximum number of files in the cache * @param minAgeStr the minimum age of a file in the cache to be eligible for removal (in seconds) * @param fileStorage the file storage mechanism to use to store and fetch files * @see SizeUtils#parseSizeInBytes(String) * @since 7.10-HF03, 8.1 */ public void initializeCache(String maxSizeStr, String maxCountStr, String minAgeStr, FileStorage fileStorage) throws IOException { cachedir = Framework.createTempFile("nxbincache.", ""); cachedir.delete(); cachedir.mkdir(); long maxSize = SizeUtils.parseSizeInBytes(maxSizeStr); long maxCount = Long.parseLong(maxCountStr); long minAge = Long.parseLong(minAgeStr); initializeCache(cachedir, maxSize, maxCount, minAge, fileStorage); log.info("Using binary cache directory: " + cachedir.getPath() + " size: " + maxSizeStr + " maxCount: " + maxCount + " minAge: " + minAge); // be sure FileTracker won't steal our files ! FileEventTracker.registerProtectedPath(cachedir.getAbsolutePath()); }
@Override public DocumentRef getParentRef() { if (path == null) { return null; } if (!path.isAbsolute()) { return null; } return new PathRef(path.removeLastSegments(1).toString()); }
@Override public String getPathAsString() { return path == null ? null : path.toString(); }
@Override public void setPathInfo(String parentPath, String name) { path = new Path(parentPath == null ? name : parentPath + '/' + name); ref = new PathRef(parentPath, name); }
@Override public String getName() { return path == null ? null : path.lastSegment(); }
protected static void zip(List<Blob> blobs, ZipOutputStream out) throws IOException { // use a set to avoid zipping entries with same names Collection<String> names = new HashSet<String>(); int cnt = 1; for (Blob blob : blobs) { String entry = getFileName(blob); if (!names.add(entry)) { entry = "renamed_" + (cnt++) + "_" + entry; } InputStream in = blob.getStream(); try { ZipUtils._zip(entry, in, out); } finally { in.close(); } } }
@Override public Property resolvePath(String path) throws PropertyNotFoundException { return resolvePath(new Path(path)); }
/** * Constructor to be used by clients. * <p> * A client constructed data model must contain at least the path and the type. */ public DocumentModelImpl(String parentPath, String name, String type) { this(type); String fullPath = parentPath == null ? name : parentPath + (parentPath.endsWith("/") ? "" : "/") + name; path = new Path(fullPath); ref = new PathRef(fullPath); if (getDocumentType() != null) { facets.addAll(getDocumentType().getFacets()); } schemas = computeSchemas(getDocumentType(), instanceFacets, false); schemasOrig = new HashSet<>(schemas); }