/*
* JFolder, Copyright 2001-2006 Gary Steinmetz
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jfolder.common.function;
//base classes
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
//project specific classes
import org.jfolder.common.UnexpectedSystemException;
import org.jfolder.common.tagging.AppraiseConceptTagContext;
import org.jfolder.common.tagging.BaseAppraiseConceptTagContext;
import org.jfolder.common.tagging.ConceptTag;
import org.jfolder.common.tagging.ConceptTagCharacteristic;
import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
import org.jfolder.common.tagging.ConceptTagConstraint;
import org.jfolder.common.tagging.ConceptTagConstraintHolder;
import org.jfolder.common.tagging.ConceptTagPreferences;
import org.jfolder.common.tagging.RootConceptTagHolder;
import org.jfolder.common.utils.misc.MiscHelper;
import org.jfolder.common.utils.xml.XMLHelper;
//other classes
public class WebPageTagInstanceViewContext
extends BaseAppraiseConceptTagContext {
//
private ConceptTagPreferences parentCtp = null;
private WebPageTagInstanceViewContextInfo wptivci = null;
private WebPageTagInstanceViewContext(
ConceptTagPreferences inCtp) throws IOException {
//
super(null, null);
//
this.parentCtp = inCtp;
}
//
public final static WebPageTagInstanceViewContext newInstance(
ConceptTagPreferences inCtp) throws IOException {
return new WebPageTagInstanceViewContext(inCtp);
}
//
//
//
//
//
public WebPageTagInstanceViewContextInfo getInfoAsHtml() {
//String inDefaultConstraint) {
WebPageTagInstanceViewContextInfo outValue = this.wptivci;
outValue.markAsHtml();
//if (inDefaultConstraint != null) {
// outValue.setDefaultConstraint(inDefaultConstraint);
//}
return outValue;
}
//
public WebPageTagInstanceViewContextInfo getInfoAsNonHtml() {
//String inDefaultConstraint) {
WebPageTagInstanceViewContextInfo outValue = this.wptivci;
outValue.markAsNonHtml();
//if (inDefaultConstraint != null) {
// outValue.setDefaultConstraint(inDefaultConstraint);
//}
return outValue;
}
//
public WebPageTagInstanceViewContextInfo getInfoAsIterativeNonHtml() {
//String inDefaultConstraint) {
WebPageTagInstanceViewContextInfo outValue = this.wptivci;
outValue.markAsIterativeNonHtml();
//if (inDefaultConstraint != null) {
// outValue.setDefaultConstraint(inDefaultConstraint);
//}
return outValue;
}
//
//
public ConceptTagPreferences getPreferences() {
return this.parentCtp;
}
//
//
//
//
public final static WebPageTagInstanceViewContextInfo displayRootView(
RootConceptTagHolder inRcth, WebPageTagInstanceViewContext inWptivc) {
//
WebPageTagInstanceViewContextInfo outValue = null;
//
WebPageTagPreferences wptp = new WebPageTagPreferences();
//String idHandle[] = new String[]{wptp.getRootConstraint(), "0"};
outValue = WebPageTagInstanceViewContextInfo.createRootInfo();
// idHandle);
//
ConceptTagCharacteristic localCtchar =
inRcth.getFirstCharacteristic();
displayView(localCtchar, outValue, inWptivc);
return outValue;
}
//
//
//
public final static void displayView(
ConceptTagCharacteristic inCtchar,
WebPageTagInstanceViewContextInfo inWptivci,
WebPageTagInstanceViewContext inWptivc) {
//
displayView(inCtchar, inWptivci, inWptivc, "???");
}
public final static void displayView(
ConceptTagCharacteristic inCtchar,
WebPageTagInstanceViewContextInfo inWptivci,
WebPageTagInstanceViewContext inWptivc, String inZeroMessage) {
//
displayView(
inCtchar, inWptivci, inWptivc, 0, inCtchar.getValueLength(),
inZeroMessage);
}
public final static void displayView(
ConceptTagCharacteristic inCtchar,
WebPageTagInstanceViewContextInfo inWptivci,
WebPageTagInstanceViewContext inWptivc,
int inStartIndex, int inEndIndex) {
//
displayView(
inCtchar, inWptivci,inWptivc, inStartIndex, inEndIndex, "???");
}
public final static void displayView(
ConceptTagCharacteristic inCtchar,
WebPageTagInstanceViewContextInfo inWptivci,
WebPageTagInstanceViewContext inWptivc,
int inStartIndex, int inEndIndex, String inZeroMessage) {
//
//
//ArrayList idHandle = getPartialIdHandle(inCtchar);//null;
//if (inWptivci.getIdHandle().length > 0) {
// //
// idHandle = new ArrayList();
// //
// String localIdHandle[] = inWptivci.getIdHandle();
// for (int i = 0; i < localIdHandle.length; i++) {
// idHandle.add(localIdHandle[i]);
// }
//}
//else {
// idHandle = getPartialIdHandle(inCtchar);
//}
for (int i = inStartIndex; i < inEndIndex; i++) {
//
//idHandle.add(i + "");
//
//
WebPageTagInstanceViewContextInfo currentWptivci = null;
if (inWptivci.isMarkedAsHtml()) {
currentWptivci = inWptivci.createHtmlInfo(inCtchar, i, null);
}
else if (inWptivci.isMarkedAsNonHtml()) {
currentWptivci = inWptivci.createNonHtmlInfo(inCtchar, i, null);
}
else {
throw UnexpectedSystemException.unknownState();
}
//
//currentWptivci.setIdHandle(convertIdHandleToArray(idHandle));
//
//
WebPageTagInstanceViewContextInfo parentWptivci =
inWptivc.pushInfo(currentWptivci);
//
//
if (inCtchar.isStatic(i, inWptivc)) {
//
if (inWptivci.isMarkedAsHtml()) {
//
//currentWptivci = inWptivc.getInfoAsHtml(null);
String text = inCtchar.getValueAsString(i, inWptivc);
if (text.length() == 0) {
text = "(Empty String)";
}
//text = convertTextToHtml(text);
currentWptivci.setHtmlContent(text, false);
}
else if (inWptivci.isMarkedAsNonHtml()) {
//
//currentWptivci = inWptivc.getInfoAsNonHtml(null);
String text = inCtchar.getValueAsString(i, inWptivc);
if (text.length() == 0) {
text = "(Empty String)";
}
currentWptivci.setNonHtmlContent(text);
}
else {
throw UnexpectedSystemException.unknownState();
}
}
else if (inCtchar.isHolderWithConceptTag(i, inWptivc)) {
//
ConceptTagCharacteristicHolder nextCtcharh =
inCtchar.getValueAsHolder(i, inWptivc);
ConceptTag nextCt = nextCtcharh.getConceptTag();
//
//
nextCt.appraise(inWptivc);
//
}
else if (inCtchar.isHolderWithoutConceptTag(i, inWptivc)) {
//do nothing, handled by parent ConceptTag
}
else {
throw UnexpectedSystemException.unknownState();
}
//
//
inWptivc.popInfo(parentWptivci);
//
//
//
//idHandle.remove(idHandle.size() - 1);
//
}
//
if (inCtchar.getValueLength() == 0 && inZeroMessage != null) {
//
if (inWptivci.isMarkedAsHtml()) {
//
WebPageTagInstanceViewContextInfo currentWptivci =
inWptivci.createHtmlInfo(inCtchar.getConstraintName());
//
currentWptivci.setHtmlContent(inZeroMessage, false);
}
else if (inWptivci.isMarkedAsNonHtml()) {
//
WebPageTagInstanceViewContextInfo currentWptivci =
inWptivci.createNonHtmlInfo(inCtchar.getConstraintName());
//
currentWptivci.setNonHtmlContent(inZeroMessage);
}
else {
throw UnexpectedSystemException.unknownState();
}
}
}
private final static ArrayList getPartialIdHandle(
ConceptTagCharacteristic inCtchar) {
//
ArrayList outValue = new ArrayList();
ConceptTagCharacteristicHolder localCtcharh = null;
while ((localCtcharh == null || !localCtcharh.isConceptTagPresent())
&& !(inCtchar == null && localCtcharh == null)) {
//
if (inCtchar != null) {
outValue.add(0, inCtchar.getConstraintName());
localCtcharh = inCtchar.getParentCharacteristicHolder();
inCtchar = null;
}
else if (localCtcharh != null) {
//
//don't include root ctcharh's index
if (localCtcharh.getParentCharacteristic() != null) {
outValue.add(
0, localCtcharh.getParentCharacteristicIndex() + "");
}
inCtchar = localCtcharh.getParentCharacteristic();
localCtcharh = null;
}
else {
throw UnexpectedSystemException.unknownState();
}
}
//MiscHelper.println("WebPagTagInstViewCon parHandle = " + outValue);
return outValue;
}
private final static String[] convertIdHandleToArray(ArrayList inIdHandle) {
String outValue[] = new String[inIdHandle.size()];
for (int i = 0; i < inIdHandle.size(); i++) {
outValue[i] = ((String)inIdHandle.get(i));
}
return outValue;
}
//
//
//
private WebPageTagInstanceViewContextInfo pushInfo(
WebPageTagInstanceViewContextInfo inWptivci) {
//
WebPageTagInstanceViewContextInfo outValue = this.wptivci;
this.wptivci = inWptivci;
return outValue;
}
//
private void popInfo(WebPageTagInstanceViewContextInfo inParentWptivci) {
//
this.wptivci = inParentWptivci;
}
//
//
//
//
//
//
//
//
//
//
//
public final static String convertTextToHtml(String inValue) {
String outValue = inValue;
outValue = XMLHelper.fromStringToCData(outValue);
outValue = XMLHelper.fromStringToHTML(outValue);
outValue = substituteSpecialElements(outValue);
return outValue;
}
public final static String convertTextToStudioHtml(String inValue) {
String outValue = inValue;
//if (inValue == null) {
// MiscHelper.writeMessage(
// WebPageTagInstanceViewContext.class,
// "Null Found");
//}
outValue = XMLHelper.fromStringToCData(outValue);
outValue = XMLHelper.fromStringToHTML(outValue);
outValue = substituteStudioSpecialElements(outValue);
return outValue;
}
//
//private final static String substituteSpecialCharacters(String inData) {
//
// String outValue = null;
//
// outValue = inData;
//
// outValue = outValue.replaceAll(" ", XMLHelper.NBSP_CHAR + "");
//
// return outValue;
//}
//
private final static String substituteSpecialElements(String inData) {
String outValue = null;
outValue = inData;
//make sure Windows newline doesn't show up twice
outValue = outValue.replaceAll("\\r\\n", "\n");
outValue = outValue.replaceAll("\r", "<br/>");
outValue = outValue.replaceAll("\n", "<br/>");
return outValue;
}
private final static String substituteStudioSpecialElements(String inData) {
String outValue = null;
//
//carriage return symbol should be ↵
String replaceStr = "<span style=\"color: green\"><<</span><br/>";
outValue = inData;
//make sure Windows newline doesn't show up twice
outValue = outValue.replaceAll("\\r\\n", "\n");
outValue = outValue.replaceAll("\r", replaceStr);
outValue = outValue.replaceAll("\n", replaceStr);
return outValue;
}
}
|