Example usage for org.w3c.dom Element getOwnerDocument

List of usage examples for org.w3c.dom Element getOwnerDocument

Introduction

In this page you can find the example usage for org.w3c.dom Element getOwnerDocument.

Prototype

public Document getOwnerDocument();

Source Link

Document

The Document object associated with this node.

Usage

From source file:com.enonic.vertical.adminweb.handlers.ContentBaseHandlerServlet.java

protected final void buildRelatedContentsXML(AdminService admin, User user, ExtendedMap formItems,
        Element contentsElem) {
    Document doc = contentsElem.getOwnerDocument();
    Element contentElem = XMLTool.getFirstElement(contentsElem);
    Element relatedcontentkeysElem = XMLTool.createElement(doc, contentElem, "relatedcontentkeys");
    Element relatedcontentsElem = XMLTool.createElement(doc, contentsElem, "relatedcontents");

    int[] relatedContentKeys = contentXMLBuilder.getRelatedContentKeys(formItems);
    if (relatedContentKeys != null && relatedContentKeys.length > 0) {
        for (int relatedContentKey : relatedContentKeys) {
            Element elem = XMLTool.createElement(doc, relatedcontentkeysElem, "relatedcontentkey");
            elem.setAttribute("key", Integer.toString(relatedContentKey));
            elem.setAttribute("level", "1");

            // add related content
            Document tempDoc = XMLTool.domparse(admin.getContent(user, relatedContentKey, 0, 0, 0));
            relatedcontentsElem.appendChild(doc.importNode(tempDoc.getDocumentElement().getFirstChild(), true));
        }/*from   w ww  .  j  av a2s  . c om*/
    }
}

From source file:com.enonic.vertical.engine.handlers.SectionHandler.java

public void appendSectionNames(int contentKey, Element contentElem) {

    StringBuffer sql = new StringBuffer();
    sql.append("SELECT ").append("sec.").append(db.tMenuItem.mei_lKey).append(", ").append("sec.")
            .append(db.tMenuItem.mei_men_lKey).append(", ").append("sec.").append(db.tMenuItem.mei_lKey)
            .append(", ").append("sec.").append(db.tMenuItem.mei_sName).append(", ").append("sec.")
            .append(db.tMenuItem.mei_lParent).append(", ").append(db.tSectionContent2.sco_bApproved)
            .append(", ").append(db.tContentHome.cho_mei_lKey).append(", ").append("secparent.")
            .append(db.tMenuItem.mei_lKey);
    sql.append(" FROM ").append(db.tMenuItem).append(" sec");
    sql.append(" JOIN ").append(db.tSectionContent2).append(" ON ").append("sec.").append(db.tMenuItem.mei_lKey)
            .append(" = ").append(db.tSectionContent2.sco_mei_lKey);
    sql.append(" LEFT JOIN ").append(db.tContentHome).append(" ON ").append(db.tContentHome.cho_con_lKey)
            .append(" = ").append(db.tSectionContent2.sco_con_lKey).append(" AND ")
            .append(db.tContentHome.cho_men_lKey).append(" = ").append(db.tMenuItem.mei_men_lKey);
    sql.append(" LEFT JOIN ").append(db.tMenuItem).append(" secparent").append(" ON ").append("secparent.")
            .append(db.tMenuItem.mei_lKey).append(" = sec.").append(db.tMenuItem.mei_lParent);
    XDG.appendWhereSQL(sql, db.tSectionContent2.sco_con_lKey, XDG.OPERATOR_EQUAL);
    sql.append("?");

    Connection con = null;/*  ww w  .  java 2s  . com*/
    PreparedStatement preparedStmt = null;
    ResultSet resultSet = null;
    Document doc = contentElem.getOwnerDocument();
    Element root = XMLTool.createElement(doc, contentElem, "sectionnames");
    try {
        con = getConnection();
        preparedStmt = con.prepareStatement(sql.toString());
        preparedStmt.setInt(1, contentKey);
        resultSet = preparedStmt.executeQuery();
        while (resultSet.next()) {
            int sectionKey = resultSet.getInt(1);
            int menuKey = resultSet.getInt(2);
            int menuItemKey = resultSet.getInt(3);
            String name = resultSet.getString(4);
            //                int parentKey = resultSet.getInt(5);
            boolean approved = resultSet.getBoolean(6);
            Integer homeMenuItemKey = resultSet.getInt(7);
            if (resultSet.wasNull()) {
                homeMenuItemKey = null;
            }
            Integer parentSectionKey = resultSet.getInt(8);
            if (resultSet.wasNull()) {
                parentSectionKey = null;
            }
            Element sectionName = XMLTool.createElement(doc, root, "sectionname", name);
            sectionName.setAttribute("key", Integer.toString(sectionKey));
            sectionName.setAttribute("menukey", Integer.toString(menuKey));
            sectionName.setAttribute("menuitemkey", Integer.toString(menuItemKey));
            boolean home = homeMenuItemKey != null && homeMenuItemKey == menuItemKey;
            if (home) {
                sectionName.setAttribute("home", "true");
            }
            if (parentSectionKey != null) {
                sectionName.setAttribute("supersectionkey", Integer.toString(parentSectionKey));
            }
            sectionName.setAttribute("approved", String.valueOf(approved));
        }
    } catch (SQLException sqle) {
        String message = "Failed to append section names to content: %t";
        VerticalEngineLogger.error(this.getClass(), 1, message, sqle);
    } finally {
        close(resultSet);
        close(preparedStmt);
        close(con);
    }
}

