use of org.jdom2.output.Format in project jspwiki by apache.
the class IndexPlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
String include = params.get(PARAM_INCLUDE);
String exclude = params.get(PARAM_EXCLUDE);
Element masterDiv = getElement("div", "index");
Element indexDiv = getElement("div", "header");
masterDiv.addContent(indexDiv);
try {
List<String> pages = listPages(context, include, exclude);
context.getEngine().getPageSorter().sort(pages);
char initialChar = ' ';
Element currentDiv = new Element("div", xmlns_XHTML);
for (String name : pages) {
if (name.charAt(0) != initialChar) {
if (initialChar != ' ') {
indexDiv.addContent(" - ");
}
initialChar = name.charAt(0);
masterDiv.addContent(makeHeader(String.valueOf(initialChar)));
currentDiv = getElement("div", "body");
masterDiv.addContent(currentDiv);
indexDiv.addContent(getLink("#" + initialChar, String.valueOf(initialChar)));
} else {
currentDiv.addContent(", ");
}
currentDiv.addContent(getLink(context.getURL(WikiContext.VIEW, name), name));
}
} catch (ProviderException e) {
log.warn("could not load page index", e);
throw new PluginException(e.getMessage());
}
// serialize to raw format string (no changes to whitespace)
XMLOutputter out = new XMLOutputter(Format.getRawFormat());
return out.outputString(masterDiv);
}
use of org.jdom2.output.Format in project ldapchai by ldapchai.
the class ChaiResponseSet method rsToChaiXML.
static String rsToChaiXML(final ChaiResponseSet rs) throws ChaiValidationException, ChaiOperationException {
final Element rootElement = new Element(XML_NODE_ROOT);
rootElement.setAttribute(XML_ATTRIBUTE_MIN_RANDOM_REQUIRED, String.valueOf(rs.getChallengeSet().getMinRandomRequired()));
rootElement.setAttribute(XML_ATTRIBUTE_LOCALE, rs.getChallengeSet().getLocale().toString());
rootElement.setAttribute(XML_ATTRIBUTE_VERSION, VALUE_VERSION);
rootElement.setAttribute(XML_ATTRIBUTE_CHAI_VERSION, ChaiConstant.CHAI_API_VERSION);
if (rs.caseInsensitive) {
rootElement.setAttribute(XML_ATTRIBUTE_CASE_INSENSITIVE, "true");
}
if (rs.csIdentifier != null) {
rootElement.setAttribute(XML_ATTRIBUTE_CHALLENGE_SET_IDENTIFER, rs.csIdentifier);
}
if (rs.timestamp != null) {
rootElement.setAttribute(XML_ATTRIBUTE_TIMESTAMP, getDateFormat().format(rs.timestamp));
}
if (rs.crMap != null) {
for (final Challenge loopChallenge : rs.crMap.keySet()) {
final Answer answer = rs.crMap.get(loopChallenge);
final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_RESPONSE);
rootElement.addContent(responseElement);
}
}
if (rs.helpdeskCrMap != null) {
for (final Challenge loopChallenge : rs.helpdeskCrMap.keySet()) {
final Answer answer = rs.helpdeskCrMap.get(loopChallenge);
final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_HELPDESK_RESPONSE);
rootElement.addContent(responseElement);
}
}
final Document doc = new Document(rootElement);
final XMLOutputter outputter = new XMLOutputter();
final Format format = Format.getRawFormat();
format.setTextMode(Format.TextMode.PRESERVE);
format.setLineSeparator("");
outputter.setFormat(format);
return outputter.outputString(doc);
}
use of org.jdom2.output.Format in project ldapchai by ldapchai.
the class NmasResponseSet method csToNmasXML.
static String csToNmasXML(final ChallengeSet cs, final String guidValue) {
final Element rootElement = new Element(NMAS_XML_ROOTNODE);
rootElement.setAttribute(NMAS_XML_ATTR_RANDOM_COUNT, String.valueOf(cs.getMinRandomRequired()));
if (guidValue != null) {
rootElement.setAttribute("GUID", guidValue);
} else {
rootElement.setAttribute("GUID", "0");
}
for (final Challenge challenge : cs.getChallenges()) {
final Element loopElement = new Element(NMAS_XML_NODE_CHALLENGE);
if (challenge.getChallengeText() != null) {
loopElement.setText(challenge.getChallengeText());
}
if (challenge.isAdminDefined()) {
loopElement.setAttribute(NMAS_XML_ATTR_DEFINE, "Admin");
} else {
loopElement.setAttribute(NMAS_XML_ATTR_DEFINE, "User");
}
if (challenge.isRequired()) {
loopElement.setAttribute(NMAS_XML_ATTR_TYPE, "Required");
} else {
loopElement.setAttribute(NMAS_XML_ATTR_TYPE, "Random");
}
loopElement.setAttribute(NMAS_XML_ATTR_MIN_LENGTH, String.valueOf(challenge.getMinLength()));
loopElement.setAttribute(NMAS_XML_ATTR_MAX_LENGTH, String.valueOf(challenge.getMaxLength()));
rootElement.addContent(loopElement);
}
final XMLOutputter outputter = new XMLOutputter();
final Format format = Format.getRawFormat();
format.setTextMode(Format.TextMode.PRESERVE);
format.setLineSeparator("");
outputter.setFormat(format);
return outputter.outputString(rootElement);
}
use of org.jdom2.output.Format in project mycore by MyCoRe-Org.
the class MCRAccessManager method getTrueRule.
/**
* return a rule, that allows something for everybody
*
* @return a rule, that allows something for everybody
*/
public static Element getTrueRule() {
Element condition = new Element("condition");
condition.setAttribute("format", "xml");
Element booleanOp = new Element("boolean");
booleanOp.setAttribute("operator", "true");
condition.addContent(booleanOp);
return condition;
}
use of org.jdom2.output.Format in project mycore by MyCoRe-Org.
the class MCRSimpleFCTDetector method addRule.
/**
* Adds a detection rule from the file content type definition XML file. The
* detector parses the <rules> element provided with each content type
* in the file content types XML definition.
*
* @param type
* the file content type the rule is for
* @param xRules
* the rules XML element containing the rules for detecting that
* type
*/
public void addRule(MCRFileContentType type, Element xRules) {
Vector<MCRDetectionRule> rules = new Vector<>();
rulesTable.put(type, rules);
typesList.add(type);
try {
List extensions = xRules.getChildren("extension");
for (Object extension : extensions) {
Element elem = (Element) extension;
double score = elem.getAttribute("score").getDoubleValue();
String ext = elem.getTextTrim();
rules.addElement(new MCRExtensionRule(ext, score));
}
List patterns = xRules.getChildren("pattern");
for (Object pattern1 : patterns) {
Element elem = (Element) pattern1;
double score = elem.getAttribute("score").getDoubleValue();
int offset = elem.getAttribute("offset").getIntValue();
String format = elem.getAttributeValue("format");
String pattern = elem.getTextTrim();
rules.addElement(new MCRPatternRule(pattern, format, offset, score));
}
List doctypes = xRules.getChildren("doctype");
for (Object doctype1 : doctypes) {
Element elem = (Element) doctype1;
double score = elem.getAttribute("score").getDoubleValue();
String doctype = elem.getTextTrim();
rules.addElement(new MCRDoctypeRule(doctype, score));
}
List strings = xRules.getChildren("string");
for (Object string1 : strings) {
Element elem = (Element) string1;
double score = elem.getAttribute("score").getDoubleValue();
String string = elem.getTextTrim();
rules.addElement(new MCRStringRule(string, score));
}
} catch (Exception exc) {
String msg = "Error parsing detection rules for file content type " + type.getLabel();
throw new MCRConfigurationException(msg, exc);
}
}
Aggregations