KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > cli > DeployUtils


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.deployment.cli;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.StringReader JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.List JavaDoc;
26 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
27 import org.apache.geronimo.common.DeploymentException;
28 import org.apache.geronimo.deployment.plugin.ConfigIDExtractor;
29 import org.apache.geronimo.kernel.repository.Artifact;
30
31 /**
32  * Various helpers for deployment.
33  *
34  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
35  */

36 public class DeployUtils extends ConfigIDExtractor {
37     /**
38      * Split up an output line so it indents at beginning and end (to fit in a
39      * typical terminal) and doesn't break in the middle of a word.
40      * @param source The unformatted String
41      * @param indent The number of characters to indent on the left
42      * @param endCol The maximum width of the entire line in characters,
43      * including indent (indent 10 with endCol 70 results
44      * in 60 "usable" characters).
45      */

46     public static String JavaDoc reformat(String JavaDoc source, int indent, int endCol) {
47         if(endCol-indent < 10) {
48             throw new IllegalArgumentException JavaDoc("This is ridiculous!");
49         }
50         StringBuffer JavaDoc buf = new StringBuffer JavaDoc((int)(source.length()*1.1));
51         String JavaDoc prefix = indent == 0 ? "" : buildIndent(indent);
52         try {
53             BufferedReader JavaDoc in = new BufferedReader JavaDoc(new StringReader JavaDoc(source));
54             String JavaDoc line;
55             int pos;
56             while((line = in.readLine()) != null) {
57                 if(buf.length() > 0) {
58                     buf.append('\n');
59                 }
60                 while(line.length() > 0) {
61                     line = prefix + line;
62                     if(line.length() > endCol) {
63                         pos = line.lastIndexOf(' ', endCol);
64                         if(pos < indent) {
65                             pos = line.indexOf(' ', endCol);
66                             if(pos < indent) {
67                                 pos = line.length();
68                             }
69                         }
70                         buf.append(line.substring(0, pos)).append('\n');
71                         if(pos < line.length()-1) {
72                             line = line.substring(pos+1);
73                         } else {
74                             break;
75                         }
76                     } else {
77                         buf.append(line).append("\n");
78                         break;
79                     }
80                 }
81             }
82         } catch (IOException JavaDoc e) {
83             throw new AssertionError JavaDoc("This should be impossible");
84         }
85         return buf.toString();
86     }
87
88     private static String JavaDoc buildIndent(int indent) {
89         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(indent);
90         for(int i=0; i<indent; i++) {
91             buf.append(' ');
92         }
93         return buf.toString();
94     }
95
96
97 }
98
Popular Tags