diff --git a/src/main/java/org/dita/dost/ant/DITAOTCopy.java b/src/main/java/org/dita/dost/ant/DITAOTCopy.java index 0154f6ec95..185107f1c3 100644 --- a/src/main/java/org/dita/dost/ant/DITAOTCopy.java +++ b/src/main/java/org/dita/dost/ant/DITAOTCopy.java @@ -17,7 +17,6 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.apache.tools.ant.BuildException; diff --git a/src/main/java/org/dita/dost/ant/ExtensibleAntInvoker.java b/src/main/java/org/dita/dost/ant/ExtensibleAntInvoker.java index 52be8ba005..b2b1c02bd0 100644 --- a/src/main/java/org/dita/dost/ant/ExtensibleAntInvoker.java +++ b/src/main/java/org/dita/dost/ant/ExtensibleAntInvoker.java @@ -308,10 +308,7 @@ private static Predicate combine(final Collection if (filters.isEmpty()) { return f -> true; } - final List> res = filters - .stream() - .map(FileInfoFilterElem::toFilter) - .collect(Collectors.toList()); + final List> res = filters.stream().map(FileInfoFilterElem::toFilter).toList(); return f -> { for (final Predicate filter : res) { if (filter.test(f)) { diff --git a/src/main/java/org/dita/dost/ant/types/JobMapper.java b/src/main/java/org/dita/dost/ant/types/JobMapper.java index 8b30db3cb0..7a26069bda 100644 --- a/src/main/java/org/dita/dost/ant/types/JobMapper.java +++ b/src/main/java/org/dita/dost/ant/types/JobMapper.java @@ -7,18 +7,15 @@ */ package org.dita.dost.ant.types; -import static org.dita.dost.util.Constants.ANT_TEMP_DIR; import static org.dita.dost.util.URLUtils.toFile; import static org.dita.dost.util.URLUtils.toURI; -import java.io.File; import java.net.URI; import java.util.Arrays; -import java.util.stream.Collectors; import org.apache.commons.io.FilenameUtils; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.EnumeratedAttribute; -import org.apache.tools.ant.util.*; +import org.apache.tools.ant.util.FileNameMapper; import org.dita.dost.ant.ExtensibleAntInvoker; import org.dita.dost.util.Job; @@ -70,23 +67,19 @@ public String[] mapFileName(String sourceFileName) { if (fi == null) { fi = job.getFileInfo(job.getInputDir().resolve(uri)); } - final String res; - switch (type) { - case TEMP: - res = fi.file.getPath(); - break; - case RESULT: - if (fi.result == null) { - res = sourceFileName; - } else { - final URI base = job.getInputDir(); - final URI rel = base.relativize(fi.result); - res = toFile(rel).getPath(); + final String res = + switch (type) { + case TEMP -> fi.file.getPath(); + case RESULT -> { + if (fi.result == null) { + yield sourceFileName; + } else { + final URI base = job.getInputDir(); + final URI rel = base.relativize(fi.result); + yield toFile(rel).getPath(); + } } - break; - default: - throw new IllegalArgumentException(); - } + }; return new String[] { extension != null ? (FilenameUtils.removeExtension(res) + extension) : res }; } @@ -97,7 +90,7 @@ public String[] getValues() { return Arrays .stream(Type.values()) .map(t -> t.toString().toLowerCase()) - .collect(Collectors.toList()) + .toList() .toArray(new String[Type.values().length]); } } diff --git a/src/main/java/org/dita/dost/chunk/ChunkModule.java b/src/main/java/org/dita/dost/chunk/ChunkModule.java index c726f914d2..eb9be2a426 100644 --- a/src/main/java/org/dita/dost/chunk/ChunkModule.java +++ b/src/main/java/org/dita/dost/chunk/ChunkModule.java @@ -504,7 +504,7 @@ private List rewriteCombineChunks( .stream() .filter(chunk -> chunk.operation() == COMBINE) .map(chunk -> rewriteCombineChunk(mapFile, mapDoc, normalTopicRefs, rewriteMap, chunk).build()) - .collect(Collectors.toUnmodifiableList()); + .toList(); } private ChunkBuilder rewriteCombineChunk( diff --git a/src/main/java/org/dita/dost/chunk/ChunkOperation.java b/src/main/java/org/dita/dost/chunk/ChunkOperation.java index 21d5317b3d..606843ebfc 100644 --- a/src/main/java/org/dita/dost/chunk/ChunkOperation.java +++ b/src/main/java/org/dita/dost/chunk/ChunkOperation.java @@ -8,8 +8,6 @@ package org.dita.dost.chunk; -import static java.util.Collections.unmodifiableList; - import java.net.URI; import java.util.ArrayList; import java.util.List; @@ -109,8 +107,8 @@ public ChunkBuilder addChild(final ChunkBuilder child) { public ChunkOperation build() { final URI src = this.src; final URI dst = this.dst; - final List cos = children.stream().map(ChunkBuilder::build).collect(Collectors.toList()); - return new ChunkOperation(operation, src, dst, id, topicref, unmodifiableList(cos)); + final List cos = children.stream().map(ChunkBuilder::build).toList(); + return new ChunkOperation(operation, src, dst, id, topicref, cos); } } } diff --git a/src/main/java/org/dita/dost/index/TopicrefElement.java b/src/main/java/org/dita/dost/index/TopicrefElement.java index e11c336568..e5dfb4fbce 100644 --- a/src/main/java/org/dita/dost/index/TopicrefElement.java +++ b/src/main/java/org/dita/dost/index/TopicrefElement.java @@ -4,82 +4,15 @@ * Copyright 2005 IBM Corporation * * See the accompanying LICENSE file for applicable license. - */ package org.dita.dost.index; /** * This class represent the topicref element in ditamap. * - * @version 1.0 2005-06-03 - * - * @author Wu, Zhi Qiang + * @param href The href attribute of the topicref element. + * @param format The format attribute of the topicref element. + * @param navtitle the navtitle attribute of topicref element. + * @since 1.0 */ -public final class TopicrefElement { - - /** The href attribute of the topicref element. */ - private String href = null; - - /** The format attribute of the topicref element. */ - private String format = null; - /**the navtitle attribute of topicref element.*/ - private String navtitle = null; - - /** - * Default constructor. - */ - public TopicrefElement() {} - - /** - * Get the format attribute. - * - * @return Returns the format. - */ - public String getFormat() { - return format; - } - - /** - * Set the format attribute with the given value. - * - * @param formatValue The format to set. - */ - public void setFormat(final String formatValue) { - format = formatValue; - } - - /** - * Get href attribute. - * - * @return Returns the href. - */ - public String getHref() { - return href; - } - - /** - * Set href attribute with the given value. - * - * @param hrefValue The href to set. - */ - public void setHref(final String hrefValue) { - href = hrefValue; - } - - /** - * Set navtitle attribute with the given value. - * @param aNavtitle The navtitle to set. - */ - public void setNavTitle(final String aNavtitle) { - navtitle = aNavtitle; - } - - /** - * Get navtitle attribute. - * - * @return Returns the navtitle. - */ - public String getNavTitle() { - return navtitle; - } -} +public record TopicrefElement(String href, String format, String navtitle) {} diff --git a/src/main/java/org/dita/dost/invoker/ArgumentParser.java b/src/main/java/org/dita/dost/invoker/ArgumentParser.java index e9c4512a54..98308b06ef 100644 --- a/src/main/java/org/dita/dost/invoker/ArgumentParser.java +++ b/src/main/java/org/dita/dost/invoker/ArgumentParser.java @@ -62,22 +62,21 @@ static Arguments.Argument getArgument(Element param) { final String name = param.getAttribute("name"); final String type = param.getAttribute("type"); final String desc = param.getAttribute("desc"); - switch (type) { - case "file": - return new Arguments.FileArgument(name, desc); - case "enum": + return switch (type) { + case "file" -> new Arguments.FileArgument(name, desc); + case "enum" -> { final Set vals = getChildElements(param).stream().map(XMLUtils::getText).collect(Collectors.toSet()); if (vals.size() == 2) { for (Map.Entry pair : TRUTHY_VALUES.entrySet()) { if (vals.contains(pair.getKey()) && vals.contains(pair.getValue())) { - return new Arguments.BooleanArgument(name, desc, pair.getKey(), pair.getValue()); + yield new Arguments.BooleanArgument(name, desc, pair.getKey(), pair.getValue()); } } } - return new Arguments.EnumArgument(name, desc, vals); - default: - return new Arguments.StringArgument(name, desc); - } + yield new Arguments.EnumArgument(name, desc, vals); + } + default -> new Arguments.StringArgument(name, desc); + }; } private static Map PLUGIN_ARGUMENTS; diff --git a/src/main/java/org/dita/dost/invoker/DefaultLogger.java b/src/main/java/org/dita/dost/invoker/DefaultLogger.java index dc3c3b7043..52ebcad102 100644 --- a/src/main/java/org/dita/dost/invoker/DefaultLogger.java +++ b/src/main/java/org/dita/dost/invoker/DefaultLogger.java @@ -58,14 +58,14 @@ class DefaultLogger extends AbstractLogger implements BuildLogger { /** PrintStream to write error messages to */ private PrintStream err; - /** Lowest level of message to write out */ + //** Lowest level of message to write out */ // private int msgOutputLevel = Project.MSG_ERR; /** Time of the start of the build */ private long startTime = System.currentTimeMillis(); // CheckStyle:ConstantNameCheck OFF - bc - /** Line separator */ + //** Line separator */ // protected static final String lSep = StringUtils.LINE_SEP; // CheckStyle:ConstantNameCheck ON diff --git a/src/main/java/org/dita/dost/invoker/Main.java b/src/main/java/org/dita/dost/invoker/Main.java index 0a4f53f056..6843c24843 100644 --- a/src/main/java/org/dita/dost/invoker/Main.java +++ b/src/main/java/org/dita/dost/invoker/Main.java @@ -98,8 +98,8 @@ public class Main extends org.apache.tools.ant.Main implements AntMain { ); private static final String CONFIGURATION_FILE = ".ditaotrc"; - @Deprecated /** @deprecated since 4.2 */ + @Deprecated private static final String CONFIGURATION_FILE_OLD = "local.properties"; /** @@ -609,7 +609,7 @@ List> collectProperties( }); final List ditavals = Stream .concat(publications.profiles().ditavals().stream(), context.profiles().ditavals().stream()) - .collect(Collectors.toList()); + .toList(); if (!ditavals.isEmpty()) { final String filters = ditavals .stream() diff --git a/src/main/java/org/dita/dost/log/AbstractLogger.java b/src/main/java/org/dita/dost/log/AbstractLogger.java index fa4c2f50a9..6494cd7304 100644 --- a/src/main/java/org/dita/dost/log/AbstractLogger.java +++ b/src/main/java/org/dita/dost/log/AbstractLogger.java @@ -33,7 +33,7 @@ public abstract class AbstractLogger extends MarkerIgnoringBase implements DITAO protected int msgOutputLevel = Project.MSG_DEBUG; protected boolean useColor; - protected boolean legacyFormat = Configuration.configuration + protected final boolean legacyFormat = Configuration.configuration .getOrDefault("cli.log-format", "legacy") .equals("legacy"); diff --git a/src/main/java/org/dita/dost/module/CleanPreprocessModule.java b/src/main/java/org/dita/dost/module/CleanPreprocessModule.java index 499044c755..e1097aeb35 100644 --- a/src/main/java/org/dita/dost/module/CleanPreprocessModule.java +++ b/src/main/java/org/dita/dost/module/CleanPreprocessModule.java @@ -273,7 +273,7 @@ URI getCommonBase(final URI left, final URI right) { if (OS_NAME.toLowerCase().contains(OS_NAME_WINDOWS) && commons.size() <= 1) { return null; } else { - final String path = commons.stream().collect(Collectors.joining("/")) + "/"; + final String path = String.join("/", commons) + "/"; return URLUtils.setPath(left, path); } } diff --git a/src/main/java/org/dita/dost/module/ConrefPushModule.java b/src/main/java/org/dita/dost/module/ConrefPushModule.java index 8f4f05ddb1..357f821a3d 100644 --- a/src/main/java/org/dita/dost/module/ConrefPushModule.java +++ b/src/main/java/org/dita/dost/module/ConrefPushModule.java @@ -12,7 +12,6 @@ import java.util.Collection; import java.util.Hashtable; import java.util.Map; -import java.util.stream.Collectors; import org.dita.dost.exception.DITAOTException; import org.dita.dost.pipeline.AbstractPipelineInput; import org.dita.dost.pipeline.AbstractPipelineOutput; @@ -29,11 +28,7 @@ final class ConrefPushModule extends AbstractPipelineModuleImpl { @Override public AbstractPipelineOutput execute(final AbstractPipelineInput input) { - final Collection fis = job - .getFileInfo(fileInfoFilter) - .stream() - .filter(f -> f.isConrefPush) - .collect(Collectors.toList()); + final Collection fis = job.getFileInfo(fileInfoFilter).stream().filter(f -> f.isConrefPush).toList(); if (!fis.isEmpty()) { final ConrefPushReader reader = new ConrefPushReader(); reader.setLogger(logger); diff --git a/src/main/java/org/dita/dost/module/GenMapAndTopicListModule.java b/src/main/java/org/dita/dost/module/GenMapAndTopicListModule.java index b04e84d4da..15ed967311 100644 --- a/src/main/java/org/dita/dost/module/GenMapAndTopicListModule.java +++ b/src/main/java/org/dita/dost/module/GenMapAndTopicListModule.java @@ -780,9 +780,7 @@ private void outputResult() throws DITAOTException { job.setInputMap(rootTemp); //If root input file is marked resource only due to conref or other feature, remove that designation - if (resourceOnlySet.contains(rootFile)) { - resourceOnlySet.remove(rootFile); - } + resourceOnlySet.remove(rootFile); job.setProperty(INPUT_DITAMAP_LIST_FILE_LIST, USER_INPUT_FILE_LIST_FILE); final File inputfile = new File(job.tempDir, USER_INPUT_FILE_LIST_FILE); diff --git a/src/main/java/org/dita/dost/module/XmlFilterModule.java b/src/main/java/org/dita/dost/module/XmlFilterModule.java index da95ada963..08bfb7761e 100644 --- a/src/main/java/org/dita/dost/module/XmlFilterModule.java +++ b/src/main/java/org/dita/dost/module/XmlFilterModule.java @@ -12,7 +12,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import java.util.stream.Collectors; import org.dita.dost.exception.DITAOTException; @@ -76,12 +75,11 @@ private List getProcessingPipe(final FileInfo fi) { .stream() .filter(p -> p.predicate.test(fi)) .map(FilterPair::newInstance) - .map(f -> { + .peek(f -> { logger.debug("Configure filter " + f.getClass().getCanonicalName()); f.setCurrentFile(fileToParse); f.setJob(job); f.setLogger(logger); - return f; }) .collect(Collectors.toList()); } diff --git a/src/main/java/org/dita/dost/module/XsltModule.java b/src/main/java/org/dita/dost/module/XsltModule.java index 48e3f17b7f..45af473174 100644 --- a/src/main/java/org/dita/dost/module/XsltModule.java +++ b/src/main/java/org/dita/dost/module/XsltModule.java @@ -134,7 +134,7 @@ public AbstractPipelineOutput execute(AbstractPipelineInput input) throws DITAOT } }) .filter(Objects::nonNull) - .collect(Collectors.toList()); + .toList(); for (Entry entry : tmps) { try { logger.info("Move " + entry.getKey().toURI() + " to " + entry.getValue().toURI()); diff --git a/src/main/java/org/dita/dost/module/filter/AbstractBranchFilterModule.java b/src/main/java/org/dita/dost/module/filter/AbstractBranchFilterModule.java index bce51d197b..26d2cf0f19 100644 --- a/src/main/java/org/dita/dost/module/filter/AbstractBranchFilterModule.java +++ b/src/main/java/org/dita/dost/module/filter/AbstractBranchFilterModule.java @@ -78,13 +78,11 @@ SubjectScheme getSubjectScheme(final XdmNode root) { logger.debug("Loading subject schemes"); var enumerationDefs = root.select(Steps.descendant(SUBJECTSCHEME_ENUMERATIONDEF::matches)).toList(); if (!enumerationDefs.isEmpty()) { - enumerationDefs - .stream() - .forEach(enumerationDef -> { - final XdmNode schemeRoot = enumerationDef.select(Steps.ancestor(SUBMAP::matches)).findFirst().orElse(root); - var subjectDefinitions = subjectSchemeReader.getSubjectDefinition(schemeRoot); - subjectSchemeReader.processEnumerationDef(subjectDefinitions, enumerationDef); - }); + enumerationDefs.forEach(enumerationDef -> { + final XdmNode schemeRoot = enumerationDef.select(Steps.ancestor(SUBMAP::matches)).findFirst().orElse(root); + var subjectDefinitions = subjectSchemeReader.getSubjectDefinition(schemeRoot); + subjectSchemeReader.processEnumerationDef(subjectDefinitions, enumerationDef); + }); return subjectSchemeReader.getSubjectSchemeMap(); } else { return new SubjectScheme(Map.of()); diff --git a/src/main/java/org/dita/dost/module/reader/AbstractReaderModule.java b/src/main/java/org/dita/dost/module/reader/AbstractReaderModule.java index aac5fa326c..bfa8d81772 100644 --- a/src/main/java/org/dita/dost/module/reader/AbstractReaderModule.java +++ b/src/main/java/org/dita/dost/module/reader/AbstractReaderModule.java @@ -207,7 +207,7 @@ void initFilters() { * Init xml reader used for pipeline parsing. * * @param validate whether validate input file - * @throws SAXException parsing exception + * @throws DITAOTException parsing exception */ void initXMLReader(final boolean validate) throws DITAOTException { try { @@ -696,8 +696,7 @@ void outputResult() throws DITAOTException { job.setProperty("tempdirToinputmapdir.relative.value", StringUtils.escapeRegExp(getPrefix(relativeRootFile))); - final Set res = new HashSet<>(); - res.addAll(listFilter.getResourceOnlySet()); + final Set res = new HashSet<>(listFilter.getResourceOnlySet()); res.removeAll(listFilter.getNormalProcessingRoleSet()); resourceOnlySet.addAll(res); diff --git a/src/main/java/org/dita/dost/platform/Integrator.java b/src/main/java/org/dita/dost/platform/Integrator.java index 93c2ab07da..5cc7eedd24 100644 --- a/src/main/java/org/dita/dost/platform/Integrator.java +++ b/src/main/java/org/dita/dost/platform/Integrator.java @@ -410,16 +410,12 @@ private List readMessages(Path messagesXmlFile) throws IOException { switch (type) { case XMLEvent.START_ELEMENT: switch (src.getLocalName()) { - case "message": + case "message" -> { id = src.getAttributeValue(XMLConstants.NULL_NS_URI, "id"); severity = src.getAttributeValue(XMLConstants.NULL_NS_URI, "type"); - break; - case "reason": - reason = src.getElementText(); - break; - case "response": - response = src.getElementText(); - break; + } + case "reason" -> reason = src.getElementText(); + case "response" -> response = src.getElementText(); } break; case XMLEvent.END_ELEMENT: @@ -537,20 +533,20 @@ private Properties readMessageBundle() throws IOException, XMLStreamException { while (src.hasNext()) { final int type = src.next(); switch (type) { - case XMLEvent.START_ELEMENT: + case XMLEvent.START_ELEMENT -> { if (src.getLocalName().equals("message")) { id = src.getAttributeValue(XMLConstants.NULL_NS_URI, "id"); } else if (id != null) { buf.append(src.getElementText()).append(' '); } - break; - case XMLEvent.END_ELEMENT: + } + case XMLEvent.END_ELEMENT -> { if (src.getLocalName().equals("message")) { messages.put(id, convertMessage(buf.toString())); id = null; buf.delete(0, buf.length()); } - break; + } } } src.close(); @@ -627,12 +623,9 @@ private Map getParserConfiguration() { final List fsv = fs .stream() .map(f -> f.getAttribute("name") + "=" + f.getAttribute("value")) - .collect(Collectors.toList()); + .toList(); if (!fsv.isEmpty()) { - res.put( - CONF_PARSER_FORMAT + format + ".features", - fsv.stream().collect(Collectors.joining(PARAM_VALUE_SEPARATOR)) - ); + res.put(CONF_PARSER_FORMAT + format + ".features", String.join(PARAM_VALUE_SEPARATOR, fsv)); } } } diff --git a/src/main/java/org/dita/dost/platform/ListTranstypeAction.java b/src/main/java/org/dita/dost/platform/ListTranstypeAction.java index 662507fa80..1d8f1fe8b5 100644 --- a/src/main/java/org/dita/dost/platform/ListTranstypeAction.java +++ b/src/main/java/org/dita/dost/platform/ListTranstypeAction.java @@ -7,7 +7,6 @@ */ package org.dita.dost.platform; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; @@ -28,7 +27,7 @@ final class ListTranstypeAction extends ImportAction { @Override public void getResult(final ContentHandler buf) throws SAXException { final String separator = paramTable.getOrDefault("separator", "|"); - final List v = valueSet.stream().map(Value::value).distinct().sorted().collect(Collectors.toList()); + final List v = valueSet.stream().map(Value::value).distinct().sorted().toList(); final StringBuilder retBuf = new StringBuilder(); for (final Iterator i = v.iterator(); i.hasNext();) { retBuf.append(i.next()); diff --git a/src/main/java/org/dita/dost/reader/CopyToReader.java b/src/main/java/org/dita/dost/reader/CopyToReader.java index 9b5b6271a1..ef8dcd6234 100644 --- a/src/main/java/org/dita/dost/reader/CopyToReader.java +++ b/src/main/java/org/dita/dost/reader/CopyToReader.java @@ -18,7 +18,6 @@ import java.util.Map; import java.util.Stack; import org.dita.dost.log.MessageUtils; -import org.dita.dost.util.DitaClass; import org.dita.dost.writer.AbstractXMLFilter; import org.xml.sax.Attributes; import org.xml.sax.SAXException; diff --git a/src/main/java/org/dita/dost/reader/DitamapIndexTermReader.java b/src/main/java/org/dita/dost/reader/DitamapIndexTermReader.java index 577d1836cc..3ac4283d19 100644 --- a/src/main/java/org/dita/dost/reader/DitamapIndexTermReader.java +++ b/src/main/java/org/dita/dost/reader/DitamapIndexTermReader.java @@ -9,8 +9,9 @@ package org.dita.dost.reader; -import static org.apache.commons.io.FilenameUtils.*; -import static org.dita.dost.index.IndexTerm.IndexTermPrefix.*; +import static org.apache.commons.io.FilenameUtils.normalize; +import static org.dita.dost.index.IndexTerm.IndexTermPrefix.SEE; +import static org.dita.dost.index.IndexTerm.IndexTermPrefix.SEE_ALSO; import static org.dita.dost.util.Constants.*; import java.io.File; @@ -144,7 +145,7 @@ public void endElement(final String uri, final String localName, final String qN obj = elementStack.peek(); if (obj instanceof TopicrefElement) { - if (((TopicrefElement) obj).getHref() != null) { + if (((TopicrefElement) obj).href() != null) { genTargets(indexTerm, (TopicrefElement) obj); //IndexTermCollection.getInstantce().addTerm(indexTerm); result.addTerm(indexTerm); @@ -172,7 +173,7 @@ private void genTargets(final IndexTerm indexTerm, final TopicrefElement obj) { final IndexTermTarget target = new IndexTermTarget(); String targetURI; - final String href = obj.getHref(); + final String href = obj.href(); final StringBuilder buffer = new StringBuilder(); if (!href.contains(COLON_DOUBLE_SLASH) && !FileUtils.isAbsolutePath(href)) { @@ -186,8 +187,8 @@ private void genTargets(final IndexTerm indexTerm, final TopicrefElement obj) { targetURI = href; } - if (obj.getNavTitle() != null) { - target.setTargetName(obj.getNavTitle()); + if (obj.navtitle() != null) { + target.setTargetName(obj.navtitle()); } else { target.setTargetName(href); } @@ -203,8 +204,8 @@ private void assignTarget(final IndexTerm indexTerm, final IndexTermTarget targe } if (indexTerm.hasSubTerms()) { - for (final Object subTerm : indexTerm.getSubTerms()) { - assignTarget((IndexTerm) subTerm, target); + for (final IndexTerm subTerm : indexTerm.getSubTerms()) { + assignTarget(subTerm, target); } } } @@ -241,14 +242,11 @@ public void startElement(final String uri, final String localName, final String } if (topicrefSpecList.contains(localName)) { - final String href = attributes.getValue(ATTRIBUTE_NAME_HREF); - final String format = attributes.getValue(ATTRIBUTE_NAME_FORMAT); - final String navtitle = attributes.getValue(ATTRIBUTE_NAME_NAVTITLE); - final TopicrefElement topicref = new TopicrefElement(); - - topicref.setHref(href); - topicref.setFormat(format); - topicref.setNavTitle(navtitle); + final TopicrefElement topicref = new TopicrefElement( + attributes.getValue(ATTRIBUTE_NAME_HREF), + attributes.getValue(ATTRIBUTE_NAME_FORMAT), + attributes.getValue(ATTRIBUTE_NAME_NAVTITLE) + ); elementStack.push(topicref); return; @@ -328,9 +326,9 @@ private boolean needPushTerm() { if ( indexMoved && ( - elem.getFormat() == null || - elem.getFormat().equals(ATTR_FORMAT_VALUE_DITA) || - elem.getFormat().equals(ATTR_FORMAT_VALUE_DITAMAP) + elem.format() == null || + elem.format().equals(ATTR_FORMAT_VALUE_DITA) || + elem.format().equals(ATTR_FORMAT_VALUE_DITAMAP) ) ) { return false; diff --git a/src/main/java/org/dita/dost/reader/SubjectSchemeReader.java b/src/main/java/org/dita/dost/reader/SubjectSchemeReader.java index cd97618f76..b82f29d8aa 100644 --- a/src/main/java/org/dita/dost/reader/SubjectSchemeReader.java +++ b/src/main/java/org/dita/dost/reader/SubjectSchemeReader.java @@ -33,13 +33,13 @@ public class SubjectSchemeReader { public static final String ANY_ELEMENT = "*"; - private static net.sf.saxon.s9api.QName ATTRIBUTE_QNAME_KEYREF = net.sf.saxon.s9api.QName.fromClarkName( + private static final net.sf.saxon.s9api.QName ATTRIBUTE_QNAME_KEYREF = net.sf.saxon.s9api.QName.fromClarkName( ATTRIBUTE_NAME_KEYREF ); - private static net.sf.saxon.s9api.QName ATTRIBUTE_QNAME_KEYS = net.sf.saxon.s9api.QName.fromClarkName( + private static final net.sf.saxon.s9api.QName ATTRIBUTE_QNAME_KEYS = net.sf.saxon.s9api.QName.fromClarkName( ATTRIBUTE_NAME_KEYS ); - private static net.sf.saxon.s9api.QName ATTRIBUTE_QNAME_NAME = net.sf.saxon.s9api.QName.fromClarkName( + private static final net.sf.saxon.s9api.QName ATTRIBUTE_QNAME_NAME = net.sf.saxon.s9api.QName.fromClarkName( ATTRIBUTE_NAME_NAME ); diff --git a/src/main/java/org/dita/dost/store/AbstractStore.java b/src/main/java/org/dita/dost/store/AbstractStore.java index 8df5127990..4a3ad2ad1d 100644 --- a/src/main/java/org/dita/dost/store/AbstractStore.java +++ b/src/main/java/org/dita/dost/store/AbstractStore.java @@ -15,7 +15,6 @@ import java.io.File; import java.io.IOException; import java.net.URI; -import java.net.URISyntaxException; import java.util.List; import net.sf.saxon.s9api.XsltTransformer; import org.dita.dost.exception.DITAOTException; diff --git a/src/main/java/org/dita/dost/store/CacheStore.java b/src/main/java/org/dita/dost/store/CacheStore.java index 161a79cc8c..4bdc59802f 100644 --- a/src/main/java/org/dita/dost/store/CacheStore.java +++ b/src/main/java/org/dita/dost/store/CacheStore.java @@ -614,22 +614,9 @@ private Source toSource(final Entry entry, final URI path) { } } - private static class Entry { - - private final Document doc; - private final XdmNode node; - private final byte[] bytes; - private final long lastModified; - + private record Entry(Document doc, XdmNode node, byte[] bytes, long lastModified) { private Entry(final Document doc, final XdmNode node, final byte[] bytes) { this(doc, node, bytes, System.currentTimeMillis()); } - - private Entry(final Document doc, final XdmNode node, final byte[] bytes, final long lastModified) { - this.doc = doc; - this.node = node; - this.bytes = bytes; - this.lastModified = lastModified; - } } } diff --git a/src/main/java/org/dita/dost/util/FilterUtils.java b/src/main/java/org/dita/dost/util/FilterUtils.java index 48de725785..946caf514f 100644 --- a/src/main/java/org/dita/dost/util/FilterUtils.java +++ b/src/main/java/org/dita/dost/util/FilterUtils.java @@ -658,11 +658,9 @@ private void insertAction( return; } - final LinkedList queue = new LinkedList<>(); - // Skip the sub-tree root because it has been added already. List children = subTree.children(); - queue.addAll(children); + final LinkedList queue = new LinkedList<>(children); while (!queue.isEmpty()) { final SubjectDefinition node = queue.poll(); diff --git a/src/main/java/org/dita/dost/util/Job.java b/src/main/java/org/dita/dost/util/Job.java index dae2c782e5..13c2078df5 100644 --- a/src/main/java/org/dita/dost/util/Job.java +++ b/src/main/java/org/dita/dost/util/Job.java @@ -14,10 +14,7 @@ import java.io.*; import java.lang.reflect.Field; import java.net.URI; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.StandardOpenOption; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -28,16 +25,13 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.Result; import javax.xml.transform.dom.DOMResult; import org.dita.dost.exception.DITAOTException; import org.dita.dost.module.reader.TempFileNameScheme; import org.dita.dost.store.Store; import org.w3c.dom.Document; import org.xml.sax.Attributes; -import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; /** diff --git a/src/main/java/org/dita/dost/util/MergeUtils.java b/src/main/java/org/dita/dost/util/MergeUtils.java index 44b0e90b75..c0a345e1ab 100644 --- a/src/main/java/org/dita/dost/util/MergeUtils.java +++ b/src/main/java/org/dita/dost/util/MergeUtils.java @@ -10,12 +10,10 @@ import static org.dita.dost.util.URLUtils.*; -import java.io.File; import java.net.URI; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import org.dita.dost.log.DITAOTLogger; -import org.xml.sax.XMLReader; /** * Utility that topic merge utilize. An instance can be reused by calling diff --git a/src/main/java/org/dita/dost/util/StringUtils.java b/src/main/java/org/dita/dost/util/StringUtils.java index ae9195b402..d5d701aa3b 100644 --- a/src/main/java/org/dita/dost/util/StringUtils.java +++ b/src/main/java/org/dita/dost/util/StringUtils.java @@ -113,7 +113,7 @@ public static String replaceAll(final String input, final String pattern, final * Parse {@code props} attribute specializations * * @param domains input domain - * @return list of {@code props} attribute specializations + * @return array of {@code props} attribute specializations */ public static QName[][] getExtProps(final String domains) { // FIXME Dont' mix arrays and collections @@ -122,7 +122,7 @@ public static QName[][] getExtProps(final String domains) { int propsEnd = domains.indexOf(")", propsStart); while (propsStart != -1 && propsEnd != -1) { final String propPath = domains.substring(propsStart + 2, propsEnd).trim(); - final List propList = Stream.of(propPath.split("\\s+")).map(QName::valueOf).collect(Collectors.toList()); + final List propList = Stream.of(propPath.split("\\s+")).map(QName::valueOf).toList(); propsBuffer.add(propList.toArray(new QName[0])); propsStart = domains.indexOf("a(" + ATTRIBUTE_NAME_PROPS, propsEnd); propsEnd = domains.indexOf(")", propsStart); @@ -134,21 +134,15 @@ public static QName[][] getExtProps(final String domains) { * Parse {@code props} attribute specializations * * @param specializations input domain - * @return list of {@code props} attribute specializations + * @return array of {@code props} attribute specializations */ public static QName[][] getExtPropsFromSpecializations(final String specializations) { // FIXME Dont' mix arrays and collections return Arrays .stream(specializations.trim().split("\\s+")) .filter(s -> !s.isEmpty()) - .map(token -> - Arrays - .stream(token.substring(1).split("/")) - .map(QName::valueOf) - .collect(Collectors.toList()) - .toArray(new QName[0]) - ) - .collect(Collectors.toList()) + .map(token -> Arrays.stream(token.substring(1).split("/")).map(QName::valueOf).toList().toArray(new QName[0])) + .toList() .toArray(new QName[0][]); } diff --git a/src/main/java/org/dita/dost/util/URLUtils.java b/src/main/java/org/dita/dost/util/URLUtils.java index 00bad43daa..4c6cb0f9ac 100644 --- a/src/main/java/org/dita/dost/util/URLUtils.java +++ b/src/main/java/org/dita/dost/util/URLUtils.java @@ -108,7 +108,7 @@ private static String uncorrect(final String s) { final char current = s.charAt(i); ch = current; switch (ch) { - case '%': + case '%' -> { if (i + 2 < s.length()) { // Avoid java.lang.StringIndexOutOfBoundsException... ch = s.charAt(++i); @@ -120,10 +120,11 @@ private static String uncorrect(final String s) { b = (hb << 4) | lb; applyUTF8dec = true; } - break; - default: + } + default -> { b = ch; applyUTF8dec = false; + } } // Decode byte b as UTF-8, sumb collects incomplete chars if (applyUTF8dec) { diff --git a/src/main/java/org/dita/dost/util/XMLUtils.java b/src/main/java/org/dita/dost/util/XMLUtils.java index cf23f7a35c..4856f94d27 100644 --- a/src/main/java/org/dita/dost/util/XMLUtils.java +++ b/src/main/java/org/dita/dost/util/XMLUtils.java @@ -915,8 +915,8 @@ public static XMLReader getXMLReader() throws SAXException { * Get reader for input format * * @param format input document format - * @param processingMode - * @return reader for given forma + * @param processingMode processing mode + * @return reader for given format * @throws SAXException if creating reader failed */ public static Optional getXmlReader(final String format, Configuration.Mode processingMode) diff --git a/src/main/java/org/dita/dost/writer/DitaMetaWriter.java b/src/main/java/org/dita/dost/writer/DitaMetaWriter.java index 61f6ef9bae..4ace9e83d9 100644 --- a/src/main/java/org/dita/dost/writer/DitaMetaWriter.java +++ b/src/main/java/org/dita/dost/writer/DitaMetaWriter.java @@ -9,7 +9,7 @@ import static org.dita.dost.util.Constants.*; -import java.util.*; +import java.util.List; import org.dita.dost.util.DitaClass; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -19,36 +19,42 @@ */ public final class DitaMetaWriter extends AbstractDitaMetaWriter { - private static final List titlealtsPosition = Collections.unmodifiableList( - Collections.singletonList(TOPIC_TITLE) + private static final List titlealtsPosition = List.of(TOPIC_TITLE); + private static final List titlealtsOrder = List.of(TOPIC_NAVTITLE, MAP_SEARCHTITLE, TOPIC_SEARCHTITLE); + private static final List prologPosition = List.of( + TOPIC_TITLE, + TOPIC_TITLEALTS, + TOPIC_SHORTDESC, + TOPIC_ABSTRACT ); - private static final List titlealtsOrder = Collections.unmodifiableList( - Arrays.asList(TOPIC_NAVTITLE, MAP_SEARCHTITLE, TOPIC_SEARCHTITLE) + private static final List prologOrder = List.of( + TOPIC_AUTHOR, + TOPIC_SOURCE, + TOPIC_PUBLISHER, + TOPIC_COPYRIGHT, + TOPIC_CRITDATES, + TOPIC_PERMISSIONS, + TOPIC_METADATA, + TOPIC_RESOURCEID, + TOPIC_DATA, + TOPIC_DATA_ABOUT, + TOPIC_FOREIGN, + TOPIC_UNKNOWN ); - private static final List prologPosition = Collections.unmodifiableList( - Arrays.asList(TOPIC_TITLE, TOPIC_TITLEALTS, TOPIC_SHORTDESC, TOPIC_ABSTRACT) + private static final List metadataPosition = List.of( + TOPIC_AUTHOR, + TOPIC_SOURCE, + TOPIC_PUBLISHER, + TOPIC_COPYRIGHT, + TOPIC_CRITDATES, + TOPIC_PERMISSIONS ); - private static final List prologOrder = Collections.unmodifiableList( - Arrays.asList( - TOPIC_AUTHOR, - TOPIC_SOURCE, - TOPIC_PUBLISHER, - TOPIC_COPYRIGHT, - TOPIC_CRITDATES, - TOPIC_PERMISSIONS, - TOPIC_METADATA, - TOPIC_RESOURCEID, - TOPIC_DATA, - TOPIC_DATA_ABOUT, - TOPIC_FOREIGN, - TOPIC_UNKNOWN - ) - ); - private static final List metadataPosition = Collections.unmodifiableList( - Arrays.asList(TOPIC_AUTHOR, TOPIC_SOURCE, TOPIC_PUBLISHER, TOPIC_COPYRIGHT, TOPIC_CRITDATES, TOPIC_PERMISSIONS) - ); - private static final List metadataOrder = Collections.unmodifiableList( - Arrays.asList(TOPIC_AUDIENCE, TOPIC_CATEGORY, TOPIC_KEYWORDS, TOPIC_PRODINFO, TOPIC_OTHERMETA) + private static final List metadataOrder = List.of( + TOPIC_AUDIENCE, + TOPIC_CATEGORY, + TOPIC_KEYWORDS, + TOPIC_PRODINFO, + TOPIC_OTHERMETA ); public Document process(final Document doc) { diff --git a/src/main/java/org/dita/dost/writer/ImageMetadataFilter.java b/src/main/java/org/dita/dost/writer/ImageMetadataFilter.java index 6fca8ff3b5..22438735e4 100644 --- a/src/main/java/org/dita/dost/writer/ImageMetadataFilter.java +++ b/src/main/java/org/dita/dost/writer/ImageMetadataFilter.java @@ -19,7 +19,6 @@ import java.io.InputStream; import java.net.URI; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; import javax.imageio.ImageIO; diff --git a/src/main/java/org/dita/dost/writer/KeyrefPaser.java b/src/main/java/org/dita/dost/writer/KeyrefPaser.java index d70acdf388..4aef5b33d8 100644 --- a/src/main/java/org/dita/dost/writer/KeyrefPaser.java +++ b/src/main/java/org/dita/dost/writer/KeyrefPaser.java @@ -268,7 +268,7 @@ public void endElement(final String uri, final String localName, final String na // If current element name doesn't equal the key reference element // just grab the content from the matching element of key definition for (final XdmNode node : elem.select(descendant().where(hasLocalName(name))).asList()) { - for (final XdmNode n : node.select(child().where(isText())).collect(toList())) { + for (final XdmNode n : node.select(child().where(isText())).toList()) { final char[] ch = n.getStringValue().toCharArray(); getContentHandler().characters(ch, 0, ch.length); break; @@ -284,7 +284,7 @@ public void endElement(final String uri, final String localName, final String na final List keywordsInKeywords = keywords .stream() .filter(item -> TOPIC_KEYWORDS.matches(item.getParent())) - .collect(toList()); + .toList(); // XXX: No need to look for term as content model for keywords doesn't allow it // if (nodeList.getLength() == 0) { // nodeList = elem.descendant(TOPIC_TERM.localName); @@ -761,18 +761,18 @@ private void domToSax(final XdmNode elem, final boolean retainElements, final bo } for (final XdmNode node : elem.children()) { switch (node.getNodeKind()) { - case ELEMENT: + case ELEMENT -> { // retain tm and text elements if (TOPIC_TM.matches(node) || TOPIC_TEXT.matches(node)) { domToSax(node, true, swapMapClass); } else { domToSax(node, retainElements, swapMapClass); } - break; - case TEXT: + } + case TEXT -> { final char[] ch = node.getStringValue().toCharArray(); getContentHandler().characters(ch, 0, ch.length); - break; + } } } if (retainElements) { diff --git a/src/main/java/org/dita/dost/writer/NormalizeSimpleTableFilter.java b/src/main/java/org/dita/dost/writer/NormalizeSimpleTableFilter.java index a2598a5066..214e041c3b 100644 --- a/src/main/java/org/dita/dost/writer/NormalizeSimpleTableFilter.java +++ b/src/main/java/org/dita/dost/writer/NormalizeSimpleTableFilter.java @@ -82,7 +82,7 @@ public void startElement(final String uri, final String localName, final String } return s.y > 1 ? new Span(s.x, s.y - 1) : null; }) - .collect(Collectors.toList()); + .toList(); tableState.currentRow = new ArrayList<>(fromPrew); } else { tableState.currentRow = new ArrayList<>(); diff --git a/src/main/java/org/dita/dost/writer/NormalizeTableFilter.java b/src/main/java/org/dita/dost/writer/NormalizeTableFilter.java index cb21d799ea..34c714d4f0 100644 --- a/src/main/java/org/dita/dost/writer/NormalizeTableFilter.java +++ b/src/main/java/org/dita/dost/writer/NormalizeTableFilter.java @@ -123,7 +123,7 @@ public void startElement(final String uri, final String localName, final String } return s.y > 1 ? new Span(s.x, s.y - 1) : null; }) - .collect(Collectors.toList()); + .toList(); tableState.currentRow = new ArrayList<>(fromPrew); } else { tableState.currentRow = new ArrayList<>(); diff --git a/src/main/java/org/dita/dost/writer/ProfilingFilter.java b/src/main/java/org/dita/dost/writer/ProfilingFilter.java index e8b7474d53..7670907224 100644 --- a/src/main/java/org/dita/dost/writer/ProfilingFilter.java +++ b/src/main/java/org/dita/dost/writer/ProfilingFilter.java @@ -12,7 +12,6 @@ import java.util.*; import java.util.stream.Collectors; import javax.xml.namespace.QName; -import org.dita.dost.log.MessageUtils; import org.dita.dost.util.DitaClass; import org.dita.dost.util.FilterUtils; import org.dita.dost.util.FilterUtils.Flag; diff --git a/src/main/java/org/dita/dost/writer/SubjectSchemeFilter.java b/src/main/java/org/dita/dost/writer/SubjectSchemeFilter.java index afee3ce146..84f470c4d2 100644 --- a/src/main/java/org/dita/dost/writer/SubjectSchemeFilter.java +++ b/src/main/java/org/dita/dost/writer/SubjectSchemeFilter.java @@ -23,7 +23,7 @@ public class SubjectSchemeFilter extends AbstractXMLFilter { - private static Pattern WHITESPACE = Pattern.compile("\\s+"); + private static final Pattern WHITESPACE = Pattern.compile("\\s+"); private Map> defaultValueMap = null; private Map>> validateMap = null; diff --git a/src/main/java/org/dita/dost/writer/TopicCleanFilter.java b/src/main/java/org/dita/dost/writer/TopicCleanFilter.java index 4e450ef95d..75d1bed356 100644 --- a/src/main/java/org/dita/dost/writer/TopicCleanFilter.java +++ b/src/main/java/org/dita/dost/writer/TopicCleanFilter.java @@ -50,23 +50,15 @@ public void startDocument() throws SAXException { @Override public void processingInstruction(String target, String data) throws SAXException { - switch (target) { - case "path2project": - getContentHandler() - .processingInstruction( - target, - pathToRootDir.equals(SINGLE_URI_STEP) ? "" : pathToRootDir.replace('/', File.separatorChar) - ); - break; - case "path2project-uri": - getContentHandler().processingInstruction(target, pathToRootDir); - break; - case "path2rootmap-uri": - getContentHandler().processingInstruction(target, pathToMapDir != null ? pathToMapDir : data); - break; - default: - getContentHandler().processingInstruction(target, data); - break; - } + final String res = + switch (target) { + case "path2project" -> pathToRootDir.equals(SINGLE_URI_STEP) + ? "" + : pathToRootDir.replace('/', File.separatorChar); + case "path2project-uri" -> pathToRootDir; + case "path2rootmap-uri" -> pathToMapDir != null ? pathToMapDir : data; + default -> data; + }; + getContentHandler().processingInstruction(target, res); } } diff --git a/src/main/java/org/dita/dost/writer/ValidationFilter.java b/src/main/java/org/dita/dost/writer/ValidationFilter.java index 68349207fa..77b7265b01 100644 --- a/src/main/java/org/dita/dost/writer/ValidationFilter.java +++ b/src/main/java/org/dita/dost/writer/ValidationFilter.java @@ -237,17 +237,14 @@ private AttributesImpl validateReference( } } catch (final URISyntaxException e) { switch (processingMode) { - case STRICT: - throw new RuntimeException( - MessageUtils.getMessage("DOTJ054E", attrName, href).setLocation(locator) + ": " + e.getMessage(), - e - ); - case SKIP: - logger.error( - MessageUtils.getMessage("DOTJ054E", attrName, href).setLocation(locator) + ", using invalid value." - ); - break; - case LAX: + case STRICT -> throw new RuntimeException( + MessageUtils.getMessage("DOTJ054E", attrName, href).setLocation(locator) + ": " + e.getMessage(), + e + ); + case SKIP -> logger.error( + MessageUtils.getMessage("DOTJ054E", attrName, href).setLocation(locator) + ", using invalid value." + ); + case LAX -> { try { final URI uri = new URI(URLUtils.clean(href.trim())); if (res == null) { @@ -265,7 +262,7 @@ private AttributesImpl validateReference( MessageUtils.getMessage("DOTJ054E", attrName, href).setLocation(locator) + ", using invalid value." ); } - break; + } } } } diff --git a/src/main/java/org/dita/dost/writer/include/IncludeXml.java b/src/main/java/org/dita/dost/writer/include/IncludeXml.java index 2bad675f77..86d4f021cd 100644 --- a/src/main/java/org/dita/dost/writer/include/IncludeXml.java +++ b/src/main/java/org/dita/dost/writer/include/IncludeXml.java @@ -21,7 +21,6 @@ import net.sf.saxon.s9api.XdmNode; import org.dita.dost.log.DITAOTLogger; import org.dita.dost.util.Job; -import org.dita.dost.util.XMLUtils; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; diff --git a/src/main/java/org/ditang/relaxng/defaults/RNCDefaultValues.java b/src/main/java/org/ditang/relaxng/defaults/RNCDefaultValues.java index 60df2b8f63..7f35c0783f 100644 --- a/src/main/java/org/ditang/relaxng/defaults/RNCDefaultValues.java +++ b/src/main/java/org/ditang/relaxng/defaults/RNCDefaultValues.java @@ -20,7 +20,6 @@ import com.thaiopensource.util.VoidValue; import com.thaiopensource.validate.SchemaReader; import javax.xml.transform.sax.SAXSource; -import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.Locator; diff --git a/src/main/java/org/ditang/relaxng/defaults/RelaxNGDefaultValues.java b/src/main/java/org/ditang/relaxng/defaults/RelaxNGDefaultValues.java index 93cf7d9359..2887b39060 100644 --- a/src/main/java/org/ditang/relaxng/defaults/RelaxNGDefaultValues.java +++ b/src/main/java/org/ditang/relaxng/defaults/RelaxNGDefaultValues.java @@ -148,22 +148,12 @@ public void defaultValue( /** * Stores information about a default attribute. + * + * @param localName attribute local name + * @param namespace attribute namespace + * @param value attribute default value */ - class Attribute { - - /** The attribute local name */ - final String localName; - /** The attribute namespace */ - final String namespace; - /** The attribute default value */ - final String value; - - public Attribute(String localName, String namespace, String value) { - this.localName = localName; - this.namespace = namespace; - this.value = value; - } - } + record Attribute(String localName, String namespace, String value) {} /** * Updates the annotation model. diff --git a/src/main/java/org/ditang/relaxng/defaults/RelaxNGDefaultsComponent.java b/src/main/java/org/ditang/relaxng/defaults/RelaxNGDefaultsComponent.java index 56b43200cb..a5e1122b7a 100644 --- a/src/main/java/org/ditang/relaxng/defaults/RelaxNGDefaultsComponent.java +++ b/src/main/java/org/ditang/relaxng/defaults/RelaxNGDefaultsComponent.java @@ -469,24 +469,24 @@ private void checkAndAddDefaults(QName name, XMLAttributes atts) { //EXM-24143 it is possible that the namespace of the default attribute is empty //and the namespace of the attribute declared in the XMLAttributes is NULL. boolean alreadyDeclared = false; - alreadyDeclared = atts.getIndex(a.namespace, a.localName) >= 0; + alreadyDeclared = atts.getIndex(a.namespace(), a.localName()) >= 0; if (!alreadyDeclared) { - if ("".equals(a.namespace)) { + if ("".equals(a.namespace())) { //Extra check with NULL Namespace - alreadyDeclared = atts.getIndex(null, a.localName) >= 0; + alreadyDeclared = atts.getIndex(null, a.localName()) >= 0; } } if (!alreadyDeclared) { String prefix = null; - String rawname = a.localName; - if (a.namespace != null && a.namespace.length() > 0) { - prefix = context.getPrefix(a.namespace); + String rawname = a.localName(); + if (a.namespace() != null && a.namespace().length() > 0) { + prefix = context.getPrefix(a.namespace()); if (prefix == null) { for (int i = 0; i < atts.getLength(); i++) { String attname = atts.getQName(i); if (attname.startsWith("xmlns:")) { - if (a.namespace.equals(atts.getValue(i))) { + if (a.namespace().equals(atts.getValue(i))) { prefix = attname.substring(6); } } @@ -494,18 +494,18 @@ private void checkAndAddDefaults(QName name, XMLAttributes atts) { } if (prefix != null && prefix.length() > 0) { - rawname = prefix + ":" + a.localName; + rawname = prefix + ":" + a.localName(); // double check in case of no namespace aware parsers. // if we want to fully handle this case we may need further // processing. if (atts.getIndex(rawname) < 0) { QName attName = new QName( fSymbolTable.addSymbol(prefix), - fSymbolTable.addSymbol(a.localName), + fSymbolTable.addSymbol(a.localName()), fSymbolTable.addSymbol(rawname), - fSymbolTable.addSymbol(a.namespace) + fSymbolTable.addSymbol(a.namespace()) ); - atts.addAttribute(attName, "CDATA", a.value); + atts.addAttribute(attName, "CDATA", a.value()); int attrIndex = atts.getIndex(attName.uri, attName.localpart); atts.setSpecified(attrIndex, false); } @@ -515,7 +515,7 @@ private void checkAndAddDefaults(QName name, XMLAttributes atts) { //EXM-24494 Prefer this prefix //See the implementation in: org.dita.dost.reader.MergeTopicParser.startElement(String, String, String, Attributes) //If the file is a composite no attributes are copied from the root element. - "http://dita.oasis-open.org/architecture/2005/".equals(a.namespace) + "http://dita.oasis-open.org/architecture/2005/".equals(a.namespace()) ) { prefix = "ditaarch"; } else { @@ -525,7 +525,7 @@ private void checkAndAddDefaults(QName name, XMLAttributes atts) { k++; prefix = "ns" + k; } - rawname = prefix + ":" + a.localName; + rawname = prefix + ":" + a.localName(); QName attNs = new QName( fSymbolTable.addSymbol("xmlns"), @@ -533,23 +533,23 @@ private void checkAndAddDefaults(QName name, XMLAttributes atts) { fSymbolTable.addSymbol("xmlns:" + prefix), fSymbolTable.addSymbol("http://www.w3.org/2000/xmlns/") ); - atts.addAttribute(attNs, "CDATA", a.namespace); - context.declarePrefix(prefix, a.namespace); + atts.addAttribute(attNs, "CDATA", a.namespace()); + context.declarePrefix(prefix, a.namespace()); QName attName = new QName( fSymbolTable.addSymbol(prefix), - fSymbolTable.addSymbol(a.localName), + fSymbolTable.addSymbol(a.localName()), fSymbolTable.addSymbol(rawname), - fSymbolTable.addSymbol(a.namespace) + fSymbolTable.addSymbol(a.namespace()) ); - atts.addAttribute(attName, "CDATA", a.value); + atts.addAttribute(attName, "CDATA", a.value()); int attrIndex = atts.getIndex(attName.uri, attName.localpart); atts.setSpecified(attrIndex, false); } } else { - String attname = fSymbolTable.addSymbol(a.localName); + String attname = fSymbolTable.addSymbol(a.localName()); QName attName = new QName(null, attname, attname, null); - atts.addAttribute(attName, "CDATA", a.value); + atts.addAttribute(attName, "CDATA", a.value()); int attrIndex = atts.getIndex(attname); atts.setSpecified(attrIndex, false); }