public Template(TemplateService plugin, String path) { this(plugin, Path.parse(path)); }
@Override public Absolute as(String rawName, String ext) { return (Absolute)super.as(rawName, ext); } }
/** * Returns the path simple name: the raw name followed by the extension. * * @return the simple name */ public String getSimpleName() { String ext = getExt(); String rawName = getRawName(); if (ext != null) { return rawName + "." + ext; } else { return rawName; } }
/** * Resolve a path with respect to this name and return an absolute path. * * @param path the path * @return the corresponding absolute path */ public Path.Absolute resolve(Path path) { if (path instanceof Path.Absolute) { return (Path.Absolute)path; } else { return Path.absolute(append(path.getName()), path.getExt()); } }
if (userText != null && userText.length() > 0) { try { Path path = Path.parse(userText); if (path.isRelative()) { File from; String suffix; if (path.getExt() == null) { from = sourcePath.getPath(root, path.getName()); if (from == null) { from = sourcePath.getPath(root, path.getDirs()); suffix = path.getSimpleName(); } else { suffix = ""; from = sourcePath.getPath(root, path.getDirs()); suffix = path.getSimpleName();
private void assertPath(boolean absolute, String[] names, String name, String extension, Path test) { Assert.assertEquals(absolute, test.isAbsolute()); Iterable<String> qn = test.getDirs(); Assert.assertNotNull(qn); Assert.assertEquals(Arrays.asList(names), Tools.list(qn)); Assert.assertEquals(name, test.getRawName()); Assert.assertEquals(extension, test.getExt()); }
@Override public Path.Absolute resolveTemplate(Path path) { if (path.getCanonical().equals("index.gtmpl")) { return (Path.Absolute)Path.parse("/plugin/template/tag/decorate/templates/index.gtmpl"); } else { return null; } } });
public TemplatesDescriptor( ApplicationDescriptor application, ClassLoader loader, JSON config) throws Exception { ArrayList<BeanDescriptor> beans = new ArrayList<BeanDescriptor>(); List<TemplateDescriptor> templates = new ArrayList<TemplateDescriptor>(); // String packageName = config.getString("package"); Name pkg = Name.parse(packageName); // Load templates for (String fqn : config.getList("templates", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); TemplateDescriptor descriptor = (TemplateDescriptor)f.get(null); templates.add(descriptor); juzu.impl.common.Path.Absolute path = (juzu.impl.common.Path.Absolute)juzu.impl.common.Path.parse(descriptor.getPath()); Path qualifier; if (pkg.isPrefix(path.getName())) { juzu.impl.common.Path.Relative relativePath = juzu.impl.common.Path.relative(path.getName().subName(pkg.size()), path.getExt()); qualifier = new PathLiteral(relativePath.getCanonical()); } else { qualifier = new PathLiteral(path.getCanonical()); } beans.add(BeanDescriptor.createFromImpl(Template.class, null, Arrays.<Annotation>asList(qualifier), descriptor.getType())); } // this.templates = templates; this.pkg = pkg; this.beans = beans; }
public String getCanonical() { if (canonical == null) { StringBuilder sb = new StringBuilder(); if (isAbsolute()) { sb.append('/'); } for (int i = 0;i < name.size();i++) { if (i > 0) { sb.append('/'); } sb.append(name.get(i)); } String ext = getExt(); if (ext != null) { sb.append('.').append(ext); } canonical = sb.toString(); } return canonical; }
public final boolean isRelative() { return !isAbsolute(); }
@Override public String toString() { return "Path[" + getCanonical() + "]"; }
if (userText != null && userText.length() > 0) { try { Path path = Path.parse(userText); if (path.isRelative()) { File from; String suffix; if (path.getExt() == null) { from = sourcePath.getPath(root, path.getName()); if (from == null) { from = sourcePath.getPath(root, path.getDirs()); suffix = path.getSimpleName(); } else { suffix = ""; from = sourcePath.getPath(root, path.getDirs()); suffix = path.getSimpleName();
private void assertPath(boolean absolute, String[] names, String name, String extension, Path test) { Assert.assertEquals(absolute, test.isAbsolute()); Iterable<String> qn = test.getDirs(); Assert.assertNotNull(qn); Assert.assertEquals(Arrays.asList(names), Tools.list(qn)); Assert.assertEquals(name, test.getRawName()); Assert.assertEquals(extension, test.getExt()); }
@Test public void testAppendIAE() { assertPath(false, new String[]{}, "b", null, Path.parse("").append("b")); assertPath(false, new String[]{}, "b", "c", Path.parse("").append("b.c")); assertPath(false, new String[]{}, "b", null, Path.parse("").append("./b")); assertPath(false, new String[]{}, "c", null, Path.parse("a/b").append("../c")); assertPath(false, new String[]{}, "b", null, Path.parse("").append("a/../b")); assertPath(false, new String[]{}, "b", "c", Path.parse("").append("b.c")); assertPath(false, new String[]{"a"}, "c", null, Path.parse("a/b").append("c")); assertPath(false, new String[]{"a"}, "d", null, Path.parse("a/b.c").append("d")); }
@Override public Path.Absolute resolveTemplate(Path path) { if (path.getCanonical().equals("index.gtmpl")) { return (Path.Absolute)Path.parse("/plugin/template/tag/decorate/templates/index.gtmpl"); } else { return null; } } });
public TemplatesDescriptor( ApplicationDescriptor application, ClassLoader loader, JSON config) throws Exception { ArrayList<BeanDescriptor> beans = new ArrayList<BeanDescriptor>(); List<TemplateDescriptor> templates = new ArrayList<TemplateDescriptor>(); // String packageName = config.getString("package"); Name pkg = Name.parse(packageName); // Load templates for (String fqn : config.getList("templates", String.class)) { Class<?> clazz = loader.loadClass(fqn); Field f = clazz.getField("DESCRIPTOR"); TemplateDescriptor descriptor = (TemplateDescriptor)f.get(null); templates.add(descriptor); juzu.impl.common.Path.Absolute path = (juzu.impl.common.Path.Absolute)juzu.impl.common.Path.parse(descriptor.getPath()); Path qualifier; if (pkg.isPrefix(path.getName())) { juzu.impl.common.Path.Relative relativePath = juzu.impl.common.Path.relative(path.getName().subName(pkg.size()), path.getExt()); qualifier = new PathLiteral(relativePath.getCanonical()); } else { qualifier = new PathLiteral(path.getCanonical()); } beans.add(BeanDescriptor.createFromImpl(Template.class, null, Arrays.<Annotation>asList(qualifier), descriptor.getType())); } // this.templates = templates; this.pkg = pkg; this.beans = beans; }