List of usage examples for org.springframework.util MethodInvoker setStaticMethod
public void setStaticMethod(String staticMethod)
From source file:org.dkpro.lab.Util.java
public static void createSymbolicLink(File aSource, File aTarget) throws IOException { if (aTarget.exists()) { throw new FileExistsException(aTarget); }/*from w w w .j a v a2s .co m*/ File parentDir = aTarget.getAbsoluteFile().getParentFile(); if (parentDir != null && !parentDir.exists()) { FileUtils.forceMkdir(parentDir); } // Try Java 7 methods try { Object fromPath = MethodUtils.invokeExactMethod(aSource, "toPath", new Object[0]); Object toPath = MethodUtils.invokeExactMethod(aTarget, "toPath", new Object[0]); Object options = Array.newInstance(Class.forName("java.nio.file.attribute.FileAttribute"), 0); MethodInvoker inv = new MethodInvoker(); inv.setStaticMethod("java.nio.file.Files.createSymbolicLink"); inv.setArguments(new Object[] { toPath, fromPath, options }); inv.prepare(); inv.invoke(); return; } catch (ClassNotFoundException e) { // Ignore } catch (NoSuchMethodException e) { // Ignore } catch (IllegalAccessException e) { // Ignore } catch (InvocationTargetException e) { if ("java.nio.file.FileAlreadyExistsException".equals(e.getTargetException().getClass().getName())) { throw new FileExistsException(aTarget); } } // If the Java 7 stuff is not available, fall back to Runtime.exec String[] cmdline = { "ln", "-s", aSource.getAbsolutePath(), aTarget.getAbsolutePath() }; Execute exe = new Execute(); exe.setVMLauncher(false); exe.setCommandline(cmdline); exe.execute(); if (exe.isFailure()) { throw new IOException("Unable to create symlink from [" + aSource + "] to [" + aTarget + "]"); } }
From source file:architecture.ee.web.view.freemarker.ExtendedTemplateLoader.java
@Override public Object findTemplateSource(String name) throws IOException { log.debug("searching... " + name + ", customized : " + isCustomizedEnabled()); if (isCustomizedEnabled()) { try {/*ww w . j a va 2s . c o m*/ MethodInvoker invoker = new MethodInvoker(); invoker.setStaticMethod("architecture.ee.web.struts2.util.ActionUtils.getAction"); invoker.prepare(); Object action = invoker.invoke(); if (action instanceof WebSiteAware) { WebSite site = ((WebSiteAware) action).getWebSite(); String nameToUse = SEP_IS_SLASH ? name : name.replace('/', File.separatorChar); if (nameToUse.charAt(0) == File.separatorChar) { nameToUse = File.separatorChar + "sites" + File.separatorChar + site.getName().toLowerCase() + nameToUse; } else { nameToUse = File.separatorChar + "sites" + File.separatorChar + site.getName().toLowerCase() + File.separatorChar + nameToUse; } log.debug((new StringBuilder()).append("website:").append(site.getName().toLowerCase()) .append(", template: ").append(nameToUse).toString()); File source = new File(baseDir, SEP_IS_SLASH ? name : name.replace('/', File.separatorChar)); return super.findTemplateSource(nameToUse); } } catch (Exception e) { log.warn(e); } } return null; /* if( usingDatabase() ){ try { MethodInvoker invoker = new MethodInvoker(); invoker.setStaticMethod("architecture.ee.web.struts2.util.ActionUtils.getAction"); invoker.prepare(); Object action = invoker.invoke(); if( action instanceof TemplateAware ){ Template template = ((TemplateAware)action).getTargetTemplate(); if( log.isDebugEnabled() ) log.debug( name + " < compare > template from action:" + template.getTitle() + ", type=" + template.getTemplateType() + ", locaion=" + template.getLocation()); if( "ftl".equals(template.getTemplateType()) && name.contains(template.getLocation() )) return template; } } catch (Exception e) { log.warn(e); } List<Template> contents = getCurrentCompanyTemplates(); for( Template template : contents){ if( log.isDebugEnabled() ) log.debug( name + "< compare > template from database :" + template.getTitle() + ", type:" + template.getTemplateType() + ", match:" + template.getLocation() .contains(name) ); if( template.getLocation() .contains(name)){ return template; } } } */ }