From source file:com.evolveum.midpoint.prism.parser.DomSerializer.java

private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement,
        QName elementOrAttributeName, boolean asAttribute) throws SchemaException {
    QName typeQName = xprim.getTypeQName();

    // if typeQName is not explicitly specified, we try to determine it from parsed value
    // TODO we should probably set typeQName when parsing the value...
    if (typeQName == null && xprim.isParsed()) {
        Object v = xprim.getValue();
        if (v != null) {
            typeQName = XsdTypeMapper.toXsdType(v.getClass());
        }//from   w  ww  .  ja  v a 2s  . c  o  m
    }

    if (typeQName == null) { // this means that either xprim is unparsed or it is empty
        if (com.evolveum.midpoint.prism.PrismContext.isAllowSchemalessSerialization()) {
            // We cannot correctly serialize without a type. But this is needed
            // sometimes. So just default to string
            String stringValue = xprim.getStringValue();
            if (stringValue != null) {
                if (asAttribute) {
                    DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(),
                            stringValue);
                    DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations());
                } else {
                    Element element;
                    try {
                        element = createElement(elementOrAttributeName, parentElement);
                        appendCommentIfPresent(element, xprim);
                    } catch (DOMException e) {
                        throw new DOMException(e.code, e.getMessage() + "; creating element "
                                + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
                    }
                    parentElement.appendChild(element);
                    DOMUtil.setElementTextContent(element, stringValue);
                    DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations());
                }
            }
            return;
        } else {
            throw new IllegalStateException("No type for primitive element " + elementOrAttributeName
                    + ", cannot serialize (schemaless serialization is disabled)");
        }
    }

    // typeName != null after this point

    if (StringUtils.isBlank(typeQName.getNamespaceURI())) {
        typeQName = XsdTypeMapper.determineQNameWithNs(typeQName);
    }

    Element element = null;

    if (typeQName.equals(ItemPath.XSD_TYPE)) {
        ItemPath itemPath = (ItemPath) xprim.getValue();
        if (itemPath != null) {
            if (asAttribute) {
                throw new UnsupportedOperationException(
                        "Serializing ItemPath as an attribute is not supported yet");
            }
            XPathHolder holder = new XPathHolder(itemPath);
            element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument());
            parentElement.appendChild(element);
        }

    } else {
        // not an ItemPathType

        if (!asAttribute) {
            try {
                element = createElement(elementOrAttributeName, parentElement);
            } catch (DOMException e) {
                throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName
                        + " in element " + DOMUtil.getQName(parentElement));
            }
            appendCommentIfPresent(element, xprim);
            parentElement.appendChild(element);
        }

        if (typeQName.equals(DOMUtil.XSD_QNAME)) {
            QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME);
            value = setQNamePrefixExplicitIfNeeded(value);
            if (asAttribute) {
                try {
                    DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value);
                } catch (DOMException e) {
                    throw new DOMException(e.code,
                            e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart()
                                    + " in element " + DOMUtil.getQName(parentElement) + " to QName value "
                                    + value);
                }
            } else {
                DOMUtil.setQNameValue(element, value);
            }
        } else {
            // not ItemType nor QName
            String value = xprim.getGuessedFormattedValue();

            if (asAttribute) {
                DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value);
            } else {
                DOMUtil.setElementTextContent(element, value);
            }
        }

    }
    if (!asAttribute && xprim.isExplicitTypeDeclaration()) {
        DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName));
    }
}

