Java 类org.jdom2.output.DOMOutputter 实例源码

项目:stdlib    文件:JDOMUtils.java   
/**
 * Convert a JDOM Document to a DOM Document
 *
 * @param node
 *
 * @return
 */
public static org.w3c.dom.Document convert(org.jdom2.Document node) throws JDOMException
{
    if (node == null)
        return null; // Convert null->null

    try
    {
        DOMOutputter outputter = new DOMOutputter();

        return outputter.output(node);
    }
    catch (JDOMException e)
    {
        throw new RuntimeException("Error converting JDOM to DOM: " + e.getMessage(), e);
    }
}
项目:stdlib    文件:JDOMUtils.java   
/**
 * Convert a JDOM Element to a DOM Element
 *
 * @param node
 *
 * @return
 */

public static org.w3c.dom.Element convert(org.jdom2.Element node) throws JDOMException
{
    if (node == null)
        return null; // Convert null->null

    try
    {
        DOMOutputter outputter = new DOMOutputter();

        return outputter.output(node);
    }
    catch (JDOMException e)
    {
        throw new RuntimeException("Error converting JDOM to DOM: " + e.getMessage(), e);
    }
}
项目:mycore    文件:MCRXEditorValidatorTest.java   
private void addRule(MCREditorSession session, String baseXPath, String... attributes) throws JDOMException {
    Element rule = new Element("validation-rule");
    for (int i = 0; i < attributes.length;) {
        rule.setAttribute(attributes[i++], attributes[i++]);
    }
    new Document(rule);
    org.w3c.dom.Element ruleAsDOMElement = new DOMOutputter().output(rule);
    session.getValidator().addRule(baseXPath, ruleAsDOMElement);
}
项目:mycore    文件:MCRMODSPagesHelper.java   
public static NodeSet buildExtentPagesNodeSet(String input) throws JDOMException {
    Element extent = buildExtentPages(input);
    org.w3c.dom.Element domElement = new DOMOutputter().output(extent);
    NodeSet nodeSet = new NodeSet();
    nodeSet.addNode(domElement);
    return nodeSet;
}
项目:mycore    文件:MCRWebsiteWriteProtection.java   
public static org.w3c.dom.Document getMessage() throws JDOMException, IOException {
    Element config = getConfiguration();
    if (config == null) {
        return new DOMOutputter().output(new Document());
    } else {
        Element messageElem = config.getChild("message");
        Document message = new Document(messageElem.clone());
        return new DOMOutputter().output(message);
    }
}
项目:mycore    文件:MCRXMLFunctions.java   
public static Node document(String uri) throws JDOMException, IOException, SAXException, TransformerException {
    MCRSourceContent sourceContent = MCRSourceContent.getInstance(uri);
    if (sourceContent == null) {
        throw new TransformerException("Could not load document: " + uri);
    }
    DOMOutputter out = new DOMOutputter();
    return out.output(sourceContent.asXML());
}
项目:mycore    文件:MCRXMLFunctions.java   
/**
 * @param uri the uri to resolve
 */
public static NodeList resolve(String uri) throws JDOMException {
    org.jdom2.Element element = MCRURIResolver.instance().resolve(uri);
    element.detach();
    org.jdom2.Document document = new org.jdom2.Document(element);
    return new DOMOutputter().output(document).getDocumentElement().getChildNodes();
}
项目:FTLAV    文件:DatParser.java   
public Blueprints readBlueprints(InputStream stream, String fileName) throws IOException, JAXBException, JDOMException {

        String streamText = TextUtilities.decodeText(stream, fileName).text;
        streamText = xmlDeclPtn.matcher(streamText).replaceFirst("");
        streamText = "<blueprints>"+ streamText +"</blueprints>";
        StringBuilder sb = new StringBuilder(streamText);
        String ptn; Pattern p; Matcher m;

        if ("blueprints.xml".equals(fileName)) {
            // blueprints.xml: LONG_ELITE_MED shipBlueprint (FTL 1.03.1)
            // blueprints.xml: LONG_ELITE_HARD shipBlueprint (FTL 1.03.1)
            streamText = streamText.replaceAll(" img=\"rebel_long_hard\"", " img=\"rebel_long_elite\"");
        }

        if ("blueprints.xml".equals(fileName)) {
            // blueprints.xml: SYSTEM_CASING augBlueprint (FTL 1.02.6)
            ptn = "";
            ptn += "\\s*<title>Reinforced System Casing</title>"; // Extra title.
            ptn += "(\\s*<title>Titanium System Casing</title>)";

            p = Pattern.compile(ptn);
            m = p.matcher(sb);
            if (m.find()) {
                sb.replace(m.start(), m.end(), m.group(1));
                m.reset();
            }
        }

        Document doc = TextUtilities.parseStrictOrSloppyXML(sb.toString(), fileName);
        DOMOutputter domOutputter = new DOMOutputter();

        JAXBContext jc = JAXBContext.newInstance(Blueprints.class);
        Unmarshaller u = jc.createUnmarshaller();
        Blueprints bps = (Blueprints)u.unmarshal(domOutputter.output(doc));

        return bps;
    }
