javax.naming.OperationNotSupportedException#org.jdom2.Document源码实例Demo

下面列出了javax.naming.OperationNotSupportedException#org.jdom2.Document 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mycore   文件: MCRWCMSUtil.java
/**
 * Converts the navigation.xml to the old format.
 */
private static byte[] convertToOldFormat(byte[] xml) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(new ByteArrayInputStream(xml));
    Element rootElement = doc.getRootElement();
    rootElement.setAttribute("href", rootElement.getName());
    List<Element> children = rootElement.getChildren();
    for (Element menu : children) {
        String id = menu.getAttributeValue("id");
        menu.setName(id);
        menu.setAttribute("href", id);
        menu.removeAttribute("id");
    }
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    ByteArrayOutputStream bout = new ByteArrayOutputStream(xml.length);
    out.output(doc, bout);
    return bout.toByteArray();
}
 
源代码2 项目: mycore   文件: MCRPIXPathMetadataService.java
@Override
public void insertIdentifier(MCRPersistentIdentifier identifier, MCRBase obj, String additional)
    throws MCRPersistentIdentifierException {
    String xpath = getProperties().get("Xpath");
    Document xml = obj.createXML();
    MCRNodeBuilder nb = new MCRNodeBuilder();
    try {
        nb.buildElement(xpath, identifier.asString(), xml);
        if (obj instanceof MCRObject) {
            final Element metadata = xml.getRootElement().getChild("metadata");
            ((MCRObject) obj).getMetadata().setFromDOM(metadata);
        } else {
            throw new MCRPersistentIdentifierException(obj.getId() + " is no MCRObject!",
                new OperationNotSupportedException(getClass().getName() + " only supports "
                    + MCRObject.class.getName() + "!"));
        }

    } catch (Exception e) {
        throw new MCRException("Error while inscribing PI to " + obj.getId(), e);

    }
}
 
源代码3 项目: yawl   文件: TestParseXML.java
public void testparseXML(){

        Document doc = JDOMUtil.fileToDocument("c:/temp/resourcing2.xml") ;
        Element resElem = doc.getRootElement();

        ResourceMap rMap = new ResourceMap("null") ;
        rMap.parse(resElem);

        String s = rMap.getOfferInteraction().toXML();
        System.out.println(s) ;

        s = rMap.getAllocateInteraction().toXML();
        System.out.println(s) ;

        s = rMap.getStartInteraction().toXML();
        System.out.println(s) ;

        s = rMap.getTaskPrivileges().toXML();
        System.out.println(s) ;
    }
 
源代码4 项目: mycore   文件: MCRChangeTrackerTest.java
@Test
public void testAddElement() throws JaxenException {
    Document doc = new Document(new MCRNodeBuilder().buildElement("document[title][title[2]]", null, null));
    MCRChangeTracker tracker = new MCRChangeTracker();

    Element title = new Element("title");
    doc.getRootElement().getChildren().add(1, title);
    assertEquals(3, doc.getRootElement().getChildren().size());
    assertTrue(doc.getRootElement().getChildren().contains(title));

    tracker.track(MCRAddedElement.added(title));
    tracker.undoChanges(doc);

    assertEquals(2, doc.getRootElement().getChildren().size());
    assertFalse(doc.getRootElement().getChildren().contains(title));
}
 
源代码5 项目: mycore   文件: MCRXMLHelperTest.java
@Test
public void jsonSerialize() throws Exception {
    // simple text
    Element e = new Element("hallo").setText("Hallo Welt");
    JsonObject json = MCRXMLHelper.jsonSerialize(e);
    assertEquals("Hallo Welt", json.getAsJsonPrimitive("$text").getAsString());
    // attribute
    e = new Element("hallo").setAttribute("hallo", "welt");
    json = MCRXMLHelper.jsonSerialize(e);
    assertEquals("welt", json.getAsJsonPrimitive("_hallo").getAsString());

    // complex world class test
    URL world = MCRXMLHelperTest.class.getResource("/worldclass.xml");
    SAXBuilder builder = new SAXBuilder();
    Document worldDocument = builder.build(world.openStream());
    json = MCRXMLHelper.jsonSerialize(worldDocument.getRootElement());
    assertNotNull(json);
    assertEquals("World", json.getAsJsonPrimitive("_ID").getAsString());
    assertEquals("http://www.w3.org/2001/XMLSchema-instance", json.getAsJsonPrimitive("_xmlns:xsi").getAsString());
    JsonObject deLabel = json.getAsJsonArray("label").get(0).getAsJsonObject();
    assertEquals("de", deLabel.getAsJsonPrimitive("_xml:lang").getAsString());
    assertEquals("Staaten", deLabel.getAsJsonPrimitive("_text").getAsString());
    assertEquals(2, json.getAsJsonObject("categories").getAsJsonArray("category").size());
}
 