From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalWriter.java

private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement,
        QName elementOrAttributeName, boolean asAttribute) throws SchemaException {
    QName typeQName = xprim.getTypeQName();

    // if typeQName is not explicitly specified, we try to determine it from parsed value
    // TODO we should probably set typeQName when parsing the value...
    if (typeQName == null && xprim.isParsed()) {
        Object v = xprim.getValue();
        if (v != null) {
            typeQName = XsdTypeMapper.toXsdType(v.getClass());
        }//from www  . ja  va 2 s .  co  m
    }

    if (typeQName == null) { // this means that either xprim is unparsed or it is empty
        if (com.evolveum.midpoint.prism.PrismContextImpl.isAllowSchemalessSerialization()) {
            // We cannot correctly serialize without a type. But this is needed
            // sometimes. So just default to string
            String stringValue = xprim.getStringValue();
            if (stringValue != null) {
                if (asAttribute) {
                    DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(),
                            stringValue);
                    DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations());
                } else {
                    Element element;
                    try {
                        element = createElement(elementOrAttributeName, parentElement);
                        appendCommentIfPresent(element, xprim);
                    } catch (DOMException e) {
                        throw new DOMException(e.code, e.getMessage() + "; creating element "
                                + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
                    }
                    parentElement.appendChild(element);
                    DOMUtil.setElementTextContent(element, stringValue);
                    DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations());
                }
            }
            return;
        } else {
            throw new IllegalStateException("No type for primitive element " + elementOrAttributeName
                    + ", cannot serialize (schemaless serialization is disabled)");
        }
    }

    // typeName != null after this point

    if (StringUtils.isBlank(typeQName.getNamespaceURI())) {
        typeQName = XsdTypeMapper.determineQNameWithNs(typeQName);
    }

    Element element = null;

    if (ItemPathType.COMPLEX_TYPE.equals(typeQName)) {
        //ItemPathType itemPathType = //ItemPathType.asItemPathType(xprim.getValue());         // TODO fix this hack
        ItemPathType itemPathType = (ItemPathType) xprim.getValue();
        if (itemPathType != null) {
            if (asAttribute) {
                throw new UnsupportedOperationException(
                        "Serializing ItemPath as an attribute is not supported yet");
            }
            ItemPathHolder holder = new ItemPathHolder(itemPathType.getItemPath());
            element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument());
            parentElement.appendChild(element);
        }

    } else {
        // not an ItemPathType

        if (!asAttribute) {
            try {
                element = createElement(elementOrAttributeName, parentElement);
            } catch (DOMException e) {
                throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName
                        + " in element " + DOMUtil.getQName(parentElement));
            }
            appendCommentIfPresent(element, xprim);
            parentElement.appendChild(element);
        }

        if (DOMUtil.XSD_QNAME.equals(typeQName)) {
            QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME);
            value = setQNamePrefixExplicitIfNeeded(value);
            if (asAttribute) {
                try {
                    DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value);
                } catch (DOMException e) {
                    throw new DOMException(e.code,
                            e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart()
                                    + " in element " + DOMUtil.getQName(parentElement) + " to QName value "
                                    + value);
                }
            } else {
                DOMUtil.setQNameValue(element, value);
            }
        } else {
            // not ItemType nor QName
            String value = xprim.getGuessedFormattedValue();

            if (asAttribute) {
                DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value);
            } else {
                DOMUtil.setElementTextContent(element, value);
            }
        }

    }
    if (!asAttribute && xprim.isExplicitTypeDeclaration()) {
        DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName));
    }
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_//from   w  ww.j  ava2 s  .c o m
 */