项目:FTLAV    文件:DatParser.java   
public ShipChassis readChassis(InputStream stream, String fileName) throws IOException, JAXBException, JDOMException {

        String streamText = TextUtilities.decodeText(stream, fileName).text;
        streamText = xmlDeclPtn.matcher(streamText).replaceFirst("");
        streamText = "<shipChassis>"+ streamText +"</shipChassis>";
        Document doc = TextUtilities.parseStrictOrSloppyXML(streamText, fileName);
        DOMOutputter domOutputter = new DOMOutputter();

        JAXBContext jc = JAXBContext.newInstance(ShipChassis.class);
        Unmarshaller u = jc.createUnmarshaller();
        ShipChassis sch = (ShipChassis)u.unmarshal(domOutputter.output(doc));

        return sch;
    }
项目:FTLAV    文件:DatParser.java   
public List<CrewNameList> readCrewNames(InputStream stream, String fileName) throws IOException, JAXBException, JDOMException {

        String streamText = TextUtilities.decodeText(stream, fileName).text;
        streamText = xmlDeclPtn.matcher(streamText).replaceFirst("");
        streamText = "<nameLists>"+ streamText  +"</nameLists>";
        Document doc = TextUtilities.parseStrictOrSloppyXML(streamText, fileName);
        DOMOutputter domOutputter = new DOMOutputter();

        JAXBContext jc = JAXBContext.newInstance(CrewNameLists.class);
        Unmarshaller u = jc.createUnmarshaller();
        CrewNameLists cnl = (CrewNameLists)u.unmarshal(domOutputter.output(doc));

        return cnl.getCrewNameLists();
    }
项目:FTLAV    文件:DatParser.java   
public SectorData readSectorData(InputStream stream, String fileName) throws IOException, JAXBException, JDOMException {

        String streamText = TextUtilities.decodeText(stream, fileName).text;
        streamText = xmlDeclPtn.matcher(streamText).replaceFirst("");
        streamText = "<sectorData>"+ streamText +"</sectorData>";
        Document doc = TextUtilities.parseStrictOrSloppyXML(streamText, fileName);
        DOMOutputter domOutputter = new DOMOutputter();

        JAXBContext jc = JAXBContext.newInstance(SectorData.class);
        Unmarshaller u = jc.createUnmarshaller();
        SectorData sectorData = (SectorData)u.unmarshal(domOutputter.output(doc));

        return sectorData;
    }
项目:FTLAV    文件:DatParser.java   
public Encounters readEvents(InputStream stream, String fileName) throws IOException, JAXBException, JDOMException {

        String streamText = TextUtilities.decodeText(stream, fileName).text;
        streamText = xmlDeclPtn.matcher(streamText).replaceFirst("");
        streamText = "<events>"+ streamText  +"</events>";
        Document doc = TextUtilities.parseStrictOrSloppyXML(streamText, fileName);
        DOMOutputter domOutputter = new DOMOutputter();

        JAXBContext jc = JAXBContext.newInstance(Encounters.class);
        Unmarshaller u = jc.createUnmarshaller();
        Encounters evts = (Encounters)u.unmarshal(domOutputter.output(doc));

        return evts;
    }
项目:FTLAV    文件:DatParser.java   
public List<ShipEvent> readShipEvents(InputStream stream, String fileName) throws IOException, JAXBException, JDOMException {

        String streamText = TextUtilities.decodeText(stream, fileName).text;
        streamText = xmlDeclPtn.matcher(streamText).replaceFirst("");
        streamText = "<shipEvents>"+ streamText  +"</shipEvents>";
        Document doc = TextUtilities.parseStrictOrSloppyXML(streamText, fileName);
        DOMOutputter domOutputter = new DOMOutputter();

        JAXBContext jc = JAXBContext.newInstance(ShipEvents.class);
        Unmarshaller u = jc.createUnmarshaller();
        ShipEvents shvts = (ShipEvents)u.unmarshal(domOutputter.output(doc));

        return shvts.getShipEvents();
    }
