2 * Copyright (c) 2002-2004 Widespace, OU 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
9 * Igor Malinin - initial contribution
11 * $Id: AbstractDocumentProvider.java,v 1.1 2004-09-02 18:28:03 jsurfer Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
16 import java.io.BufferedInputStream;
17 import java.io.IOException;
18 import java.io.InputStream;
20 import org.eclipse.jface.text.rules.IWhitespaceDetector;
22 import net.sourceforge.phpeclipse.ui.editor.I18NDocumentProvider;
28 * @author Igor Malinin
30 public abstract class AbstractDocumentProvider extends I18NDocumentProvider {
31 protected IWhitespaceDetector detector = new WhitespaceDetector();
34 * @see org.eclipse.ui.editors.text.IStorageDocumentProvider#getDefaultEncoding()
36 public String getDefaultEncoding() {
40 public String getDeclaredEncoding( InputStream in ) throws IOException {
41 if ( !in.markSupported() ) {
42 in = new BufferedInputStream( in, 512 );
46 String encoding = super.getDeclaredEncoding( in );
47 if ( encoding != null ) {
53 // check Prolog-Start <?xml
54 if ( !skipXMLDecl(in) ) {
70 if ( detector.isWhitespace((char) ch) ) {
74 if ( ch == '"' || ch == '\'' ) {
82 StringBuffer buf = new StringBuffer();
90 if ( ch == delimiter ) {
94 buf.append( (char) ch );
97 return buf.toString();
100 private boolean skipXMLDecl( InputStream in ) throws IOException {
129 private boolean skipEncoding( InputStream in ) throws IOException {
132 boolean whitespace = false;
139 if ( detector.isWhitespace((char) ch) ) {
145 if ( ch == '?' || ch == '<' ) {
160 if ( (ch = in.read()) == 'n' &&
161 (ch = in.read()) == 'c' &&
162 (ch = in.read()) == 'o' &&
163 (ch = in.read()) == 'd' &&
164 (ch = in.read()) == 'i' &&
165 (ch = in.read()) == 'n' &&
166 (ch = in.read()) == 'g' ) {
180 if ( detector.isWhitespace((char) ch) ) {