public void doExport() {
    try {
        String filename = FileManager.getWriteFile(FileManager.FILTER_XML, FileManager.SUFFIX_XML);
        if (filename == null) {
            return;
        }

        Document doc = XmlUtil.makeDocument();
        Element root = doc.createElement(TAG_FLYTHROUGH);
        for (int i = 0; i < tilt.length; i++) {
            root.setAttribute(ATTR_TILT[i], "" + tilt[i]);
        }
        root.setAttribute(ATTR_ZOOM, "" + getZoom());

        List<FlythroughPoint> thePoints = this.pointsToUse;
        for (FlythroughPoint pt : thePoints) {
            Element ptNode = XmlUtil.create(TAG_POINT, root);

            if (pt.getDescription() != null) {
                XmlUtil.create(root.getOwnerDocument(), TAG_DESCRIPTION, ptNode, pt.getDescription());
            }

            EarthLocation el = pt.getEarthLocation();
            if (pt.getDateTime() != null) {
                ptNode.setAttribute(ATTR_DATE, formatDate(pt.getDateTime()));
            }
            ptNode.setAttribute(ATTR_LAT, "" + el.getLatitude().getValue(CommonUnit.degree));
            ptNode.setAttribute(ATTR_LON, "" + el.getLongitude().getValue(CommonUnit.degree));
            ptNode.setAttribute(ATTR_ALT, "" + getAlt(el));
            if (pt.hasTiltX()) {
                ptNode.setAttribute(ATTR_TILT[0], "" + pt.getTiltX());
            }
            if (pt.hasTiltY()) {
                ptNode.setAttribute(ATTR_TILT[1], "" + pt.getTiltY());
            }
            if (pt.hasTiltZ()) {
                ptNode.setAttribute(ATTR_TILT[2], "" + pt.getTiltZ());
            }
            if (pt.hasZoom()) {
                ptNode.setAttribute(ATTR_ZOOM, "" + pt.getZoom());
            }

            double[] m = pt.getMatrix();
            if (m != null) {
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < m.length; i++) {
                    if (i > 0) {
                        sb.append(",");
                    }
                    sb.append(m[i]);
                }
                ptNode.setAttribute(ATTR_MATRIX, sb.toString());
            }

        }
        String xml = XmlUtil.toString(root);
        IOUtil.writeFile(filename, xml);
    } catch (Exception exc) {
        logException("Exporting flythrough", exc);
    }

}

From source file:com.ext.portlet.epsos.EpsosHelperService.java

public final SpiritUserClientDto createPatientConfirmationPlain(SpiritUserClientDto usr, String purpose,
        SpiritEhrWsClientInterface webservice, Assertion idAs, EhrPatientClientDto patient)
        throws PortalException, SystemException {
    //User user = PortalUtil.getUser(request);
    //SpiritUserClientDto usr = (SpiritUserClientDto)request.getSession().getAttribute(EPSOS_LOGIN_INFORMATION_ATTRIBUTE);
    SpiritUserClientDto usr1 = null;/*from   ww  w. j a  v  a 2 s  . com*/
    EpsosHelperService epsos = null;

    boolean created = false;
    EpsosHelperService.getInstance().createLog("PURPOSE OF USE:" + patient.getGivenName() + " " + purpose, usr);

    Document document = null;
    Document signedDoc = null;
    try {
        // netsmart assertion
        String pat = "";
        try {
            epsos = EpsosHelperService.getInstance();
            pat = patient.getPid().get(0).getPatientID() + "^^^&"
                    + patient.getPid().get(0).getDomain().getAuthUniversalID() + "&"
                    + patient.getPid().get(0).getDomain().getAuthUniversalIDType();
            TRCAssertionRequest req1 = new TRCAssertionRequest.Builder(idAs, pat).PurposeOfUse(purpose).build();
            Assertion trc = req1.request();
            //TODO EXIT IF ERROR
            AssertionMarshaller marshaller = new AssertionMarshaller();
            Element element = marshaller.marshall(trc);
            document = element.getOwnerDocument();
            //EpsosHelperService.sendXMLtoStream(document,System.out);
            EpsosHelperService.getInstance().createLog("CREATING TRCA : " + pat, usr);
            usr1 = webservice.setTRCAssertion(document.getDocumentElement());
            created = true;
        } catch (Exception e) {
            EpsosHelperService.getInstance()
                    .createLog("ERROR CREATING ASSERTION:" + patient.getGivenName() + " " + purpose, usr);
        }

        // netsmart assertion

        //request.getSession().setAttribute(EPSOS_LOGIN_INFORMATION_ATTRIBUTE, usr);

    } catch (Exception e2) {
        e2.printStackTrace();
    }
    return usr1;
}