public static LatLonRect getSpatialExtent(Document doc) {
  Element root = doc.getRootElement();
  Element latlonBox = root.getChild("LatLonBox");
  if (latlonBox == null)
    return null;

  String westS = latlonBox.getChildText("west");
  String eastS = latlonBox.getChildText("east");
  String northS = latlonBox.getChildText("north");
  String southS = latlonBox.getChildText("south");
  if ((westS == null) || (eastS == null) || (northS == null) || (southS == null))
    return null;

  try {
    double west = Double.parseDouble(westS);
    double east = Double.parseDouble(eastS);
    double south = Double.parseDouble(southS);
    double north = Double.parseDouble(northS);
    return new LatLonRect(LatLonPoint.create(south, east), LatLonPoint.create(north, west));

  } catch (Exception e) {
    return null;
  }
}
 
源代码7 项目: mycore   文件: MCRChangeTrackerTest.java
@Test
public void testSwapElements() throws JaxenException {
    Element root = new MCRNodeBuilder().buildElement("parent[name='a'][note][foo][name[2]='b'][note[2]]", null,
        null);
    Document doc = new Document(root);

    assertEquals("a", root.getChildren().get(0).getText());
    assertEquals("b", root.getChildren().get(3).getText());

    MCRChangeTracker tracker = new MCRChangeTracker();
    tracker.track(MCRSwapElements.swap(root, 0, 3));

    assertEquals("b", root.getChildren().get(0).getText());
    assertEquals("a", root.getChildren().get(3).getText());

    tracker.undoChanges(doc);

    assertEquals("a", root.getChildren().get(0).getText());
    assertEquals("b", root.getChildren().get(3).getText());
}
 
源代码8 项目: pcgen   文件: NameGenPanel.java
private void loadFromDocument(Document nameSet) throws DataConversionException
{
	Element generator = nameSet.getRootElement();
	java.util.List<?> rulesets = generator.getChildren("RULESET");
	java.util.List<?> lists = generator.getChildren("LIST");
	ListIterator<?> listIterator = lists.listIterator();

	while (listIterator.hasNext())
	{
		Element list = (Element) listIterator.next();
		loadList(list);
	}

	for (final Object ruleset : rulesets)
	{
		Element ruleSet = (Element) ruleset;
		RuleSet rs = loadRuleSet(ruleSet);
		allVars.addDataElement(rs);
	}
}
 
源代码9 项目: mycore   文件: MCRSwapInsertTargetTest.java
@Test
public void testCloneInsertParam() throws JaxenException, JDOMException {
    String x = "mods:mods[mods:name[@type='personal']='p1'][mods:name[@type='personal'][2]='p2'][mods:name[@type='corporate']='c1']";
    Element template = new MCRNodeBuilder().buildElement(x, null, null);
    Document doc = new Document(template);
    MCRBinding root = new MCRBinding(doc);

    MCRRepeatBinding repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 2, 10, "clone");
    repeat.bindRepeatPosition();
    String insertParam = MCRInsertTarget.getInsertParameter(repeat);
    assertEquals("/mods:mods|1|clone|mods:name[(@type = \"personal\")]", insertParam);
    repeat.detach();

    new MCRInsertTarget().handle(insertParam, root);
    repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 1, 10, "build");
    assertEquals(3, repeat.getBoundNodes().size());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(1))).getText());
    assertEquals("name", ((Element) (repeat.getBoundNodes().get(1))).getName());
    assertEquals("personal", ((Element) (repeat.getBoundNodes().get(1))).getAttributeValue("type"));
    assertEquals("p2", ((Element) (repeat.getBoundNodes().get(2))).getText());
}
 
源代码10 项目: gocd   文件: CommandSnippetXmlParser.java
public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) {
    try {
        Document document = buildXmlDocument(xmlContent, CommandSnippet.class.getResource("command-snippet.xsd"));
        CommandSnippetComment comment = getComment(document);

        Element execTag = document.getRootElement();
        String commandName = execTag.getAttributeValue("command");
        List<String> arguments = new ArrayList<>();
        for (Object child : execTag.getChildren()) {
            Element element = (Element) child;
            arguments.add(element.getValue());
        }
        return new CommandSnippet(commandName, arguments, comment, fileName, relativeFilePath);
    } catch (Exception e) {
        String errorMessage = String.format("Reason: %s", e.getMessage());
        LOGGER.info("Could not load command '{}'. {}", fileName, errorMessage);
        return CommandSnippet.invalid(fileName, errorMessage, new EmptySnippetComment());
    }
}
 
