|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.pde.internal.core.text; |
| 12 |
|
| 13 |
import java.io.PrintWriter; |
| 14 |
import java.io.Writer; |
| 15 |
import org.eclipse.core.resources.*; |
| 16 |
import org.eclipse.core.runtime.Platform; |
| 17 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
| 18 |
import org.eclipse.core.runtime.preferences.IScopeContext; |
| 19 |
|
| 20 |
/** |
| 21 |
* A print writer that uses a line separator associated with a resource. |
| 22 |
* |
| 23 |
* @since 3.5 |
| 24 |
*/ |
| 25 |
public class ResourcePrintWriter extends PrintWriter { |
| 26 |
|
| 27 |
private String fLineSeparator = null; |
| 28 |
|
| 29 |
/** |
| 30 |
* Creates a writer that will print new lines based on the resource's |
| 31 |
* associated line separator property. |
| 32 |
* |
| 33 |
* @param out writer |
| 34 |
* @param resource to retrieve line separator property from |
| 35 |
*/ |
| 36 |
public ResourcePrintWriter(Writer out, IResource resource) { |
| 37 |
super(out); |
| 38 |
IProject project = resource.getProject(); |
| 39 |
if (project != null) { |
| 40 |
ProjectScope scope = new ProjectScope(project); |
| 41 |
IScopeContext[] scopeContext = new IScopeContext[] {scope}; |
| 42 |
IEclipsePreferences node = scopeContext[0].getNode(Platform.PI_RUNTIME); |
| 43 |
fLineSeparator = node.get(Platform.PREF_LINE_SEPARATOR, null); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/* (non-Javadoc) |
| 48 |
* @see java.io.PrintWriter#println() |
| 49 |
*/ |
| 50 |
public void println() { |
| 51 |
if (fLineSeparator == null) { |
| 52 |
super.println(); |
| 53 |
} else { |
| 54 |
write(fLineSeparator); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
} |