Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:BaseXdb/basex into webdav

Conflicts:
	src/main/java/org/basex/query/util/Err.java
	src/main/java/org/basex/server/Session.java
  • Loading branch information...
commit 9063e7f3d4884107bc85f5f53e0c403121e56f54 2 parents a2b05b7 + ff8ed14
dimitarp authored
Showing with 1,749 additions and 1,329 deletions.
  1. +1 −0  .classpath
  2. +6 −0 .project
  3. +3 −0  .settings/dict
  4. +3 −3 src/main/java/org/basex/BaseXServer.java
  5. +2 −1  src/main/java/org/basex/api/jaxp/BXDocBuilder.java
  6. +24 −26 src/main/java/org/basex/build/{xml → }/DirParser.java
  7. +1 −1  src/main/java/org/basex/build/DiskBuilder.java
  8. +2 −2 src/main/java/org/basex/build/MemBuilder.java
  9. +48 −52 src/main/java/org/basex/build/Parser.java
  10. +7 −7 src/main/java/org/basex/build/{FileParser.java → SingleParser.java}
  11. +24 −0 src/main/java/org/basex/build/TargetParser.java
  12. +3 −4 src/main/java/org/basex/build/file/CSVParser.java
  13. +7 −5 src/main/java/org/basex/build/file/HTMLParser.java
  14. +3 −4 src/main/java/org/basex/build/file/MAB2Parser.java
  15. +1 −1  src/main/java/org/basex/build/{ → file}/ParserProp.java
  16. +3 −4 src/main/java/org/basex/build/file/TextParser.java
  17. +7 −7 src/main/java/org/basex/build/xml/{CatalogResolverWrapper.java → CatalogWrapper.java}
  18. +5 −7 src/main/java/org/basex/build/xml/{DOCWrapper.java → DOMWrapper.java}
  19. +43 −51 src/main/java/org/basex/build/xml/SAXWrapper.java
  20. +11 −11 src/main/java/org/basex/build/xml/XMLParser.java
  21. +5 −5 src/main/java/org/basex/core/Context.java
  22. +2 −2 src/main/java/org/basex/core/Events.java
  23. +2 −2 src/main/java/org/basex/core/cmd/ACreate.java
  24. +7 −10 src/main/java/org/basex/core/cmd/Add.java
  25. +1 −1  src/main/java/org/basex/core/cmd/Create.java
  26. +17 −17 src/main/java/org/basex/core/cmd/CreateDB.java
  27. +2 −2 src/main/java/org/basex/core/cmd/DropUser.java
  28. +1 −1  src/main/java/org/basex/core/cmd/Find.java
  29. +1 −1  src/main/java/org/basex/core/cmd/OptimizeAll.java
  30. +3 −4 src/main/java/org/basex/core/cmd/Replace.java
  31. +1 −1  src/main/java/org/basex/data/Serializer.java
  32. +4 −4 src/main/java/org/basex/gui/dialog/DialogParsing.java
  33. +1 −1  src/main/java/org/basex/gui/dialog/DialogPass.java
  34. +1 −2  src/main/java/org/basex/gui/layout/BaseXEditor.java
  35. +2 −2 src/main/java/org/basex/gui/layout/XQuerySyntax.java
  36. +20 −5 src/main/java/org/basex/gui/view/editor/EditorArea.java
  37. +9 −10 src/main/java/org/basex/gui/view/editor/EditorView.java
  38. +18 −15 src/main/java/org/basex/io/BufferInput.java
  39. +30 −28 src/main/java/org/basex/io/IO.java
  40. +2 −9 src/main/java/org/basex/io/IOContent.java
  41. +17 −8 src/main/java/org/basex/io/IOFile.java
  42. +10 −8 src/main/java/org/basex/io/IOUrl.java
  43. +2 −2 src/main/java/org/basex/io/WrapInputStream.java
  44. +1 −1  src/main/java/org/basex/query/QueryContext.java
  45. +1 −1  src/main/java/org/basex/query/QueryException.java
  46. +3 −3 src/main/java/org/basex/query/QueryParser.java
  47. +1 −1  src/main/java/org/basex/query/QueryProcessor.java
  48. +1 −1  src/main/java/org/basex/query/QueryResources.java
  49. +569 −1 src/main/java/org/basex/query/QueryText.java
  50. +0 −573 src/main/java/org/basex/query/QueryTokens.java
  51. +0 −1  src/main/java/org/basex/query/expr/And.java
  52. +1 −1  src/main/java/org/basex/query/expr/Arith.java
  53. +3 −3 src/main/java/org/basex/query/expr/CAttr.java
  54. +2 −2 src/main/java/org/basex/query/expr/CComm.java
  55. +2 −2 src/main/java/org/basex/query/expr/CDoc.java
  56. +3 −3 src/main/java/org/basex/query/expr/CElem.java
  57. +1 −1  src/main/java/org/basex/query/expr/CFrag.java
  58. +2 −2 src/main/java/org/basex/query/expr/CPI.java
  59. +2 −2 src/main/java/org/basex/query/expr/CTxt.java
  60. +1 −1  src/main/java/org/basex/query/expr/Cast.java
  61. +1 −1  src/main/java/org/basex/query/expr/Castable.java
  62. +1 −1  src/main/java/org/basex/query/expr/Catch.java
  63. +0 −1  src/main/java/org/basex/query/expr/CmpG.java
  64. +1 −1  src/main/java/org/basex/query/expr/CmpN.java
  65. +0 −1  src/main/java/org/basex/query/expr/CmpR.java
  66. +1 −2  src/main/java/org/basex/query/expr/CmpV.java
  67. +1 −1  src/main/java/org/basex/query/expr/Constr.java
  68. +1 −1  src/main/java/org/basex/query/expr/Extension.java
  69. +1 −1  src/main/java/org/basex/query/expr/For.java
  70. +0 −1  src/main/java/org/basex/query/expr/GFLWOR.java
  71. +1 −1  src/main/java/org/basex/query/expr/Group.java
  72. +0 −1  src/main/java/org/basex/query/expr/If.java
  73. +1 −1  src/main/java/org/basex/query/expr/IndexAccess.java
  74. +1 −1  src/main/java/org/basex/query/expr/InlineFunc.java
  75. +1 −1  src/main/java/org/basex/query/expr/Instance.java
  76. +1 −1  src/main/java/org/basex/query/expr/Let.java
  77. +1 −1  src/main/java/org/basex/query/expr/List.java
  78. +2 −2 src/main/java/org/basex/query/expr/LitMap.java
  79. +0 −1  src/main/java/org/basex/query/expr/Or.java
  80. +1 −1  src/main/java/org/basex/query/expr/Order.java
  81. +1 −1  src/main/java/org/basex/query/expr/OrderByExpr.java
  82. +1 −1  src/main/java/org/basex/query/expr/OrderByStable.java
  83. +14 −1 src/main/java/org/basex/query/expr/ParseExpr.java
  84. +1 −1  src/main/java/org/basex/query/expr/PartFunApp.java
  85. +1 −1  src/main/java/org/basex/query/expr/Pos.java
  86. +1 −1  src/main/java/org/basex/query/expr/Pragma.java
  87. +1 −1  src/main/java/org/basex/query/expr/Quantifier.java
  88. +3 −3 src/main/java/org/basex/query/expr/Range.java
  89. +1 −1  src/main/java/org/basex/query/expr/RangeAccess.java
  90. +1 −1  src/main/java/org/basex/query/expr/Set.java
  91. +1 −1  src/main/java/org/basex/query/expr/Switch.java
  92. +1 −1  src/main/java/org/basex/query/expr/Treat.java
  93. +1 −1  src/main/java/org/basex/query/expr/TypeCase.java
  94. +1 −1  src/main/java/org/basex/query/expr/TypeSwitch.java
  95. +1 −1  src/main/java/org/basex/query/expr/Unary.java
  96. +0 −1  src/main/java/org/basex/query/expr/UserFunc.java
  97. +0 −1  src/main/java/org/basex/query/expr/UserFuncCall.java
  98. +1 −1  src/main/java/org/basex/query/expr/VarRef.java
  99. +1 −1  src/main/java/org/basex/query/ft/FTAnd.java
  100. +0 −1  src/main/java/org/basex/query/ft/FTContains.java
  101. +1 −1  src/main/java/org/basex/query/ft/FTContainsIndex.java
  102. +1 −1  src/main/java/org/basex/query/ft/FTContent.java
  103. +4 −4 src/main/java/org/basex/query/ft/FTDistance.java
  104. +1 −1  src/main/java/org/basex/query/ft/FTExtensionSelection.java
  105. +1 −1  src/main/java/org/basex/query/ft/FTIndexAccess.java
  106. +1 −1  src/main/java/org/basex/query/ft/FTMildNot.java
  107. +1 −1  src/main/java/org/basex/query/ft/FTNot.java
  108. +1 −1  src/main/java/org/basex/query/ft/FTOr.java
  109. +3 −3 src/main/java/org/basex/query/ft/FTOrder.java
  110. +1 −1  src/main/java/org/basex/query/ft/FTScope.java
  111. +2 −2 src/main/java/org/basex/query/ft/FTWeight.java
  112. +3 −3 src/main/java/org/basex/query/ft/FTWindow.java
  113. +1 −1  src/main/java/org/basex/query/ft/FTWords.java
  114. +23 −14 src/main/java/org/basex/query/func/FNGen.java
  115. +1 −1  src/main/java/org/basex/query/func/FNId.java
  116. +1 −1  src/main/java/org/basex/query/func/FNIndex.java
  117. +0 −13 src/main/java/org/basex/query/func/FNMap.java
  118. +2 −2 src/main/java/org/basex/query/func/FNNode.java
  119. +1 −1  src/main/java/org/basex/query/func/FNPat.java
  120. +1 −1  src/main/java/org/basex/query/func/FNQName.java
  121. +23 −22 src/main/java/org/basex/query/func/FNUtil.java
  122. +148 −0 src/main/java/org/basex/query/func/FNXslt.java
  123. +5 −2 src/main/java/org/basex/query/func/FNZip.java
  124. +1 −1  src/main/java/org/basex/query/func/FuncCall.java
  125. +8 −1 src/main/java/org/basex/query/func/Function.java
  126. +1 −1  src/main/java/org/basex/query/func/JavaFunc.java
  127. +16 −10 src/main/java/org/basex/query/func/{VarDef.java → Variable.java}
  128. +1 −1  src/main/java/org/basex/query/item/AtomType.java
  129. +1 −1  src/main/java/org/basex/query/item/DBNode.java
  130. +1 −1  src/main/java/org/basex/query/item/DBNodeSeq.java
  131. +1 −1  src/main/java/org/basex/query/item/Empty.java
  132. +1 −1  src/main/java/org/basex/query/item/FAttr.java
  133. +1 −1  src/main/java/org/basex/query/item/FDoc.java
  134. +1 −1  src/main/java/org/basex/query/item/FElem.java
  135. +1 −1  src/main/java/org/basex/query/item/FPI.java
  136. +5 −5 src/main/java/org/basex/query/item/FTxt.java
  137. +1 −1  src/main/java/org/basex/query/item/FuncItem.java
  138. +1 −1  src/main/java/org/basex/query/item/FuncType.java
  139. +1 −1  src/main/java/org/basex/query/item/Item.java
  140. +1 −1  src/main/java/org/basex/query/item/ItemSeq.java
  141. +1 −1  src/main/java/org/basex/query/item/ItrSeq.java
  142. +1 −1  src/main/java/org/basex/query/item/MapType.java
  143. +2 −2 src/main/java/org/basex/query/item/NodeType.java
  144. +1 −1  src/main/java/org/basex/query/item/RangeSeq.java
  145. +1 −1  src/main/java/org/basex/query/item/Seq.java
  146. +1 −1  src/main/java/org/basex/query/item/Types.java
  147. +2 −2 src/main/java/org/basex/query/item/Uri.java
  148. +1 −1  src/main/java/org/basex/query/item/map/Leaf.java
  149. +1 −1  src/main/java/org/basex/query/item/map/List.java
  150. +32 −13 src/main/java/org/basex/query/item/map/Map.java
  151. +1 −1  src/main/java/org/basex/query/path/AxisStep.java
  152. +1 −1  src/main/java/org/basex/query/up/expr/Delete.java
  153. +1 −1  src/main/java/org/basex/query/up/expr/Insert.java
  154. +1 −1  src/main/java/org/basex/query/up/expr/Rename.java
  155. +1 −1  src/main/java/org/basex/query/up/expr/Replace.java
  156. +1 −1  src/main/java/org/basex/query/up/expr/Transform.java
  157. +43 −68 src/main/java/org/basex/query/util/Err.java
  158. +2 −1  src/main/java/org/basex/query/util/NSGlobal.java
  159. +1 −1  src/main/java/org/basex/query/util/NSLocal.java
  160. +1 −1  src/main/java/org/basex/query/util/UserFuncs.java
  161. +1 −1  src/main/java/org/basex/query/util/Var.java
  162. +1 −1  src/main/java/org/basex/query/util/format/DecFormatter.java
  163. +1 −1  src/main/java/org/basex/query/util/http/ResponseHandler.java
  164. +2 −2 src/main/java/org/basex/query/util/pkg/JarParser.java
  165. +2 −2 src/main/java/org/basex/query/util/pkg/PkgParser.java
  166. +37 −36 src/main/java/org/basex/server/{ServerProcess.java → ClientListener.java}
  167. +1 −1  src/main/java/org/basex/server/ClientQuery.java
  168. +3 −3 src/main/java/org/basex/server/ClientSession.java
  169. +4 −4 src/main/java/org/basex/server/LocalQuery.java
  170. +4 −3 src/main/java/org/basex/server/LocalSession.java
  171. +6 −5 src/main/java/org/basex/server/Log.java
  172. +1 −1  src/main/java/org/basex/server/LoginException.java
  173. +10 −10 src/main/java/org/basex/server/Query.java
  174. +3 −3 src/main/java/org/basex/server/{QueryProcess.java → QueryListener.java}
  175. +18 −13 src/main/java/org/basex/server/Session.java
  176. +4 −4 src/main/java/org/basex/server/Sessions.java
  177. +1 −1  src/main/java/org/basex/util/BoolList.java
  178. +2 −1  src/main/java/org/basex/util/ElementList.java
  179. +1 −1  src/main/java/org/basex/util/IntArrayList.java
  180. +1 −1  src/main/java/org/basex/util/IntList.java
  181. +71 −27 src/main/java/org/basex/util/Reflect.java
  182. +4 −5 src/main/java/org/basex/util/Token.java
  183. +128 −0 src/main/java/org/basex/util/Xslt.java
  184. +1 −1  src/main/java/org/basex/util/ft/FTOpt.java
  185. +1 −1  src/main/java/org/basex/util/ft/LuceneStemmer.java
  186. +3 −3 src/main/java/org/basex/util/ft/SnowballStemmer.java
  187. +2 −2 src/main/java/org/basex/util/ft/WordnetStemmer.java
  188. +45 −0 src/test/java/org/basex/test/query/advanced/FNXsltTest.java
  189. +18 −12 src/test/java/org/basex/test/query/advanced/FNZipTest.java
  190. +5 −6 src/test/java/org/basex/test/server/LockingTest.java