源代码11 项目: yawl   文件: TestWSIFInvoker.java
public void testGetQuote() {
        HashMap map = null;
        try {
            Document doc = _builder.build(new StringReader("<data><input>NAB.AX</input></data>"));
            map = WSIFInvoker.invokeMethod(
                    "http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl",
                    "", "getQuote",
                    doc.getRootElement(),
                    _authconfig);
        } catch (Exception e) {
            e.printStackTrace();
        }
//        System.out.println("map = " + map);
        assertTrue(map.size() == 1);
        assertTrue(map.toString(), map.containsKey("Result"));
    }
 
源代码12 项目: yawl   文件: DataMapper.java
/**
 * Get all RUPs from the database that start after "from" and end before
 * "to". Allow for specifying a set of Yawl case Ids that are to be excluded
 * from the result. Also, it is possible to select only RUPs that are active.
 * 
 * @author jku, tbe
 * @param from
 * @param to
 * @param yCaseIdsToExclude
 * @param activeOnly
 * @return List<Case> all cases with RUPs that meet the selection criteria
 */
public List<Case> getRupsByInterval(Date from, Date to,
                                  List<String> yCaseIdsToExclude, boolean activeOnly) {

       if (yCaseIdsToExclude == null) yCaseIdsToExclude = new ArrayList<String>();
       List<Case> caseList = new ArrayList<Case>();
       for (Case c : getAllRups()) {
           if ((activeOnly && (! c.isActive())) || yCaseIdsToExclude.contains(c.getCaseId())) {
               continue;
           }
           Document rup = c.getRUP();
           long fromTime = getTime(rup, "//Activity/From");
           long toTime = getTime(rup, "//Activity/To");
           if ((fromTime > -1) && (toTime > -1) && (fromTime >= from.getTime()) && 
                   (toTime <= to.getTime())) {
               caseList.add(c);
           }
       }
       return caseList;
}
 
源代码13 项目: PoseidonX   文件: XMLUtil.java
public static List readNodeStore(InputStream in) {
    List<Element> returnElement=new LinkedList<Element>();
    try {
        boolean validate = false;
        SAXBuilder builder = new SAXBuilder(validate);
        Document doc = builder.build(in);
        Element root = doc.getRootElement();
        // 获取根节点 <university>
        for(Element  element: root.getChildren()){
            List<Element> childElement= element.getChildren();
            for(Element tmpele:childElement){
                returnElement.add(tmpele);
            }

        }
        return returnElement;
        //readNode(root, "");
    } catch (Exception e) {
        LOGGER.error(e.getMessage(),e);
    }
    return returnElement;
}
 
源代码14 项目: ProjectAres   文件: PlayableRegionModule.java
public static PlayableRegionModule parse(MapModuleContext context, Logger log, Document doc) throws InvalidXMLException {
    Element playableRegionElement = doc.getRootElement().getChild("playable");
    if(playableRegionElement != null) {
        return new PlayableRegionModule(context.needModule(RegionParser.class).property(playableRegionElement).legacy().union());
    }
    return null;
}
 
源代码15 项目: mycore   文件: MCRXSLTransformationTest.java
@Test
public void transform() {
    Element root = new Element("root");
    Document in = new Document(root);
    root.addContent(new Element("child").setAttribute("hasChildren", "no"));
    Document out = MCRXSLTransformation.transform(in, stylesheet.getAbsolutePath());
    assertTrue("Input not the same as Output", MCRXMLHelper.deepEqual(in, out));
}
 
源代码16 项目: mycore   文件: MCRDefaultAltoChangeApplier.java
private Document readALTO(MCRPath altoFilePath) {
    try (InputStream inputStream = Files.newInputStream(altoFilePath, StandardOpenOption.READ)) {
        return new SAXBuilder().build(inputStream);
    } catch (JDOMException | IOException e) {
        throw new MCRException(e);
    }
}
 
