View Javadoc
1   package org.kuali.common.devops.metadata.function;
2   
3   import static org.kuali.common.util.Encodings.UTF8;
4   import static org.kuali.common.util.base.Exceptions.illegalState;
5   import static org.kuali.common.util.base.Precondition.checkNotNull;
6   
7   import java.io.ByteArrayInputStream;
8   import java.io.IOException;
9   import java.util.Properties;
10  
11  import org.kuali.common.util.project.ProjectUtils;
12  import org.kuali.common.util.project.model.Project;
13  
14  import com.google.common.base.Function;
15  
16  public class ProjectFunction implements Function<String, Project> {
17  
18  	@Override
19  	public Project apply(String content) {
20  		checkNotNull(content, "content");
21  		Properties properties = getProperties(content);
22  		return ProjectUtils.getProject(properties);
23  	}
24  
25  	protected Properties getProperties(String content) {
26  		try {
27  			ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes(UTF8));
28  			Properties props = new Properties();
29  			props.load(in);
30  			return props;
31  		} catch (IOException e) {
32  			throw illegalState(e, "unexpected io error loading properties -> \n\n%s\n\n", content);
33  		}
34  	}
35  
36  }