View
1  .classpath
@@ -5,6 +5,7 @@
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry excluding="**/*.html" kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
View
6 .project
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
View
3  .settings/dict
@@ -276,3 +276,6 @@ zipping
unzip
payload
credentials
+xslt
+unwatches
+unwatching
View
6 src/main/java/org/basex/BaseXServer.java
@@ -13,7 +13,7 @@
import org.basex.server.LocalSession;
import org.basex.server.Log;
import org.basex.server.LoginException;
-import org.basex.server.ServerProcess;
+import org.basex.server.ClientListener;
import org.basex.server.Session;
import org.basex.util.Args;
import org.basex.util.Performance;
@@ -118,7 +118,7 @@ public void run() {
while(running) {
try {
final Socket s = socket.accept();
- final ServerProcess sp = new ServerProcess(s, context, log);
+ final ClientListener sp = new ClientListener(s, context, log);
if(stop.exists()) {
if(!stop.delete()) log.write(Util.info(DBNOTDELETED, stop));
quit(false);
@@ -321,7 +321,7 @@ public void run() {
}
final BufferInput bi = new BufferInput(es.getInputStream());
final long id = Long.parseLong(bi.readString());
- for(final ServerProcess s : context.sessions) {
+ for(final ClientListener s : context.sessions) {
if(s.getId() == id) {
s.register(es);
break;
View
3  src/main/java/org/basex/api/jaxp/BXDocBuilder.java
@@ -71,7 +71,8 @@ public Document newDocument() {
@Override
public Document parse(final InputSource is) throws IOException {
final String id = is.getSystemId();
- final SAXWrapper p = new SAXWrapper(new SAXSource(parser, is), ctx.prop);
+ final SAXSource ss = new SAXSource(parser, is);
+ final SAXWrapper p = new SAXWrapper(ss, "", ctx.prop);
final Data data = MemBuilder.build(p, ctx.prop, id == null ? "" : id);
return new BXDoc(new DBNode(data, 0));
}
View
50 ...n/java/org/basex/build/xml/DirParser.java → src/main/java/org/basex/build/DirParser.java
@@ -1,22 +1,20 @@
-package org.basex.build.xml;
+package org.basex.build;
import java.io.IOException;
import java.util.regex.Pattern;
-import org.basex.build.Builder;
-import org.basex.build.Parser;
import org.basex.core.Prop;
import org.basex.io.IO;
import org.basex.io.IOFile;
import org.basex.util.Util;
/**
- * This class parses the tokens that are delivered by the
- * {@link XMLScanner} and sends them to the specified database builder.
+ * This class recursively scans files and directories and parses all
+ * relevant files.
*
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
-public final class DirParser extends Parser {
+public final class DirParser extends TargetParser {
/** File pattern. */
private final Pattern filter;
/** Properties. */
@@ -31,39 +29,39 @@
/**
* Constructor.
- * @param f file reference
+ * @param source source path
* @param pr database properties
*/
- public DirParser(final IO f, final Prop pr) {
- this(f, pr, "");
+ public DirParser(final IO source, final Prop pr) {
+ this(source, "", pr);
}
/**
* Constructor, specifying a target path.
- * @param path file reference
+ * @param source source path
+ * @param target target path
* @param pr database properties
- * @param t target path
*/
- public DirParser(final IO path, final Prop pr, final String t) {
- super(path, t);
+ public DirParser(final IO source, final String target, final Prop pr) {
+ super(source, target);
prop = pr;
- final String dir = path.dir();
+ final String dir = source.dir();
root = dir.endsWith("/") ? dir : dir + '/';
- filter = !path.isDir() ? null :
+ filter = !source.isDir() ? null :
Pattern.compile(IOFile.regex(pr.get(Prop.CREATEFILTER)));
}
@Override
- public void parse(final Builder b) throws IOException {
- b.meta.filesize = 0;
- b.meta.path = file.path();
- parse(b, file);
+ public void parse(final Builder build) throws IOException {
+ build.meta.filesize = 0;
+ build.meta.path = src.path();
+ parse(build, src);
}
/**
* Parses the specified file or its children.
* @param b builder
- * @param io input
+ * @param io current input
* @throws IOException I/O exception
*/
private void parse(final Builder b, final IO io) throws IOException {
@@ -71,18 +69,18 @@ private void parse(final Builder b, final IO io) throws IOException {
// only {@link IOFile} instances can have children
for(final IO f : ((IOFile) io).children()) parse(b, f);
} else {
- file = io;
- if(!b.meta.prop.is(Prop.ADDARCHIVES) && file.archive()) return;
+ src = io;
+ if(!b.meta.prop.is(Prop.ADDARCHIVES) && src.archive()) return;
while(io.more()) {
final String nm = Prop.WIN ? io.name().toLowerCase() : io.name();
if(filter != null && !filter.matcher(nm).matches()) continue;
- b.meta.filesize += file.length();
+ b.meta.filesize += src.length();
// use global target as prefix
- String targ = !target.isEmpty() ? target + '/' : "";
- final String name = file.name();
- String path = file.path();
+ String targ = !trg.isEmpty() ? trg + '/' : "";
+ final String name = src.name();
+ String path = src.path();
// add relative path without root (prefix) and file name (suffix)
if(path.endsWith('/' + name)) {
path = path.substring(0, path.length() - name.length());
View
2  src/main/java/org/basex/build/DiskBuilder.java
@@ -57,7 +57,7 @@ public DiskData build(final String name) throws IOException {
DropDB.drop(name, prop);
prop.dbpath(name).mkdirs();
- final IO file = parser.file;
+ final IO file = parser.src;
meta = new MetaData(name, prop);
meta.path = file != null ? file.path() : "";
meta.filesize = file != null ? file.length() : 0;
View
4 src/main/java/org/basex/build/MemBuilder.java
@@ -35,7 +35,7 @@ public MemBuilder(final Parser parse, final Prop pr) {
*/
public static Data build(final Parser parser, final Prop prop)
throws IOException {
- return build(parser, prop, parser.file.name());
+ return build(parser, prop, parser.src.name());
}
/**
@@ -60,7 +60,7 @@ public MemData build(final String name) throws IOException {
meta.textindex = true;
meta.attrindex = true;
meta.ftindex = false;
- final IO file = parser.file;
+ final IO file = parser.src;
meta.path = file != null ? file.path() : "";
meta.filesize = file != null ? file.length() : 0;
meta.time = file != null ? file.date() : System.currentTimeMillis();
View
100 src/main/java/org/basex/build/Parser.java
@@ -15,97 +15,93 @@
import org.basex.util.Atts;
/**
- * This class defines a parser for creating databases from various sources.
- * If TagSoup is found in the classpath, HTML files are automatically converted
- * to well-formed XML.
- *
- * TagSoup was written by John Cowan and licensed under Apache 2.0
- * {@code http://home.ccil.org/~cowan/XML/tagsoup/}.
+ * This class defines a parser, which is used to create new databases instances.
*
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
public abstract class Parser extends Progress {
- /** Input file. */
- public IO file;
-
+ /** Source document, or {@code null}. */
+ public IO src;
/** Temporary attribute array.
To speed up processing, the same instance is used over and over. */
protected final Atts atts = new Atts();
- /** Target path. */
- protected final String target;
/**
* Constructor.
- * @param io parser input
+ * @param source document source, or {@code null}
*/
- protected Parser(final String io) {
- this(io == null ? null : IO.get(io), "");
+ protected Parser(final String source) {
+ this(source == null ? null : IO.get(source));
}
/**
* Constructor.
- * @param f file reference
- * @param t target path
+ * @param source document source, or {@code null}
*/
- public Parser(final IO f, final String t) {
- file = f;
- target = t;
+ protected Parser(final IO source) {
+ src = source;
}
/**
- * Returns a file parser instance.
- * @param io input
- * @param prop database properties
- * @param target relative path reference
- * @return xml parser
+ * Parses all nodes and sends events to the specified builder.
+ * @param build database builder
* @throws IOException I/O exception
*/
- public static FileParser fileParser(final IO io, final Prop prop,
- final String target) throws IOException {
+ public abstract void parse(final Builder build) throws IOException;
- // use file specific parser
- final String parser = prop.get(Prop.PARSER).toLowerCase();
- if(parser.equals(DataText.M_HTML)) return new HTMLParser(io, target, prop);
- if(parser.equals(DataText.M_TEXT)) return new TextParser(io, target, prop);
- if(parser.equals(DataText.M_CSV)) return new CSVParser(io, target, prop);
- if(parser.equals(DataText.M_MAB2)) return new MAB2Parser(io, target, prop);
- return xmlParser(io, prop, target);
+ // STATIC METHODS ===========================================================
+
+ /**
+ * Returns a parser instance for creating empty databases.
+ * @return parser
+ */
+ public static Parser emptyParser() {
+ return new Parser((IO) null) {
+ @Override
+ public void parse(final Builder build) { /* empty */ }
+ };
}
/**
* Returns an XML parser instance.
- * @param io input
+ * @param source input
* @param prop database properties
* @param target relative path reference
* @return xml parser
* @throws IOException I/O exception
*/
- public static FileParser xmlParser(final IO io, final Prop prop,
+ public static SingleParser xmlParser(final IO source, final Prop prop,
final String target) throws IOException {
// XML: use internal parser
- if(prop.is(Prop.INTPARSE)) return new XMLParser(io, target, prop);
+ if(prop.is(Prop.INTPARSE)) return new XMLParser(source, target, prop);
// use default parser
- final SAXSource s = new SAXSource(io.inputSource());
- return new SAXWrapper(s, io.name(), target, prop);
+ final SAXSource s = new SAXSource(source.inputSource());
+ return new SAXWrapper(s, source.name(), target, prop);
}
/**
- * Returns a parser instance for creating empty databases.
- * @return parser
- */
- public static Parser emptyParser() {
- return new Parser(null) {
- @Override
- public void parse(final Builder build) { /* empty */ }
- };
- }
-
- /**
- * Parses all nodes and sends events to the specified builder.
- * @param build database builder
+ * Returns a file parser instance.
+ * @param source document source
+ * @param prop database properties
+ * @param target relative path reference
+ * @return xml parser
* @throws IOException I/O exception
*/
- public abstract void parse(Builder build) throws IOException;
+ public static SingleParser fileParser(final IO source, final Prop prop,
+ final String target) throws IOException {
+
+ // use file specific parser
+ final String parser = prop.get(Prop.PARSER).toLowerCase();
+ if(parser.equals(DataText.M_HTML))
+ return new HTMLParser(source, target, prop);
+ if(parser.equals(DataText.M_TEXT))
+ return new TextParser(source, target, prop);
+ if(parser.equals(DataText.M_MAB2))
+ return new MAB2Parser(source, target, prop);
+ if(parser.equals(DataText.M_CSV))
+ return new CSVParser(source, target, prop);
+ return xmlParser(source, prop, target);
+ }
}
View
14 ...main/java/org/basex/build/FileParser.java → ...in/java/org/basex/build/SingleParser.java
@@ -5,28 +5,28 @@
import org.basex.io.IO;
/**
- * This class defines an abstract parser for single files.
+ * This class defines an abstract parser for single documents.
*
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
-public abstract class FileParser extends Parser {
+public abstract class SingleParser extends TargetParser {
/** Builder reference. */
protected Builder builder;
/**
* Constructor.
- * @param io parser input
- * @param tar collection target
+ * @param source document source
+ * @param target target path
*/
- public FileParser(final IO io, final String tar) {
- super(io, tar);
+ public SingleParser(final IO source, final String target) {
+ super(source, target);
}
@Override
public final void parse(final Builder build) throws IOException {
builder = build;
- builder.startDoc(token(target + file.name()));
+ builder.startDoc(token(trg + src.name()));
parse();
builder.endDoc();
}
View
24 src/main/java/org/basex/build/TargetParser.java
@@ -0,0 +1,24 @@
+package org.basex.build;
+
+import org.basex.io.IO;
+
+/**
+ * This class defines an abstract parser, specifying a target path.
+ *
+ * @author BaseX Team 2005-11, BSD License
+ * @author Christian Gruen
+ */
+public abstract class TargetParser extends Parser {
+ /** Target path. */
+ protected final String trg;
+
+ /**
+ * Constructor.
+ * @param source document source
+ * @param target target path
+ */
+ public TargetParser(final IO source, final String target) {
+ super(source);
+ trg = target;
+ }
+}
View
7 src/main/java/org/basex/build/file/CSVParser.java
@@ -3,8 +3,7 @@
import static org.basex.util.Token.*;
import static org.basex.core.Text.*;
import java.io.IOException;
-import org.basex.build.FileParser;
-import org.basex.build.ParserProp;
+import org.basex.build.SingleParser;
import org.basex.core.Prop;
import org.basex.io.BufferInput;
import org.basex.io.IO;
@@ -44,7 +43,7 @@
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
-public final class CSVParser extends FileParser {
+public final class CSVParser extends SingleParser {
/** Separators. */
public static final String[] SEPARATORS = { "comma", "semicolon", "tab" };
/** Formats. */
@@ -113,7 +112,7 @@ public void parse() throws IOException {
builder.startElem(CSV, atts);
final TokenBuilder tb = new TokenBuilder();
- final BufferInput bi = new BufferInput(file.path());
+ final BufferInput bi = new BufferInput(src.path());
bi.encoding(encoding);
boolean quoted = false, open = true;
View
12 src/main/java/org/basex/build/file/HTMLParser.java
@@ -19,6 +19,8 @@
/**
* This class uses TagSoup to convert HTML input to well-formed XML.
+ * If TagSoup is not found in the classpath, the original document is passed on.
+ *
* TagSoup was written by John Cowan and is based on the Apache 2.0 License:
* {@code http://home.ccil.org/~cowan/XML/tagsoup/}.
*
@@ -43,14 +45,14 @@ public static boolean available() {
/**
* Constructor.
- * @param f file reference
- * @param tar target for collection adding
+ * @param source document source
+ * @param target target path
* @param pr database properties
* @throws IOException I/O exception
*/
- public HTMLParser(final IO f, final String tar, final Prop pr)
+ public HTMLParser(final IO source, final String target, final Prop pr)
throws IOException {
- super(toXML(f), tar, pr);
+ super(toXML(source), target, pr);
}
/**
@@ -67,7 +69,7 @@ private static IO toXML(final IO io) {
byte[] content = io.content();
final ArrayInput ai = new ArrayInput(content);
String enc = ai.encoding();
- content = ai.content().toArray();
+ content = ai.token().toArray();
// looks for a charset definition
final byte[] encoding = token("charset=");
View
7 src/main/java/org/basex/build/file/MAB2Parser.java
@@ -8,8 +8,7 @@
import java.util.Arrays;
import org.basex.build.BuildException;
-import org.basex.build.FileParser;
-import org.basex.build.ParserProp;
+import org.basex.build.SingleParser;
import org.basex.core.Prop;
import org.basex.io.DataAccess;
import org.basex.io.IO;
@@ -28,7 +27,7 @@
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
-public final class MAB2Parser extends FileParser {
+public final class MAB2Parser extends SingleParser {
/** Encoding of MAB2 input. */
private static final String ENCODING = "iso-8859-1";
/** Temporary token builder. */
@@ -140,7 +139,7 @@ public void parse() throws IOException {
}
// create input reference
- final DataAccess input = new DataAccess(new File(file.path()));
+ final DataAccess input = new DataAccess(new File(src.path()));
// check beginning of input file
if(input.read1() != '#' || input.read1() != '#' || input.read1() != '#') {
View
2  ...main/java/org/basex/build/ParserProp.java → ...java/org/basex/build/file/ParserProp.java
@@ -1,4 +1,4 @@
-package org.basex.build;
+package org.basex.build.file;
import static org.basex.core.Text.*;
import java.io.IOException;
View
7 src/main/java/org/basex/build/file/TextParser.java
@@ -3,8 +3,7 @@
import static org.basex.util.Token.*;
import java.io.IOException;
-import org.basex.build.FileParser;
-import org.basex.build.ParserProp;
+import org.basex.build.SingleParser;
import org.basex.core.Prop;
import org.basex.io.BufferInput;
import org.basex.io.IO;
@@ -32,7 +31,7 @@
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
-public final class TextParser extends FileParser {
+public final class TextParser extends SingleParser {
/** Text element. */
private static final byte[] TEXT = token("text");
/** Line element. */
@@ -65,7 +64,7 @@ public TextParser(final IO path, final String ta, final Prop prop)
public void parse() throws IOException {
builder.startElem(TEXT, atts);
- final BufferInput bi = new BufferInput(file.path());
+ final BufferInput bi = new BufferInput(src.path());
bi.encoding(encoding);
final TokenBuilder tb = new TokenBuilder();
View
14 ...sex/build/xml/CatalogResolverWrapper.java → ...a/org/basex/build/xml/CatalogWrapper.java
@@ -14,7 +14,7 @@
* @author BaseX Team 2005-11, BSD License
* @author Michael Seiferle
*/
-public final class CatalogResolverWrapper {
+public final class CatalogWrapper {
/** Package declaration for CatalogManager. */
private static final Class<?> CMP = find(
"org.apache.xml.resolver.CatalogManager",
@@ -27,7 +27,7 @@
private static final Object CM = get(CMP);
/** Hidden constructor. */
- private CatalogResolverWrapper() { }
+ private CatalogWrapper() { }
/**
* Checks if a CatalogResolver is available.
@@ -45,11 +45,11 @@ public static boolean available() {
*/
public static void set(final XMLReader reader, final String cat) {
if(CM == null) return;
- invoke(find(CMP, "setIgnoreMissingProperties", boolean.class), CM, true);
- invoke(find(CMP, "setCatalogFiles", String.class), CM, cat);
- invoke(find(CMP, "setPreferPublic", boolean.class), CM, true);
- invoke(find(CMP, "setUseStaticCatalog", boolean.class), CM, false);
- invoke(find(CMP, "setVerbosity", int.class), CM, 0);
+ invoke(method(CMP, "setIgnoreMissingProperties", boolean.class), CM, true);
+ invoke(method(CMP, "setCatalogFiles", String.class), CM, cat);
+ invoke(method(CMP, "setPreferPublic", boolean.class), CM, true);
+ invoke(method(CMP, "setUseStaticCatalog", boolean.class), CM, false);
+ invoke(method(CMP, "setVerbosity", int.class), CM, 0);
reader.setEntityResolver((EntityResolver) get(CRP, CM));
}
}
View
12 .../java/org/basex/build/xml/DOCWrapper.java → .../java/org/basex/build/xml/DOMWrapper.java
@@ -18,14 +18,12 @@
import org.w3c.dom.Text;
/**
- * This class parses an XML document via a conventional SAX parser.
- * Would be the easiest solution, but some large file cannot be parsed
- * with the default parser.
+ * This class converts an DOM document instance to a database representation.
*
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
-public final class DOCWrapper extends Parser {
+public final class DOMWrapper extends Parser {
/** Name of the document. */
private final String filename;
/** Root document. */
@@ -35,12 +33,12 @@
/**
* Constructor.
- * @param d document instance
+ * @param doc document instance
* @param fn filename
*/
- public DOCWrapper(final Document d, final String fn) {
+ public DOMWrapper(final Document doc, final String fn) {
super(fn);
- root = d;
+ root = doc;
filename = fn;
}
View
94 src/main/java/org/basex/build/xml/SAXWrapper.java
@@ -8,7 +8,7 @@
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.sax.SAXSource;
-import org.basex.build.FileParser;
+import org.basex.build.SingleParser;
import org.basex.core.ProgressException;
import org.basex.core.Prop;
import org.basex.io.IO;
@@ -19,14 +19,15 @@
import org.xml.sax.XMLReader;
/**
- * This class parses an XML document with Java's default SAX parser. Note that
- * large file cannot be parsed with the default parser due to entity handling
- * (e.g. the DBLP data).
+ * This class parses an XML document with Java's internal SAX parser. Note that
+ * not all files cannot be parsed with the default parser; for example, the
+ * DBLP documents contain too many entities and cause an out of memory error.
+ * The internal {@link XMLParser} can be used as alternative.
*
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
-public final class SAXWrapper extends FileParser {
+public final class SAXWrapper extends SingleParser {
/** External DTD parsing. */
private static final String EXTDTD =
"http://apache.org/xml/features/nonvalidating/load-external-dtd";
@@ -40,9 +41,9 @@
int line = 1;
/** SAX handler reference. */
- private SAXHandler sax;
+ private SAXHandler saxh;
/** Optional XML reader. */
- private final SAXSource src;
+ private final SAXSource saxs;
/** File length. */
private long length;
/** Properties. */
@@ -50,46 +51,37 @@
/**
* Constructor.
- * @param s sax source
+ * @param source sax source
+ * @param target target path to insert into
* @param pr Properties
*/
- public SAXWrapper(final SAXSource s, final Prop pr) {
- this(s, IO.get(s.getSystemId()).name(), "", pr);
- }
-
- /**
- * Constructor.
- * @param s sax source
- * @param n name
- * @param ta target to insert into
- * @param pr Properties
- */
- public SAXWrapper(final SAXSource s, final String n, final String ta,
+ public SAXWrapper(final SAXSource source, final String target,
final Prop pr) {
- super(io(s, n), ta);
- src = s;
+ super(IO.get(source.getSystemId()), target);
+ saxs = source;
prop = pr;
}
/**
- * Returns IO reference.
- * @param s sax source
- * @param n name
- * @return io
+ * Constructor.
+ * @param source sax source
+ * @param name name
+ * @param target target to insert into
+ * @param pr Properties
*/
- private static IO io(final SAXSource s, final String n) {
- final IO io = IO.get(s.getSystemId());
- io.name(n);
- return io;
+ public SAXWrapper(final SAXSource source, final String name,
+ final String target, final Prop pr) {
+ this(source, target, pr);
+ src.name(name);
}
@Override
public void parse() throws IOException {
- final InputSource is = wrap(src.getInputSource());
- final String input = src.getSystemId() == null ? "..." : src.getSystemId();
+ final InputSource is = wrap(saxs.getInputSource());
+ final String in = saxs.getSystemId() == null ? "..." : saxs.getSystemId();
try {
- XMLReader r = src.getXMLReader();
+ XMLReader r = saxs.getXMLReader();
if(r == null) {
final SAXParserFactory f = SAXParserFactory.newInstance();
f.setFeature(EXTDTD, prop.is(Prop.DTD));
@@ -100,19 +92,19 @@ public void parse() throws IOException {
r = f.newSAXParser().getXMLReader();
}
- sax = new SAXHandler(builder);
+ saxh = new SAXHandler(builder);
final String cat = prop.get(Prop.CATFILE);
- if(!cat.isEmpty()) CatalogResolverWrapper.set(r, cat);
+ if(!cat.isEmpty()) CatalogWrapper.set(r, cat);
- r.setDTDHandler(sax);
- r.setContentHandler(sax);
- r.setProperty(LEXHANDLER, sax);
- r.setErrorHandler(sax);
+ r.setDTDHandler(saxh);
+ r.setContentHandler(saxh);
+ r.setProperty(LEXHANDLER, saxh);
+ r.setErrorHandler(saxh);
if(is != null) r.parse(is);
- else r.parse(src.getSystemId());
+ else r.parse(saxs.getSystemId());
} catch(final SAXParseException ex) {
- final String msg = Util.info(SCANPOS, input, ex.getLineNumber(),
+ final String msg = Util.info(SCANPOS, in, ex.getLineNumber(),
ex.getColumnNumber()) + ": " + ex.getMessage();
final IOException ioe = new IOException(msg);
ioe.setStackTrace(ex.getStackTrace());
@@ -123,15 +115,15 @@ public void parse() throws IOException {
// occurs, e.g. if document encoding is invalid:
// prefix message with source id
String msg = ex.getMessage();
- if(input != null) msg = "\"" + input + "\": " + msg;
+ if(in != null) msg = "\"" + in + "\": " + msg;
// wrap and return original message
final IOException ioe = new IOException(msg);
ioe.setStackTrace(ex.getStackTrace());
throw ioe;
} finally {
try {
- final InputStream in = is.getByteStream();
- if(in != null) in.close();
+ final InputStream ist = is.getByteStream();
+ if(ist != null) ist.close();
final Reader r = is.getCharacterStream();
if(r != null) r.close();
} catch(final IOException ex) {
@@ -147,10 +139,10 @@ public void parse() throws IOException {
* @throws IOException I/O exception
*/
private InputSource wrap(final InputSource is) throws IOException {
- if(!(file instanceof IOFile) || is == null || is.getByteStream() != null
+ if(!(src instanceof IOFile) || is == null || is.getByteStream() != null
|| is.getSystemId() == null || is.getSystemId().isEmpty()) return is;
- final InputSource in = new InputSource(new FileInputStream(file.path()) {
+ final InputSource in = new InputSource(new FileInputStream(src.path()) {
@Override
public int read(final byte[] b, final int off, final int len)
throws IOException {
@@ -160,20 +152,20 @@ public int read(final byte[] b, final int off, final int len)
return i;
}
});
- src.setInputSource(in);
- src.setSystemId(is.getSystemId());
- length = file.length();
+ saxs.setInputSource(in);
+ saxs.setSystemId(is.getSystemId());
+ length = src.length();
return in;
}
@Override
public String det() {
- return length == 0 ? super.det() : Util.info(SCANPOS, file.name(), line);
+ return length == 0 ? super.det() : Util.info(SCANPOS, src.name(), line);
}
@Override
public double prog() {
- return length == 0 ? sax == null ? 0 : sax.nodes / 3000000d % 1
+ return length == 0 ? saxh == null ? 0 : saxh.nodes / 3000000d % 1
: (double) counter / length;
}
}
View
22 src/main/java/org/basex/build/xml/XMLParser.java
@@ -4,35 +4,35 @@
import static org.basex.util.Token.*;
import java.io.IOException;
import org.basex.build.BuildException;
-import org.basex.build.FileParser;
+import org.basex.build.SingleParser;
import org.basex.build.BuildText.Type;
import org.basex.core.Prop;
import org.basex.io.IO;
/**
* This class parses the tokens that are delivered by the {@link XMLScanner} and
- * sends them to the specified database builder.
+ * sends them to the specified database builder. This class offers a more
+ * tolerant alternative to Java's internal SAX parser, which is used by the
+ * {@link SAXWrapper} class.
*
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
-public class XMLParser extends FileParser {
+public class XMLParser extends SingleParser {
/** Scanner reference. */
private final XMLScanner scanner;
/**
- * Creates a new XMLParser instance for collection creation.
- * The length of the rootPath is passed in to correctly chop
- * the relative path inside the collection.
- * @param io parser input
- * @param tar target for collection adding
+ * Constructor.
+ * @param source document source
+ * @param target target path
* @param pr database properties
* @throws IOException I/O exception
*/
- public XMLParser(final IO io, final String tar, final Prop pr)
+ public XMLParser(final IO source, final String target, final Prop pr)
throws IOException {
- super(io, tar);
- scanner = new XMLScanner(io, pr);
+ super(source, target);
+ scanner = new XMLScanner(source, pr);
}
@Override
View
10 src/main/java/org/basex/core/Context.java
@@ -6,7 +6,7 @@
import org.basex.data.Nodes;
import org.basex.io.IO;
import org.basex.query.util.pkg.Repo;
-import org.basex.server.ServerProcess;
+import org.basex.server.ClientListener;
import org.basex.server.Sessions;
/**
@@ -32,7 +32,7 @@
public final Repo repo;
/** Session reference. */
- public ServerProcess session;
+ public ClientListener session;
/** User reference. */
public User user;
/** Current query file. */
@@ -72,7 +72,7 @@ public Context() {
* @param ctx parent database context
* @param s server process
*/
- public Context(final Context ctx, final ServerProcess s) {
+ public Context(final Context ctx, final ClientListener s) {
session = s;
datas = ctx.datas;
events = ctx.events;
@@ -212,7 +212,7 @@ public void unregister(final boolean w) {
* Adds the specified session.
* @param s session to be added
*/
- public void add(final ServerProcess s) {
+ public void add(final ClientListener s) {
sessions.add(s);
}
@@ -220,7 +220,7 @@ public void add(final ServerProcess s) {
* Removes the specified session.
* @param s session to be removed
*/
- public void delete(final ServerProcess s) {
+ public void delete(final ClientListener s) {
sessions.remove(s);
}
View
4 src/main/java/org/basex/core/Events.java
@@ -11,7 +11,7 @@
import org.basex.io.DataInput;
import org.basex.io.DataOutput;
import org.basex.io.IO;
-import org.basex.server.ServerProcess;
+import org.basex.server.ClientListener;
import org.basex.server.Sessions;
import org.basex.util.Token;
import org.basex.util.TokenBuilder;
@@ -111,7 +111,7 @@ public synchronized boolean notify(final Context ctx, final byte[] name,
// event was not found
if(sess == null) return false;
- for(final ServerProcess srv : sess) {
+ for(final ClientListener srv : sess) {
// ignore active client
if(srv == ctx.session) continue;
try {
View
4 src/main/java/org/basex/core/cmd/ACreate.java
@@ -107,13 +107,13 @@ protected final boolean build(final Parser p, final String db) {
abort();
final String msg = ex.getMessage();
return error(msg != null && msg.length() != 0 ? msg :
- Util.info(PARSEERR, p.file));
+ Util.info(PARSEERR, p.src));
} catch(final Exception ex) {
// known exceptions:
// - IllegalArgumentException (UTF8, zip files)
Util.debug(ex);
abort();
- return error(Util.info(PARSEERR, p.file));
+ return error(Util.info(PARSEERR, p.src));
}
}
View
17 src/main/java/org/basex/core/cmd/Add.java
@@ -1,15 +1,13 @@
package org.basex.core.cmd;
import static org.basex.core.Text.*;
-import java.io.BufferedInputStream;
import java.io.IOException;
-import java.io.InputStream;
import javax.xml.transform.sax.SAXSource;
import org.basex.build.Builder;
+import org.basex.build.DirParser;
import org.basex.build.DiskBuilder;
import org.basex.build.MemBuilder;
import org.basex.build.Parser;
-import org.basex.build.xml.DirParser;
import org.basex.build.xml.SAXWrapper;
import org.basex.core.BaseXException;
import org.basex.core.CommandBuilder;
@@ -79,7 +77,7 @@ protected boolean run() {
}
final String trg = path(args[2]);
- final DirParser p = new DirParser(io, context.prop, trg);
+ final DirParser p = new DirParser(io, trg, context.prop);
try {
return info(add(p, context, trg, name, this));
} catch(final BaseXException ex) {
@@ -97,7 +95,7 @@ public void build(final CommandBuilder cb) {
* @param name name of document. If {@code null}, the name of the input
* will be used
* @param target target. If {@code null}, target will be set to root
- * @param input XML input stream
+ * @param input XML input source
* @param ctx database context
* @param cmd calling command
* @param lock if {@code true}, register a write lock in context
@@ -105,7 +103,7 @@ public void build(final CommandBuilder cb) {
* @throws BaseXException database exception
*/
public static String add(final String name, final String target,
- final InputStream input, final Context ctx, final Add cmd,
+ final InputSource input, final Context ctx, final Add cmd,
final boolean lock) throws BaseXException {
final Data data = ctx.data;
@@ -114,8 +112,7 @@ public static String add(final String name, final String target,
String trg = path(target);
if(!trg.isEmpty()) trg = trg + '/';
- final BufferedInputStream is = new BufferedInputStream(input);
- final SAXSource sax = new SAXSource(new InputSource(is));
+ final SAXSource sax = new SAXSource(input);
final Parser parser = new SAXWrapper(sax, name, trg, ctx.prop);
try {
if(lock) ctx.register(true);
@@ -141,11 +138,11 @@ public static String add(final Parser parser, final Context ctx,
final Performance p = new Performance();
final String path = target + (target.isEmpty() ? "/" : "") +
- (name == null ? parser.file.name() : name);
+ (name == null ? parser.src.name() : name);
// create disk instances for large documents
// test does not work for input streams and directories
- final long fl = parser.file.length();
+ final long fl = parser.src.length();
boolean large = false;
final Runtime rt = Runtime.getRuntime();
if(fl > rt.freeMemory() / 3) {
View
2  src/main/java/org/basex/core/cmd/Create.java
@@ -28,7 +28,7 @@ public Create(final Parser p, final String name) {
@Override
protected boolean run() {
// check if file exists
- if(!parser.file.exists()) return error(FILEWHICH, parser.file);
+ if(!parser.src.exists()) return error(FILEWHICH, parser.src);
// run the build process
return build(parser, args[0]);
}
View
34 src/main/java/org/basex/core/cmd/CreateDB.java
@@ -8,10 +8,10 @@
import javax.xml.transform.sax.SAXSource;
import org.basex.build.BuildException;
import org.basex.build.Builder;
+import org.basex.build.DirParser;
import org.basex.build.DiskBuilder;
import org.basex.build.MemBuilder;
import org.basex.build.Parser;
-import org.basex.build.xml.DirParser;
import org.basex.build.xml.SAXWrapper;
import org.basex.core.BaseXException;
import org.basex.core.CommandBuilder;
@@ -50,18 +50,18 @@ public CreateDB(final String name) {
}
/**
- * Constructor, specifying an input.
+ * Constructor, specifying an initial database input.
* @param name name of database
- * @param input input file path or XML string
+ * @param input input reference (local/remote file or XML string)
*/
public CreateDB(final String name, final String input) {
this(name, input, null);
}
/**
- * Constructor, specifying an input.
+ * Constructor, specifying an initial database input.
* @param name name of database
- * @param input input file path or XML string
+ * @param input input reference (local/remote file or XML string)
* @param p parser reference
*/
public CreateDB(final String name, final String input, final Parser p) {
@@ -95,7 +95,7 @@ public static synchronized String create(final String name,
final InputStream is = input instanceof BufferedInputStream ||
input instanceof BufferInput ? input : new BufferedInputStream(input);
final SAXSource sax = new SAXSource(new InputSource(is));
- return create(name, new SAXWrapper(sax, ctx.prop), ctx);
+ return create(name, new SAXWrapper(sax, "", ctx.prop), ctx);
}
/**
@@ -143,16 +143,16 @@ public static Data empty(final String name, final Context ctx)
/**
* Returns a database instance for the specified input.
* @param name name of the database
- * @param input input reference
+ * @param source document source
* @param ctx database context
* @return new database instance
* @throws IOException I/O exception
*/
- public static synchronized Data xml(final String name, final IO input,
+ public static synchronized Data xml(final String name, final IO source,
final Context ctx) throws IOException {
- if(!input.exists()) throw new BuildException(FILEWHICH, input);
- return xml(name, new DirParser(input, ctx.prop), ctx);
+ if(!source.exists()) throw new BuildException(FILEWHICH, source);
+ return xml(name, new DirParser(source, ctx.prop), ctx);
}
/**
@@ -211,27 +211,27 @@ public static synchronized Data xml(final Parser parser, final Context ctx)
/**
* Returns a main memory database instance for the specified input reference.
- * @param io input reference
+ * @param source document source
* @param ctx database context
* @return new database instance
* @throws IOException I/O exception
*/
- public static synchronized Data xml(final IO io, final Context ctx)
+ public static synchronized Data xml(final IO source, final Context ctx)
throws IOException {
- if(!io.exists()) throw new BuildException(FILEWHICH, io.path());
- return xml(new DirParser(io, ctx.prop), ctx);
+ if(!source.exists()) throw new BuildException(FILEWHICH, source.path());
+ return xml(new DirParser(source, ctx.prop), ctx);
}
/**
* Returns a main memory database instance from the specified SAX source.
- * @param sax sax source
+ * @param source sax source
* @param ctx database context
* @return new database instance
* @throws IOException I/O exception
*/
- public static synchronized Data xml(final SAXSource sax, final Context ctx)
+ public static synchronized Data xml(final SAXSource source, final Context ctx)
throws IOException {
- return xml(new SAXWrapper(sax, ctx.prop) , ctx);
+ return xml(new SAXWrapper(source, "", ctx.prop) , ctx);
}
@Override
View
4 src/main/java/org/basex/core/cmd/DropUser.java
@@ -7,7 +7,7 @@
import org.basex.core.Commands.Cmd;
import org.basex.core.Commands.CmdDrop;
import org.basex.data.Data;
-import org.basex.server.ServerProcess;
+import org.basex.server.ClientListener;
import org.basex.util.Util;
/**
@@ -46,7 +46,7 @@ protected boolean run(final String user, final String db) {
// drop global user
if(db == null) {
- for(final ServerProcess s : context.sessions) {
+ for(final ClientListener s : context.sessions) {
if(s.user().name.equals(user)) return !info(USERLOG, user);
}
context.users.drop(context.users.get(user));
View
2  src/main/java/org/basex/core/cmd/Find.java
@@ -1,6 +1,6 @@
package org.basex.core.cmd;
-import static org.basex.query.QueryTokens.*;
+import static org.basex.query.QueryText.*;
import static org.basex.util.Token.*;
import org.basex.core.Context;
import org.basex.data.MetaData;
View
2  src/main/java/org/basex/core/cmd/OptimizeAll.java
@@ -109,7 +109,7 @@ public void build(final CommandBuilder cb) {
public final class DBParser extends Parser {
/** Constructor. */
protected DBParser() {
- super(old.meta.path.isEmpty() ? null : IO.get(old.meta.path), "");
+ super(old.meta.path.isEmpty() ? null : IO.get(old.meta.path));
}
@Override
View
7 src/main/java/org/basex/core/cmd/Replace.java
@@ -3,14 +3,13 @@
import static org.basex.util.Token.*;
import static org.basex.core.Text.*;
-import java.io.InputStream;
-
import org.basex.core.BaseXException;
import org.basex.core.Context;
import org.basex.core.User;
import org.basex.data.Data;
import org.basex.io.IO;
import org.basex.util.Util;
+import org.xml.sax.InputSource;
/**
* Evaluates the 'replace' command and replaces documents in a collection.
@@ -35,7 +34,7 @@ protected boolean run() {
if(!io.exists()) return error(FILEWHICH, io);
try {
- return info(replace(args[0], io.inputStream(), context, false), perf);
+ return info(replace(args[0], io.inputSource(), context, false), perf);
} catch(final Exception ex) {
return error(ex.getMessage());
}
@@ -50,7 +49,7 @@ protected boolean run() {
* @return info string
* @throws BaseXException database exception
*/
- public static String replace(final String p, final InputStream input,
+ public static String replace(final String p, final InputSource input,
final Context ctx, final boolean lock) throws BaseXException {
final Data data = ctx.data;
String path = path(p);
View
2  src/main/java/org/basex/data/Serializer.java
@@ -1,7 +1,7 @@
package org.basex.data;
import static org.basex.util.Token.*;
-import static org.basex.query.QueryTokens.*;
+import static org.basex.query.QueryText.*;
import java.io.IOException;
import org.basex.io.IO;
import org.basex.util.Atts;
View
8 src/main/java/org/basex/gui/dialog/DialogParsing.java
@@ -4,10 +4,10 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
-import org.basex.build.ParserProp;
import org.basex.build.file.CSVParser;
import org.basex.build.file.HTMLParser;
-import org.basex.build.xml.CatalogResolverWrapper;
+import org.basex.build.file.ParserProp;
+import org.basex.build.xml.CatalogWrapper;
import org.basex.core.Prop;
import org.basex.data.DataText;
import org.basex.gui.GUIConstants;
@@ -143,7 +143,7 @@ void createOptionsPanels() {
xmlopts.add(new BaseXLabel());
// catalog resolver
- final boolean rsen = CatalogResolverWrapper.available();
+ final boolean rsen = CatalogWrapper.available();
final BaseXBack fl = new BaseXBack(new TableLayout(2, 2, 8, 0));
usecat.setEnabled(rsen);
fl.add(usecat);
@@ -237,7 +237,7 @@ void action(final Object cmp) {
final boolean uc = usecat.isSelected();
intparse.setEnabled(!uc);
entities.setEnabled(ip);
- usecat.setEnabled(!ip && CatalogResolverWrapper.available());
+ usecat.setEnabled(!ip && CatalogWrapper.available());
cfile.setEnabled(uc);
browsec.setEnabled(uc);
}
View
2  src/main/java/org/basex/gui/dialog/DialogPass.java
@@ -55,7 +55,7 @@ public void keyReleased(final KeyEvent e) {
@Override
public void action(final Object cmp) {
- final String nm = new String(pass.getPassword());
+ final String nm = pass();
ok = !nm.isEmpty() && nm.matches("[^ ;'\\\"]*");
info.setText(ok || nm.isEmpty() ? null :
Util.info(INVALID, SERVERPW), Msg.ERROR);
View
3  src/main/java/org/basex/gui/layout/BaseXEditor.java
@@ -191,8 +191,7 @@ public final void setText(final byte[] t, final int s) {
*/
public final void setSyntax(final IO file) {
// choose XML or XQuery highlighter
- setSyntax(file.name().endsWith(IO.XMLSUFFIX) ? new XMLSyntax() :
- new XQuerySyntax());
+ setSyntax(file.xml() ? new XMLSyntax() : new XQuerySyntax());
}
/**
View
4 src/main/java/org/basex/gui/layout/XQuerySyntax.java
@@ -4,7 +4,7 @@
import java.lang.reflect.Field;
import java.util.HashSet;
import org.basex.gui.GUIConstants;
-import org.basex.query.QueryTokens;
+import org.basex.query.QueryText;
import org.basex.query.func.Function;
import org.basex.util.Util;
import org.basex.util.XMLToken;
@@ -37,7 +37,7 @@
// initialize xquery keys
static {
try {
- for(final Field f : QueryTokens.class.getFields()) {
+ for(final Field f : QueryText.class.getFields()) {
if(f.getName().equals("IGNORE")) break;
final String s = (String) f.get(null);
for(final String ss : s.split("-")) KEYS.add(ss);
View
25 src/main/java/org/basex/gui/view/editor/EditorArea.java
@@ -8,7 +8,6 @@
import org.basex.gui.GUIProp;
import org.basex.gui.layout.BaseXLabel;
import org.basex.gui.layout.BaseXEditor;
-import org.basex.io.IO;
import org.basex.io.IOFile;
import org.basex.query.QueryContext;
import org.basex.query.QueryException;
@@ -26,9 +25,9 @@
final BaseXLabel label;
/** View reference. */
private final EditorView view;
-
/** File in tab. */
- IOFile file;
+ private IOFile file;
+
/** Flag for modified content. */
boolean mod;
/** Opened flag; states if file was opened from disk. */
@@ -55,7 +54,6 @@
view = v;
file = f;
label = new BaseXLabel(f.name());
- setSyntax(f);
}
@Override
@@ -96,7 +94,7 @@ protected void release(final boolean force) {
gui.context.query = file;
last = in;
- if(file.name().endsWith(IO.XMLSUFFIX)) {
+ if(file.xml()) {
view.info("", true);
exec = false;
} else {
@@ -125,6 +123,23 @@ void query() {
}
/**
+ * Returns the currently assigned file.
+ * @return file
+ */
+ IOFile file() {
+ return file;
+ }
+
+ /**
+ * Sets the file reference.
+ * @param f file
+ */
+ void file(final IOFile f) {
+ file = f;
+ setSyntax(file);
+ }
+
+ /**
* Highlights the error.
*/
void markError() {
View
19 src/main/java/org/basex/gui/view/editor/EditorView.java
@@ -316,13 +316,12 @@ public boolean saveAs() {
// open file chooser for XML creation
final EditorArea edit = getEditor();
final BaseXFileChooser fc =
- new BaseXFileChooser(GUISAVEAS, edit.file.path(), gui);
+ new BaseXFileChooser(GUISAVEAS, edit.file().path(), gui);
fc.addFilter(CREATEXQEXDESC, IO.XQSUFFIXES);
final IOFile file = fc.select(BaseXFileChooser.Mode.FSAVE);
if(file == null) return false;
- edit.file = file;
- edit.setSyntax(file);
+ edit.file(file);
save(edit);
return true;
}
@@ -357,7 +356,7 @@ public EditorArea open(final IOFile file) {
try {
edit.setText(file.content());
edit.opened = true;
- edit.file = file;
+ edit.file(file);
gui.gprop.recent(file);
refresh(false, true);
if(gui.gprop.is(GUIProp.EXECRT)) edit.query();
@@ -472,7 +471,7 @@ void refresh(final boolean mod, final boolean force) {
refreshMark();
if(edit.mod == mod && !force) return;
- String title = edit.file.name();
+ String title = edit.file().name();
if(mod) title += "*";
edit.label.setText(title);
edit.mod = mod;
@@ -487,7 +486,7 @@ void refresh(final boolean mod, final boolean force) {
*/
EditorArea find(final IO file, final boolean opened) {
for(final EditorArea edit : editors()) {
- if(edit.file.eq(file) && (!opened || edit.opened)) return edit;
+ if(edit.file().eq(file) && (!opened || edit.opened)) return edit;
}
return null;
}
@@ -498,9 +497,9 @@ EditorArea find(final IO file, final boolean opened) {
*/
private void save(final EditorArea edit) {
try {
- edit.file.write(getEditor().getText());
+ edit.file().write(getEditor().getText());
edit.opened = true;
- gui.gprop.recent(edit.file);
+ gui.gprop.recent(edit.file());
refresh(false, true);
} catch(final IOException ex) {
Dialog.error(gui, NOTSAVED);
@@ -516,7 +515,7 @@ private IOFile newTabFile() {
final BoolList bl = new BoolList();
for(final EditorArea edit : editors()) {
if(edit.opened) continue;
- final String n = edit.file.name().substring(EDITORFILE.length());
+ final String n = edit.file().name().substring(EDITORFILE.length());
bl.set(true, n.isEmpty() ? 1 : Integer.parseInt(n));
}
// find first free file number
@@ -590,7 +589,7 @@ private BaseXButton tabButton(final String icon) {
private boolean confirm(final EditorArea edit) {
if(edit.mod) {
final Boolean ok = Dialog.yesNoCancel(gui,
- Util.info(XQUERYCONF, edit.file.name()));
+ Util.info(XQUERYCONF, edit.file().name()));
if(ok == null || ok && !save()) return false;
}
return true;
View
33 src/main/java/org/basex/io/BufferInput.java
@@ -16,6 +16,8 @@
/**
* This class serves as a buffered wrapper for textual input streams.
+ * In contrast to default input streams, the value {@code 0}
+ * (instead of {@code -1}) indicates the end of the stream.
*
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
@@ -29,6 +31,7 @@
protected int pos;
/** Input length. */
protected long length;
+
/** Current buffer size. */
private int size;
/** Number of read bytes. */
@@ -105,13 +108,13 @@ public final String encoding() {
/**
* Sets a new encoding.
- * @param e encoding
+ * @param encoding encoding
* @throws IOException IO Exception
*/
- public final void encoding(final String e) throws IOException {
+ public final void encoding(final String encoding) throws IOException {
try {
- enc = normEncoding(e, enc);
- csd = Charset.forName(e).newDecoder();
+ enc = normEncoding(encoding, enc);
+ csd = Charset.forName(encoding).newDecoder();
} catch(final Exception ex) {
throw new IOException(ex.toString());
}
@@ -123,7 +126,7 @@ public final int read() throws IOException {
}
/**
- * Returns the next byte, or 0 if all bytes have been read.
+ * Returns the next byte, or {@code 0} if all bytes have been read.
* @return next byte
* @throws IOException I/O exception
*/
@@ -136,20 +139,20 @@ public byte readByte() throws IOException {
}
/**
- * Reads a string from the input stream, suffixed by a 0 byte.
+ * Reads a string from the input stream, suffixed by a {@code 0} byte.
* @return string
* @throws IOException IO Exception
*/
public final String readString() throws IOException {
- return content().toString();
+ return token().toString();
}
/**
- * Reads a token from the input stream, suffixed by a 0 byte.
- * @return resulting byte list
+ * Reads a token from the input stream, suffixed by a {@code 0} byte.
+ * @return token
* @throws IOException IO Exception
*/
- public final ByteList content() throws IOException {
+ public final ByteList token() throws IOException {
final ByteList bl = new ByteList();
for(byte l; (l = readByte()) != 0;) bl.add(l);
return bl;
@@ -166,8 +169,8 @@ private void next() throws IOException {
}
/**
- * Returns the next character, 0 if all bytes have been read or
- * a negative character value -1 if the read byte is invalid.
+ * Returns the next character, or {@code 0} if all bytes have been read.
+ * Erroneous characters are ignored.
* @return next character
* @throws IOException I/O exception
*/
@@ -210,7 +213,7 @@ public final void close() throws IOException {
}
/**
- * Number of read bytes.
+ * Returns the number of read bytes.
* @return read bytes
*/
final int size() {
@@ -218,8 +221,8 @@ final int size() {
}
/**
- * Length of input.
- * @return read bytes
+ * Returns the input length.
+ * @return input length
*/
final long length() {
return length;
View
58 src/main/java/org/basex/io/IO.java
@@ -1,10 +1,7 @@
package org.basex.io;
-import java.io.BufferedInputStream;
import java.io.IOException;
-import java.io.InputStream;
import org.basex.data.Data;
-import org.basex.util.ByteList;
import org.basex.util.Token;
import org.xml.sax.InputSource;
@@ -40,6 +37,9 @@
/** ZIP suffixes. */
public static final String[] ZIPSUFFIXES =
{ ZIPSUFFIX, ".docx", ".pptx", ".xslx", ".odt", ".odp", ".ods", ".gz" };
+ /** XML suffixes. */
+ public static final String[] XMLSUFFIXES =
+ { XMLSUFFIX, ".xsl", ".xslt" };
/** HTML suffixes. */
public static final String[] HTMLSUFFIXES =
{ ".xhtml", ".html", ".htm" };
@@ -92,12 +92,27 @@ protected final void init(final String p) {
}
/**
- * Constructor.
- * @param s source
+ * <p>Returns an {@link IO} representation for the specified string. The type
+ * of the returned {@link IO} instance is dynamically chosen; it depends
+ * on the string value:</p>
+ * <ul>
+ * <li>{@link IOContent}: if the string starts with an angle bracket (&lt;)
+ * or if it is a {@code null} reference, it is interpreted as XML fragment
+ * and handled as byte array</li>
+ * <li>{@link IOFile}: if the string starts with <code>file:</code>, or if it
+ * does not contain the substring <code>://</code>, it is interpreted as
+ * local file instance</li>
+ * <li>{@link IOUrl}: otherwise, it is handled as URL</li>
+ * </ul>
+ * If the content of the string value is known in advance, it is advisable
+ * to call the direct constructors of the correspondent sub class.
+ *
+ * @param source source string
* @return IO reference
*/
- public static IO get(final String s) {
- if(s == null) return new IOFile("");
+ public static IO get(final String source) {
+ if(source == null) return new IOContent(Token.EMPTY);
+ final String s = source.trim();
if(s.startsWith("<")) return new IOContent(Token.token(s));
if(!s.contains("://") || s.startsWith(FILEPREF)) return new IOFile(s);
return new IOUrl(s);
@@ -175,13 +190,6 @@ public boolean more() throws IOException {
public abstract BufferInput buffer() throws IOException;
/**
- * Returns a simple input stream for the input.
- * @return input stream
- * @throws IOException I/O exception
- */
- public abstract InputStream inputStream() throws IOException;
-
- /**
* Merges two filenames.
* @param fn file name/path to be merged
* @return contents
@@ -197,6 +205,14 @@ public boolean archive() {
}
/**
+ * Checks if this file contains XML.
+ * @return result of check
+ */
+ public boolean xml() {
+ return false;
+ }
+
+ /**
* Chops the path and the file suffix of the specified filename
* and returns the database name.
* @return database name
@@ -260,18 +276,4 @@ public final boolean eq(final IO io) {
public<