源代码17 项目: netcdf-java   文件: CatalogBuilder.java
private Element readMetadataFromUrl(java.net.URI uri) throws java.io.IOException {
  SAXBuilder saxBuilder = new SAXBuilder();
  Document doc;
  try {
    doc = saxBuilder.build(uri.toURL());
  } catch (Exception e) {
    throw new IOException(e.getMessage());
  }
  return doc.getRootElement();
}
 
源代码18 项目: yawl   文件: ComplexityMetric.java
public double getWeightedUDTCount(Document doc) {
    double weight = Config.getUDTComplexityWeight();
    if (doc == null || weight <= 0) return 0;
    Element root = doc.getRootElement();
    Element spec = root.getChild("specification", YAWL_NAMESPACE);
    Element dataSchema = spec.getChild("schema", XSD_NAMESPACE);
    return dataSchema.getChildren().size() * weight;
}
 
源代码19 项目: mycore   文件: MCRDerivate.java
/**
 * This methode create a XML stream for all object data.
 * 
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Document with the XML data of the object as byte array
 */
@Override
public Document createXML() throws MCRException {
    Document doc = super.createXML();
    Element elm = doc.getRootElement();
    elm.setAttribute("order", String.valueOf(order));
    elm.addContent(mcrDerivate.createXML());
    elm.addContent(mcrService.createXML());
    return doc;
}
 
源代码20 项目: ldapchai   文件: NmasResponseSet.java
static ChallengeSet parseNmasUserResponseXML( final String str )
        throws IOException, JDOMException, ChaiValidationException
{
    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 Element rootElement = doc.getRootElement();
    final int minRandom = StringHelper.convertStrToInt( rootElement.getAttributeValue( "RandomQuestions" ), 0 );

    final String guidValue;
    {
        final Attribute guidAttribute = rootElement.getAttribute( "GUID" );
        guidValue = guidAttribute == null ? null : guidAttribute.getValue();
    }

    for ( Iterator iter = doc.getDescendants( new ElementFilter( "Challenge" ) ); 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" ), 2 );
        final String defineStrValue = loopQ.getAttributeValue( "Define" );
        final boolean adminDefined = "Admin".equalsIgnoreCase( defineStrValue );
        final String typeStrValue = loopQ.getAttributeValue( "Type" );
        final boolean required = "Required".equalsIgnoreCase( typeStrValue );
        final String challengeText = loopQ.getText();

        final Challenge challenge = new ChaiChallenge( required, challengeText, minLength, maxLength, adminDefined, 0, false );
        returnList.add( challenge );
    }

    return new ChaiChallengeSet( returnList, minRandom, null, guidValue );
}
 
源代码21 项目: ProjectAres   文件: TimeLimitModule.java
@Override
public TimeLimitModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
    TimeLimitDefinition timeLimit = parseTimeLimit(doc.getRootElement());
    timeLimit = parseLegacyTimeLimit(context, doc.getRootElement(), "score", timeLimit);
    timeLimit = parseLegacyTimeLimit(context, doc.getRootElement(), "blitz", timeLimit);

    // TimeLimitModule always loads
    return new TimeLimitModule(timeLimit);
}
 
源代码22 项目: yawl   文件: ComplexityMetric.java
public double getWeightedResourceCount(Document doc) {
    double weight = Config.getResourcingComplexityWeight();
    if (doc == null || weight <= 0) return 0;
    List<Element> elementList = JDOMUtil.selectElementList(
            doc, "//yawl:role", YAWL_NAMESPACE);
    return elementList.size() + weight;
}
 
源代码23 项目: iaf   文件: XmlBuilder.java
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);
}
 
源代码24 项目: emissary   文件: JDOMUtil.java
/**
 * creates a JDOM document from the InputSource
 *
 * @param is an XML document in an InputSource
 * @param filter an XMLFilter to receive callbacks during processing
 * @param validate if true, XML should be validated
 * @return the JDOM representation of that XML document
 */
public static Document createDocument(final InputSource is, final XMLFilter filter, final boolean validate) throws JDOMException {
    final SAXBuilder builder = createSAXBuilder(validate);
    if (filter != null) {
        builder.setXMLFilter(filter);
    }

    try {
        return builder.build(is);
    } catch (IOException iox) {
        throw new JDOMException("Could not parse document: " + iox.getMessage(), iox);
    }
}
 
源代码25 项目: netcdf-java   文件: PointConfigXML.java
/**
 * Create an XML document from this info
 *
 * @return netcdfDatasetInfo XML document
 */
