inital plugin from webtools project
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.core / src / net / sourceforge / phpdt / monitor / core / internal / ContentFilter.java
1 /**********************************************************************
2  * Copyright (c) 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  **********************************************************************/
11 package net.sourceforge.phpdt.monitor.core.internal;
12
13 import java.io.IOException;
14
15 import net.sourceforge.phpdt.monitor.core.IContentFilter;
16 import net.sourceforge.phpdt.monitor.core.IContentFilterDelegate;
17 import net.sourceforge.phpdt.monitor.core.IRequest;
18
19 import org.eclipse.core.runtime.IConfigurationElement;
20 /**
21  * 
22  */
23 public class ContentFilter implements IContentFilter {
24         protected IConfigurationElement element;
25         protected IContentFilterDelegate delegate;
26         
27         protected ContentFilter(IConfigurationElement element) {
28                 this.element = element;
29         }
30
31         public String getId() {
32                 return element.getAttribute("id");
33         }
34         
35         public int getOrder() {
36                 try {
37                         return Integer.parseInt(element.getAttribute("order"));
38                 } catch (Exception e) {
39                         return 0;
40                 }
41         }
42
43         public String getName() {
44                 return element.getAttribute("name");
45         }
46
47         public byte[] filter(IRequest request, boolean isRequest, byte[] b) throws IOException {
48                 if (delegate == null) {
49                         try {
50                                 delegate = (IContentFilterDelegate) element.createExecutableExtension("class");
51                         } catch (Exception e) {
52                                 Trace.trace(Trace.SEVERE, "Could not create content filter delegate: " + getId(), e);
53                                 return new byte[0];
54                         }
55                 }
56                 return delegate.filter(request, isRequest, b);
57         }
58 }