1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.binaryxml; 18 19 import com.android.SdkConstants; 20 import com.android.ide.eclipse.adt.AdtPlugin; 21 22 import org.eclipse.core.resources.IStorage; 23 import org.eclipse.core.runtime.IPath; 24 import org.eclipse.jdt.core.IPackageFragmentRoot; 25 import org.eclipse.jdt.internal.core.JarEntryFile; 26 import org.eclipse.jdt.internal.ui.javaeditor.JarEntryEditorInput; 27 import org.eclipse.ui.IEditorInput; 28 import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; 29 30 import java.io.File; 31 32 /** 33 * The XML editor is an editor that open Android xml files from the android.jar file 34 * <p> 35 * The editor checks if the file is contained in jar and is so, 36 * convert editor input to XmlStorageEditorInput that handles 37 * corresponding file from Android SDK. 38 * 39 */ 40 public class BinaryXMLMultiPageEditorPart extends XMLMultiPageEditorPart { 41 42 /* 43 * (non-Javadoc) 44 * 45 * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput) 46 */ 47 @Override 48 protected void setInput(IEditorInput input) { 49 if (input instanceof JarEntryEditorInput) { 50 JarEntryEditorInput jarInput = (JarEntryEditorInput) input; 51 IStorage storage = jarInput.getStorage(); 52 if (storage instanceof JarEntryFile) { 53 JarEntryFile jarEntryFile = (JarEntryFile) storage; 54 IPackageFragmentRoot fragmentRoot = jarEntryFile.getPackageFragmentRoot(); 55 if (fragmentRoot == null) { 56 super.setInput(input); 57 return; 58 } 59 IPath path = fragmentRoot.getPath(); 60 if (path == null) { 61 super.setInput(input); 62 return; 63 } 64 path = path.removeLastSegments(1); 65 IPath filePath = path.append(SdkConstants.FD_DATA).append( 66 jarEntryFile.getFullPath().toPortableString()); 67 File file = new File(filePath.toOSString()); 68 if (!(file.isFile())) { 69 super.setInput(input); 70 return; 71 } 72 try { 73 XmlStorageEditorInput newInput = new XmlStorageEditorInput( 74 new FileStorage(file)); 75 super.setInput(newInput); 76 return; 77 } catch (Exception e) { 78 AdtPlugin.log(e, e.getMessage(), null); 79 } 80 } 81 } 82 super.setInput(input); 83 } 84 85 } 86