Search in sources :

Example 81 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project ParadoxosModManager by ThibautSF.

the class MyXML method readFile.

// public MyXML(){}
/**
 * @param file
 * @throws IOException
 * @throws JDOMException
 * @throws Exception
 */
public void readFile(String file) throws JDOMException, IOException {
    SAXBuilder sxb = new SAXBuilder();
    File xml = new File(file);
    if (xml.exists()) {
        document = sxb.build(xml);
        root = document.getRootElement();
    } else {
        root = new Element(USER_LISTS);
        document = new Document(root);
    }
    // Init for export lists
    root_exported = new Element(EXPORTED_LIST);
    root_exported.setAttribute(GAME_ID, ModManager.STEAM_ID.toString());
    document_exported = new Document(root_exported);
    this.file = file;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File)

Example 82 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project ParadoxosModManager by ThibautSF.

the class MyXML method readSettingFile.

/**
 * @param file
 * @throws Exception
 */
public void readSettingFile(String file) throws Exception {
    SAXBuilder sxb = new SAXBuilder();
    File xml = new File(file);
    if (xml.exists()) {
        document = sxb.build(xml);
        root = document.getRootElement();
    } else {
        root = new Element(APP_SETTINGS);
        document = new Document(root);
    }
    this.file = file;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File)

Example 83 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project xwiki-platform by xwiki.

the class DefaultEntityResourceActionLister method initialize.

@Override
public void initialize() throws InitializationException {
    // Parse the Struts config file (struts-config.xml) to extract all available actions
    List<String> actionNames = new ArrayList<>();
    SAXBuilder builder = new SAXBuilder();
    // Make sure we don't require an Internet Connection to parse the Struts config file!
    builder.setEntityResolver(new EntityResolver() {

        @Override
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            return new InputSource(new StringReader(""));
        }
    });
    // Step 1: Get a stream on the Struts config file if it exists
    InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource());
    if (strutsConfigStream != null) {
        // Step 2: Parse the Strust config file, looking for action names
        Document document;
        try {
            document = builder.build(strutsConfigStream);
        } catch (JDOMException | IOException e) {
            throw new InitializationException(String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e);
        }
        Element mappingElement = document.getRootElement().getChild("action-mappings");
        for (Element element : mappingElement.getChildren("action")) {
            // We extract the action name from the path mapping. Note that we cannot use the "name" attribute since
            // it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its
            // "name" element value.
            actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/"));
        }
    }
    this.strutsActionNames = actionNames;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InitializationException(org.xwiki.component.phase.InitializationException) SAXException(org.xml.sax.SAXException) StringReader(java.io.StringReader)

Example 84 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project iaf by ibissource.

the class XmlBuilder method toXML.

public String toXML(boolean xmlHeader) {
    Document document = new Document(element.detach());
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.setFormat(Format.getPrettyFormat().setOmitDeclaration(!xmlHeader));
    return xmlOutputter.outputString(document);
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Document(org.jdom2.Document)

Example 85 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project ldapchai by ldapchai.

the class NmasResponseSet method parseNmasPolicyXML.

static List<Challenge> parseNmasPolicyXML(final String str, final Locale locale) throws IOException, JDOMException {
    final List<Challenge> returnList = new ArrayList<Challenge>();
    final Reader xmlreader = new StringReader(str);
    final SAXBuilder builder = new SAXBuilder();
    final Document doc = builder.build(xmlreader);
    final boolean required = doc.getRootElement().getName().equals("RequiredQuestions");
    for (final Iterator questionIterator = doc.getDescendants(new ElementFilter("Question")); questionIterator.hasNext(); ) {
        final Element loopQ = (Element) questionIterator.next();
        final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255);
        final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1);
        final String challengeText = readDisplayString(loopQ, locale);
        final Challenge challenge = new ChaiChallenge(required, challengeText, minLength, maxLength, true, 0, false);
        returnList.add(challenge);
    }
    for (Iterator iter = doc.getDescendants(new ElementFilter("UserDefined")); iter.hasNext(); ) {
        final Element loopQ = (Element) iter.next();
        final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255);
        final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1);
        final Challenge challenge = new ChaiChallenge(required, null, minLength, maxLength, false, 0, false);
        returnList.add(challenge);
    }
    return returnList;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) Document(org.jdom2.Document) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) ElementFilter(org.jdom2.filter.ElementFilter) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge)

Aggregations

Document (org.jdom2.Document)391 Element (org.jdom2.Element)243 Test (org.junit.Test)104 SAXBuilder (org.jdom2.input.SAXBuilder)84 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)22 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 MCRException (org.mycore.common.MCRException)21 Document (com.google.cloud.language.v1.Document)20 HashMap (java.util.HashMap)19 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 URL (java.net.URL)18