Skip to content

Commit

Permalink
Merge pull request #230 from shabanovd/develop
Browse files Browse the repository at this point in the history
code review
  • Loading branch information
dizzzz committed Jun 8, 2014
2 parents 23ed15d + dda2d68 commit 309f5cf
Show file tree
Hide file tree
Showing 50 changed files with 269 additions and 425 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ test/temp/
nbproject/build/
nbproject/private/
/target
build/intellij
eXist.iws
2 changes: 1 addition & 1 deletion eXist.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/extensions/fluent/src" isTestSource="false" />
Expand Down
6 changes: 2 additions & 4 deletions eXist.ipr
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@
</profile>
</annotationProcessing>
</component>
<component name="CopyrightManager" default="">
<module2copyright />
</component>
<component name="CopyrightManager" default="" />
<component name="DependenciesAnalyzeManager">
<option name="myForwardDirection" value="false" />
</component>
Expand Down Expand Up @@ -272,7 +270,7 @@
<component name="ProjectResources">
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/intellij" />
</component>
<component name="ResourceManagerContainer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package org.exist.indexing.ngram;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand Down Expand Up @@ -82,6 +81,8 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
*
* Each index entry maps a key (collectionId, ngram) to a list of occurrences, which has the
Expand Down Expand Up @@ -957,13 +958,8 @@ public SearchCallback(int contextId, String query, String ngram, DocumentSet doc

@Override
public boolean indexInfo(Value key, long pointer) throws TerminatedException {
String ngram;
try {
ngram = new String(key.getData(), NGramQNameKey.NGRAM_OFFSET, key.getLength() - NGramQNameKey.NGRAM_OFFSET, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOG.error(e.getMessage(), e);
return true;
}
String ngram = new String(key.getData(), NGramQNameKey.NGRAM_OFFSET, key.getLength() - NGramQNameKey.NGRAM_OFFSET, UTF_8);

VariableByteInput is;
try {
is = index.db.getAsStream(pointer);
Expand Down Expand Up @@ -1054,13 +1050,8 @@ private final class IndexScanCallback implements BTreeCallback {
*/
@Override
public boolean indexInfo(Value key, long pointer) throws TerminatedException {
String term;
try {
term = new String(key.getData(), NGramQNameKey.NGRAM_OFFSET, key.getLength() - NGramQNameKey.NGRAM_OFFSET, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOG.error(e.getMessage(), e);
return true;
}
String term = new String(key.getData(), NGramQNameKey.NGRAM_OFFSET, key.getLength() - NGramQNameKey.NGRAM_OFFSET, UTF_8);

VariableByteInput is;
try {
is = index.db.getAsStream(pointer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

import java.util.Properties;

import static java.nio.charset.StandardCharsets.UTF_8;


/**
* Performs HTTP Put method
Expand Down Expand Up @@ -110,15 +112,10 @@ public Sequence eval( Sequence[] args, Sequence contextSequence ) throws XPathEx

if( Type.subTypeOf( payload.getType(), Type.NODE ) ) {
//serialize the node to SAX
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = null;

try {
osw = new OutputStreamWriter( baos, "UTF-8" );
}
catch( UnsupportedEncodingException e ) {
throw( new XPathException( this, "Internal error" ) );
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();

OutputStreamWriter osw = new OutputStreamWriter( baos, UTF_8 );

IndentingXMLWriter xmlWriter = new IndentingXMLWriter( osw );
Properties outputProperties = new Properties();
outputProperties.setProperty(OutputKeys.ENCODING, "UTF-8");
Expand All @@ -145,7 +142,7 @@ public Sequence eval( Sequence[] args, Sequence contextSequence ) throws XPathEx

} else if( Type.subTypeOf( payload.getType(), Type.BASE64_BINARY ) ) {

entity = new ByteArrayRequestEntity((byte[]) ((BinaryValue)payload).toJavaObject(byte[].class));
entity = new ByteArrayRequestEntity(payload.toJavaObject(byte[].class));

} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import org.exist.config.Configuration;
import org.exist.config.Configurator;
Expand Down Expand Up @@ -57,7 +58,7 @@ public class ActiveDirectoryRealmTest {
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
InputStream is = new ByteArrayInputStream(config.getBytes("UTF-8"));
InputStream is = new ByteArrayInputStream(config.getBytes(StandardCharsets.UTF_8));

Configuration config = Configurator.parse(is);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.junit.BeforeClass;
import org.junit.Test;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
*
Expand All @@ -55,7 +57,7 @@ public class LDAPRealmTest {
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
InputStream is = new ByteArrayInputStream(config.getBytes("UTF-8"));
InputStream is = new ByteArrayInputStream(config.getBytes(UTF_8));

Configuration config = Configurator.parse(is);

Expand Down
4 changes: 3 additions & 1 deletion samples/src/org/exist/examples/http/PostExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.exist.Namespaces;
import org.exist.xmldb.XmldbURI;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* PostExample
* Execute: bin\run.bat org.exist.examples.http.PostExample
Expand Down Expand Up @@ -69,7 +71,7 @@ private void doPost(String request) throws IOException {
connect.setDoOutput(true);

OutputStream os = connect.getOutputStream();
os.write(request.getBytes("UTF-8"));
os.write(request.getBytes(UTF_8));
connect.connect();

BufferedReader is = new BufferedReader(new InputStreamReader(connect.getInputStream()));
Expand Down
10 changes: 3 additions & 7 deletions samples/src/org/exist/examples/soap/QueryExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.exist.soap.*;
import java.io.*;

import static java.nio.charset.StandardCharsets.UTF_8;

public class QueryExample {

/**
Expand Down Expand Up @@ -53,13 +55,7 @@ public static void main( String[] args ) throws Exception {

// we send the data in base64 encoding to avoid
// difficulties with XML special chars in the query.
byte[] queryData;
try {
queryData = xquery.getBytes("UTF-8");
} catch(UnsupportedEncodingException e) {
// should never happen
queryData = xquery.getBytes();
}
byte[] queryData = xquery.getBytes(UTF_8);

QueryService service = new QueryServiceLocator();
Query query = service.getQuery();
Expand Down
4 changes: 3 additions & 1 deletion samples/src/org/exist/examples/soap/XUpdateExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.exist.xmldb.XmldbURI;
import org.exist.xupdate.XUpdateProcessor;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* Execute xupdate via SOAP. First create /db/test collection in database.
*
Expand Down Expand Up @@ -61,7 +63,7 @@ public static void main( String[] args ) throws Exception {
Query query = queryService.getQuery();

String session = admin.connect("guest", "guest");
admin.store(session, document.getBytes("UTF-8"), "UTF-8", XmldbURI.ROOT_COLLECTION + "/test/notes.xml", true);
admin.store(session, document.getBytes(UTF_8), "UTF-8", XmldbURI.ROOT_COLLECTION + "/test/notes.xml", true);
admin.xupdateResource(session, XmldbURI.ROOT_COLLECTION + "/test/notes.xml", xupdate);

String data = query.getResource(session,
Expand Down
10 changes: 2 additions & 8 deletions src/org/exist/ant/XMLDBExtractTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
import org.exist.xmldb.ExtendedResource;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

import java.util.Properties;
Expand Down Expand Up @@ -233,11 +231,9 @@ private void extractSubCollections( Collection base, String path ) throws XMLDBE
* @param dest DOCUMENT ME!
*
* @throws XMLDBException DOCUMENT ME!
* @throws FileNotFoundException DOCUMENT ME!
* @throws UnsupportedEncodingException DOCUMENT ME!
* @throws IOException DOCUMENT ME!
*/
private void writeResource( Resource res, File dest ) throws XMLDBException, FileNotFoundException, UnsupportedEncodingException, IOException
private void writeResource( Resource res, File dest ) throws XMLDBException, IOException
{
if( res instanceof XMLResource ) {
writeXMLResource( (XMLResource)res, dest );
Expand Down Expand Up @@ -313,11 +309,9 @@ private void writeXMLResource( XMLResource res, File dest ) throws IOException,
* @param dest DOCUMENT ME!
*
* @throws XMLDBException DOCUMENT ME!
* @throws FileNotFoundException DOCUMENT ME!
* @throws UnsupportedEncodingException DOCUMENT ME!
* @throws IOException DOCUMENT ME!
*/
private void writeBinaryResource( Resource res, File dest ) throws XMLDBException, FileNotFoundException, UnsupportedEncodingException, IOException
private void writeBinaryResource( Resource res, File dest ) throws XMLDBException, IOException
{
if( createdirectories == true ) {
final File parentDir = new File( dest.getParent() );
Expand Down
7 changes: 3 additions & 4 deletions src/org/exist/backup/ExportGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import java.util.List;

Expand All @@ -46,6 +45,8 @@
import javax.swing.filechooser.FileFilter;
import org.exist.security.PermissionDeniedException;

import static java.nio.charset.StandardCharsets.UTF_8;


/**
* DOCUMENT ME!
Expand Down Expand Up @@ -612,9 +613,7 @@ private void openLog( String dir )
try {
final File file = SystemExport.getUniqueFile( "report", ".log", dir );
final OutputStream os = new BufferedOutputStream( new FileOutputStream( file ) );
logWriter = new PrintWriter( new OutputStreamWriter( os, "UTF-8" ) );
}
catch( final UnsupportedEncodingException e ) {
logWriter = new PrintWriter( new OutputStreamWriter( os, UTF_8 ) );
}
catch( final FileNotFoundException e ) {
System.err.println( "ERROR: failed to create log file" );
Expand Down
7 changes: 3 additions & 4 deletions src/org/exist/client/InteractiveClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.io.PrintStream;
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -126,6 +125,8 @@
import org.xmldb.api.modules.XPathQueryService;
import org.xmldb.api.modules.XUpdateQueryService;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* Command-line client based on the XML:DB API.
*
Expand Down Expand Up @@ -2101,11 +2102,9 @@ protected CommandlineOptions getCommandlineOptions(final String args[], final Pr
final String traceFile = option.getArgument();
final File f = new File(traceFile);
try {
traceWriter = new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");
traceWriter = new OutputStreamWriter(new FileOutputStream(f, false), UTF_8);
traceWriter.write("<?xml version=\"1.0\"?>" + EOL);
traceWriter.write("<query-log>" + EOL);
} catch (final UnsupportedEncodingException e1) {
LOG.warn(e1);
} catch (final FileNotFoundException e1) {
errorln("Cannot open file " + traceFile);
return null;
Expand Down
9 changes: 3 additions & 6 deletions src/org/exist/config/Configurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -80,6 +79,8 @@
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* This class handle all configuration needs: extracting and saving,
* reconfiguring & etc.
Expand Down Expand Up @@ -1122,14 +1123,10 @@ public static Configuration parse(final Configurable instance, final DBBroker br
if (data == null || data.length() == 0) {
return null;
}
return parse(new ByteArrayInputStream(data.getBytes("UTF-8")));
return parse(new ByteArrayInputStream(data.getBytes(UTF_8)));

} catch (final SAXException saxe) {
throw new ConfigurationException(saxe.getMessage(), saxe);

} catch (final UnsupportedEncodingException uee) {
LOG.warn(uee.getMessage());
return null;
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/org/exist/dom/AttrImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.w3c.dom.TypeInfo;
import org.w3c.dom.UserDataHandler;

import java.io.UnsupportedEncodingException;
import static java.nio.charset.StandardCharsets.UTF_8;

public class AttrImpl extends NamedNode implements Attr {

Expand Down Expand Up @@ -201,13 +201,8 @@ public static void addToList(DBBroker broker, byte[] data, int start, int len, A
pos += prefixLen;
}
final String namespace = nsId == 0 ? "" : broker.getBrokerPool().getSymbols().getNamespace(nsId);
String value;
try {
value = new String( data, pos, len - (pos - start), "UTF-8" );
} catch (final UnsupportedEncodingException uee) {
LOG.warn(uee);
value = new String( data, pos, len - (pos - start));
}
String value = new String( data, pos, len - (pos - start), UTF_8 );

list.addAttribute(broker.getBrokerPool().getSymbols().getQName(Node.ATTRIBUTE_NODE, namespace, name, prefix), value, attrType, dln);
}

Expand Down
Loading

0 comments on commit 309f5cf

Please sign in to comment.