Fixed encoding bug,Added writeString support,Started on config bean.

This commit is contained in:
Willem Cazander 2013-06-23 15:31:19 +02:00
parent 8d71b63a6f
commit 6f2815491b
20 changed files with 319 additions and 95 deletions

4
.gitignore vendored
View file

@ -65,3 +65,7 @@ nbproject
Thumbs.db
Desktop.ini
# Ignore kde dolphin files
.directory

View file

@ -13,7 +13,7 @@
- Add doc version upgrade handler;
- per version step xslt doc upgrade (check dyna sax piplining hooking)
- per version eld + support code + backing objects
- per version eld + support code + backing objects (DONE)
- per version eld for dyna tree convert to new backing objects.
- Add *Local layer for X4OLanguage* classes.
- Add default define (EL) layer

View file

@ -30,7 +30,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.x4o.xml.lang.X4OLanguageClassLoader;
import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.SAXException;
/**
@ -102,9 +104,7 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
if (resourceName==null) {
throw new NullPointerException("Can't read null resourceName from classpath.");
}
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) cl = getClass().getClassLoader(); // fallback
URL url = cl.getResource(resourceName);
URL url = X4OLanguageClassLoader.getResource(resourceName);
if (url==null) {
throw new NullPointerException("Could not find resource on classpath: "+resourceName);
}
@ -114,7 +114,7 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
baseUrl = baseUrl.substring(0,lastSlash+1);
}
URL basePath = new URL(baseUrl);
InputStream inputStream = cl.getResourceAsStream(resourceName);
InputStream inputStream = X4OLanguageClassLoader.getResourceAsStream(resourceName);
try {
return readContext(inputStream,url.toExternalForm(),basePath);
} finally {
@ -123,8 +123,8 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
}
/**
* Converts a String to a InputStream to is can me readd by SAX.
* @param xmlString The xml as String to read.
* Converts a String to a InputStream to is can me read by SAX.
* @param xmlString The xml as (UTF-8) String to read.
* @throws X4OConnectionException Is thrown after x4o exception.
* @throws SAXException Is thrown after sax xml exception.
* @throws IOException Is thrown after io exception.
@ -135,7 +135,8 @@ abstract public class AbstractX4OReaderContext<T> extends AbstractX4OConnection
throw new NullPointerException("Can't read null xml string.");
}
URL basePath = new File(System.getProperty("user.dir")).toURI().toURL();
return readContext(new ByteArrayInputStream(xmlString.getBytes()),"inline-xml",basePath);
String encoding = getLanguageContext().getLanguagePropertyString(X4OLanguageProperty.READER_INPUT_ENCODING);
return readContext(new ByteArrayInputStream(xmlString.getBytes(encoding)),"inline-xml",basePath);
}
/**

View file

@ -77,4 +77,8 @@ public abstract class AbstractX4OWriter<T> extends AbstractX4OWriterContext<T> i
public void writeFile(T object,File file) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
writeFileContext(toObjectContext(object), file);
}
public String writeString(T object) throws X4OConnectionException,SAXException,IOException,FileNotFoundException {
return writeStringContext(toObjectContext(object));
}
}

View file

@ -22,12 +22,14 @@
*/
package org.x4o.xml.io;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.x4o.xml.lang.X4OLanguageContext;
import org.x4o.xml.lang.X4OLanguageProperty;
import org.xml.sax.SAXException;
/**
@ -60,4 +62,11 @@ public abstract class AbstractX4OWriterContext<T> extends AbstractX4OConnection
outputStream.close();
}
}
public String writeStringContext(X4OLanguageContext context) throws X4OConnectionException,SAXException,IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
writeContext(context, out);
String encoding = context.getLanguagePropertyString(X4OLanguageProperty.WRITER_OUTPUT_ENCODING);
return out.toString(encoding);
}
}

View file

@ -41,4 +41,6 @@ public interface X4OWriter<T> extends X4OConnection {
void writeFile(T object,String fileName) throws X4OConnectionException,SAXException,IOException;
void writeFile(T object,File file) throws X4OConnectionException,SAXException,IOException;
String writeString(T object) throws X4OConnectionException,SAXException,IOException;
}

View file

@ -42,4 +42,6 @@ public interface X4OWriterContext<T> extends X4OWriter<T> {
void writeFileContext(X4OLanguageContext context,String fileName) throws X4OConnectionException,SAXException,IOException;
void writeFileContext(X4OLanguageContext context,File file) throws X4OConnectionException,SAXException,IOException;
String writeStringContext(X4OLanguageContext context) throws X4OConnectionException,SAXException,IOException;
}

View file

@ -83,6 +83,14 @@ public class AbstractContentWriterHandler implements ContentHandler {
prefixMapping = new HashMap<String,String>(15);
printedMappings = new ArrayList<String>(15);
elements = new Stack<String>();
/*
ContentConfig conf = new ContentConfig(
new ContentConfigItem("writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
new ContentConfigItem("content/writer/output/charTab",String.class)
);
conf.getPropertyString("");
*/
}
// TODO: check location of this. (add to api?)
@ -227,12 +235,8 @@ public class AbstractContentWriterHandler implements ContentHandler {
attributeValue = "null"; // TODO: Add null value key to config.
}
String attributeValueSafe = XMLConstants.escapeAttributeValue(attributeValue);
boolean printNewLine = attributeValueSafe.length()>80; // TODO add config
if (i==0) {
startElement.append(' ');
} else if (!printNewLine) {
startElement.append(' ');
}
if (XMLConstants.NULL_NS_URI.equals(attributeUri) | attributeUri ==null) {
startElement.append(attributeName);
} else {
@ -243,6 +247,7 @@ public class AbstractContentWriterHandler implements ContentHandler {
startElement.append("=\"");
startElement.append(attributeValueSafe);
startElement.append('"');
boolean printNewLine = attributeValueSafe.length()>80; // TODO add config
if (printNewLine) {
startElement.append(XMLConstants.CHAR_NEWLINE);
for (int ii = 0; ii < indent+1; ii++) {
@ -385,6 +390,10 @@ public class AbstractContentWriterHandler implements ContentHandler {
}
/**
* Prints xml ignorable whitespace.
*
* @param text The text to print.
* @throws SAXException When IOException has happend while printing.
* @see org.x4o.xml.io.sax.ext.ContentWriter#ignorableWhitespace(java.lang.String)
*/
public void ignorableWhitespace(String text) throws SAXException {
@ -395,6 +404,12 @@ public class AbstractContentWriterHandler implements ContentHandler {
write(text); // TODO: check chars
}
/**
* Prints xml ignorable whitespace character.
*
* @param c The character to print.
* @throws SAXException When IOException has happend while printing.
*/
public void ignorableWhitespace(char c) throws SAXException {
ignorableWhitespace(new char[]{c},0,1);
}
@ -462,6 +477,8 @@ public class AbstractContentWriterHandler implements ContentHandler {
}
/**
* Prints xml comment.
*
* @see org.x4o.xml.io.sax.ext.ContentWriter#comment(java.lang.String)
*/
public void comment(String text) throws SAXException {
@ -480,6 +497,11 @@ public class AbstractContentWriterHandler implements ContentHandler {
printReturn = true;
}
/**
* Checks if the value contains any new lines and sets the printReturn field.
*
* @param value The value to check.
*/
private void checkPrintedReturn(String value) {
if (value.indexOf(XMLConstants.CHAR_NEWLINE)>0) {
printReturn = true;

View file

@ -0,0 +1,158 @@
/*
* Copyright (c) 2004-2013, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.io.sax.ext;
import java.util.HashMap;
import java.util.Map;
/**
* ContentConfig Defines checked config options.
*
* @author Willem Cazander
* @version 1.0 May 1, 2013
*/
public final class ContentConfig {
private final ContentConfigItem[] items;
private final Map<String,Integer> itemKeys;
public ContentConfig(ContentConfigItem...items) {
this.items=items;
itemKeys = new HashMap<String,Integer>(items.length);
for (int i=0;i<items.length;i++) {
ContentConfigItem item = items[i];
itemKeys.put(item.getKey(),i);
}
}
public static final class ContentConfigItem {
private String key = null;
private Class<?> valueType = null;
private Object defaultValue = null;
private Object value = null;
public ContentConfigItem(String key,Class<?> valueType) {
this(key,valueType,null);
}
public ContentConfigItem(String key,Class<?> valueType,Object defaultValue) {
setKey(key);
setValueType(valueType);
setDefaultValue(defaultValue);
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key the key to set
*/
public void setKey(String key) {
this.key = key;
}
/**
* @return the valueType
*/
public Class<?> getValueType() {
return valueType;
}
/**
* @param valueType the valueType to set
*/
public void setValueType(Class<?> valueType) {
this.valueType = valueType;
}
/**
* @return the defaultValue
*/
public Object getDefaultValue() {
return defaultValue;
}
/**
* @param defaultValue the defaultValue to set
*/
public void setDefaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
}
/**
* @return the value
*/
public Object getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(Object value) {
this.value = value;
}
}
private final ContentConfigItem getContentConfigItem(String key) {
Integer keyIdx = itemKeys.get(key);
if (keyIdx==null) {
throw new IllegalArgumentException("Could not find config item for: "+key);
}
ContentConfigItem item = items[keyIdx];
return item;
}
public final void setProperty(String key,Object value) {
ContentConfigItem item = getContentConfigItem(key);
item.setValue(value);
}
public final Object getProperty(String key) {
ContentConfigItem item = getContentConfigItem(key);
return item.getValue();
}
public final boolean getPropertyBoolean(String key) {
ContentConfigItem item = getContentConfigItem(key);
Object value = item.getValue();
if (value instanceof Boolean) {
return (Boolean)value;
}
return (Boolean)item.getDefaultValue();
}
public final int getPropertyInteger(String key) {
ContentConfigItem item = getContentConfigItem(key);
Object value = item.getValue();
if (value instanceof Integer) {
return (Integer)value;
}
return (Integer)item.getDefaultValue();
}
public final String getPropertyString(String key) {
ContentConfigItem item = getContentConfigItem(key);
Object value = item.getValue();
if (value instanceof String) {
return (String)value;
}
return (String)item.getDefaultValue();
}
}

View file

@ -1,38 +0,0 @@
/*
* Copyright (c) 2004-2013, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.io.sax.ext;
/**
* ContentWriterConfig Defines config options for ContentWriter.
*
* @author Willem Cazander
* @version 1.0 May 1, 2013
*/
public interface ContentWriterConfig {
String getCharNewLine();
String getCharTab();
String getReplaceCdataStart();
String getReplaceCdataEnd();
}

View file

@ -22,6 +22,9 @@
*/
package org.x4o.xml.lang;
import java.io.InputStream;
import java.net.URL;
/**
* X4OLanguageClassLoader is short hand for safe class loading.
*
@ -82,4 +85,24 @@ public final class X4OLanguageClassLoader {
public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
return newInstance(loadClass(className));
}
/**
* Gets a resource from the classloader to an url.
* @param resourceName The resource to get from the classloader.
* @return The url to the resource or null if not found.
* @see java.lang.ClassLoader#getResource(String)
*/
public static URL getResource(String resourceName) {
return getClassLoader().getResource(resourceName);
}
/**
* Gets a resource from the classloader to an inputstream.
* @param resourceName The resource to get from the classloader.
* @return The inputstream to the resource or null if not found.
* @see java.lang.ClassLoader#getResourceAsStream(String)
*/
public static InputStream getResourceAsStream(String resourceName) {
return getClassLoader().getResourceAsStream(resourceName);
}
}

View file

@ -33,6 +33,7 @@ import java.util.Map;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import org.x4o.xml.io.XMLConstants;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
@ -60,7 +61,7 @@ public enum X4OLanguageProperty {
READER_INPUT_STREAM(IO.READER,"reader/input/stream",InputStream.class),
/** When set it overrides automatic encoding detection of sax parser. */
READER_INPUT_ENCODING(IO.READER,"reader/input/encoding",String.class),
READER_INPUT_ENCODING(IO.READER,"reader/input/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
/** When set use this InputSource instance for parsing. */
READER_INPUT_SOURCE(IO.READER,"reader/input/source",InputSource.class),
@ -107,7 +108,7 @@ public enum X4OLanguageProperty {
WRITER_OUTPUT_STREAM(IO.WRITER,"writer/output/stream",OutputStream.class),
/** The writer output encoding. */
WRITER_OUTPUT_ENCODING(IO.WRITER,"writer/output/encoding",String.class),
WRITER_OUTPUT_ENCODING(IO.WRITER,"writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
/** The writer output newline. */
WRITER_OUTPUT_CHAR_NEWLINE(IO.WRITER,"writer/output/char/newline",String.class),
@ -129,7 +130,7 @@ public enum X4OLanguageProperty {
SCHEMA_WRITER_OUTPUT_PATH(IO.SCHEMA_WRITER,"schema-writer/output/path",File.class),
/** The schema writer output encoding. */
SCHEMA_WRITER_OUTPUT_ENCODING(IO.SCHEMA_WRITER,"schema-writer/output/encoding",String.class),
SCHEMA_WRITER_OUTPUT_ENCODING(IO.SCHEMA_WRITER,"schema-writer/output/encoding",String.class,XMLConstants.XML_DEFAULT_ENCODING),
/** The schema writer output newline. */
SCHEMA_WRITER_OUTPUT_CHAR_NEWLINE(IO.SCHEMA_WRITER,"schema-writer/output/char/newline",String.class),

View file

@ -630,8 +630,8 @@ public class X4OPhaseLanguageRead {
return; // has already runned.
}
try {
//if (parser.hasX4ODebugWriter()) {
// parser.getX4ODebugWriter().debugElement(element);
//if (element.getLanguageContext().hasX4ODebugWriter()) {
// element.getLanguageContext().getX4ODebugWriter().debugElement(element);
//}
element.doElementRun();
} catch (ElementException e) {

View file

@ -22,6 +22,15 @@
*/
package org.x4o.xml.eld;
import org.x4o.xml.X4ODriver;
import org.x4o.xml.X4ODriverManager;
import org.x4o.xml.io.X4OReader;
import org.x4o.xml.io.X4OWriter;
import org.x4o.xml.lang.DefaultX4OLanguageModule;
import org.x4o.xml.lang.X4OLanguage;
import org.x4o.xml.lang.X4OLanguageLocal;
import org.x4o.xml.lang.X4OLanguageModule;
import junit.framework.TestCase;
/**
@ -95,10 +104,27 @@ public class EldParserTest extends TestCase {
}
public void testRunEldParser() throws Exception {
//EldDriver parser = new EldDriver(false);
//parser.parseResource("META-INF/test/test-lang.eld");
//X4ODriver<X4OLanguageModule> driver = (X4ODriver<X4OLanguageModule>)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
//X4OReader<X4OLanguageModule> reader = driver.createReader();
//reader.readResource("META-INF/test/test-lang.eld");
X4ODriver<X4OLanguageModule> driver = (X4ODriver<X4OLanguageModule>)X4ODriverManager.getX4ODriver(EldDriver.LANGUAGE_NAME);
X4OReader<X4OLanguageModule> reader = driver.createReader();
X4OWriter<X4OLanguageModule> writer = driver.createWriter();
X4OLanguage language = driver.createLanguage(driver.getLanguageVersionDefault());
X4OLanguageModule mod = new DefaultX4OLanguageModule();
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE_CONFIGURATION, language.getLanguageConfiguration());
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_LANGUAGE, language);
reader.addELBeanInstance(EldModuleLoader.EL_PARENT_ELEMENT_LANGUAGE_MODULE, mod);
X4OLanguageModule modNew = reader.readResource("META-INF/test/test-lang.eld");
//int binds = mod.getElementBindingHandlers().size();
//System.out.println(binds);
String output = writer.writeString(mod);
assertNotNull(output);
// TODO; fix element config+event to new interface + reserse for writing.
//System.out.println(output);
}
}

View file

@ -72,6 +72,7 @@
</eld:classBindingHandler>
</eld:elementInterface>
<!-- TODO: fix writer, run EldParserTest
<eld:configuratorGlobal bean.class="org.x4o.xml.test.element.TestElementConfigurator" id="testConfigGlobal">
<eld:description>Test the global element configurator.</eld:description>
</eld:configuratorGlobal>
@ -83,6 +84,7 @@
<eld:description>Test the global element attribute2 handler.</eld:description>
<eld:attributeHandlerNextAttribute attributeName="tt.attr1"/>
</eld:attributeHandler>
-->
<eld:namespace
uri="http://test.x4o.org/xml/ns/test-root"
@ -116,10 +118,12 @@
</eld:element>
<eld:element tag="configBean" objectClass="org.x4o.xml.test.models.TestBean">
<!-- TODO: fix writer
<eld:configurator bean.class="org.x4o.xml.test.element.TestElementConfigurator" id="testConfig1">
<eld:description>The test element config.</eld:description>
</eld:configurator>
<eld:configurator bean.class="org.x4o.xml.test.element.TestElementConfigurator" id="testConfig2"/>
-->
<eld:elementSkipPhase name="runAttributesPhase"/>
<eld:elementSkipPhase name="transformPhase"/>
</eld:element>

View file

@ -101,6 +101,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
List<String> navList = new ArrayList<String>(10);
Map<String,String> navLinks = new HashMap<String,String>(10);
Map<String,String> navNames = new HashMap<String,String>(10);
Map<String,String> navTitles = new HashMap<String,String>(10);
String pathPrefix;
String prev;
String next;
@ -169,15 +170,19 @@ public class ApiDocContentWriter extends ContentWriterHtml {
for (String navKey:conf.navList) {
String navName = conf.navNames.get(navKey);
String navLink = conf.navLinks.get(navKey);
String navTitle = conf.navTitles.get(navKey);
String selectedCss = null;
if (navKey.equals(conf.navSelected)) {
selectedCss = "navBarCell1Rev";
navLink = null; // disables link
}
if (navTitle==null) {
navTitle = navName;
}
if (navLink==null) {
printTagCharacters(Tag.li, navName, selectedCss);
} else {
docNavBarListItemHref(pathPrefix+navLink,navName,selectedCss);
docNavBarListItemHref(pathPrefix+navLink,navName,navTitle,selectedCss,null,null);
}
}
endElement("", "ul", "");
@ -203,12 +208,12 @@ public class ApiDocContentWriter extends ContentWriterHtml {
if (conf.prev==null) {
printTagCharacters(Tag.li, "Prev");
} else {
docNavBarListItemHref(pathPrefix+conf.prev,"Prev",null,"strong",null);
docNavBarListItemHref(pathPrefix+conf.prev,"Prev","Previous Item",null,"strong",null);
}
if (conf.next==null) {
printTagCharacters(Tag.li, "Next");
} else {
docNavBarListItemHref(pathPrefix+conf.next,"Next",null,"strong",null);
docNavBarListItemHref(pathPrefix+conf.next,"Next","Next Item",null,"strong",null);
}
printTagEnd(Tag.ul);
if (conf.frame!=null) {
@ -223,7 +228,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
}
if (conf.noFrameAllName!=null && conf.noFrameAllLink!=null) {
printTagStart(Tag.ul,ApiDocContentCss.navList,"allclasses_"+barId);
docNavBarListItemHref(pathPrefix+conf.noFrameAllLink,conf.noFrameAllName,null,null,null);
docNavBarListItemHref(pathPrefix+conf.noFrameAllLink,conf.noFrameAllName,null,null,null,null);
printTagEnd(Tag.ul);
printTagStart(Tag.div);
if (isTop) {
@ -233,6 +238,7 @@ public class ApiDocContentWriter extends ContentWriterHtml {
}
printTagEnd(Tag.div);
}
String tabSpace = "&nbsp;|&nbsp;";
boolean printLink = conf.linkConstructors || conf.linkFields || conf.linkMethods;
if (printLink) {
@ -241,13 +247,13 @@ public class ApiDocContentWriter extends ContentWriterHtml {
printTagStart(Tag.li);charactersRaw("Summary:&nbsp;");printTagEnd(Tag.li);
//printTagText(Tag.li,"Nested | "); // TODO: Nested
if (conf.linkFields) {
docNavBarListItemHref("#field_summary",conf.linkFieldName,null,null,tabSpace);
docNavBarListItemHrefLinkSpace("#field_summary",conf.linkFieldName);
} else {
printTagCharacters(Tag.li,conf.linkFieldName);charactersRaw(tabSpace);
}
if (conf.linkConstructors) {
docNavBarListItemHref("#constructor_summary",conf.linkConstructorName,null,null,tabSpace);
docNavBarListItemHrefLinkSpace("#constructor_summary",conf.linkConstructorName);
} else {
printTagCharacters(Tag.li,conf.linkConstructorName);charactersRaw(tabSpace);
}
@ -262,12 +268,12 @@ public class ApiDocContentWriter extends ContentWriterHtml {
printTagStart(Tag.li);charactersRaw("Detail:&nbsp;");printTagEnd(Tag.li);
//printTagText(Tag.li,"Nested | ");
if (conf.linkFields) {
docNavBarListItemHref("#field_detail",conf.linkFieldName,null,null,tabSpace);
docNavBarListItemHrefLinkSpace("#field_detail",conf.linkFieldName);
} else {
printTagCharacters(Tag.li,conf.linkFieldName);charactersRaw(tabSpace);
}
if (conf.linkConstructors) {
docNavBarListItemHref("#constructor_detail",conf.linkConstructorName,null,null,tabSpace);
docNavBarListItemHrefLinkSpace("#constructor_detail",conf.linkConstructorName);
} else {
printTagCharacters(Tag.li,conf.linkConstructorName);charactersRaw(tabSpace);
}
@ -286,12 +292,17 @@ public class ApiDocContentWriter extends ContentWriterHtml {
comment("========= END OF "+barComment+" NAVBAR =======");
}
private void docNavBarListItemHref(String href,String title,String cssClass) throws SAXException {
docNavBarListItemHref(href, title, cssClass, null, null);
private void docNavBarListItemHrefLinkSpace(String href,String title) throws SAXException {
String tabSpace = "&nbsp;|&nbsp;";
docNavBarListItemHref(href, title, title, null, null, tabSpace);
}
private void docNavBarListItemHref(String href,String title,String cssClass,String spanCss,String linkSpace) throws SAXException {
private void docNavBarListItemHref(String href,String title, String cssClass) throws SAXException {
docNavBarListItemHref(href, title, title, cssClass, null, null);
}
private void docNavBarListItemHref(String href,String title,String text,String cssClass,String spanCss,String linkSpace) throws SAXException {
printTagStart(Tag.li,cssClass);
printHref(href,title,title,spanCss);
printHref(href,title,text,spanCss);
charactersRaw(linkSpace);
printTagEnd(Tag.li);
}

View file

@ -24,7 +24,6 @@ package org.x4o.xml.eld.doc.api;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.x4o.xml.eld.doc.api.dom.ApiDoc;
@ -56,11 +55,11 @@ public class ApiDocNodeWriterBean implements ApiDocNodeWriter {
public ApiDocNodeWriterBean(ApiDocNodeBody nodeBody,Object bean,String method,Class<?>...classes) {
this();
this.nodeBody=nodeBody;
this.bean=bean;
this.method=method;
if (classes!=null && classes.length>0) {
targetClasses.addAll(Arrays.asList(classes));
setNodeBody(nodeBody);
setBean(bean);
setMethod(method);
for (Class<?> cl:classes) {
addtargetClass(cl);
}
}
@ -91,10 +90,10 @@ public class ApiDocNodeWriterBean implements ApiDocNodeWriter {
}
public void writeNodeContent(ApiDocWriteEvent<ApiDocNode> event) throws SAXException {
Class<?> beanClass = bean.getClass();
Class<?> beanClass = getBean().getClass();
try {
Method methodBean = beanClass.getMethod(method, new Class[]{ApiDocWriteEvent.class});
methodBean.invoke(bean, new Object[]{event});
Method methodBean = beanClass.getMethod(getMethod(), new Class[]{ApiDocWriteEvent.class});
methodBean.invoke(getBean(), new Object[]{event});
} catch (Exception e) {
throw new SAXException(e);
}

View file

@ -244,6 +244,7 @@ public class ApiDocWriter {
if (concept.getParent()!=null && !concept.getParent().getId().equals(doc.getRootNode().getId())) {
ApiDocConcept conceptParent = concept.getParent();
conf.navLinks.put(conceptParent.getId(), ApiDocContentWriter.toSafeUri(pathClean)+prefix+"/index.html");
conf.navTitles.put(conceptParent.getId(), conceptParent.getDescriptionName());
configActiveNavConceptLinks(conf,node,concept.getParent(),prefix+"/..");
}
}

View file

@ -60,11 +60,6 @@ public class ApiDoc {
treeNodeClassExcludes = new ArrayList<Class<?>>(5);
}
public ApiDoc(ApiDocNode rootNode) {
this();
setRootNode(rootNode);
}
public void checkModel() throws NullPointerException,IllegalArgumentException {
checkNull(name,"name");
checkNull(description,"description");
@ -79,16 +74,16 @@ public class ApiDoc {
throw new IllegalStateException("Can't work with empty nodeBodyWriters");
}
if (frameNavOverviewPrintParent==null) {
frameNavOverviewPrintParent=false;
setFrameNavOverviewPrintParent(false);
}
if (frameNavPrintParent==null) {
frameNavPrintParent=false;
setFrameNavPrintParent(false);
}
if (frameNavPrintParentParent==null) {
frameNavPrintParentParent=false;
setFrameNavPrintParentParent(false);
}
if (frameNavPrintParentId==null) {
frameNavPrintParentId=false;
setFrameNavPrintParentId(false);
}
}