项目:yawl    文件:DigitalSignature.java   
public String PrepareDocumentToBeSign(Element element)
{

    try{
         //extract the Document to sign and transform it in a valid XML DOM 
        Element rootElement = new Element(element.getName());
        rootElement.setContent(element.cloneContent());
        //convert the Element in a JDOM Document
        Document xdoc = new Document( rootElement );
        //create a DOMOutputter to write the content of the JDOM document in a DOM document
        DOMOutputter outputter = new DOMOutputter();
        org.w3c.dom.Document Doctosign = outputter.output(xdoc);

        // Show the document before being sign 
        System.out.println("xml to Sign:");
        XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
        sortie.output(xdoc, System.out);

        //Transform the XML DOM in a String using the xml transformer
         DOMSource domSource = new DOMSource(Doctosign);
         StringWriter writer = new StringWriter();
         StreamResult result = new StreamResult(writer);
         TransformerFactory tf = TransformerFactory.newInstance();
         Transformer transformer = tf.newTransformer();
         transformer.transform(domSource, result);
         String StringTobeSign = writer.toString();

         return StringTobeSign;

    }   catch (Exception e) {
        e.printStackTrace();  
        return null;
        }

    }
项目:BPMNspector    文件:SchematronBPMNValidator.java   
public void validate(BPMNProcess process, ValidationResult validationResult)
        throws ValidationException {

    LOGGER.info("Validating {}", process.getBaseURI());

    try {
            // EXT.002 checks whether there are ID duplicates - as ID
            // duplicates in a single file are already detected during XSD
            // validation this is only relevant if other processes are imported
            if(!process.getChildren().isEmpty()) {
                ext002Checker.checkConstraint002(process, validationResult);
            }

            org.jdom2.Document documentToCheck = preProcessor.preProcess(process);
            DOMOutputter domOutputter = new DOMOutputter();
            Document w3cDoc = domOutputter
                    .output(documentToCheck);
            DOMSource domSource = new DOMSource(w3cDoc);
            for(ISchematronResource schematronFile : schemaToCheck) {
                SchematronOutputType schematronOutputType = schematronFile
                        .applySchematronValidationToSVRL(domSource);

                schematronOutputType.getActivePatternAndFiredRuleAndFailedAssert().stream()
                        .filter(obj -> obj instanceof FailedAssert)
                        .forEach(obj -> handleSchematronErrors(process, validationResult, (FailedAssert) obj));
            }
    } catch (Exception e) { // NOPMD
        LOGGER.debug("exception during schematron validation. Cause: {}", e);
        throw new ValidationException(
                "Something went wrong during schematron validation!");
    }

    LOGGER.info("Validating process successfully done, file is valid: {}",
            validationResult.isValid());
}
项目:mycore    文件:MCRIdentifierXSLUtils.java   
/**
 * Gets all available services which are configured.
 * e.g.
 *   <ul>
 *     <li>&lt;service id="service1" inscribed="false" permission="true" type="urn" /&gt;</li>
 *     <li>&lt;service id="service2" inscribed="true" permission="false"type="doi" /&gt;</li>
 *   </ul>
 *
 * @param objectID the object
 * @return a Nodelist
 * @throws JDOMException
 */