public Document makeDocument() {
  Element rootElem = new Element("pointConfig");
  Document doc = new Document(rootElem);
  if (tableConfigurerClass != null)
    rootElem.addContent(new Element("tableConfigurer").setAttribute("class", tableConfigurerClass));
  if (tc.featureType != null)
    rootElem.setAttribute("featureType", tc.featureType.toString());

  rootElem.addContent(writeTable(tc));

  return doc;
}
 
源代码26 项目: jframe   文件: XMLUtil.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Map doXMLParse(String strxml) throws JDOMException,
        IOException {
    strxml = strxml.replaceFirst("encoding=\".*\"", "encoding=\"UTF-8\"");

    if (null == strxml || "".equals(strxml)) {
        return null;
    }

    Map m = new HashMap();

    InputStream in = new ByteArrayInputStream(strxml.getBytes("UTF-8"));
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(in);
    Element root = doc.getRootElement();
    List list = root.getChildren();
    Iterator it = list.iterator();
    while (it.hasNext()) {
        Element e = (Element) it.next();
        String k = e.getName();
        String v = "";
        List children = e.getChildren();
        if (children.isEmpty()) {
            v = e.getTextNormalize();
        } else {
            v = XMLUtil.getChildrenText(children);
        }

        m.put(k, v);
    }

    in.close();

    return m;
}
 
源代码27 项目: tds   文件: DescribeCoverage.java
Document generateDescribeCoverageDoc() {
  // CoverageDescription (wcs) [1]
  Element coverageDescriptionsElem = new Element("CoverageDescription", wcsNS);
  coverageDescriptionsElem.addNamespaceDeclaration(gmlNS);
  coverageDescriptionsElem.addNamespaceDeclaration(xlinkNS);
  coverageDescriptionsElem.setAttribute("version", this.getVersion());
  // ToDo Consider dealing with "updateSequence"
  // coverageDescriptionsElem.setAttribute( "updateSequence", this.getCurrentUpdateSequence() );

  for (String curCoverageId : this.coverages)
    coverageDescriptionsElem.addContent(genCoverageOfferingElem(curCoverageId));

  return new Document(coverageDescriptionsElem);
}
 
源代码28 项目: mycore   文件: MCRAccessCommands.java
private static Element getRuleFromFile(String fileName) throws Exception {
    if (!checkFilename(fileName)) {
        LOGGER.warn("Wrong file format or file doesn't exist");
        return null;
    }
    Document ruleDom = MCRXMLParserFactory.getParser().parseXML(new MCRFileContent(fileName));
    Element rule = ruleDom.getRootElement();
    if (!rule.getName().equals("condition")) {
        LOGGER.warn("ROOT element is not valid, a valid rule would be for example:");
        LOGGER.warn("<condition format=\"xml\"><boolean operator=\"true\" /></condition>");
        return null;
    }
    return rule;
}
 
public static String getAltUnits(Document doc) {
  Element root = doc.getRootElement();
  String altUnits = root.getChildText("AltitudeUnits");
  if (altUnits == null || altUnits.isEmpty())
    return null;
  return altUnits;
}
 
源代码30 项目: yawl   文件: YNetRunner.java
private synchronized void processCompletedSubnet(YPersistenceManager pmgr,
                                                 YIdentifier caseIDForSubnet,
                                                 YCompositeTask busyCompositeTask,
                                                 Document rawSubnetData)
        throws YDataStateException, YStateException, YQueryException,
        YPersistenceException {

    _logger.debug("--> processCompletedSubnet");

    if (caseIDForSubnet == null) throw new RuntimeException();

    if (busyCompositeTask.t_complete(pmgr, caseIDForSubnet, rawSubnetData)) {
        _busyTasks.remove(busyCompositeTask);
        if (pmgr != null) pmgr.updateObject(this);
        logCompletingTask(caseIDForSubnet, busyCompositeTask);

        //check to see if completing this task resulted in completing the net.
        if (endOfNetReached()) {
            if (_containingCompositeTask != null) {
                YNetRunner parentRunner = _engine.getNetRunner(_caseIDForNet.getParent());
                if ((parentRunner != null) && _containingCompositeTask.t_isBusy()) {
                    parentRunner.setEngine(_engine);           // added to avoid NPE
                    Document dataDoc = _net.usesSimpleRootData() ?
                                _net.getInternalDataDocument() :
                                _net.getOutputData() ;
                    parentRunner.processCompletedSubnet(pmgr, _caseIDForNet,
                                _containingCompositeTask, dataDoc);
                }
            }
        }
        kick(pmgr);
    }
    _logger.debug("<-- processCompletedSubnet");
}