1 23 package org.enhydra.kelp.common.deployer; 24 25 import org.enhydra.tool.common.ToolException; 27 import org.enhydra.tool.common.PathHandle; 28 import org.enhydra.tool.common.FileUtil; 29 30 import org.enhydra.kelp.common.AbstractEchoBuilder; 32 import org.enhydra.kelp.common.PathUtil; 33 import org.enhydra.kelp.common.event.WriteListener; 34 import org.enhydra.kelp.common.map.Mapper; 35 import org.enhydra.kelp.common.node.OtterImageFileNode; 36 import org.enhydra.kelp.common.node.OtterTextFileNode; 37 import org.enhydra.kelp.common.node.OtterDocumentNode; 38 import org.enhydra.kelp.common.node.OtterFileNode; 39 import org.enhydra.kelp.common.node.OtterNode; 40 import org.enhydra.kelp.common.node.OtterProject; 41 42 import java.io.File ; 44 import java.util.ArrayList ; 45 import java.util.Arrays ; 46 import java.util.ResourceBundle ; 47 48 public class ContentBuilder extends AbstractEchoBuilder { 50 static ResourceBundle res = 51 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); private Mapper mapper = null; 53 private PathHandle resourcePath = null; 54 private String copyingTo = res.getString("Copying_to"); 55 56 public ContentBuilder(WriteListener listener) { 57 super(listener); 58 } 59 60 protected void buildImpl() { 61 makeStaticDocuments(); 62 makeNonDocumentContent(); 63 makeDeploymentDesc(); 64 } 65 66 public void setProject(OtterProject p) { 67 super.setProject(p); 68 mapper = new Mapper(getProject()); 69 resourcePath = 70 PathHandle.createPathHandle(getProject().getDeployResourcePath()); 71 } 72 73 private void makeStaticDocuments() { 74 75 OtterDocumentNode[] docs = getProject().getAllDocuments(); 78 File source = null; 79 File dest = null; 80 String destPath = new String (); 81 82 for (int i = 0; i < docs.length; i++) { 83 if (docs[i].isStatic()) { 84 destPath = getResourceDestPath(docs[i]); 85 dest = new File (destPath); 86 source = new File (docs[i].getFilePath()); 87 try { 88 FileUtil.copy(source, dest); 89 echo(copyingTo + destPath); 90 } catch (ToolException e) { 91 echo(e); 92 e.printStackTrace(); 93 } 94 } 95 } 96 } 97 98 102 private void makeNonDocumentContent() { 103 104 String [] types = new String [0]; 107 OtterFileNode[] content = new OtterFileNode[0]; 108 PathHandle cursorPath = null; 109 110 types = getProject().getNonDocumentContentTypes(); 111 content = getProject().findFileNodesByType(types); 112 File source = null; 113 File dest = null; 114 String destPath = new String (); 115 116 for (int i = 0; i < content.length; i++) { 117 cursorPath = 118 PathHandle.createPathHandle(content[i].getFilePath()); 119 if (resourcePath.parentOf(cursorPath)) { 120 destPath = getResourceDestPath(content[i]); 121 dest = new File (destPath); 122 source = cursorPath.getFile(); 123 try { 124 FileUtil.copy(source, dest); 125 echo(copyingTo + destPath); 126 } catch (ToolException e) { 127 echo(e); 128 e.printStackTrace(); 129 } 130 } 131 } 132 } 133 134 private void makeDeploymentDesc() { 135 136 OtterTextFileNode[] descs = getProject().getAllDeploymentDescs(); 139 File source = null; 140 File dest = null; 141 String sourcePath = null; 142 String rawFile = null; 143 StringBuffer outPath = new StringBuffer (); 144 145 for (int i = 0; i < descs.length; i++) { 146 source = new File (descs[i].getFilePath()); 147 sourcePath = getProject().getSourcePathOf(descs[i]); 148 rawFile = (new File (descs[i].getFilePath())).getAbsolutePath(); 149 outPath.append(PathUtil.getDeployContentPath(getProject())); 150 outPath.append(rawFile.substring(sourcePath.length())); 151 dest = new File (outPath.toString()); 152 try { 153 FileUtil.copy(source, dest); 154 echo(copyingTo + PathHandle.createPathString(dest)); 155 } catch (ToolException e) { 156 echo(e); 157 e.printStackTrace(); 158 } 159 } 160 } 161 162 169 private String getResourceDestPath(OtterFileNode resource) { 170 StringBuffer destPath = new StringBuffer (); 171 PathHandle sourceFilePath = null; 172 int type = OtterProject.TYPE_WEBAPP; 173 174 type = getProject().getDeployType(); 175 sourceFilePath = PathHandle.createPathHandle(resource.getFilePath()); 176 if (type == OtterProject.TYPE_EN3APP) { 177 destPath.append(mapper.getMappedOutputPath(resource)); 178 } else { 179 String suffix = new String (); 180 181 destPath.append(PathUtil.getDeployContentPath(getProject())); 182 suffix = 183 sourceFilePath.getPath().substring(resourcePath.getPath().length()); 184 if ((suffix.length() == 0) || (suffix.charAt(0) != '/')) { 185 destPath.append('/'); 186 } 187 destPath.append(suffix); 188 } 189 return PathHandle.createPathString(destPath.toString()); 190 } 191 192 } 193 | Popular Tags |