public static NodeList getPIServiceInformation(String objectID) throws JDOMException {
    Element e = new Element("list");

    MCRBase obj = MCRMetadataManager.retrieve(MCRObjectID.getInstance(objectID));
    MCRConfiguration.instance().getPropertiesMap("MCR.PI.Registration.")
        .keySet()
        .stream()
        .map(s -> s.substring("MCR.PI.Registration.".length()))
        .filter(id -> !id.contains("."))
        .map((serviceID) -> MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID))
        .map((rs -> {
            Element service = new Element("service");

            service.setAttribute("id", rs.getRegistrationServiceID());

            // Check if the inscriber of this service can read a PI
            try {
                if (rs.getMetadataManager().getIdentifier(obj, "").isPresent()) {
                    service.setAttribute("inscribed", "true");
                } else {
                    service.setAttribute("inscribed", "false");
                }
            } catch (MCRPersistentIdentifierException e1) {
                LOGGER.warn("Error happened while try to read PI from object: {}", objectID, e1);
                service.setAttribute("inscribed", "false");
            }

            // rights
            String permission = "register-" + rs.getRegistrationServiceID();
            Boolean canRegister = MCRAccessManager.checkPermission(objectID, "writedb") &&
                MCRAccessManager.checkPermission(obj.getId(), permission);

            service.setAttribute("permission", canRegister.toString().toLowerCase(Locale.ROOT));

            // add the type
            service.setAttribute("type", rs.getType());

            return service;
        }))
        .forEach(e::addContent);
    return new DOMOutputter().output(e).getElementsByTagName("service");
}
项目:mycore    文件:MCRLayoutUtilities.java   
public static org.w3c.dom.Document getPersonalNavigation() throws JDOMException, XPathExpressionException {
    Document navi = getNavi();
    DOMOutputter accessCleaner = new DOMOutputter(new AccessCleaningDOMOutputProcessor());
    org.w3c.dom.Document personalNavi = accessCleaner.output(navi);
    XPath xpath = javax.xml.xpath.XPathFactory.newInstance().newXPath();
    NodeList emptyGroups = (NodeList) xpath.evaluate("/navigation/menu/group[not(item)]", personalNavi,
        XPathConstants.NODESET);
    for (int i = 0; i < emptyGroups.getLength(); ++i) {
        org.w3c.dom.Element group = (org.w3c.dom.Element) emptyGroups.item(i);
        group.getParentNode().removeChild(group);
    }
    NodeList emptyMenu = (NodeList) xpath.evaluate("/navigation/menu[not(item or group)]", personalNavi,
        XPathConstants.NODESET);
    for (int i = 0; i < emptyMenu.getLength(); ++i) {
        org.w3c.dom.Element menu = (org.w3c.dom.Element) emptyMenu.item(i);
        menu.getParentNode().removeChild(menu);
    }
    NodeList emptyNodes = (NodeList) xpath.evaluate("//text()[normalize-space(.) = '']", personalNavi,
        XPathConstants.NODESET);
    for (int i = 0; i < emptyNodes.getLength(); ++i) {
        Node emptyTextNode = emptyNodes.item(i);
        emptyTextNode.getParentNode().removeChild(emptyTextNode);
    }
    personalNavi.normalizeDocument();
    if (LOGGER.isDebugEnabled()) {
        try {
            String encoding = "UTF-8";
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            transformer.transform(new DOMSource(personalNavi), new StreamResult(bout));
            LOGGER.debug("personal navigation: {}", bout.toString(encoding));
        } catch (IllegalArgumentException | TransformerFactoryConfigurationError | TransformerException
            | UnsupportedEncodingException e) {
            LOGGER.warn("Error while getting debug information.", e);
        }

    }
    return personalNavi;
}
项目:isis-app-quickstart    文件:ExportToWordMenu.java   
private org.w3c.dom.Document asInputW3cDocument(final List<QuickObject> items) throws JDOMException {
    final Document jdomDoc = asInputDocument(items);

    final DOMOutputter domOutputter = new DOMOutputter();
    return domOutputter.output(jdomDoc);
}
项目:isis-app-todoapp    文件:ExportToWordService.java   
private org.w3c.dom.Document asInputW3cDocument(final List<ToDoItem> items) throws JDOMException {
    final Document jdomDoc = asInputDocument(items);

    final DOMOutputter domOutputter = new DOMOutputter();
    return domOutputter.output(jdomDoc);
}
项目:marmotta    文件:WireFeedOutput.java   
/**
 * Creates a W3C DOM document for the given WireFeed.
 * <p>
 * This method does not use the feed encoding property.
 * <p>
 * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
 * <p>
 * @param feed Abstract feed to create W3C DOM document from. The type of the WireFeed must match
 *        the type given to the FeedOuptut constructor.
 * @return the W3C DOM document for the given WireFeed.
 * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
 * @throws FeedException thrown if the W3C DOM document for the feed could not be created.
 *
 */
public org.w3c.dom.Document outputW3CDom(WireFeed feed) throws IllegalArgumentException,FeedException {
    Document doc = outputJDom(feed);
    DOMOutputter outputter = new DOMOutputter();
    try {
        return outputter.output(doc);
    }
    catch (JDOMException jdomEx) {
        throw new FeedException("Could not create DOM",jdomEx);
    }
}
项目:rome    文件:WireFeedOutput.java   
/**
 * Creates a W3C DOM document for the given WireFeed.
 * <p>
 * This method does not use the feed encoding property.
 * <p>
 * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
 * <p>
 *
 * @param feed Abstract feed to create W3C DOM document from. The type of the WireFeed must
 *            match the type given to the FeedOuptut constructor.
 * @return the W3C DOM document for the given WireFeed.
 * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed
 *             don't match.
 * @throws FeedException thrown if the W3C DOM document for the feed could not be created.
 *
 */
public org.w3c.dom.Document outputW3CDom(final WireFeed feed) throws IllegalArgumentException, FeedException {
    final Document doc = outputJDom(feed);
    final DOMOutputter outputter = new DOMOutputter();
    try {
        return outputter.output(doc);
    } catch (final JDOMException jdomEx) {
        throw new FeedException("Could not create DOM", jdomEx);
    }
}