[FOray-commit] SF.net SVN: foray:[12588] trunk/foray/foray-content
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-02-12 13:41:41
|
Revision: 12588
http://sourceforge.net/p/foray/code/12588
Author: victormote
Date: 2022-02-12 13:41:38 +0000 (Sat, 12 Feb 2022)
Log Message:
-----------
Add a ContentTree implementation.
Modified Paths:
--------------
trunk/foray/foray-content/build.gradle
Added Paths:
-----------
trunk/foray/foray-content/src/main/java/org/foray/content/ContentTree4a.java
Modified: trunk/foray/foray-content/build.gradle
===================================================================
--- trunk/foray/foray-content/build.gradle 2022-02-12 13:07:48 UTC (rev 12587)
+++ trunk/foray/foray-content/build.gradle 2022-02-12 13:41:38 UTC (rev 12588)
@@ -12,6 +12,8 @@
api (group: 'org.axsl', name: 'axsl-orthography', version: axslVersion) { transitive = false }
api (group: 'org.axsl', name: 'axsl-kp-model', version: axslVersion) { transitive = false }
+ api (project(':foray-common')) { transitive = false }
+
implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackClassicVersion
testImplementation group: 'junit', name: 'junit', version: junitVersion
Added: trunk/foray/foray-content/src/main/java/org/foray/content/ContentTree4a.java
===================================================================
--- trunk/foray/foray-content/src/main/java/org/foray/content/ContentTree4a.java (rev 0)
+++ trunk/foray/foray-content/src/main/java/org/foray/content/ContentTree4a.java 2022-02-12 13:41:38 UTC (rev 12588)
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2022 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.content;
+
+import org.foray.common.MarkedIndexOutOfBoundsException;
+import org.foray.common.para.ParaBranch4aIterator;
+
+import org.axsl.content.Content;
+import org.axsl.content.ContentTree;
+import org.axsl.kp.KpBranch;
+import org.axsl.kp.KpLeaf;
+import org.axsl.kp.KpNode;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * FOray implementation of {@link ContentTree}.
+ */
+public class ContentTree4a implements ContentTree {
+
+ /** The content item children of this tree. */
+ private List<Content> children = new ArrayList<Content>();
+
+ @Override
+ public Type getParaNodeType() {
+ return Type.BRANCH;
+ }
+
+ @Override
+ public int qtyParaNodes() {
+ int count = 0;
+ for (int index = 0; index < this.children.size(); index ++) {
+ final Content content = this.children.get(index);
+ if (content instanceof KpNode) {
+ count ++;
+ }
+ }
+ return count;
+ }
+
+ @Override
+ public KpNode paraNodeAt(final int nodeIndex) {
+ int count = 0;
+ for (int index = 0; index < this.children.size(); index ++) {
+ final Content content = this.children.get(index);
+ if (content instanceof KpNode) {
+ final KpNode node = (KpNode) content;
+ if (count == nodeIndex) {
+ return node;
+ }
+ count ++;
+ }
+ }
+ throw new MarkedIndexOutOfBoundsException(nodeIndex, qtyParaNodes());
+ }
+
+ @Override
+ public int qtyParaLeaves() {
+ int count = 0;
+ for (int index = 0; index < this.children.size(); index ++) {
+ final Content content = this.children.get(index);
+ if (content instanceof KpNode) {
+ final KpNode node = (KpNode) content;
+ count += node.qtyParaLeaves();
+ }
+ }
+ return count;
+ }
+
+ @Override
+ public KpLeaf paraLeafAt(final int leafIndex) {
+ int leafCount = 0;
+ for (int index = 0; index < this.children.size(); index ++) {
+ final Content content = this.children.get(index);
+ if (content instanceof KpNode) {
+ final KpNode node = (KpNode) content;
+ leafCount += node.qtyParaLeaves();
+ if (leafCount >= leafIndex) {
+ if (node instanceof KpLeaf) {
+ return (KpLeaf) node;
+ }
+ final KpBranch branch = (KpBranch) node;
+ final int localIndex = leafCount - leafIndex;
+ return branch.paraLeafAt(localIndex);
+ }
+ }
+ }
+ throw new MarkedIndexOutOfBoundsException(leafIndex, qtyParaLeaves());
+ }
+
+ @Override
+ public int qtyKpLeaves() {
+ int count = 0;
+ for (int index = 0; index < this.children.size(); index ++) {
+ final Content content = this.children.get(index);
+ if (content instanceof KpNode) {
+ final KpNode node = (KpNode) content;
+ count += node.qtyKpLeaves();
+ }
+ }
+ return count;
+ }
+
+ @Override
+ public ListIterator<KpLeaf> leafIterator() {
+ return new ParaBranch4aIterator(this);
+ }
+
+ @Override
+ public CharSequence getText() {
+ final StringBuilder builder = new StringBuilder();
+ for (int index = 0; index < this.children.size(); index ++) {
+ final Content content = this.children.get(index);
+ if (content instanceof KpNode) {
+ final KpNode node = (KpNode) content;
+ builder.append(node.getText());
+ }
+ }
+ return builder.toString();
+ }
+
+}
Property changes on: trunk/foray/foray-content/src/main/java/org/foray/content/ContentTree4a.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|