From source file:com.enonic.vertical.engine.handlers.MenuHandler.java

private Element getMenuData(Element rootElement, int menuId) {
    Document doc = rootElement.getOwnerDocument();
    Element menuElement = XMLTool.createElement(doc, rootElement, "menu");

    Connection con = null;//from www .jav a  2 s  .c o  m
    PreparedStatement preparedStmt = null;
    ResultSet result = null;
    try {
        con = getConnection();

        preparedStmt = con.prepareStatement(MENU_SELECT_BY_KEY);
        preparedStmt.setInt(1, menuId);
        result = preparedStmt.executeQuery();
        if (result.next()) {
            int languageKey = result.getInt("men_lan_lKey");

            menuElement.setAttribute("key", String.valueOf(menuId));
            menuElement.setAttribute("languagekey", String.valueOf(languageKey));
            menuElement.setAttribute("languagecode", result.getString("lan_sCode"));
            menuElement.setAttribute("language", result.getString("lan_sDescription"));
            menuElement.setAttribute("runas", result.getString("men_usr_hRunAs"));

            String name = result.getString("men_sName");
            if (!result.wasNull()) {
                XMLTool.createElement(doc, menuElement, "name", name);
            } else {
                XMLTool.createElement(doc, menuElement, "name");
            }

            // firstpage:
            int frontpageKey = result.getInt("men_mei_firstPage");
            if (!result.wasNull()) {
                XMLTool.createElement(doc, menuElement, "firstpage").setAttribute("key",
                        String.valueOf(frontpageKey));
            } else {
                XMLTool.createElement(doc, menuElement, "firstpage");
            }

            // loginpage:
            int loginpageKey = result.getInt("men_mei_loginPage");
            if (!result.wasNull()) {
                XMLTool.createElement(doc, menuElement, "loginpage").setAttribute("key",
                        String.valueOf(loginpageKey));
            } else {
                XMLTool.createElement(doc, menuElement, "loginpage");
            }

            // errorpage:
            int errorpageKey = result.getInt("men_mei_errorPage");
            if (!result.wasNull()) {
                XMLTool.createElement(doc, menuElement, "errorpage").setAttribute("key",
                        String.valueOf(errorpageKey));
            } else {
                XMLTool.createElement(doc, menuElement, "errorpage");
            }

            // Page template:
            int defaultPagetemplate = result.getInt("men_pat_lKey");
            if (!result.wasNull()) {
                XMLTool.createElement(doc, menuElement, "defaultpagetemplate").setAttribute("pagetemplatekey",
                        String.valueOf(defaultPagetemplate));
            }

            // XML data:
            InputStream is = result.getBinaryStream("men_xmlData");
            if (!result.wasNull()) {
                Document tmpDoc = XMLTool.domparse(is);
                menuElement.appendChild(doc.importNode(tmpDoc.getDocumentElement(), true));
            }

            // Menu details.
            Element detailsElement = XMLTool.createElement(doc, menuElement, "details");

            //Statistics URL:
            String statisticsURL = result.getString(db.tMenu.men_sStatisticsURL.getName());
            if (!result.wasNull()) {
                XMLTool.createElement(doc, detailsElement, db.tMenu.men_sStatisticsURL.getXPath())
                        .setTextContent(statisticsURL);
            } else {
                XMLTool.createElement(doc, detailsElement, db.tMenu.men_sStatisticsURL.getXPath());
            }

            /* Missing fields. New fields are only implemented in SiteXmlCreator. */
        } else {
            String message = "No menu found for menu ID: %0";
            VerticalEngineLogger.error(this.getClass(), 10, message, menuId, null);
        }
    } catch (SQLException sqle) {
        VerticalEngineLogger.error(this.getClass(), 20, "A database error occurred: %t", sqle);
    } finally {
        close(result);
        close(preparedStmt);
        close(con);
    }

    return menuElement;
}

