Changeset 1992
- Timestamp:
- 03/11/08 11:20:56 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/builder/SELinuxSystem.java
r1991 r1992 531 531 IFile metadataFile = getProject ().getFile(mLayer.getProjectRelativePath().append("metadata.xml")); //$NON-NLS-1$ 532 532 533 String summary = "<summary> </summary>";533 String summary = "<summary>CDSFramework Policy Layer</summary>\n"; 534 534 InputStream stream = new ByteArrayInputStream (summary.getBytes()); //$NON-NLS-1$ 535 535 metadataFile.create(stream, true, null); … … 762 762 private IFile[] mModule; 763 763 764 public CPolicyContainer(String mod _postfix)765 { 766 CUSTOM_MODULE_NAME = "cds-custom " + mod_postfix;764 public CPolicyContainer(String module_postfix) 765 { 766 CUSTOM_MODULE_NAME = "cds-custom-" + module_postfix; 767 767 mModified = new HashMap (10); 768 768 } … … 794 794 InputStream stream = new ByteArrayInputStream (((String)array[i][1]).getBytes()); 795 795 mModule[i] = file; 796 mModule[i].create (stream, true, null); 797 mModule[i].refreshLocal (IResource.DEPTH_ZERO, null); 796 if( mModule[i].exists() ) 797 { 798 mModule[i].appendContents (stream, IResource.KEEP_HISTORY, null); 799 mModule[i].refreshLocal (IResource.DEPTH_ZERO, null); 800 } 801 else 802 { 803 mModule[i].create (stream, true, null); 804 mModule[i].refreshLocal (IResource.DEPTH_ZERO, null); 805 } 798 806 } 799 807 } branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/editor/custom/AddCustomPolicy.java
r1991 r1992 13 13 import java.io.OutputStream; 14 14 15 import org.eclipse.core.internal.resources.WorkspaceRoot;16 15 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IFolder;18 16 import org.eclipse.core.resources.IResource; 19 17 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IPath;21 import org.eclipse.core.runtime.Platform;22 18 import org.eclipse.gef.ui.actions.SelectionAction; 23 19 import org.eclipse.jface.dialogs.ErrorDialog; … … 27 23 import org.eclipse.swt.widgets.Shell; 28 24 import org.eclipse.ui.PartInitException; 29 import org.eclipse.ui.PlatformUI;30 25 import org.eclipse.ui.ide.IDE; 31 26 … … 43 38 import com.tresys.framework.plugin.editor.policy.graphic.parts.AccessEditPart; 44 39 import com.tresys.framework.plugin.editor.policy.graphic.parts.DomainEditPart; 40 import com.tresys.framework.plugin.editor.policy.graphic.parts.PolicyEditPart; 45 41 import com.tresys.framework.plugin.editor.policy.graphic.parts.ShapeEditPart; 46 42 import com.tresys.slide.plugin.editors.module.ModuleEditor; 47 //import com.tresys.slide.plugin.editors.module.ModuleEditorInput;48 //import com.tresys.slide.plugin.views.policyexplorer.PLayer;49 //import com.tresys.slide.plugin.views.policyexplorer.PModule;50 43 51 44 public class AddCustomPolicy … … 105 98 return; 106 99 107 /**108 * Get the selection, get policy of the selection109 * and get the file system resource for editor input.110 */111 OutputStream stream = getPolicy ();112 if( stream == null )113 {114 System.out.println ("AddCustomPolicy.run() --> No Policy Found");115 return;116 }117 118 119 100 try 120 101 { … … 130 111 if( files[CPolicyContainer.TE_FILE].exists () ) 131 112 { 113 /** 114 * Get the selection, get policy of the selection 115 * and get the file system resource for editor input. 116 */ 117 OutputStream stream = getPolicy (); 118 if( stream == null ) 119 { 120 System.out.println ("AddCustomPolicy.run() --> No Policy Found"); 121 return; 122 } 123 132 124 ByteArrayInputStream input = new ByteArrayInputStream(stream.toString ().getBytes ()); 133 files[ 0].appendContents (input, IResource.KEEP_HISTORY, null);125 files[CPolicyContainer.TE_FILE].appendContents (input, IResource.KEEP_HISTORY, null); 134 126 } 135 127 /** … … 150 142 private final boolean customizationAllowed(Object selected_item) 151 143 { 152 Linkage linkage = mEditor.getSystem ().getLinkage ();153 SELinuxPolicy policy = new SELinuxPolicy(linkage, null, null);154 155 144 boolean supports_customization = false; 156 145 157 if( selected_item instanceof ShapeEditPart)158 { 159 ShapeEditPart shape_part = (ShapeEditPart)selected_item;160 Object model = shape_part.getModel ();146 if( selected_item instanceof PolicyEditPart) 147 { 148 PolicyEditPart policy_part = (PolicyEditPart)selected_item; 149 Object model = policy_part.getModel (); 161 150 if( model instanceof Shape ) 162 151 { … … 164 153 Component comp = shape.getComponent (); 165 154 if( comp instanceof ICustomPolicy ) 166 supports_customization = ((ICustomPolicy)comp).supportsCustomPolicy (); 167 } 168 } 169 else if( selected_item instanceof DomainEditPart) 170 { 171 DomainEditPart part = (DomainEditPart)selected_item; 172 Object model = part.getModel (); 173 if( model instanceof Shape ) 174 { 175 Shape shape = (Shape)model; 176 Component comp = shape.getComponent (); 177 if( comp instanceof ICustomPolicy ) 178 supports_customization = ((ICustomPolicy)comp).supportsCustomPolicy (); 179 } 180 } 181 else if( selected_item instanceof AbstractConnectionEditPart ) 182 { 183 AbstractConnectionEditPart part = (AbstractConnectionEditPart)selected_item; 184 185 Object ab = ((AccessEditPart)selected_item).getModel (); 186 Object model = part.getModel (); 187 if( model instanceof Connection) 188 { 189 Connection con = (Connection)model; 190 GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 191 if( con instanceof ICustomPolicy ) 192 supports_customization = ((ICustomPolicy)con).supportsCustomPolicy (); 193 con.Accept (meta_visitor); 194 OutputStream p = policy.GetPolicy (); 195 print_debug (p); 196 } 197 } 198 return supports_customization; 199 } 200 201 202 private final Object getModel() 203 { 204 IStructuredSelection selection = (StructuredSelection)getSelection (); 205 Object selected_item = selection.getFirstElement (); 206 207 Linkage linkage = mEditor.getSystem ().getLinkage (); 208 SELinuxPolicy policy = new SELinuxPolicy(linkage, null, null); 209 210 if( selected_item instanceof ShapeEditPart) 211 { 212 ShapeEditPart shape_part = (ShapeEditPart)selected_item; 213 Object model = shape_part.getModel (); 155 { 156 ICustomPolicy customization = (ICustomPolicy)comp; 157 boolean can_be_customized = customization.supportsCustomPolicy (); 158 boolean modified = !customization.hasCustomization (); 159 supports_customization = (can_be_customized & modified); 160 } 161 } 214 162 } 215 163 else if( selected_item instanceof AbstractConnectionEditPart ) … … 220 168 { 221 169 Connection con = (Connection)model; 222 GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 223 } 224 } 225 return null; 226 } 227 228 void getPolicy(Object model) 229 { 170 if( con instanceof ICustomPolicy ) 171 { 172 ICustomPolicy customization = (ICustomPolicy)con; 173 boolean can_be_customized = customization.supportsCustomPolicy (); 174 boolean modified = !customization.hasCustomization (); 175 supports_customization = (can_be_customized & modified); 176 } 177 } 178 } 179 return supports_customization; 230 180 } 231 181 … … 238 188 SELinuxPolicy policy = new SELinuxPolicy(linkage, null, null); 239 189 240 if( selected_item instanceof ShapeEditPart)241 { 242 ShapeEditPart shape_part = (ShapeEditPart)selected_item;243 Object model = shape_part.getModel ();190 if( selected_item instanceof PolicyEditPart) 191 { 192 PolicyEditPart policy_part = (PolicyEditPart)selected_item; 193 Object model = policy_part.getModel (); 244 194 if( model instanceof Shape ) 245 195 { 246 196 Shape shape = (Shape)model; 247 shape.getComponent ().Accept (policy); 248 // generated policy 249 OutputStream p = policy.GetPolicy (); 250 System.out.println (p); 251 return p; 252 } 253 } 254 if( selected_item instanceof DomainEditPart) 255 { 256 DomainEditPart part = (DomainEditPart)selected_item; 257 258 Object model = part.getModel (); 259 if( model instanceof Shape ) 260 { 261 Shape shape = (Shape)model; 262 shape.getComponent ().Accept (policy); 263 // generated policy 264 OutputStream p = policy.GetPolicy (); 265 System.out.println (p); 266 return p; 267 } 268 } 269 270 if( selected_item instanceof AbstractConnectionEditPart ) 197 Component comp = shape.getComponent (); 198 if( comp instanceof ICustomPolicy) 199 { 200 ICustomPolicy customization = (ICustomPolicy)comp; 201 customization.markCustomized (); 202 comp.Accept (policy); 203 // generated policy 204 OutputStream p = policy.GetPolicy (); 205 return p; 206 } 207 } 208 } 209 else if( selected_item instanceof AbstractConnectionEditPart ) 271 210 { 272 211 AbstractConnectionEditPart part = (AbstractConnectionEditPart)selected_item; … … 275 214 { 276 215 Connection con = (Connection)model; 277 GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 278 con.Accept (meta_visitor); 279 280 // text policy 281 OutputStream p = policy.GetPolicy (); 282 System.out.println (p); 283 return p; 216 if( con instanceof ICustomPolicy) 217 { 218 ICustomPolicy customization = (ICustomPolicy)con; 219 customization.markCustomized (); 220 GraphicPolicyMetaVisitor meta_visitor = new GraphicPolicyMetaVisitor(policy); 221 con.Accept (meta_visitor); 222 // text policy 223 OutputStream p = policy.GetPolicy (); 224 return p; 225 } 284 226 } 285 227 }
