[FOray-commit] SF.net SVN: foray: [10452] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2008-03-19 19:55:21
|
Revision: 10452
http://foray.svn.sourceforge.net/foray/?rev=10452&view=rev
Author: victormote
Date: 2008-03-19 12:55:27 -0700 (Wed, 19 Mar 2008)
Log Message:
-----------
Rename font-related classes starting with "FOray" to instead end with "4a". This better distinguishes our classes from our modules and cleans up some naming in testing classes.
Modified Paths:
--------------
trunk/foray/doc/web/00-release/notes-unreleased.html
trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java
trunk/foray/foray-app/src/javatest/org/foray/app/area/AreaTreeCreator.java
trunk/foray/foray-app/src/javatest/org/foray/app/fo/FoDocumentReader.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/FOTreeBuilder.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/Namespace.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/HyphenationTree.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/MorphHyphenation.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/util/ValidateChars.java
trunk/foray/foray-hyphen/src/javatest/org/foray/hyphen/TestFOrayHyphenationServer.java
trunk/foray/foray-hyphen/src/javatest/org/foray/hyphen/util/TestNaturalLanguage.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXFormEps.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PDFXFormSvg.java
trunk/foray/foray-pdf/src/java/org/foray/pdf/object/PdfXFormMath.java
trunk/foray/foray-render/src/java/org/foray/render/ps/PSRenderer.java
trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java
trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java
trunk/foray/foray-text/src/java/org/foray/text/line/PatientLineBreaker.java
trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java
Added Paths:
-----------
trunk/foray/foray-areatree/src/java/org/foray/area/AreaTreeFactory4a.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/FoTreeServer4a.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/HyphenBreak4a.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/Hyphenation4a.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/HyphenationServer4a.java
trunk/foray/foray-ps/src/java/org/foray/ps/BoundingBox4a.java
trunk/foray/foray-text/src/java/org/foray/text/TextServer4a.java
Removed Paths:
-------------
trunk/foray/foray-areatree/src/java/org/foray/area/FOrayAreaTreeFactory.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/FOrayFOTreeServer.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenBreak.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenation.java
trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenationServer.java
trunk/foray/foray-ps/src/java/org/foray/ps/FOrayBoundingBox.java
trunk/foray/foray-text/src/java/org/foray/text/TextServer.java
Modified: trunk/foray/doc/web/00-release/notes-unreleased.html
===================================================================
--- trunk/foray/doc/web/00-release/notes-unreleased.html 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/doc/web/00-release/notes-unreleased.html 2008-03-19 19:55:27 UTC (rev 10452)
@@ -56,6 +56,8 @@
registered with the GraphicServer to do similar things for the supported output
formats. See GraphicServer4a.registerGraphicOutputFactory(GraphicOutputFactory
factory) for details.
+ <li>Renamed many classes that implement aXSL interfaces so that they end with "4a" instead of
+starting with "FOray".</li>
</li>
</ul>
Modified: trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java
===================================================================
--- trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-app/src/java/org/foray/app/FOraySpecific.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -28,14 +28,14 @@
package org.foray.app;
-import org.foray.area.FOrayAreaTreeFactory;
+import org.foray.area.AreaTreeFactory4a;
import org.foray.common.Logging;
import org.foray.common.url.URLFactory;
import org.foray.core.FOrayException;
import org.foray.core.FOraySession;
import org.foray.core.SessionConfig;
import org.foray.font.FontServer4a;
-import org.foray.fotree.FOrayFOTreeServer;
+import org.foray.fotree.FoTreeServer4a;
import org.foray.graphic.GraphicServer4a;
import org.foray.pioneer.PioneerFactory;
import org.foray.speech.SpeechServer4a;
@@ -158,7 +158,7 @@
*/
public static TextServer makeTextServer(final Log logger,
final HyphenationServer hyphenServer) throws FOrayException {
- return new org.foray.text.TextServer(logger, hyphenServer);
+ return new org.foray.text.TextServer4a(logger, hyphenServer);
}
/**
@@ -171,7 +171,7 @@
final SessionConfig configuration) {
final URL hyphenationDir =
configuration.optionHyphenationBaseDirectory();
- return new org.foray.hyphen.FOrayHyphenationServer(logger,
+ return new org.foray.hyphen.HyphenationServer4a(logger,
hyphenationDir);
}
@@ -203,7 +203,7 @@
final GraphicServer graphicServer, final TextServer textServer)
throws FOrayException {
final URL[] graphicSearchPath = buildGraphicSearchPath(configuration);
- return new FOrayFOTreeServer(logger, fontServer, textServer,
+ return new FoTreeServer4a(logger, fontServer, textServer,
graphicServer, graphicSearchPath,
configuration.optionCacheGraphics());
}
@@ -233,9 +233,9 @@
* @return The newly-created AreaTreeFactory instance.
* @throws FOrayException For errors creating the server.
*/
- public static FOrayAreaTreeFactory makeAreaTreeFactory(final Log logger)
+ public static AreaTreeFactory4a makeAreaTreeFactory(final Log logger)
throws FOrayException {
- return new FOrayAreaTreeFactory(logger);
+ return new AreaTreeFactory4a(logger);
}
/**
Modified: trunk/foray/foray-app/src/javatest/org/foray/app/area/AreaTreeCreator.java
===================================================================
--- trunk/foray/foray-app/src/javatest/org/foray/app/area/AreaTreeCreator.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-app/src/javatest/org/foray/app/area/AreaTreeCreator.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -31,11 +31,11 @@
import org.foray.app.FOraySpecific;
import org.foray.app.fo.FoDocumentReader;
import org.foray.area.AreaTree;
-import org.foray.area.FOrayAreaTreeFactory;
+import org.foray.area.AreaTreeFactory4a;
import org.foray.area.PageCollection;
import org.foray.core.FOrayException;
import org.foray.fotree.FOTreeBuilder;
-import org.foray.fotree.FOrayFOTreeServer;
+import org.foray.fotree.FoTreeServer4a;
import org.foray.fotree.fo.obj.PageSequence;
import org.foray.fotree.fo.obj.Root;
import org.foray.pioneer.PioneerFactory;
@@ -56,7 +56,7 @@
private static AreaTreeCreator theInstance;
/** The area tree factory. */
- private FOrayAreaTreeFactory areaTreeFactory;
+ private AreaTreeFactory4a areaTreeFactory;
/** The layout factory. */
private PioneerFactory layoutFactory;
@@ -68,9 +68,9 @@
* objects.
*/
private AreaTreeCreator() throws IOException, FOrayException {
- final FOrayFOTreeServer treeServer = FoDocumentReader.getInstance()
+ final FoTreeServer4a treeServer = FoDocumentReader.getInstance()
.getTreeServer();
- final FOrayAreaTreeFactory areaTreeFactory =
+ final AreaTreeFactory4a areaTreeFactory =
FOraySpecific.makeAreaTreeFactory(treeServer.getLogger());
this.areaTreeFactory = areaTreeFactory;
final PioneerFactory layoutFactory = FOraySpecific.makeLayoutFactory(
Modified: trunk/foray/foray-app/src/javatest/org/foray/app/fo/FoDocumentReader.java
===================================================================
--- trunk/foray/foray-app/src/javatest/org/foray/app/fo/FoDocumentReader.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-app/src/javatest/org/foray/app/fo/FoDocumentReader.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -36,7 +36,7 @@
import org.foray.core.FOrayException;
import org.foray.core.SessionConfig;
import org.foray.fotree.FOTreeBuilder;
-import org.foray.fotree.FOrayFOTreeServer;
+import org.foray.fotree.FoTreeServer4a;
import org.axsl.font.FontConsumer;
import org.axsl.font.FontServer;
@@ -72,7 +72,7 @@
private File testDirectory;
/** The tree server. */
- private FOrayFOTreeServer treeServer;
+ private FoTreeServer4a treeServer;
/**
* Constructor.
@@ -99,7 +99,7 @@
graphicSearchPath[0] = URLFactory.createURL(testDirUrl, "fo/");
final boolean cachingGraphics = false;
- this.treeServer = new FOrayFOTreeServer(logger, fontServer, textServer,
+ this.treeServer = new FoTreeServer4a(logger, fontServer, textServer,
graphicServer, graphicSearchPath, cachingGraphics);
}
@@ -161,7 +161,7 @@
* Returns the tree server.
* @return The tree server.
*/
- public FOrayFOTreeServer getTreeServer() {
+ public FoTreeServer4a getTreeServer() {
return this.treeServer;
}
Copied: trunk/foray/foray-areatree/src/java/org/foray/area/AreaTreeFactory4a.java (from rev 10074, trunk/foray/foray-areatree/src/java/org/foray/area/FOrayAreaTreeFactory.java)
===================================================================
--- trunk/foray/foray-areatree/src/java/org/foray/area/AreaTreeFactory4a.java (rev 0)
+++ trunk/foray/foray-areatree/src/java/org/foray/area/AreaTreeFactory4a.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2005 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.area;
+
+import org.axsl.area.AreaTreeFactory;
+import org.axsl.fo.fo.Root;
+
+import org.apache.commons.logging.Log;
+
+/**
+ * The top-level object in the FOTree implementation.
+ * FOTreeServer encapsulates the FOTree at a high level of abstraction for a
+ * client application.
+ */
+public class AreaTreeFactory4a implements AreaTreeFactory {
+
+ /** The logger. */
+ private Log logger;
+
+ /**
+ * Constructor.
+ * @param logger The logger.
+ */
+ public AreaTreeFactory4a(final Log logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public AreaTree makeAreaTree(final Root root) {
+ final AreaTree areaTree = AreaTree.makeAreaTree(root, getLogger());
+ return areaTree;
+ }
+
+ /**
+ * Returns the logger.
+ * @return The logger.
+ */
+ public Log getLogger() {
+ return this.logger;
+ }
+
+ /**
+ * Sets the logger to be used by AreaTree instances.
+ * If a new logger is needed for each AreaTree instance created, this method
+ * should be run before running {@link #makeAreaTree(Root)}.
+ * @param logger The new logger.
+ */
+ public void setLogger(final Log logger) {
+ this.logger = logger;
+ }
+
+}
Deleted: trunk/foray/foray-areatree/src/java/org/foray/area/FOrayAreaTreeFactory.java
===================================================================
--- trunk/foray/foray-areatree/src/java/org/foray/area/FOrayAreaTreeFactory.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-areatree/src/java/org/foray/area/FOrayAreaTreeFactory.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -1,80 +0,0 @@
-/*
- * Copyright 2005 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.area;
-
-import org.axsl.area.AreaTreeFactory;
-import org.axsl.fo.fo.Root;
-
-import org.apache.commons.logging.Log;
-
-/**
- * The top-level object in the FOTree implementation.
- * FOTreeServer encapsulates the FOTree at a high level of abstraction for a
- * client application.
- */
-public class FOrayAreaTreeFactory implements AreaTreeFactory {
-
- /** The logger. */
- private Log logger;
-
- /**
- * Constructor.
- * @param logger The logger.
- */
- public FOrayAreaTreeFactory(final Log logger) {
- this.logger = logger;
- }
-
- /**
- * {@inheritDoc}
- */
- public AreaTree makeAreaTree(final Root root) {
- final AreaTree areaTree = AreaTree.makeAreaTree(root, getLogger());
- return areaTree;
- }
-
- /**
- * Returns the logger.
- * @return The logger.
- */
- public Log getLogger() {
- return this.logger;
- }
-
- /**
- * Sets the logger to be used by AreaTree instances.
- * If a new logger is needed for each AreaTree instance created, this method
- * should be run before running {@link #makeAreaTree(Root)}.
- * @param logger The new logger.
- */
- public void setLogger(final Log logger) {
- this.logger = logger;
- }
-
-}
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/FOTreeBuilder.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/FOTreeBuilder.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/FOTreeBuilder.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -85,7 +85,7 @@
private ForeignXML activeForeignXML = null;
/** The parent server. */
- private FOrayFOTreeServer server;
+ private FoTreeServer4a server;
/** The logger. */
private Log logger;
@@ -118,7 +118,7 @@
* @param server The parent server.
* @param logger The logger.
*/
- public FOTreeBuilder(final FOrayFOTreeServer server, final Log logger) {
+ public FOTreeBuilder(final FoTreeServer4a server, final Log logger) {
this.server = server;
this.logger = logger;
}
@@ -495,7 +495,7 @@
* Return the "parent" FO Tree server.
* @return The FO Tree server.
*/
- public FOrayFOTreeServer getTreeServer() {
+ public FoTreeServer4a getTreeServer() {
return this.server;
}
Deleted: trunk/foray/foray-fotree/src/java/org/foray/fotree/FOrayFOTreeServer.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/FOrayFOTreeServer.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/FOrayFOTreeServer.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -1,306 +0,0 @@
-/*
- * Copyright 2005 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.fotree;
-
-import org.foray.common.ClassService;
-import org.foray.fotree.axsl.NamespaceAxsl;
-import org.foray.fotree.fo.NamespaceFO;
-import org.foray.fotree.foray.NamespaceForay;
-import org.foray.fotree.math.MathNamespace;
-import org.foray.fotree.svg.NamespaceSVG;
-import org.foray.fotree.xml.NamespaceXML;
-
-import org.axsl.fo.FoTreeFactory;
-import org.axsl.font.FontServer;
-import org.axsl.graphic.GraphicServer;
-import org.axsl.text.TextServer;
-
-import org.apache.commons.logging.Log;
-
-import java.net.URL;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The top-level object in the FOTree implementation.
- * FOTreeServer encapsulates the FOTree at a high level of abstraction for a
- * client application.
- */
-public class FOrayFOTreeServer implements FoTreeFactory {
-
- /** The logger. */
- private Log logger;
-
- /** The font server. */
- private FontServer fontServer;
-
- /** The graphic server. */
- private GraphicServer graphicServer;
-
- /** The text server. */
- private TextServer textServer;
-
- /** The array of URLs in which graphics should be searched. */
- private URL[] graphicSearchPath;
-
- /** Indicates whether we are caching graphics for reuse. */
- private boolean cachingGraphics;
-
- /** Map whose key is a String of the namespace URI, and whose value is
- * a Namespace instance that knows how to parse items in that namespace. */
- private Map<String, Namespace> namespaceMap
- = new HashMap<String, Namespace>();
-
- /** The "FO" namespace. */
- private NamespaceFO namespaceFO;
-
- /** The namespace to use for "foray" items. */
- private NamespaceForay namespaceForay;
-
- /** The namespace to use for "axsl" items. */
- private NamespaceAxsl namespaceAxsl;
-
- /** The "SVG" namespace. */
- private NamespaceSVG namespaceSVG;
-
- /** The "MathML" namespace. */
- private MathNamespace namespaceMath;
-
- /** The "XML namespace. */
- private NamespaceXML namespaceXML;
-
- /**
- * Constructor.
- * @param logger The logger.
- * @param fontServer The font server.
- * @param textServer The text server.
- * @param graphicServer The graphic server.
- * @param graphicSearchPath The array of URLs in which graphics should be
- * searched.
- * @param cachingGraphics Indicates whether we are caching graphics for
- * reuse.
- */
- public FOrayFOTreeServer(final Log logger,
- final FontServer fontServer,
- final TextServer textServer,
- final GraphicServer graphicServer,
- final URL[] graphicSearchPath,
- final boolean cachingGraphics) {
- this.logger = logger;
- this.fontServer = fontServer;
- this.graphicServer = graphicServer;
- this.textServer = textServer;
- this.graphicSearchPath = graphicSearchPath;
- this.cachingGraphics = cachingGraphics;
- setupNamespaces();
- }
-
- /**
- * Creates and registers the standard Namespace instances and those custom
- * namespaces that are embedded.
- */
- private void setupNamespaces() {
- // Register the standard Namespaces.
- final NamespaceFO fo = new NamespaceFO();
- registerNamespace(fo);
- this.namespaceFO = fo;
- final NamespaceXML xml = new NamespaceXML();
- registerNamespace(xml);
- this.namespaceXML = xml;
- final NamespaceSVG svg = new NamespaceSVG();
- registerNamespace(svg);
- this.namespaceSVG = svg;
- final MathNamespace math = new MathNamespace();
- this.registerNamespace(math);
- this.namespaceMath = math;
- final NamespaceForay extensions = new NamespaceForay();
- registerNamespace(extensions);
- this.namespaceForay = extensions;
- final NamespaceAxsl namespaceAxsl = new NamespaceAxsl();
- registerNamespace(namespaceAxsl);
- this.namespaceAxsl = namespaceAxsl;
-
- // Register custom embedded Namespaces from available services
- final List<String> providers = ClassService.providers(
- org.foray.fotree.Namespace.class);
- if (providers != null) {
- for (String str : providers) {
- try {
- final Namespace ns = createNonstandardNamespace(str);
- registerNamespace(ns);
- } catch (final IllegalArgumentException e) { }
- }
- }
- }
-
- /**
- * Add a Namespace instance to the list of namespaces that we should be
- * able to parse.
- * @param namespace A Namespace instance to be added.
- */
- public void registerNamespace(final Namespace namespace) {
- this.namespaceMap.put(namespace.getNamespaceURI(), namespace);
- }
-
- /**
- * Returns the namespace for a given name.
- * @param namespaceURI The namespace URI for which a namespace is needed.
- * @return The namespace instance.
- */
- public Namespace getNamespace(final String namespaceURI) {
- return this.namespaceMap.get(namespaceURI);
- }
-
- /**
- * Returns the namespace used for "FO" items.
- * @return The namespace used for "FO" items.
- */
- public NamespaceFO getFONamespace() {
- return this.namespaceFO;
- }
-
- /**
- * Returns the namespace used for extension items.
- * @return The namespace used for extension items.
- */
- public NamespaceForay getForayNamespace() {
- return this.namespaceForay;
- }
-
- /**
- * Returns the namespace used for "SVG" items.
- * @return The namespace used for "SVG" items.
- */
- public NamespaceSVG getSVGNamespace() {
- return this.namespaceSVG;
- }
-
- /**
- * Returns the namespace used for "MathML" items.
- * @return The namespace used for "MathML" items.
- */
- public MathNamespace getMathNamespace() {
- return this.namespaceMath;
- }
-
- /**
- * Returns the namespace used for "XML" items.
- * @return The namespace used for "XML" items.
- */
- public NamespaceXML getXMLNamespace() {
- return this.namespaceXML;
- }
-
- /**
- * Returns the namespace used for "axsl" items.
- * @return The namespace used for "axsl" items.
- */
- public NamespaceAxsl getAxslNamespace() {
- return this.namespaceAxsl;
- }
-
- /**
- * Returns the text property name for a given PropertyType instance.
- * @param propertyType The property type whose name is needed.
- * @return The text property name.
- */
- public String getPropertyName(final PropertyType propertyType) {
- final String propertyName = propertyType.toStringUnparsed();
- for (Namespace ns : this.namespaceMap.values()) {
- if (propertyName != null
- && ! propertyName.equals("")) {
- return ns.getTypicalPrefix() + ":" + propertyName;
- }
- }
- return null;
- }
-
- /**
- * Creates a Namespace instance for the given class name.
- * @param mappingClassName The name of the Namespace subclass for which
- * an instance should be created.
- * @return The namespace instance.
- */
- public Namespace createNonstandardNamespace(final String mappingClassName) {
- try {
- return (Namespace) Class.forName(mappingClassName).newInstance();
- } catch (final ClassNotFoundException e) {
- throw new IllegalArgumentException("Could not find "
- + mappingClassName);
- } catch (final InstantiationException e) {
- throw new IllegalArgumentException("Could not instantiate "
- + mappingClassName);
- } catch (final IllegalAccessException e) {
- throw new IllegalArgumentException("Could not access "
- + mappingClassName);
- } catch (final ClassCastException e) {
- throw new IllegalArgumentException(mappingClassName
- + " is not an ElementMapping");
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public FOTreeBuilder makeFoTree() {
- final FOTreeBuilder foTreeBuilder = new FOTreeBuilder(this,
- this.getLogger());
- foTreeBuilder.setGraphicServer(this.graphicServer);
- foTreeBuilder.setTextServer(this.textServer);
- foTreeBuilder.setGraphicSearchPath(this.graphicSearchPath);
- foTreeBuilder.setCachingGraphics(this.cachingGraphics);
- return foTreeBuilder;
- }
-
- /**
- * Returns the logger.
- * @return The logger.
- */
- public Log getLogger() {
- return this.logger;
- }
-
- /**
- * Returns the text server.
- * @return The text server.
- */
- public TextServer getTextServer() {
- return this.textServer;
- }
-
- /**
- * Returns the font server.
- * @return The font server.
- */
- public FontServer getFontServer() {
- return this.fontServer;
- }
-
-}
Copied: trunk/foray/foray-fotree/src/java/org/foray/fotree/FoTreeServer4a.java (from rev 10279, trunk/foray/foray-fotree/src/java/org/foray/fotree/FOrayFOTreeServer.java)
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/FoTreeServer4a.java (rev 0)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/FoTreeServer4a.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -0,0 +1,306 @@
+/*
+ * Copyright 2005 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fotree;
+
+import org.foray.common.ClassService;
+import org.foray.fotree.axsl.NamespaceAxsl;
+import org.foray.fotree.fo.NamespaceFO;
+import org.foray.fotree.foray.NamespaceForay;
+import org.foray.fotree.math.MathNamespace;
+import org.foray.fotree.svg.NamespaceSVG;
+import org.foray.fotree.xml.NamespaceXML;
+
+import org.axsl.fo.FoTreeFactory;
+import org.axsl.font.FontServer;
+import org.axsl.graphic.GraphicServer;
+import org.axsl.text.TextServer;
+
+import org.apache.commons.logging.Log;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The top-level object in the FOTree implementation.
+ * FOTreeServer encapsulates the FOTree at a high level of abstraction for a
+ * client application.
+ */
+public class FoTreeServer4a implements FoTreeFactory {
+
+ /** The logger. */
+ private Log logger;
+
+ /** The font server. */
+ private FontServer fontServer;
+
+ /** The graphic server. */
+ private GraphicServer graphicServer;
+
+ /** The text server. */
+ private TextServer textServer;
+
+ /** The array of URLs in which graphics should be searched. */
+ private URL[] graphicSearchPath;
+
+ /** Indicates whether we are caching graphics for reuse. */
+ private boolean cachingGraphics;
+
+ /** Map whose key is a String of the namespace URI, and whose value is
+ * a Namespace instance that knows how to parse items in that namespace. */
+ private Map<String, Namespace> namespaceMap
+ = new HashMap<String, Namespace>();
+
+ /** The "FO" namespace. */
+ private NamespaceFO namespaceFO;
+
+ /** The namespace to use for "foray" items. */
+ private NamespaceForay namespaceForay;
+
+ /** The namespace to use for "axsl" items. */
+ private NamespaceAxsl namespaceAxsl;
+
+ /** The "SVG" namespace. */
+ private NamespaceSVG namespaceSVG;
+
+ /** The "MathML" namespace. */
+ private MathNamespace namespaceMath;
+
+ /** The "XML namespace. */
+ private NamespaceXML namespaceXML;
+
+ /**
+ * Constructor.
+ * @param logger The logger.
+ * @param fontServer The font server.
+ * @param textServer The text server.
+ * @param graphicServer The graphic server.
+ * @param graphicSearchPath The array of URLs in which graphics should be
+ * searched.
+ * @param cachingGraphics Indicates whether we are caching graphics for
+ * reuse.
+ */
+ public FoTreeServer4a(final Log logger,
+ final FontServer fontServer,
+ final TextServer textServer,
+ final GraphicServer graphicServer,
+ final URL[] graphicSearchPath,
+ final boolean cachingGraphics) {
+ this.logger = logger;
+ this.fontServer = fontServer;
+ this.graphicServer = graphicServer;
+ this.textServer = textServer;
+ this.graphicSearchPath = graphicSearchPath;
+ this.cachingGraphics = cachingGraphics;
+ setupNamespaces();
+ }
+
+ /**
+ * Creates and registers the standard Namespace instances and those custom
+ * namespaces that are embedded.
+ */
+ private void setupNamespaces() {
+ // Register the standard Namespaces.
+ final NamespaceFO fo = new NamespaceFO();
+ registerNamespace(fo);
+ this.namespaceFO = fo;
+ final NamespaceXML xml = new NamespaceXML();
+ registerNamespace(xml);
+ this.namespaceXML = xml;
+ final NamespaceSVG svg = new NamespaceSVG();
+ registerNamespace(svg);
+ this.namespaceSVG = svg;
+ final MathNamespace math = new MathNamespace();
+ this.registerNamespace(math);
+ this.namespaceMath = math;
+ final NamespaceForay extensions = new NamespaceForay();
+ registerNamespace(extensions);
+ this.namespaceForay = extensions;
+ final NamespaceAxsl namespaceAxsl = new NamespaceAxsl();
+ registerNamespace(namespaceAxsl);
+ this.namespaceAxsl = namespaceAxsl;
+
+ // Register custom embedded Namespaces from available services
+ final List<String> providers = ClassService.providers(
+ org.foray.fotree.Namespace.class);
+ if (providers != null) {
+ for (String str : providers) {
+ try {
+ final Namespace ns = createNonstandardNamespace(str);
+ registerNamespace(ns);
+ } catch (final IllegalArgumentException e) { }
+ }
+ }
+ }
+
+ /**
+ * Add a Namespace instance to the list of namespaces that we should be
+ * able to parse.
+ * @param namespace A Namespace instance to be added.
+ */
+ public void registerNamespace(final Namespace namespace) {
+ this.namespaceMap.put(namespace.getNamespaceURI(), namespace);
+ }
+
+ /**
+ * Returns the namespace for a given name.
+ * @param namespaceURI The namespace URI for which a namespace is needed.
+ * @return The namespace instance.
+ */
+ public Namespace getNamespace(final String namespaceURI) {
+ return this.namespaceMap.get(namespaceURI);
+ }
+
+ /**
+ * Returns the namespace used for "FO" items.
+ * @return The namespace used for "FO" items.
+ */
+ public NamespaceFO getFONamespace() {
+ return this.namespaceFO;
+ }
+
+ /**
+ * Returns the namespace used for extension items.
+ * @return The namespace used for extension items.
+ */
+ public NamespaceForay getForayNamespace() {
+ return this.namespaceForay;
+ }
+
+ /**
+ * Returns the namespace used for "SVG" items.
+ * @return The namespace used for "SVG" items.
+ */
+ public NamespaceSVG getSVGNamespace() {
+ return this.namespaceSVG;
+ }
+
+ /**
+ * Returns the namespace used for "MathML" items.
+ * @return The namespace used for "MathML" items.
+ */
+ public MathNamespace getMathNamespace() {
+ return this.namespaceMath;
+ }
+
+ /**
+ * Returns the namespace used for "XML" items.
+ * @return The namespace used for "XML" items.
+ */
+ public NamespaceXML getXMLNamespace() {
+ return this.namespaceXML;
+ }
+
+ /**
+ * Returns the namespace used for "axsl" items.
+ * @return The namespace used for "axsl" items.
+ */
+ public NamespaceAxsl getAxslNamespace() {
+ return this.namespaceAxsl;
+ }
+
+ /**
+ * Returns the text property name for a given PropertyType instance.
+ * @param propertyType The property type whose name is needed.
+ * @return The text property name.
+ */
+ public String getPropertyName(final PropertyType propertyType) {
+ final String propertyName = propertyType.toStringUnparsed();
+ for (Namespace ns : this.namespaceMap.values()) {
+ if (propertyName != null
+ && ! propertyName.equals("")) {
+ return ns.getTypicalPrefix() + ":" + propertyName;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Creates a Namespace instance for the given class name.
+ * @param mappingClassName The name of the Namespace subclass for which
+ * an instance should be created.
+ * @return The namespace instance.
+ */
+ public Namespace createNonstandardNamespace(final String mappingClassName) {
+ try {
+ return (Namespace) Class.forName(mappingClassName).newInstance();
+ } catch (final ClassNotFoundException e) {
+ throw new IllegalArgumentException("Could not find "
+ + mappingClassName);
+ } catch (final InstantiationException e) {
+ throw new IllegalArgumentException("Could not instantiate "
+ + mappingClassName);
+ } catch (final IllegalAccessException e) {
+ throw new IllegalArgumentException("Could not access "
+ + mappingClassName);
+ } catch (final ClassCastException e) {
+ throw new IllegalArgumentException(mappingClassName
+ + " is not an ElementMapping");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public FOTreeBuilder makeFoTree() {
+ final FOTreeBuilder foTreeBuilder = new FOTreeBuilder(this,
+ this.getLogger());
+ foTreeBuilder.setGraphicServer(this.graphicServer);
+ foTreeBuilder.setTextServer(this.textServer);
+ foTreeBuilder.setGraphicSearchPath(this.graphicSearchPath);
+ foTreeBuilder.setCachingGraphics(this.cachingGraphics);
+ return foTreeBuilder;
+ }
+
+ /**
+ * Returns the logger.
+ * @return The logger.
+ */
+ public Log getLogger() {
+ return this.logger;
+ }
+
+ /**
+ * Returns the text server.
+ * @return The text server.
+ */
+ public TextServer getTextServer() {
+ return this.textServer;
+ }
+
+ /**
+ * Returns the font server.
+ * @return The font server.
+ */
+ public FontServer getFontServer() {
+ return this.fontServer;
+ }
+
+}
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/Namespace.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/Namespace.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/Namespace.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -296,7 +296,7 @@
* parser & ignored by us. */
continue;
}
- final FOrayFOTreeServer treeServer = builder.getTreeServer();
+ final FoTreeServer4a treeServer = builder.getTreeServer();
final String namespaceURI = attributes.getURI(i);
Namespace namespace = null;
if (namespaceURI == null
Deleted: trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenBreak.java
===================================================================
--- trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenBreak.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenBreak.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -1,143 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-/*
- * Known contributors:
- * Carlos Villegas <ca...@un...> (Original author), who credited
- * TeX for the basic scheme.
- */
-
-package org.foray.hyphen;
-
-import org.foray.common.WKConstants;
-
-import org.axsl.hyphen.HyphenBreak;
-
-import java.io.Serializable;
-
-/**
- * <p>Specialized information about a specific hyphenation break opportunity in
- * a word.
- * This handles "hard" hyphenation cases, such as those where the word changes
- * spelling when it is hyphenated.
- * See {@link org.axsl.hyphen.HyphenBreak} for more information about the
- * general use of this class.</p>
- *
- * <p>A 'full' hyphen is made of 3 parts:
- * the pre-break text, post-break text and no-break. If no line-break
- * is generated at this position, the no-break text is used, otherwise,
- * pre-break and post-break are used. Typically, pre-break is equal to
- * the hyphen character and the others are empty.</p>
- */
-public class FOrayHyphenBreak implements Serializable, HyphenBreak {
-
- /** Constant needed for serialization. */
- private static final long serialVersionUID = 990405609314441965L;
-
- /** The pre-break text. */
- private String preBreak;
-
- /** The no-break text. */
- private String noBreak;
-
- /** The post-break text. */
- private String postBreak;
-
- /**
- * Constructor.
- * @param pre The pre-break text.
- * @param no The no-break text (can be null).
- * @param post The post-break text (can be null).
- */
- FOrayHyphenBreak(final String pre, final String no, final String post) {
- this.preBreak = pre;
- this.noBreak = no;
- this.postBreak = post;
- }
-
- /**
- * {@inheritDoc}
- */
- public String toString() {
- if (this.noBreak == null
- && this.postBreak == null
- && this.preBreak != null
- && this.preBreak.equals("-")) {
- return "-";
- }
- final StringBuilder res = new StringBuilder("{");
- res.append(this.preBreak);
- res.append("}{");
- res.append(this.postBreak);
- res.append("}{");
- res.append(this.noBreak);
- res.append('}');
- return res.toString();
- }
-
- /**
- * Returns the "no break" String.
- * @return Returns the noBreak.
- */
- public String getNoBreak() {
- return this.noBreak;
- }
-
- /**
- * {@inheritDoc}
- */
- public String preDelete() {
- /* TODO: Implement this. */
- return WKConstants.EMPTY_STRING;
- }
-
- /**
- * {@inheritDoc}
- */
- public String preInsert() {
- /* TODO: Implement this. */
- return WKConstants.EMPTY_STRING;
- }
-
- /**
- * {@inheritDoc}
- */
- public String postDelete() {
- /* TODO: Implement this. */
- return WKConstants.EMPTY_STRING;
- }
-
- /**
- * {@inheritDoc}
- */
- public String postInsert() {
- /* TODO: Implement this. */
- return WKConstants.EMPTY_STRING;
- }
-
-}
Deleted: trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenation.java
===================================================================
--- trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenation.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenation.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -1,205 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-/*
- * Known contributors:
- * Carlos Villegas <ca...@un...> (original author)
- */
-
-package org.foray.hyphen;
-
-import org.axsl.hyphen.HyphenBreak;
-import org.axsl.hyphen.HyphenationException;
-
-import java.io.Serializable;
-
-/**
- * This class represents a hyphenated word.
- */
-public class FOrayHyphenation implements org.axsl.hyphen.Hyphenation,
- Serializable {
-
- /** Constant needed for serialization. */
- static final long serialVersionUID = -576778461126231672L;
-
- /** The word being hyphenated. */
- private String word;
-
- /** The hyphenation points for the word. See {@link #hyphenValues} for the
- * weights. */
- private byte[] hyphenPoints;
-
- /** The Liang weights that correspond to {@link #hyphenPoints}. */
- private byte[] hyphenValues;
-
- /**
- * Constructor for already-computed hyphenation points.
- * @param word The word being hyphenated.
- * @param points The hyphenation points for the word.
- * @param values The Liang weights that correspond to
- * <code>hyphenPoints</code>.
- */
- FOrayHyphenation(final String word, final byte[] points,
- final byte[] values) {
- this.word = word;
- this.hyphenPoints = points;
- this.hyphenValues = values;
- }
-
- /**
- * Factory class to create the correct variant of this class.
- * @param word The word being hyphenated.
- * @param points The hyphenation points for the word.
- * @param values The Liang weights that correspond to
- * <code>hyphenPoints</code>.
- * @param qtySpecialBreaks The number of morphing breaks that will be
- * added to this hyphenation.
- * @return The newly created {@link FOrayHyphenation} variant.
- */
- static FOrayHyphenation makeHyphenation(final String word,
- final byte[] points, final byte[] values,
- final int qtySpecialBreaks) {
- if (qtySpecialBreaks > 0) {
- try {
- return new MorphHyphenation(word, points, values,
- qtySpecialBreaks);
- } catch (final HyphenationException e) {
- /* Ignore this. It can't happen. */
- }
- }
- return new FOrayHyphenation(word, points, values);
- }
-
- /**
- * {@inheritDoc}
- */
- public byte[] getPoints() {
- return this.hyphenPoints;
- }
-
- /**
- * {@inheritDoc}
- */
- public byte[] getLiangWeights() {
- return this.hyphenValues;
- }
-
- /**
- * {@inheritDoc}
- */
- public byte[] getWeights() {
- if (this.hyphenValues == null) {
- return null;
- }
- final byte[] returnArray = new byte[this.hyphenValues.length];
- for (int i = 0; i < this.hyphenValues.length; i++) {
- final byte value = this.hyphenValues[i];
- try {
- returnArray[i] = convertLiangToWeight(value);
- } catch (final HyphenationException e) {
- /* TODO: This exception should be passed upstream further. */
- returnArray[i] = Byte.MIN_VALUE;
- }
- }
- return returnArray;
- }
-
- /**
- * {@inheritDoc}
- */
- public String toString() {
- final StringBuilder str = new StringBuilder();
- int start = 0;
- for (int i = 0; i < this.hyphenPoints.length; i++) {
- str.append(this.word.substring(start, this.hyphenPoints[i]) + "-");
- start = this.hyphenPoints[i];
- }
- str.append(this.word.substring(start));
- return str.toString();
- }
-
- /**
- * Converts the raw value from the Liang data to a weighted value.
- * In the Liang system, 1) even values are negative, 2) odd values are
- * positive, and the magnitude of the number conveys the magnitude of
- * the direction.
- * @param liangValue Any positive byte value that contains a Liang-style
- * algorithm weight. (Liang input is only in the range 0 to 5, but we will
- * handle any positive input).
- * @return A value that reflects the numeric weight of the raw Liang value.
- * @throws HyphenationException For an invalid <code>liangValue</code>.
- */
- public static byte convertLiangToWeight(final byte liangValue)
- throws HyphenationException {
- if (liangValue < 0) {
- throw new HyphenationException("Invalid Liang input: "
- + liangValue);
- }
- byte modifiedLiangValue = liangValue;
- /* Save the low-order bit. */
- final boolean good = (modifiedLiangValue & 1) == 1;
- modifiedLiangValue ++;
- modifiedLiangValue /= 2;
- if (! good) {
- modifiedLiangValue *= -1;
- }
- return modifiedLiangValue;
- }
-
- /**
- * {@inheritDoc}
- */
- public HyphenBreak getHyphenBreak(final int index) {
- /* Not supported by this class. See {@link MorphHyphenation} where this
- * is implemented. */
- return null;
- }
-
- /**
- * Takes exception input like "oblig-a-tory" and converts it to the
- * unhyphenated equivalent, that is "obligatory", so that it can be used
- * for searches on input words.
- * @param exceptionWord The hyphenated exception.
- * @param hyphenationChar The character used in the exception to signify
- * a hyphenation opportunity. This may be different from the character used
- * to show the hyphenation point in the output.
- * @return The unhyphenated equivalent of <code>exceptionWord</code>.
- */
- public static String normalizeException(final String exceptionWord,
- final char hyphenationChar) {
- final StringBuilder builder = new StringBuilder();
- for (int j = 0; j < exceptionWord.length(); j++) {
- final char c = exceptionWord.charAt(j);
- if (c != hyphenationChar) {
- builder.append(c);
- }
- }
- return builder.toString();
- }
-
-}
Deleted: trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenationServer.java
===================================================================
--- trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenationServer.java 2008-03-19 19:03:20 UTC (rev 10451)
+++ trunk/foray/foray-hyphen/src/java/org/foray/hyphen/FOrayHyphenationServer.java 2008-03-19 19:55:27 UTC (rev 10452)
@@ -1,649 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-/*
- * Known contributors:
- * @author Carlos Villegas <ca...@un...> (original author)
- */
-
-package org.foray.hyphen;
-
-import org.foray.common.FOrayConstants;
-import org.foray.common.Logging;
-import org.foray.common.url.URLFactory;
-import org.foray.hyphen.util.NatLangParser;
-import org.foray.hyphen.util.NaturalLanguage;
-
-import org.axsl.common.value.Iso3166;
-import org.axsl.common.value.Iso639;
-import org.axsl.hyphen.HyphenationException;
-
-import org.apache.commons.logging.Log;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * This class is the main entry point to the hyphenation package.
- */
-public class FOrayHyphenationServer
- implements org.axsl.hyphen.HyphenationServer {
-
- /** The path to the hyphenation patterns. */
- public static final String PATTERN_RESOURCE_PATH =
- "org/foray/hyphen/resource/patterns";
-
- /** Standard text for some user messages. */
- private static final String PATTERN_MISSING_TEXT =
- "Hyphenation pattern not found: ";
-
- /** The logger. */
- private Log logger;
-
- /**
- * Collection of HyphenationTree instances that have been successfully
- * deserialized or parsed. The key is the language or language and country
- * connected by an underscore (e.g. en_US).
- */
- private Map<String, HyphenationTree> hyphenTrees
- = new HashMap<String, HyphenationTree>();
-
- /**
- * Collection of language and language_country combinations for which we
- * already know we can't instantiate a HyphenationTree. This is used to
- * log only one error message per language.
- */
- private List<String> hyphenTreesNotFound = new ArrayList<String>();
-
- /** The hyphenation directory. */
- private URL hyphenationDir;
-
- /** Map of all Natural Language instances. */
- private Map<Iso639, NaturalLanguage> languages =
- new HashMap<Iso639, NaturalLanguage>();
-
- /**
- * Constructor.
- * @param logger The Log instance for user messages. Null can safely be
- * passed here as a default logger will be created by the server.
- * @param hyphenationDir The base URL for hyphenation patterns.
- */
- public FOrayHyphenationServer(final Log logger, final URL hyphenationDir) {
- if (logger == null) {
- this.logger = Logging.makeDefaultLogger();
- } else {
- this.logger = logger;
- }
- this.hyphenationDir = hyphenationDir;
- }
-
- /**
- * The main search algorithm.
- * @param rawLanguageCode The language code for which a hyphenation tree is
- * needed.
- * @param rawCountryCode The country code for which a hyphenation tree is
- * needed. This is a differentiator between hyphenation schemes within the
- * same language, and may be null.
- * @return The hyphenation tree if it exists, or null otherwise.
- * @throws HyphenationException For errors retrieving the hyphenation tree.
- */
- private HyphenationTree getHyphenationTree(final Iso639 rawLanguageCode,
- final Iso3166 rawCountryCode) throws HyphenationException {
-
- /* Bail out if the language code is null. */
- if (rawLanguageCode == null
- || rawLanguageCode.equals(Iso639.UNDETERMINED)
- || rawLanguageCode.equals(Iso639.NULL)) {
- return null;
- }
-
- /* Normalize the input. */
- final String languageKey = rawLanguageCode.getAbbrev3().toLowerCase();
- final String countryKey = buildCountryKey(languageKey, rawCountryCode);
-
- /* Look for the countryKey in all possible locations before looking
- * for the languageKey, because the countryKey is more specific. */
- HyphenationTree tree = this.findTreeForKey(countryKey, rawLanguageCode,
- rawCountryCode);
- if (tree != null) {
- return tree;
- }
- tree = this.findTreeForKey(languageKey, rawLanguageCode,
- rawCountryCode);
- return tree;
- }
-
- /**
- * Tries to find a hyphenation tree for a specific key in all possible
- * locations.
- * @param key The language- or country-key for which the tree is sought.
- * @param language The language code (used for user messages).
- * @param country The country code (used for user messages).
- * @return The HyphenationTree if it is found, or null if it is not found.
- * @throws HyphenationException For errors retrieving the hyphenation tree.
- */
- private HyphenationTree findTreeForKey(final String key,
- final Iso639 language, final Iso3166 country)
- throws HyphenationException {
- if (key == null) {
- return null;
- }
-
- /* Look in the cache first. */
- if (this.hyphenTrees.containsKey(key)) {
- return this.hyphenTrees.get(key);
- }
-
- /* If we have already tried and failed, no need to check again. */
- for (int i = 0; i < this.hyphenTreesNotFound.size(); i++) {
- final String testKey = this.hyphenTreesNotFound.get(i);
- if (testKey.equals(key)) {
- return null;
- }
- }
-
- /* If it is available as a resource (i.e. in our classpath), return
- * it. */
- HyphenationTree hyphenationTree = getHyphenationTree(key);
- if (hyphenationTree != null) {
- this.hyphenTrees.put(key, hyphenationTree);
- return hyphenationTree;
- }
-
- /* If the XML file is in the hyphenation-base-directory, parse it and
- * use it. */
- hyphenationTree = loadHyphenationTree(key);
- if (hyphenationTree != null) {
- this.hyphenTrees.put(key, hyphenationTree);
- return hyphenationTree;
- }
-
- final StringBuilder warningMessage = new StringBuilder(
- FOrayHyphenationServer.PATTERN_MISSING_TEXT
- + key + " (" + language.getEnglishName());
- if (country != null
- && country != Iso3166.NULL) {
- warningMessage.append(", " + country.getEnglishName());
- }
- warningMessage.append(")");
- /* Log a warning and add it to the list of not found keys. */
- getLogger().warn(warningMessage);
- this.hyphenTreesNotFound.add(key);
- return null;
- }
-
- /**
- * Tries to find a given serialized hyphenation tree and return it as an
- * InputStream so that it can be deserialized.
- * @param key The language or language/country combination whose hyphenation
- * tree is sought.
- * @return The serialized hyphenation tree as an InputStream, or null if the
- * serialized hyphenation tree is not found.
- */
- private InputStream getResourceStream(final String key) {
- InputStream is = null;
- // Try to use Context Class Loader to load the properties file.
- try {
- final Method getCCL =
- Thread.class.getMethod("getContextClassLoader", new Class[0]);
- if (getCCL != null) {
- final ClassLoader contextClassLoader =
- (ClassLoader) getCCL.invoke(Thread.currentThread(),
- new Object[0]);
- is = contextClassLoader.getResourceAsStream(
- FOrayHyphenationServer.PATTERN_RESOURCE_PATH
- + "/" + key
- + "." + FOrayConstants.BINARY_SERIALIZATION_EXTENSION);
- }
- } catch (final Exception e) { }
-
- if (is == null) {
- is = FOrayHyphenationServer.class.getResourceAsStream(
- "/" + FOrayHyphenationServer.PATTERN_RESOURCE_PATH
- + "/" + key
- + "." + FOrayConstants.BINARY_SERIALIZATION_EXTENSION);
- }
-
- return is;
- }
-
- /**
- * Tries to find and deserialize a hyphenation tree.
- * @param key The language or language/country combination whose hyphenation
- * tree is sought.
- * @return The deserialized hyphenation tree, or null if the tree is not
- * found.
- */
- private HyphenationTree getHyphenationTree(final String key) {
- HyphenationTree hTree = null;
- ObjectInputStream ois = null;
- InputStream is = null;
- try {
- is = getResourceStream(key);
- if (is == null) {
- return null;
- }
- ois = new ObjectInputStream(is);
- hTree = (HyphenationTree) ois.readObject();
- } catch (final Exception e) {
- e.printStackTrace();
- } finally {
- if (ois != null) {
- try {
- ois.close();
- } catch (final IOException e) {
- getLogger().error("can't close hyphenation object stream");
- }
- }
- }
- return hTree;
- }
-
- /**
- * Load a tree from serialized file or xml file using configuration
- * settings.
- * @param key The country key or language key whose pattern is sought.
- * @return The specified hyphenation tree if it exists as a serialized
- * object or as an XML file, or null otherwise.
- * @throws HyphenationException For errors finding, deserializing, or
- * parsing the pattern files.
- */
- private HyphenationTree loadHyphenationTree(final String key)
- throws HyphenationException {
- if (this.hyphenationDir == null) {
- return null;
- }
- HyphenationTree hTree = null;
-
- /* Use the key as the base name for the file. */
-
- /* First look for the serialized object. */
- ...
[truncated message content] |