From source file:net.sf.cb2xml.convert.MainframeToXml.java

private Element convertNode(Element element, Context context) throws JCopybookUnmarshallException {
    String text = null;//from ww w .  ja v a2  s .  c  o m
    String resultElementName = element.getAttribute("name").replaceAll("[^0-9^A-Z\\-]+", "||");
    Element resultElement = resultDocument.createElement(resultElementName);
    try {
        int length = Integer.parseInt(element.getAttribute("display-length"));
        int childElementCount = 0;
        NodeList nodeList = element.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
                Element childElement = (Element) node;
                if (!childElement.getAttribute("level").equals("88")
                        && "item".equals(childElement.getNodeName())) {
                    childElementCount++;
                    if (childElement.hasAttribute("occurs")) {
                        boolean dependOn = StringUtils.isNotEmpty(childElement.getAttribute("depending-on"));
                        BigInteger count = numerics.get(childElement.getAttribute("depending-on"));
                        int childOccurs = Integer.parseInt(childElement.getAttribute("occurs"));
                        if (dependOn && count != null) {
                            childOccurs = count.intValue();
                        }
                        for (int j = 0; j < childOccurs; j++) {
                            resultElement.appendChild(convertNode(childElement, context));
                        }
                    } else {
                        if (!"item".equals(childElement.getAttribute("name")))
                            resultElement.appendChild(convertNode(childElement, context));
                    }
                }
            }
        }
        if (childElementCount == 0 && !"true".equals(element.getAttribute("redefined"))) {
            text = mainframeBuffer.substring(context.offset, context.offset + length);
            if ("true".equals(element.getAttribute("numeric"))) {
                String textForNumeric = text.trim();
                if (textForNumeric.isEmpty()) {
                    textForNumeric = "true".equals(element.getAttribute("signed")) ? "{" : "0";
                }
                textForNumeric = removeLeftZeros(textForNumeric);
                if ("true".equals(element.getAttribute("signed"))) {
                    String originalDigit = textForNumeric.substring(textForNumeric.length() - 1,
                            textForNumeric.length());
                    String digit = SignedNumericMappingTable.decodeMap.get(originalDigit);
                    if (digit == null)
                        throw new Exception("bad signed numeric last digit: " + originalDigit);
                    textForNumeric = (digit.startsWith("-") ? "-" : "")
                            + textForNumeric.substring(0, textForNumeric.length() - 1)
                            + (digit.length() == 2 ? digit.substring(1) : digit);
                }
                if (textForNumeric.length() == 0)
                    text = "0";
                else if (StringUtils.isNotEmpty(element.getAttribute("scale"))) {
                    int scale = Integer.parseInt(element.getAttribute("scale"));
                    textForNumeric = getDecimalValue(textForNumeric, scale);
                } else
                    numerics.put(resultElementName, new BigInteger(textForNumeric));
                text = textForNumeric;
            }
            context.offset += length;
            Text textNode = resultDocument.createTextNode(text.trim());
            resultElement.appendChild(textNode);
        }
        return resultElement;
    } catch (Exception e) {
        if (e instanceof JCopybookUnmarshallException)
            throw (JCopybookUnmarshallException) e;
        throw new JCopybookUnmarshallException(
                String.format("can't parse copybook string on element '%s' and text '%s'", resultElementName,
                        text),
                e, mainframeBuffer, XmlUtils.domToString(resultElement.getOwnerDocument()).toString(),
                resultElementName, text, element.getOwnerDocument());
    }
}

