1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package org.openoffice.idesupport; 23 24 import java.io.File; 25 import java.util.ArrayList; 26 import org.openoffice.idesupport.zip.ParcelZipper; 27 28 import com.sun.star.script.framework.container.ScriptEntry; 29 30 public class ExtensionFinder implements MethodFinder { 31 32 private String[] extensions; 33 private String language; 34 ExtensionFinder(String language, String[] extensions)35 public ExtensionFinder(String language, String[] extensions) { 36 this.language = language; 37 this.extensions = extensions; 38 } 39 findMethods(File basedir)40 public ScriptEntry[] findMethods(File basedir) { 41 String parcelName; 42 ArrayList files = new ArrayList(10); 43 ScriptEntry[] empty = new ScriptEntry[0]; 44 45 if (basedir == null || basedir.exists() == false || 46 basedir.isDirectory() == false) 47 return empty; 48 49 parcelName = basedir.getName(); 50 if (parcelName.equals(ParcelZipper.CONTENTS_DIRNAME)) 51 parcelName = basedir.getParentFile().getName(); 52 53 findFiles(files, basedir, parcelName); 54 55 if (files.size() != 0) 56 return (ScriptEntry[])files.toArray(empty); 57 return empty; 58 } 59 findFiles(ArrayList list, File basedir, String parcelName)60 private void findFiles(ArrayList list, File basedir, String parcelName) { 61 File[] children = basedir.listFiles(); 62 File f; 63 64 for (int i = 0; i < children.length; i++) { 65 f = children[i]; 66 67 if (f.isDirectory()) 68 findFiles(list, f, parcelName); 69 else { 70 for (int j = 0; j < extensions.length; j++) { 71 if (f.getName().endsWith(extensions[j])) { 72 ScriptEntry entry = new ScriptEntry(language, 73 f.getName(), f.getName(), parcelName); 74 list.add(entry); 75 break; 76 } 77 } 78 } 79 } 80 } 81 } 82