From source file:com.enonic.vertical.engine.handlers.MenuHandler.java

private void prepareCopy(Element menuitemsElem, CopyContext copyContext) {

    //int newSiteKey = copyContext.getNewSiteKey();
    boolean includeContents = copyContext.isIncludeContents();

    Element[] menuitemElems = XMLTool.getElements(menuitemsElem);
    for (Element menuitemElem : menuitemElems) {

        String type = menuitemElem.getAttribute("type");
        // content is document
        if ("content".equals(type)) {

            Element pageElem = XMLTool.getElement(menuitemElem, "page");
            pageElem.removeAttribute("key");
            //pageElem.setAttribute("sitekey", Integer.toString(newSiteKey));
            String oldPageTemplateKey = pageElem.getAttribute("pagetemplatekey");
            pageElem.setAttribute("pagetemplatekey",
                    String.valueOf(copyContext.getPageTemplateKey(Integer.parseInt(oldPageTemplateKey))));

            Element contentobjectsElem = XMLTool.getElement(pageElem, "contentobjects");
            Element[] contentobjectElems = XMLTool.getElements(contentobjectsElem);
            for (Element contentobjectElem : contentobjectElems) {
                String oldContentObjectKey = contentobjectElem.getAttribute("conobjkey");
                contentobjectElem.setAttribute("conobjkey",
                        String.valueOf(copyContext.getContentObjectKey(Integer.parseInt(oldContentObjectKey))));
            }/*from   w w  w  . j  av  a 2s. co  m*/

            Element documentElem = XMLTool.getElement(menuitemElem, "document");
            if (!includeContents) {
                XMLTool.removeChildNodes(documentElem, false);
                XMLTool.createCDATASection(documentElem.getOwnerDocument(), documentElem, "Scratch document");
            }
        } else if ("page".equals(type)) {

            Element pageElem = XMLTool.getElement(menuitemElem, "page");
            pageElem.removeAttribute("key");
            //pageElem.setAttribute("sitekey", Integer.toString(newSiteKey));
            String oldPageTemplateKey = pageElem.getAttribute("pagetemplatekey");
            pageElem.setAttribute("pagetemplatekey",
                    String.valueOf(copyContext.getPageTemplateKey(Integer.parseInt(oldPageTemplateKey))));

            Element contentobjectsElem = XMLTool.getElement(pageElem, "contentobjects");
            Element[] contentobjectElems = XMLTool.getElements(contentobjectsElem);
            for (Element contentobjectElem : contentobjectElems) {
                String oldContentObjectKey = contentobjectElem.getAttribute("conobjkey");
                contentobjectElem.setAttribute("conobjkey",
                        String.valueOf(copyContext.getContentObjectKey(Integer.parseInt(oldContentObjectKey))));
            }
        }

        Element elem = XMLTool.getElement(menuitemElem, "menuitems");
        prepareCopy(elem, copyContext);
    }
}

From source file:com.enonic.vertical.engine.handlers.MenuHandler.java

protected void buildShortcutTypeXML(int menuItemKey, Element menuItemElement) {
    StringBuffer sql = XDG.generateSelectSQL(db.tMenuItem, db.tMenuItem.mei_lKey);
    Object[] columnValues = getCommonHandler().getObjects(sql.toString(), menuItemKey);
    if (columnValues.length > 0) {
        Element shortcutElem = XMLTool.createElement(menuItemElement.getOwnerDocument(), menuItemElement,
                "shortcut");
        Integer shortcut = (Integer) columnValues[19];
        final String shortcutKey = (shortcut == null) ? "" : String.valueOf(shortcut);
        shortcutElem.setAttribute("key", shortcutKey);
        final String menuItemName = (shortcut == null) ? "" : getMenuItemName(shortcut);
        shortcutElem.setAttribute("name", menuItemName);
        Integer forward = (Integer) columnValues[20];
        if (forward == 0) {
            shortcutElem.setAttribute("forward", "false");
        } else {/* w  w w.  ja va 2 s .c o  m*/
            shortcutElem.setAttribute("forward", "true");
        }

    }
}